0
Commit Graph

37 Commits

Author SHA1 Message Date
David Sanders
8cfb63a917 Add missing includes of //base/check.h in //base
Bug: 1300573
Change-Id: Id5db66943f4491756604c002ff049efb89460b7f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3585516
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Owners-Override: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/main@{#992669}
2022-04-14 19:36:30 +00:00
David Sanders
6e70994bab Do IWYU for //base/base_export.h
Bug: 242216
Change-Id: Id2c129b36de8a665fab6aa7974e99b494776a738
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3567262
Reviewed-by: Lei Zhang <thestig@chromium.org>
Owners-Override: Lei Zhang <thestig@chromium.org>
Commit-Queue: David Sanders <dsanders11@ucsbalum.com>
Cr-Commit-Position: refs/heads/main@{#988857}
2022-04-05 06:49:26 +00:00
David Sanders
a47d5c6da7 Remove unused include in //base/sequence_checker.h
Fixed: 1288836
Change-Id: I95f0e0944144dd5947e546f2ec0db17811ab8a64
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3392467
Reviewed-by: Nico Weber <thakis@chromium.org>
Commit-Queue: Nico Weber <thakis@chromium.org>
Owners-Override: Nico Weber <thakis@chromium.org>
Cr-Commit-Position: refs/heads/main@{#962291}
2022-01-23 03:48:48 +00:00
Daniel Cheng
4455c984fd C++17: Allow use of [[nodiscard]] attribute.
Also converts //base from WARN_UNUSED_RESULT to [[nodiscard]] using the
tooling in the attached bug.

Bug: 1287045
Change-Id: Icb3ca1fc81592dad3012c1e8e653883987a02f5e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3387489
Reviewed-by: danakj chromium <danakj@chromium.org>
Commit-Queue: Daniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/main@{#958908}
2022-01-13 23:26:37 +00:00
Daniel Cheng
e0fc463ca6 Update base::DoNothing() / base::NullCallback() to use a type tag.
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}
2021-10-01 00:37:41 +00:00
Joshua Bell
06e5791cb0 Remove base::AdaptCallbackForRepeating
All usages have been removed from the codebase. \o/

* Remove implementation/tests from base/
* Remove clang rewriter from tools/

Bug: 730593
Change-Id: I101e65ffc0c626aa101e4e51396558fbdf16c372
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2941842
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: danakj <danakj@chromium.org>
Commit-Queue: Joshua Bell <jsbell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#890311}
2021-06-08 17:24:15 +00:00
danakj
6989c6c05e Replace AdaptCallbackForRepeating with SplitOnceCallback in content/browser/tracing
SplitOnceCallback keeps the types correct, with 2 OnceCallbacks, and
ensures only one of the two is called at runtime.

Bug: 730593
Change-Id: I0ec819954bf7feda821c95839b6c19ab295d5807
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2893604
Reviewed-by: Lei Zhang <thestig@chromium.org>
Reviewed-by: Avi Drissman <avi@chromium.org>
Commit-Queue: danakj <danakj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#882720}
2021-05-13 22:20:31 +00:00
Thomas Guilbert
5db523811a Add SplitOnceCallback
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}
2020-12-17 22:33:14 +00:00
Peter Kasting
323ccc86ad Fix a variety of small issues with ScopedClosureRunner.
* 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}
2020-11-14 01:41:24 +00:00
danakj
9eb5b72b20 Move bind_helpers.h contents to callback_helpers.h
Followups will change includes and remove the header.

R=dcheng@chromium.org
TBR=davidben@chromium.org,dalecurtis@chromium.org

Change-Id: Idd1de7bd21102b389676eda7cabdadf866b94903
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2521248
Auto-Submit: danakj <danakj@chromium.org>
Reviewed-by: Dale Curtis <dalecurtis@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Commit-Queue: Dale Curtis <dalecurtis@chromium.org>
Commit-Queue: danakj <danakj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#825160}
2020-11-07 03:03:09 +00:00
David Bienvenu
b4b441e83a remove DISALLOW_COPY_AND_ASSIGN from files in base/*
Also fixes a few cpp lint errors. No functional changes.

Bug: 1010217
Change-Id: Ibdbac42980740d26392812b39f86859b238b7a64
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2422964
Commit-Queue: David Bienvenu <davidbienvenu@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#809700}
2020-09-23 05:49:57 +00:00
Peter Kasting
56bc40c08d Use CRTP to avoid |null_callbacks_| for RepeatingCallbackList.
Bug: none
Change-Id: I5ea12772f8dddca924fb55d702129e901e236983
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2191247
Commit-Queue: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#768168}
2020-05-13 06:41:57 +00:00
Peter Kasting
670a86bd54 CallbackList improvements, part 4: OnceCallback support
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}
2020-05-06 22:50:02 +00:00
Elly Fong-Jones
91f7f79100 base: mention alternate "spellings" of ScopedClosureRunner
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}
2020-03-16 22:35:50 +00:00
Khushal
29c436c99e Revert "viz: Add temp CHECKs for debugging."
This reverts commit 1ba3926854.

Reason for revert: Change was temporary to aid debugging.

Original change's description:
> viz: Add temp CHECKs for debugging.
> 
> R=​kylechar@chromium.org
> 
> Bug: 992626
> Change-Id: If13d2f4c9660c49db82e586929b2686b54f3760a
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1797128
> Commit-Queue: Khushal <khushalsagar@chromium.org>
> Commit-Queue: kylechar <kylechar@chromium.org>
> Auto-Submit: Khushal <khushalsagar@chromium.org>
> Reviewed-by: kylechar <kylechar@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#695430}

TBR=khushalsagar@chromium.org,kylechar@chromium.org

# Not skipping CQ checks because original CL landed > 1 day ago.

Bug: 992626
Change-Id: I6388a12e22a85c8b24dacf9bb992eeeb933da101
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1848359
Reviewed-by: Khushal <khushalsagar@chromium.org>
Commit-Queue: Khushal <khushalsagar@chromium.org>
Cr-Commit-Position: refs/heads/master@{#703962}
2019-10-08 23:09:28 +00:00
Khushal
1ba3926854 viz: Add temp CHECKs for debugging.
R=kylechar@chromium.org

Bug: 992626
Change-Id: If13d2f4c9660c49db82e586929b2686b54f3760a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1797128
Commit-Queue: Khushal <khushalsagar@chromium.org>
Commit-Queue: kylechar <kylechar@chromium.org>
Auto-Submit: Khushal <khushalsagar@chromium.org>
Reviewed-by: kylechar <kylechar@chromium.org>
Cr-Commit-Position: refs/heads/master@{#695430}
2019-09-11 01:12:09 +00:00
Daniel Cheng
6bfb082b16 [🧹] Remove base::ResetAndReturn.
Bug: 841899
Tbr: thestig@chromium.org
Change-Id: I972785b8f6c189039c56049a8c132b7bf4c69876
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1584531
Commit-Queue: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: danakj <danakj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#656276}
2019-05-03 01:53:00 +00:00
jdoerrie
19cf521b39 [base] Introduce EnableIfIsBaseCallback Type Helper
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}
2019-04-26 09:50:47 +00:00
Daniel Cheng
bbd4729c3a Restrict base::ResetAndReturn() to base::{Once,Repeating}Callback
Tbr: klausw@chromium.org
Tbr: wez@chromium.org
Change-Id: Iaf9cde672f22965adcf3920f616fbeb06c7f6573
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1578953
Commit-Queue: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: danakj <danakj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#653878}
2019-04-25 02:20:15 +00:00
Bence Béky
1532745a13 Discourage base::ResetAndReturn().
See discussion at
https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/PJOXupl9ztA

Bug: 841899
Change-Id: I58158270f304c5e6d50a85d47e1d3f599b5870d5
Reviewed-on: https://chromium-review.googlesource.com/1053831
Commit-Queue: Bence Béky <bnc@chromium.org>
Reviewed-by: Nico Weber <thakis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#557665}
2018-05-10 20:59:07 +00:00
Avi Drissman
aed822394c Add a bug link to AdaptCallbackForRepeating().
BUG=730593

Change-Id: I99aba6a46ed01fe3ec3579ee1f6180670f2e6778
Reviewed-on: https://chromium-review.googlesource.com/969109
Reviewed-by: Taiju Tsuiki <tzik@chromium.org>
Commit-Queue: Avi Drissman <avi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#544345}
2018-03-20 13:36:57 +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
9532f25fad Replace base::MakeUnique with std::make_unique in base/.
Bug: 755727
Change-Id: Ia785171c1c9fd5396def9e381bbc1387e0eee0a1
Reviewed-on: https://chromium-review.googlesource.com/616842
Commit-Queue: Jeremy Roman <jbroman@chromium.org>
Reviewed-by: Nico Weber <thakis@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#494995}
2017-08-16 23:27:24 +00:00
tzik
398065c8f7 Convert base::ScopedClosureRunner to use OnceCallback
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}
2017-08-08 05:19:40 +00:00
tzik
faa3495a7a Introduce base::IgnoreReuse() to wrap OnceCallback into RepeatingCallback
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}
2017-04-20 12:19:50 +00:00
michaelpg
0f156e19b0 Update documentation for base::ResetAndReturn(Callback*)
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}
2017-03-18 02:49:09 +00:00
tzik
6eb028403e Fix OnceCallback support of base::ResetAndReturn
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}
2017-02-22 09:13:19 +00:00
tzik
9cd09f79b4 Support OnceCallback on base::ResetAndReturn
Review-Url: https://codereview.chromium.org/2662543002
Cr-Commit-Position: refs/heads/master@{#446774}
2017-01-27 21:20:14 +00:00
sergeyu
668613aa8e Fix incorrect usage of ScopedCallbackRunner.Reset().
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}
2016-07-08 00:36:39 +00:00
sergeyu
e4be191768 Add move constructor in ScopedClosureRunner.
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}
2016-06-25 00:53:35 +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
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
fischman@chromium.org
1192339cc7 Make Callback::Reset() return a copy to support use-cases where Run() ends up modifying |*this|. Callers can use
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
2012-03-24 20:37:27 +00:00
ajwong@chromium.org
59eff91b6b Callback: De-inline CallbackBase, and move to callback_helpers -> callback_internal.h
We can re-inline later if it starts being an issue.

BUG=none
TEST=unit-tests

Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=75443

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@75464 0039d316-1c4b-4281-b951-d872f2087c98
2011-02-18 23:29:31 +00:00
ajwong@chromium.org
2ab9d4d9df Revert "Callback: De-inline CallbackBase, and move to callback_helpers -> callback_internal.h"
This reverts commit r75443.

TBR=akalin

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@75445 0039d316-1c4b-4281-b951-d872f2087c98
2011-02-18 21:48:15 +00:00
ajwong@chromium.org
47d02ffb25 Callback: De-inline CallbackBase, and move to callback_helpers -> callback_internal.h
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
2011-02-18 21:30:36 +00:00
ajwong@chromium.org
b38d3578e5 Unified callback system based on tr1::function/tr1::bind and Google's internal callback code.
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
2011-02-15 01:27:38 +00:00