bind.h, callback.h, callback_forward.h, and callback_helpers.h
moved into /base/functional/. Remove the forwarding headers as
well as do some assorted cleanup related to those headers.
Fixed: 1364441
No-Try: true
Cq-Include-Trybots: luci.chrome.try:mac-chrome,win-chrome,linux-chrome,chromeos-eve-chrome,android-internal-rel
Change-Id: I309149935f721c27f2c3373ef40627c0c1f7537b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4167020
Commit-Queue: Avi Drissman <avi@chromium.org>
Commit-Queue: Daniel Cheng <dcheng@chromium.org>
Owners-Override: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Owners-Override: Avi Drissman <avi@chromium.org>
Reviewed-by: Peter Boström <pbos@chromium.org>
Auto-Submit: Avi Drissman <avi@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1093705}
This CL contains:
- removal of references to task runner handles in comments
- removal of nearly all calls, includes, and instantiations of
thread and sequenced task runner handles
Each of these were replaced with references to the new api:
TaskRunner::CurrentDefaultHandle and associated methods.
After this change, all that should be left to do for this method
refactor is the deletion of the old API.
A few of the changes were done with a script, but they were manually
audited.
Bug: 1026641
Ax-Relnotes: n/a
Change-Id: I0858dccac95b485d982aa5152c6b461c4ce05aa4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4117257
Commit-Queue: Gabriel Charette <gab@chromium.org>
Owners-Override: Gabriel Charette <gab@chromium.org>
Reviewed-by: Gabriel Charette <gab@chromium.org>
Commit-Queue: Sean Maher <spvw@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1088971}
`GetWeakPtr()` no longer lazy-initializes the flag, so the
previous recommendation to have a separate `WeakPtr<T>` field
to avoid potential races is no longer necessary. Also mention
SafeRef<T> as an alternative for base::Unretained().
Change-Id: Ie7f84a09ff8b2a127c68eb273a646f9eef9367f8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3793176
Commit-Queue: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Peter Kasting <pkasting@chromium.org>
Auto-Submit: Daniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1030301}
Add unit test to ensure that copies of a barrier callback share state.
While this is already used in multiple use cases, it was not obvious
to me.
Add basic documentation with a usage example.
Bug: 1283847
Test: New unit test
Change-Id: I84c8f61777108eed60ec8781df11de84a507359a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3361846
Reviewed-by: danakj chromium <danakj@chromium.org>
Commit-Queue: Roland Bock <rbock@google.com>
Cr-Commit-Position: refs/heads/main@{#955284}
The callback documentation was out of date after the ban on non-const
references were allowed. Add documentation about binding values for
non-const reference parameters and the use of base::OwnedRef().
Also add a compile time error message if bound parameter can't be
forwarded to a non-const reference parameter then mention std::ref() and
base::OwnedRef() to give a hint.
Bug: 1182328
Change-Id: Ic4ca06d6781442651cd09735c66f7d28f105453b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2756709
Commit-Queue: kylechar <kylechar@chromium.org>
Reviewed-by: Jan Wilken Dörrie <jdoerrie@chromium.org>
Cr-Commit-Position: refs/heads/master@{#863842}
This CL adds SplitOnceCallback, a utility function that allows to get
two OnceCallbacks out of one. Invoking any of the two split callbacks
will run the originally passed callback. Invoking the remaining callback
will result in a no-op.
Bug: 1156809
Change-Id: Iebf4542732fb6230af92fa27c4d7c5705933ad6b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2586688
Commit-Queue: Thomas Guilbert <tguilbert@chromium.org>
Reviewed-by: danakj <danakj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#838267}
This function binds a callback to a task runner. The functionality
already existed in media::BindToLoop() so it's intended to replace it
and is built on the same BindPostTaskTrampoline logic. BindToLoop() and
BindToCurrentLoop() will be replaced in a follow up CL since they are
used rather widely already.
There are some changes to the existing BindToLoop implementation:
1. Get the FROM_HERE location from the caller automatically rather than
using the BindPostTask() location.
2. If BindPostTaskTrampoline has a OnceClosure, don't rebind the closure
before posting a task.
3. Add static_assert to provide a readable error message explaining the
input callback must have a void return type.
4. Don't support RepeatingCallback. This is more problematic since we
will always PostTask() to destroy the callback. This is easier to add
later than it would be to remove support.
Bug: 1140582
Change-Id: Ibb224b44c0b0c01dd88d29e94c7e9449d3353ef5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2495055
Commit-Queue: kylechar <kylechar@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Gabriel Charette <gab@chromium.org>
Reviewed-by: danakj <danakj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#827818}
a.Then(b) will return a new callback that when Run() will
1) run |a|
2) run |b|, passing it the return value from a
3) return the result from |b|
OnceCallbacks must be destroyed when joining them together with Then(),
so the method is rvalue-qualified. This means it is used in the
same way as Run(), for example, this function posts two callbacks to
run together as a single task:
void PostTwoTasks(base::OnceClosure c1, base::OnceClosure c2) {
PostTask(std::move(c1).Then(std::move(c2)));
}
RepeatingCallback can be joined destructively via the rvalue-qualified
overload, or non-destructively otherwise. The latter is allowed for a
RepeatingCallback because it is meant to have multiple callers and
therefore having both the original callbacks and the joined callback
pointing to the same underlying functor is not problematic.
R=chrisha@chromium.org, gab@chromium.org
Bug: 1140582
Change-Id: Ie147f01d1c8adeb5ed34e4933f211e7d247e3c6b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2485642
Commit-Queue: danakj <danakj@chromium.org>
Reviewed-by: Gabriel Charette <gab@chromium.org>
Reviewed-by: Chris Hamilton <chrisha@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#820319}
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}
Code was difficult to copy-and-paste out of the callback examples
because typically one would need to add base:: to many types.
This explicitly adds "base::" to all examples.
Originally I was going to keep the references in the text unchanged and
only change the code blocks. But this ended up being confusing. As a
result, all code-formatted references have been qualified. In some cases
this is a bit verbose and repetitive, but I think its better to be
explicit and consistent.
Expands a bit on weak pointer usage which I have found myself repeatedly
looking up.
Change-Id: I961b25ea6db6151180cf0d687e576be72e327427
Reviewed-on: https://chromium-review.googlesource.com/688505
Reviewed-by: Albert J. Wong <ajwong@chromium.org>
Commit-Queue: Brett Wilson <brettw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#504781}
Adds a sentence describing what happens to a moved-from Callback; that
it is equivalent to a Reset() and that is_null() will return true
afterwards. Just trying to save future developers 15-20 minutes from
having to wade through the impl to answer this question. :-)
Change-Id: Ic3eb2c6cac847bbd95af3ed20b208c8b135860f1
Reviewed-on: https://chromium-review.googlesource.com/570127
Reviewed-by: Taiju Tsuiki <tzik@chromium.org>
Commit-Queue: Yuri Wiitala <miu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#486893}
This removes a mention to OnceCallback support of PostTask, since
PostTask does support OnceCallback now.
BUG=554299
Review-Url: https://codereview.chromium.org/2830223002
Cr-Commit-Position: refs/heads/master@{#466591}
Added the method to callback.md because it's helpful yet I hadn't discovered it (callback_helpers.h is a more obscure file than callback.h or bind_helpers.h)
BUG=none
R=tzik@chromium.org
Review-Url: https://codereview.chromium.org/2755073002
Cr-Commit-Position: refs/heads/master@{#457939}
Fixes the original example, which resulted in an invalid conversion from
base::OnceCallback<void(int)> to base::Closure. Also adds a comment that
this usage is not yet supported.
BUG=none
R=tzik@chromium.org
Review-Url: https://codereview.chromium.org/2735903002
Cr-Commit-Position: refs/heads/master@{#456886}