0
Commit Graph

59 Commits

Author SHA1 Message Date
kylechar
650caf0ede base: Cleanup callback types (part 6).
Remove some usage of deprecated callback types in base/*. Where possible
convert to the corresponding once type, otherwise replace with the
repeating type.

Bug: 714018
Change-Id: I769373b6bb9c4ae3331faf71e8a666bff6f0611f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1690929
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Commit-Queue: kylechar <kylechar@chromium.org>
Cr-Commit-Position: refs/heads/master@{#678111}
2019-07-17 03:25:41 +00:00
Xiaohan Wang
4f568e77d8 base: Introduce NullCallback
This helper makes it easier to pass in null callbacks by avoiding the
long callback names.

Also, base::NullCallback() would be more explicit that the callback is
null than FooCallback().

This CL only converts *Decoder::WaitingForDecryptionKeyCB() to use
base::NullCallback() as an example. More callbacks will be converted
later.

Bug: 842277
Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;luci.chromium.try:linux_optional_gpu_tests_rel;luci.chromium.try:mac_optional_gpu_tests_rel;luci.chromium.try:win_optional_gpu_tests_rel
Change-Id: I03bdf9d3ff6be30161b9e24118827377f5350d40
Reviewed-on: https://chromium-review.googlesource.com/1055854
Reviewed-by: Taiju Tsuiki <tzik@chromium.org>
Commit-Queue: Xiaohan Wang <xhwang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#558494}
2018-05-14 22:36:04 +00:00
Peter Kasting
341e1fbe2d Allow base::DoNothing() to handle any argument list.
This changes the form of DoNothing() from a simple no-arg function to a class
that produces callbacks via templated operator().  This allows callers to
replace base::Bind(&base::DoNothing) with base::DoNothing() for a small
boilerplate reduction; more importantly, it allows using DoNothing() to replace
existing no-op functions/lambdas that took more than zero args, and thus had to
be manually declared.  This removes dozens of such functions and around 600 LOC
total.

In a few places, DoNothing() can't be used directly, and this change also adds
explicit callback-generating Once<>() and Repeatedly<>() members that will
produce a callback with a specific signature.

BUG=811554
TEST=none

Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel;master.tryserver.chromium.android:android_optional_gpu_tests_rel;master.tryserver.chromium.linux:linux_mojo;master.tryserver.chromium.linux:linux_optional_gpu_tests_rel;master.tryserver.chromium.linux:linux_vr;master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs;master.tryserver.chromium.mac:mac_optional_gpu_tests_rel;master.tryserver.chromium.win:win_optional_gpu_tests_rel
Change-Id: I37f87b35c6c079a6a8c03ff18ec3a54e1237f126
Reviewed-on: https://chromium-review.googlesource.com/903416
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Reviewed-by: Jochen Eisinger <jochen@chromium.org>
Reviewed-by: Gabriel Charette <gab@chromium.org>
Cr-Commit-Position: refs/heads/master@{#538953}
2018-02-24 00:03:01 +00:00
Peter Kasting
a85265e3f9 Reorganize functions in base/bind*.h.
The ownership wrappers (Owned, Passed, etc.) move from bind_helpers.h to bind.h.
Most other content of bind_helpers.h was really only necessary to implement the
code in bind_internals.h, and moves there.

BUG=717138
TEST=none
TBR=jri

Change-Id: Ib6d468e58930529dbee587d331b177b93da2f13a
Reviewed-on: https://chromium-review.googlesource.com/915282
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Reviewed-by: Peter Kasting <pkasting@chromium.org>
Reviewed-by: Jana Iyengar <jri@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Taiju Tsuiki <tzik@chromium.org>
Cr-Commit-Position: refs/heads/master@{#536968}
2018-02-15 08:30:23 +00:00
tzik
d4bb5b7d53 Expand base::internal::{Copy,Repeat}Mode into base::Callback
This CL removes base::internal::CopyMode and base::internal::RepeatMode,
and splits base::Callback into base::OnceCallback and base::RepeatingCallback.

These enums are introduced to reduces duplicated implementations of
variants of base::Callback, and for cleaner conversion policy between them.
However, there are only two variants for now, and no plan to increase it to
more than three.
As these parameters makes crash logs and stack traces less readable, it's
nice to have individual classes to these Callback variants.

Bug: 
Change-Id: I1f34a882204b92f5018720645b4d04dee194615e
Reviewed-on: https://chromium-review.googlesource.com/636726
Commit-Queue: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#497826}
2017-08-28 19:08:52 +00:00
Jeremy Roman
35a31743fd Use more concise alias versions of standard type traits in base::Bind.
This gets rid of a noticeable amount of "typename std::some_trait<...>::type"
boilerplate. In a few places, the std::integral_constant conversion operator
is used to replace ::value in cases where it makes things look more concise.

Change-Id: Ib733e9e24650452dc7d6c276e51fec2713e5c30d
Reviewed-on: https://chromium-review.googlesource.com/617300
Commit-Queue: Jeremy Roman <jbroman@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#494974}
2017-08-16 22:20:53 +00:00
scheib
517357f860 Update scoped_ptr references to be unique_ptr in src/base comments.
BUG=554298

Review-Url: https://codereview.chromium.org/2625903003
Cr-Commit-Position: refs/heads/master@{#442862}
2017-01-11 10:40:49 +00:00
tzik
6c92eabcfe Support external task cancellation mechanisms in base::Callback::IsCancelled
This CL cleans up the implementation of base::Callback::IsCancelled(),
and exposes an injection point as BindCancellationChecker, so that
external code can implement the cancellation handling.
Plus, this CL adds a specialization of BindCancellationChecker for
blink::TaskRunner::Runner, so that the blink task scheduler can handle a
cancellation of a task posted via WebTaskRunner::postCancellableTask() properly.

Review-Url: https://codereview.chromium.org/2487493004
Cr-Commit-Position: refs/heads/master@{#434511}
2016-11-25 15:58:56 +00:00
tzik
001315c4ac Readd base::UnwrapTraits to support rvalue-reference wrappers
base::Bind implementation uses the function overload resolution with ADL
to dispatch bound parameters to Unwrap function. However, this works only
when the bound parameter is passed as a const reference. And other form
of bound parameters, such as rvalue-reference, are fallback to default
Unwrap and fails to compile.

This CL introduces UnwrapTraits<> as a traits struct, and converts Unwap()
function to UnwrapTraits<>::Unwrap(), so that the unwrapping function is
looked up by the normalized type name.

BUG=554299

Review-Url: https://codereview.chromium.org/2250373002
Cr-Commit-Position: refs/heads/master@{#415008}
2016-08-29 14:46:30 +00:00
tzik
e7ed5bad1c Make OwnedWrapper and PassedWrapper move-only
base::internal::OwnedWrapper and base::internal::PassedWrapper have
std::auto_ptr style destructive copy semantics, which is no longer needed.
This CL makes them move-only for saner semantics.

BUG=554299

Review-Url: https://codereview.chromium.org/2118173002
Cr-Commit-Position: refs/heads/master@{#403857}
2016-07-06 06:41:06 +00:00
tzik
99de02ba95 Remove Runnable concept from base/bind_internal.h
`Runnable` concept was useful when bind_internal.h was a huge generated
file. However, it's an unneeded layer these days.
This CL removes `Runnable` from bind_internal.h to simplify its impl.
After this CL, BindState holds the bound Functor directly in its internal
storage.

This CL contains:
 * Merge bind_internal_win.h into bind_internal.h
 * Move typechecks in Bind() into MakeBindStateType.
 * Remove no longer used HasIsMethodTag in bind_helper.h.
 * Remove InvokeHelper specialization for IgnoreResult.
 * Merge assertion-only InvokeHelper specialization into another
   specialization.
 * Factor out the type setup in BindState into MakeBindStateType.

BUG=554299

Review-Url: https://codereview.chromium.org/2106773002
Cr-Commit-Position: refs/heads/master@{#403413}
2016-07-01 05:56:32 +00:00
tzik
11d33ea93b Remove unused UnsafeBindtoRefCountedArg in bind_helpers.h
BUG=554299

Review-Url: https://codereview.chromium.org/2106123002
Cr-Commit-Position: refs/heads/master@{#403113}
2016-06-30 07:53:49 +00:00
tzik
14f813fa11 Remove overloads for Callback in bind_helpers.h
The removed overload and specializations are no longer needed, and
they prevent binding move-only functor into a callback.

BUG=554299

Review-Url: https://codereview.chromium.org/2103113002
Cr-Commit-Position: refs/heads/master@{#402752}
2016-06-29 08:20:12 +00:00
tzik
f2f8ec1f72 Remove an unused Unwrap overload and HasNonConstReferenceItem
BUG=554299

Review-Url: https://codereview.chromium.org/2103883002
Cr-Commit-Position: refs/heads/master@{#402716}
2016-06-29 04:32:35 +00:00
tzik
caf1d84bb8 Decouple Invoker from BindState
Move most of type-level logic out of BindState, and decouple Invoker
from BindState. So that we can use BindState with another Invoker impl.
- UnboundRunType calculation is moved to a separate helper template as
  MakeUnboundRuntype.
- Indices generation to extract tuple is moved from BindState to
  Invoker.
- WeakPtr handling is moved from BindState to Invoker.

This is a preparation CL as well to implement a OneShot variant of
Callback. That will share the same Callback and BindState impl with
different Invoker::Run impl and different Callback tag as Copyable
Callback and MoveOnly Callback have.

BUG=554299

Review-Url: https://codereview.chromium.org/2034633002
Cr-Commit-Position: refs/heads/master@{#402446}
2016-06-28 12:25:18 +00:00
tzik
9921447d76 Pass bound values in base::Bind as const values
This CL replace a static_assert() in base::Bind with "const" qualifier
check to make base::Bind simpler.

base::Bind has static_assert()s to prevent the target function from
modifying the bound variable directly. But, it uses complex templates
and is hard to read. The same check can be done by passing the values
as const ones.

BUG=554299

Review-Url: https://codereview.chromium.org/2039093002
Cr-Commit-Position: refs/heads/master@{#402059}
2016-06-25 10:01:13 +00:00
tzik
1ae80b2655 Introduce base::IsWeakReceiver for base::Bind to support external weak pointers
base::IsWeakReceiver is an injection point for external libraries to
configure a receiver to behave as a weak pointer. Namely, WTF::WeakPtr,
WTF::WeakPersistent and WTF::CrossThreadWeakPersistent in Blink will be
specialize base::IsWeakReceiver, and the callback will be cancelled on
null instances of them.

Review-Url: https://codereview.chromium.org/2048023004
Cr-Commit-Position: refs/heads/master@{#399689}
2016-06-14 13:21:04 +00:00
dcheng
093de9b30c Convert //base to use std::unique_ptr
With bonus IWYU fixes that weren't caught by local android gn, cros gn,
linux gn, mac gyp, and win gyp builds.

BUG=554298
TBR=brettw@chromium.org

Review URL: https://codereview.chromium.org/1852433005

Cr-Commit-Position: refs/heads/master@{#385011}
2016-04-04 21:27:51 +00:00
vmpstr
56b7390956 base: Remove scoped_refptr unwrapping for Bind arguments.
This patch removes scoped_refptr unwrapping for general Bind parameters.
Note that the only parameter that is still unwrapped is the first
one if it's an object on which the method is called.

Please see the bug for more context.

R=tzik@chromium.org, thakis@chromium.org, danakj@chromium.org
BUG=589048

Review URL: https://codereview.chromium.org/1816713002

Cr-Commit-Position: refs/heads/master@{#382730}
2016-03-22 23:35:53 +00:00
vmpstr
1d492be050 base: Add RetainedRef for unwrapping scoped_refptrs.
This patch adds a RetainedRef call in order to be used in Bind with
scoped_refptrs that are to be unwrapped before calling the function.

This is an effort to eliminate implicit scoped_refptr construction from
Bind. Currently, scoped_refptr are always unwrapped into their
underlying T*. This means that if the function does actually expect
a scoped_refptr, one will be constructed implicitly.

The plan is to stop unwrapping scoped_refptrs altogether. If the behavior
is still desired, then the object has to be wrapped in a RetainedRef
wrapper. For more details, please see crbug.com/589048

R=tzik@chromium.org, danakj@chromium.org, thakis@chromium.org
BUG=589048

Review URL: https://codereview.chromium.org/1815493002

Cr-Commit-Position: refs/heads/master@{#382076}
2016-03-18 20:48:37 +00:00
tzik
403cb6c9b1 Replace template_util.h stuff with C++11 <type_traits>
BUG=554293

Review URL: https://codereview.chromium.org/1774443002

Cr-Commit-Position: refs/heads/master@{#380369}
2016-03-10 07:19:09 +00:00
tzik
a43eff01d5 Support move-only type on base::Callback::Run
Change base::Callback<R(Args...)>::Run argument signature from
CallbackParamTraits<Args>::ForwardType to bare Arg, and forward the
arguments in the rest of the callchain to the bound function.

This implies making an extra copy when a pass-by-value argument of
Callback::Run() is a copyable-but-not-efficiently-movable types.
That is due to broken Perfect Forwarding from the callchain from
Callback::Run() to the bound function. However, Perfect Forwarding
idiom is not fully applicable to the callchain, since we have to
determine the type of a function pointer in the Callback ctor,
before Callback::Run() is called.

Also, this CL converts a copy construction to a move construction
when a pass-by-value argument of Callback::Run() is a general movable
type. E.g. std::string, std::map and others movable class without
DISALLOW_COPY_AND_ASSIGN_WITH_MOVE_FOR_BIND.

BUG=554299

Review URL: https://codereview.chromium.org/1709483002

Cr-Commit-Position: refs/heads/master@{#380080}
2016-03-09 05:47:16 +00:00
tzik
c5849de5f8 Unify BindState refcount management into the bound arguments.
* Introduce MakeArgsStorage to adjust bound args type for the internal
  storage.
* Remove MaybeScopedRefPtr.
* Move std::decay from base::Bind to BindState.

BUG=554299

Review URL: https://codereview.chromium.org/1699123002

Cr-Commit-Position: refs/heads/master@{#375718}
2016-02-17 00:16:22 +00:00
tzik
463eb426b5 Remove UnwrapTraits
Remove UnwrapTraits::ForwardType, which is no longer used, and extract
UnwrapTraits::Unwrap to be non member function.

BUG=554299

Review URL: https://codereview.chromium.org/1698223002

Cr-Commit-Position: refs/heads/master@{#375576}
2016-02-16 15:05:12 +00:00
avi
9b6f42934e Switch to standard integer types in base/.
BUG=138542
TBR=mark@chromium.org
NOPRESUBMIT=true

Review URL: https://codereview.chromium.org/1538743002

Cr-Commit-Position: refs/heads/master@{#366910}
2015-12-26 22:16:15 +00:00
tzik
3bc7779ba0 Replace typedef with using for Callback/Bind related files
This CL contains:
 * Replace typedef with using.
 * Remove |void| from no-parameter function declarations.
 * Fix an error in a comment.

BUG=

Review URL: https://codereview.chromium.org/1537553002

Cr-Commit-Position: refs/heads/master@{#366278}
2015-12-19 09:20:02 +00:00
tzik
7fe3a687ae Remove unbound base::Bind overload
This CL removes a base::Bind overload without bound arguments.
The difference to generic base::Bind is the type check for the bound
Runnable: the generic one ensures any argument of the Runnable
is not non-const reference, OTHT, the overload being removed checks
nothing.

Where, comments and tests asserts any *bound* argument should not be
non-const reference, so the generic one has been checked excessively.
This CL loosen the type check to match the requirement, and then
the overloaded base::Bind is no longer needed.

BUG=

Review URL: https://codereview.chromium.org/1512833002

Cr-Commit-Position: refs/heads/master@{#365988}
2015-12-18 02:25:05 +00:00
danakj
314d1f4414 base: Stop using Pass() on move-only types in Bind and Callback.
This replaces calls to .Pass() with calls to std::move() instead, which
will help allow us to remove the .Pass() method off of our move-only
types.

It does not dis/allow any new behaviour with Bind and Callback.
Specifically:

1. PassedWrapper is created from base::Passed. Previously PassedWrapper
called .Pass() which required a whitelisted type to compile. Now we get
a much nicer error by using enable_if on base::Passed to check that the
type is whitelisted:

../../base/callback_unittest.cc:221:66: error: no matching function for call to 'Passed'
 Callback<void(void)> callback = base::Bind(&TakeUniqueByValue, base::Passed(&i));
                                                                ^~~~~~~~~~~~

This prevents use such as base::Passed(&a_std_unique_ptr).

2. The CallbackParamTraits specialize on the whitelist, and for non-
whitelisted types it will store a T and pass a const T&. The receiving
method will take a T which will try to copy and fail for non-whitelisted
move-only types. Secondly, the constructor of BindState will fail as
Bind takes a const T& for each bound argument currently, and the storage
of T will try to copy into the BindState.

This prevents use such as base::Bind(&F, std::unique_ptr<T>()), which will
also apply to scoped_ptr.

R=Nico, dcheng
BUG=557422

Review URL: https://codereview.chromium.org/1496403002

Cr-Commit-Position: refs/heads/master@{#363635}
2015-12-08 00:46:50 +00:00
skyostil
054861d093 base: Remove most uses of MessageLoopProxy
Replace most usage of MessageLoopProxy under base/ with SingleThreadTaskRunner
and ThreadTaskRunnerHandle (excluding the implementation of MessageLoopProxy
itself which will removed later).

This patch was mostly autogenerated with
https://codereview.chromium.org/1010073002.

Depends on https://codereview.chromium.org/1086733002/.

BUG=465354
TBR=nkostylev@chromium.org,pkasting@chromium.org,pauljensen@chromium.org

Review URL: https://codereview.chromium.org/1100773004

Cr-Commit-Position: refs/heads/master@{#327755}
2015-04-30 19:07:34 +00:00
stevenjb
7669182866 Revert of base: Remove use of MessageLoopProxy (patchset id:100001 of https://codereview.chromium.org/1100773004/)
Reason for revert:
This CL caused this failure:
http://build.chromium.org/p/chromium.chromiumos/builders/Linux%20ChromiumOS%20Tests%20%281%29/builds/2126

I would strongly recommend doing this in smaller pieces since it combines mechanical changes with more subtle ones (base/prefs, base/task).

Original issue's description:
> base: Remove use of MessageLoopProxy
>
> Replace usage of MessageLoopProxy under base/ with SingleThreadTaskRunner
> and ThreadTaskRunnerHandle (excluding the implementation of MessageLoopProxy
> itself which will removed later).
>
> This patch was mostly autogenerated with
> https://codereview.chromium.org/1010073002.
>
> Depends on https://codereview.chromium.org/1086733002/.
>
> BUG=465354
> TBR=nkostylev@chromium.org,pkasting@chromium.org,pauljensen@chromium.org
>
> Committed: https://crrev.com/62aa5ca413e15738ebebbb9acd271138ec808739
> Cr-Commit-Position: refs/heads/master@{#327512}

TBR=danakj@chromium.org,skyostil@chromium.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=465354

Review URL: https://codereview.chromium.org/1113953002

Cr-Commit-Position: refs/heads/master@{#327573}
2015-04-29 21:44:18 +00:00
skyostil
62aa5ca413 base: Remove use of MessageLoopProxy
Replace usage of MessageLoopProxy under base/ with SingleThreadTaskRunner
and ThreadTaskRunnerHandle (excluding the implementation of MessageLoopProxy
itself which will removed later).

This patch was mostly autogenerated with
https://codereview.chromium.org/1010073002.

Depends on https://codereview.chromium.org/1086733002/.

BUG=465354
TBR=nkostylev@chromium.org,pkasting@chromium.org,pauljensen@chromium.org

Review URL: https://codereview.chromium.org/1100773004

Cr-Commit-Position: refs/heads/master@{#327512}
2015-04-29 16:57:27 +00:00
tzik
b953d843e9 Remove unused base::NthType
base::NthType was once added in a prototype of base::Bind refactoring
though it is no longer used in the final code.

BUG=433164

Review URL: https://codereview.chromium.org/897943003

Cr-Commit-Position: refs/heads/master@{#315337}
2015-02-09 17:57:55 +00:00
tzik
8ce6570922 Bind: Use Variadic Templates in bind_internal.h
* Introduce TypeList as helpers.
* Drop bind_internal.h.pump and replace generated codes with Variadic Templates version.

BUG=433164

Review URL: https://codereview.chromium.org/743853002

Cr-Commit-Position: refs/heads/master@{#314847}
2015-02-05 19:12:47 +00:00
ncbray@chromium.org
e160b44f3f Fix template bugs that prevent rolling gtest DEPS.
BUG=none

Review URL: https://codereview.chromium.org/431533003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@287111 0039d316-1c4b-4281-b951-d872f2087c98
2014-08-01 22:44:13 +00:00
tnagel@chromium.org
cd106ffe3e Fix typo inside comment in base/bind_helpers.h.
BUG=

Review URL: https://codereview.chromium.org/259523004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@266278 0039d316-1c4b-4281-b951-d872f2087c98
2014-04-25 23:13:44 +00:00
avi@chromium.org
1c232c2bbc Move ScopedClosureRunner to callback_helpers, add Reset.
BUG=none
TEST=none
TBR=ben@chromium.org

Review URL: https://chromiumcodereview.appspot.com/23514018

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@220473 0039d316-1c4b-4281-b951-d872f2087c98
2013-08-30 02:04:04 +00:00
etienneb@chromium.org
793b6c2203 Fix a misuse of pragma disable/default in a header file.
This may override the enable/disable of this warning in an other file which include base_helpers.h.

R=ajwong@chromium.org, erikwright@chromium.org
BUG=

Review URL: https://chromiumcodereview.appspot.com/20353002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@214573 0039d316-1c4b-4281-b951-d872f2087c98
2013-07-31 05:22:02 +00:00
ajwong@chromium.org
01c86ece02 Remove the rest of #pragma once in one big CL.
For context see this thread:
  https://groups.google.com/a/chromium.org/forum/?fromgroups#!topic/chromium-dev/RMcVNGjB4II

TBR=thakis,pkasting,jam

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@146163 0039d316-1c4b-4281-b951-d872f2087c98
2012-07-11 19:01:43 +00:00
ajwong@chromium.org
c694427c13 Remove task.h and finish base::Bind() migration.
Over 341 CLs, in ~3 months, touching 3251 unique files!

Top 5 most CLs:
(121) jhawkins
( 45)   dcheng
( 24)  achuith
( 23)    csilv
( 12)  tfarina
( 12)    groby

~1000 files touched:
(918) jhawkins

100+ files touched:
(486)   ajwong
(385) willchan
(372)   dcheng
(126)    csilv
(123) fischman
(112)  sergeyu

49+ files touched:
(65)   tfarina
(57)  acolwell
(52)     adamk
(49)      tzik

BUG=35223
TEST=existing

Review URL: http://codereview.chromium.org/9114020

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@116748 0039d316-1c4b-4281-b951-d872f2087c98
2012-01-06 22:12:28 +00:00
ajwong@chromium.org
dcde767184 Change over IgnoreReturn to IgnoreResult. remove IgnoreReturn.
BUG=98919
TEST=existing

Review URL: http://codereview.chromium.org/9111032

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@116631 0039d316-1c4b-4281-b951-d872f2087c98
2012-01-06 02:37:17 +00:00
ajwong@chromium.org
206a2ae8a1 Redo r113722 - Add Pass(), which implements move semantics, to scoped_ptr, scoped_array....
-- This time for sure. --

Add Pass(), which implements move semantics, to scoped_ptr, scoped_array, and
scoped_ptr_malloc.

This modification to the scopers implements the "moveable but not copyable"
semantics that were introduced in C++11's unique_ptr<>.

With this, is now possible to use scopers as an argument type or a return type.
This signifies, in the type system, transfer of ownership into a function or out
of a function respectively.  Calling, or returning such a function MUST use the
temporary resulting from a function or explicit cast.

This distinction makes it possible to avoid the implicit ownership transfer
issues of auto_ptr, but still allow us to have compiler enforced ownership
transfer.

Also adds a Passed() helper that allows using a scoper with Bind().

Original Review URL: http://codereview.chromium.org/8774032

BUG=96118
TEST=new unittests

Review URL: http://codereview.chromium.org/9018037

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@115607 0039d316-1c4b-4281-b951-d872f2087c98
2011-12-22 21:12:58 +00:00
jeremya@chromium.org
088badbc39 Revert 115441 - Redo r113722 - Add Pass(), which implements move semantics, to scoped_ptr, scoped_array....
(This undoes the revert in r114247. Win canaries still can't link, but
this change has been deemed safe).

Add Pass(), which implements move semantics, to scoped_ptr, scoped_array, and
scoped_ptr_malloc.

This modification to the scopers implements the "moveable but not copyable"
semantics that were introduced in C++11's unique_ptr<>.

With this, is now possible to use scopers as an argument type or a return type.
This signifies, in the type system, transfer of ownership into a function or out
of a function respectively.  Calling, or returning such a function MUST use the
temporary resulting from a function or explicit cast.

This distinction makes it possible to avoid the implicit ownership transfer
issues of auto_ptr, but still allow us to have compiler enforced ownership
transfer.

Also adds a Passed() helper that allows using a scoper with Bind().

BUG=96118
TEST=new unittests

Review URL: http://codereview.chromium.org/9021032

TBR=ajwong@chromium.org
Review URL: http://codereview.chromium.org/8949057

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@115444 0039d316-1c4b-4281-b951-d872f2087c98
2011-12-21 23:37:57 +00:00
ajwong@chromium.org
014d0f6be0 Redo r113722 - Add Pass(), which implements move semantics, to scoped_ptr, scoped_array....
(This undoes the revert in r114247. Win canaries still can't link, but
this change has been deemed safe).

Add Pass(), which implements move semantics, to scoped_ptr, scoped_array, and
scoped_ptr_malloc.

This modification to the scopers implements the "moveable but not copyable"
semantics that were introduced in C++11's unique_ptr<>.

With this, is now possible to use scopers as an argument type or a return type.
This signifies, in the type system, transfer of ownership into a function or out
of a function respectively.  Calling, or returning such a function MUST use the
temporary resulting from a function or explicit cast.

This distinction makes it possible to avoid the implicit ownership transfer
issues of auto_ptr, but still allow us to have compiler enforced ownership
transfer.

Also adds a Passed() helper that allows using a scoper with Bind().

BUG=96118
TEST=new unittests

Review URL: http://codereview.chromium.org/9021032

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@115441 0039d316-1c4b-4281-b951-d872f2087c98
2011-12-21 23:14:10 +00:00
ajwong@chromium.org
54af837075 Revert of "Redo r113722 - Add Pass(), which implements move semantics, to scoped_ptr, scoped_ar..."
This reverts commit r113922.

Win Canary has been failing to link due to OOM since the weekend.  While this was not the original cause, it might be making things worse.  Speculatively remove for now.

Also changes render_widge_host_view to use Owned() instead of Passed().

BUG=none
TEST=existing.

Review URL: http://codereview.chromium.org/8931008

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@114247 0039d316-1c4b-4281-b951-d872f2087c98
2011-12-13 19:32:25 +00:00
ajwong@chromium.org
f51223594a Revert of "Revert of "Redo r113722 - Add Pass(), which implements move semantics, to scoped_ptr..."
This reverts commit r114228.

BUG=none
TEST=none
TBR=acolwell

Review URL: http://codereview.chromium.org/8929008

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@114230 0039d316-1c4b-4281-b951-d872f2087c98
2011-12-13 18:00:44 +00:00
ajwong@chromium.org
4133452bfc Revert "Redo r113722 - Add Pass(), which implements move semantics, to scoped_ptr, scoped_array...."
This reverts commit r113922.

Win Canary has been failing to link due to OOM since the weekend.  While this was not the original cause, it might be making things worse.  Speculatively remove for now.

BUG=none
TEST=none
TBR=kareng

Review URL: http://codereview.chromium.org/8932006

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@114228 0039d316-1c4b-4281-b951-d872f2087c98
2011-12-13 17:21:51 +00:00
ajwong@chromium.org
6a849971a8 Redo r113722 - Add Pass(), which implements move semantics, to scoped_ptr, scoped_array....
Add Pass(), which implements move semantics, to scoped_ptr, scoped_array, and scoped_ptr_malloc.

This modification to the scopers implements the "moveable but not copyable" semantics that were introduced in C++11's unique_ptr<>.

With this, is now possible to use scopers as an argument type or a return type.  This signifies, in the type system, transfer of ownership into a function or out of a function respectively.  Calling, or returning such a function MUST use the temporary resultin

This distinction makes it possible to avoid the implicit ownership transfer issues of auto_ptr, but still allow us to have compiler enforced ownership transfer.

Also adds a Passed() helper that allows using a scoper with Bind().

BUG=96118
TEST=new unittests

Original review URL: http://codereview.chromium.org/8774032

Review URL: http://codereview.chromium.org/8897005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@113922 0039d316-1c4b-4281-b951-d872f2087c98
2011-12-10 01:55:47 +00:00
sergeyu@chromium.org
3e6d120bf1 Revert 113722 - Add Pass(), which implements move semantics, to scoped_ptr, scoped_array, and scoped_ptr_malloc.
This modification to the scopers implements the "moveable but not copyable" semantics that were introduced in C++11's unique_ptr<>.

With this, is now possible to use scopers as an argument type or a return type.  This signifies, in the type system, transfer of ownership into a function or out of a function respectively.  Calling, or returning such a function MUST use the temporary resulting from the scoper's Pass() function. You CANNOT just pass the scoper by copy as there is still no copy constructor or assignment operator; trying to do so will yield a compilation error.

This distinction makes it possible to avoid the implicit ownership transfer issues of auto_ptr, but still allow us to have compiler enforced ownership transfer.

Also adds a Passed() helper that allows using a scoper with Bind().

BUG=96118
TEST=new unittests

Review URL: http://codereview.chromium.org/8774032

TBR=ajwong@chromium.org
Review URL: http://codereview.chromium.org/8890060

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@113738 0039d316-1c4b-4281-b951-d872f2087c98
2011-12-09 02:25:47 +00:00
ajwong@chromium.org
63a822490b Add Pass(), which implements move semantics, to scoped_ptr, scoped_array, and scoped_ptr_malloc.
This modification to the scopers implements the "moveable but not copyable" semantics that were introduced in C++11's unique_ptr<>.

With this, is now possible to use scopers as an argument type or a return type.  This signifies, in the type system, transfer of ownership into a function or out of a function respectively.  Calling, or returning such a function MUST use the temporary resulting from the scoper's Pass() function. You CANNOT just pass the scoper by copy as there is still no copy constructor or assignment operator; trying to do so will yield a compilation error.

This distinction makes it possible to avoid the implicit ownership transfer issues of auto_ptr, but still allow us to have compiler enforced ownership transfer.

Also adds a Passed() helper that allows using a scoper with Bind().

BUG=96118
TEST=new unittests

Review URL: http://codereview.chromium.org/8774032

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@113722 0039d316-1c4b-4281-b951-d872f2087c98
2011-12-09 01:29:38 +00:00
ajwong@chromium.org
7296f2763b Callback API Change: Reimplement Bind(); support IgnoreResult, full currying, and use less types.
The main API change IgnoreResult() and fully currying.  See unittest for what the new API looks like.  The rest of the changes are done to support that.

Previously, IgnoreReturn could not be used with WeakPtr<> Bind()s as it was applied after the fact to the Callback object.  Now, IgnoreResult() wraps the function like Unretained().

As an incidental benefit, the new implementation gave us fully currying for free.

Also, the new implementation scales better when supporting higher arities of functions.  The new type growth is:

  (n^2 + 20n) / 2

as opposed to

  (3n^2 + 17n) / 2

where n == arity.

For n = 6 and n=10, the new implementation has 81 and 155 templates respectively.

The old implementation had 105 and 235 templates respectively.

BUG=35233,98919,98542
TEST=existing unittests

Review URL: http://codereview.chromium.org/8483003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@110975 0039d316-1c4b-4281-b951-d872f2087c98
2011-11-21 19:23:44 +00:00