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}
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}
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}
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}
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}
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}
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}
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}
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}
`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}
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}
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}
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}
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}
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}
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}
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}
* 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}
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}
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}
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}
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}
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}
-- 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
(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/9021032TBR=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
(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
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
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
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
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/8774032TBR=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
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
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