This allows both helpers to be used in contexts where the original
helper required templated arguments to be explicitly specified,
generally leading to more concise code.
However, since base::DoNothing() only returns a type tag now, it can no
longer be used as a functor with base::BindOnce/base::BindRepeating.
In general, this seems to be a net neutral to slight positive change:
the lambda version is actually shorter—though some might argue less
readable—and it generates more efficient code since running the callback
now jumps through one less thunk.
Bug: 1252980
Change-Id: I6b72230fe9d583865ff3d40fc51025f6195ebbc4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3180101
Commit-Queue: Daniel Cheng <dcheng@chromium.org>
Commit-Queue: danakj <danakj@chromium.org>
Reviewed-by: danakj <danakj@chromium.org>
Owners-Override: danakj <danakj@chromium.org>
Cr-Commit-Position: refs/heads/main@{#927031}
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}
* Explicit deletion of copy constructors not necessary when move
constructors are given.
* No way to check if the runner had a closure inside.
* RunAndReset() crashed if called with no closure inside.
* operator=() failed to run the outgoing closure.
Bug: none
Change-Id: I8c92dfaca95619fe6661af10c018a75dae7e25ff
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2537787
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Reviewed-by: Avi Drissman <avi@chromium.org>
Reviewed-by: danakj <danakj@chromium.org>
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#827526}
This is implemented as OnceCallbackList vs. RepeatingCallbackList. It
might in theory be nice to simply have a single CallbackList that
supports simultaneously containing both Once and Repeating callbacks.
However, I don't personally need it, and while I suspect it's possible,
I didn't want to try and figure it out.
Bug: none
Change-Id: Ib04d39adedca5b15e002b1b3d5df8957b40f2254
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2174162
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Jan Wilken Dörrie <jdoerrie@chromium.org>
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#766187}
I (and others) always forget what this class is named, so mention some
of the other guesses people make as to its name in the comment by it.
This will cause it to surface in code search.
Bug: None
Change-Id: I597313c1be76df4ac6810c4d7308c0905330ee16
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2105960
Reviewed-by: danakj <danakj@chromium.org>
Commit-Queue: Elly Fong-Jones <ellyjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#750748}
This change introduces the SFINAE friendly EnableIfIsBaseCallback type
helper, allowing code to restrict templates to classes that are
base::Callbacks (either OnceCallback or RepeatingCallback). Furthermore,
this change cleans up some code duplication.
TBR=reillyg@chromium.org
Bug: 714018
Change-Id: I0a49da990aca03e5cf2b7c71c74e7c8c53245008
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1583812
Commit-Queue: Jan Wilken Dörrie <jdoerrie@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#654390}
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}
After this CL, ScopedClosureRunner uses base::OnceClosure as its internal
callback object. That implies it gets able to take base::OnceClosure in
addition to base::Closure, and ScopedClosureRunner::Release returns
base::OnceClosure instead of base::Closure.
Bug: 714018
Change-Id: I031ef7b70bc9673ea7781e292719e26ddc74b1a7
Reviewed-on: https://chromium-review.googlesource.com/597090
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Alexander Alekseev <alemate@chromium.org>
Reviewed-by: Kazuhiro Inaba <kinaba@chromium.org>
Reviewed-by: Zijie He <zijiehe@chromium.org>
Reviewed-by: Gabriel Charette <gab@chromium.org>
Reviewed-by: Peter Beverloo <peter@chromium.org>
Commit-Queue: Taiju Tsuiki <tzik@chromium.org>
Cr-Commit-Position: refs/heads/master@{#492538}
This CL adds base::IgnoreReuse() and applies it to ImportantFileWriter.
In some rare case such as ImportantFileWriter, ServiceWorkerStorage, and
Mojo stuff, a called-only-once callback object is copied and passed to
separate code paths, that blocks OnceCallback migration.
base::IgnoreReuse() is a workaround for that by wrapping OnceCallback
into a RepeatingCallback, and ignores past-first calls.
BUG=668014
Review-Url: https://codereview.chromium.org/2820993002
Cr-Commit-Position: refs/heads/master@{#465979}
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}
ResetAndReturn's OnceCallback was broken, since it tried to copy the
move only OnceCallback. This CL fixes that and adds test for it.
Review-Url: https://codereview.chromium.org/2709913002
Cr-Commit-Position: refs/heads/master@{#451949}
ScopedCallbackRunner.Reset() was used in two places with
assumption it doesn't call current callback. Replaced Reset()
with ReplaceClosure() and RunAndReset() to make behavior clearer.
Review-Url: https://codereview.chromium.org/2094803005
Cr-Commit-Position: refs/heads/master@{#404277}
With this change ScopedClosureRunner will be movable. This will
allow to store instances of that class in STL containers, e.g. to store
list of callbacks to be called when certain event happens.
Review-Url: https://codereview.chromium.org/2091503004
Cr-Commit-Position: refs/heads/master@{#402031}
cb.Reset().Run(args...);
to avoid reentrancy-like bugs.
Replace the special-purpose versions of ResetAndRunCB in the media/ codebase
with this more-general facility.
Review URL: http://codereview.chromium.org/9717021
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@128772 0039d316-1c4b-4281-b951-d872f2087c98
We can re-inline later if it starts being an issue.
BUG=none
TEST=unit-tests
Review URL: http://codereview.chromium.org/6542026
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@75443 0039d316-1c4b-4281-b951-d872f2087c98
This callback system allows for creation of functors for normal functions, methods, and const methods. It is a superset of the functionality of NewRunnableMethod, NewRunnableFunction, NewCallback, and CreateFunctor.
We support partial binding of function arguments, and also specification of refcounting semantics by wrapping a target object in a wrapper object.
BUG=35223
TEST=none
Review URL: http://codereview.chromium.org/6109007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@74904 0039d316-1c4b-4281-b951-d872f2087c98