0
Commit Graph

43 Commits

Author SHA1 Message Date
Evan Stade
5df7469b92 Allow IgnoreArgs to take a non-closure callback.
Only consume/ignore the first N args.

Change-Id: If9041a5ec37b84417c49a86687cdbcf39bd1f254
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4895798
Commit-Queue: Evan Stade <estade@chromium.org>
Reviewed-by: Nicolas Dossou-Gbété <dgn@chromium.org>
Reviewed-by: danakj <danakj@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1204347}
2023-10-02 23:15:57 +00:00
Byron Lee
71cf8b575e Fix the example of barrier callback in doc
BUG=None
TEST=CQ

Change-Id: I153239303ec44fbd9807462ac5d007bd7fb481f2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4781818
Auto-Submit: Byron Lee <byronlee@chromium.org>
Commit-Queue: Roland Bock <rbock@google.com>
Reviewed-by: Roland Bock <rbock@google.com>
Cr-Commit-Position: refs/heads/main@{#1184043}
2023-08-16 09:10:33 +00:00
Arthur Milchior
cc277f0f9a add backticks
Bug: None
Change-Id: If4634950d18a1ef69f04e781646f0193871a4aac
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4665411
Commit-Queue: Arthur Milchior <arthurmilchior@chromium.org>
Reviewed-by: Colin Blundell <blundell@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1166359}
2023-07-06 07:59:03 +00:00
Avi Drissman
d4459dbffb Remove forwarding headers
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}
2023-01-18 02:45:14 +00:00
Sean Maher
70f2942930 Task posting v3: many manual changes to continue handle refactors
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}
2023-01-04 22:15:06 +00:00
Nicolas Dossou-Gbete
51290c2f7e Add base::IgnoreArgs
Adds a helper to allow passing a closure where a value-accepting
callback is expected.

Fixed: 1370485
Change-Id: I6235620c201bcf83b790e611a9f56bb466d6cabe
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3930830
Auto-Submit: Nicolas Dossou-Gbété <dgn@chromium.org>
Reviewed-by: Toni Barzic <tbarzic@chromium.org>
Reviewed-by: danakj <danakj@chromium.org>
Reviewed-by: David Roger <droger@chromium.org>
Commit-Queue: Nicolas Dossou-Gbété <dgn@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1060980}
2022-10-19 12:50:34 +00:00
Daniel Cheng
af16de5a95 Update callback documentation for weak pointers.
`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}
2022-08-01 22:46:04 +00:00
Dmitrii Kuragin
2e7da865d6 Update docs/callback.md.
Remove `base::DoNothing::Once` from the callback documentation because
the entity doesn't exists anymore. It is replaced by
`base::DoNothingAs`. See http://crbug.com/1252980 for details.

Bug: 1252980
Change-Id: Ic473d274912e37d06fc1c4424e70a909ff857aa5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3702843
Commit-Queue: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Auto-Submit: Dmitrii Kuragin <kuragin@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1014124}
2022-06-14 20:17:21 +00:00
Roland Bock
6269edbb8e Add documentation and a unit test for barrier callback
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}
2022-01-04 19:34:15 +00:00
Colin Blundell
ea615d420d [base::{Bind, Callback conversion] Update refs in docs/comments/misc
After the removal of the deprecated base::Bind and base::Callback APIs,
this CL sweeps through the codebase removing references that are outside
of code compiled as part of Chromium CI. This is almost entirely docs
and comments, with some other miscellaneous files as well (e.g., checks
of various kinds).

Bug: 714018
Change-Id: Ide8845d92527031821aaa9fd3a00f75f9ba76545
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2874622
Commit-Queue: Colin Blundell <blundell@chromium.org>
Reviewed-by: Matt Menke <mmenke@chromium.org>
Reviewed-by: danakj <danakj@chromium.org>
Reviewed-by: Jochen Eisinger <jochen@chromium.org>
Reviewed-by: Kyle Horimoto <khorimoto@chromium.org>
Reviewed-by: Nico Weber <thakis@chromium.org>
Reviewed-by: Jeremy Roman <jbroman@chromium.org>
Reviewed-by: Jamie Walch <jamiewalch@chromium.org>
Reviewed-by: Peter Collingbourne <pcc@chromium.org>
Reviewed-by: Sunny Sachanandani <sunnyps@chromium.org>
Cr-Commit-Position: refs/heads/master@{#881967}
2021-05-12 09:35:41 +00:00
kylechar
72e6f78d69 Update callback documentation for references
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}
2021-03-17 17:43:38 +00:00
Wen Fan
dd47202dba Fix an example in the callback documentation
Add return value to make the demo code more accurate

Bug: 1151318
Change-Id: Ia300589a5d0a722c9e3d4bbe3231ea69793df24b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2752668
Reviewed-by: danakj <danakj@chromium.org>
Commit-Queue: danakj <danakj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#862243}
2021-03-12 01:31:09 +00:00
Greg Thompson
ddc84d470a Clarify documentation for self-destructing callbacks.
It's also okay to copy a RepeatingCallback onto the stack before running
it if running it may cause it to be deleted.

Bug: 1161804
Change-Id: I4ee5d81b5ab82505c4c3b02f872d3400d3d93ceb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2607886
Auto-Submit: Greg Thompson <grt@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Commit-Queue: Greg Thompson <grt@chromium.org>
Cr-Commit-Position: refs/heads/master@{#840012}
2021-01-04 10:10:02 +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
kylechar
dde7d23996 Implement base::BindPostTask()
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}
2020-11-16 17:35:09 +00:00
danakj
db9ae7941a Rename includes from bind_helpers.h to callback_helpers.h
R=dcheng@chromium.org
NOPRESUBMIT=true
TBR=
NOTRY=true

Change-Id: I93bc6a9360997fae7adeab8c01f56e08fc025dd2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2523543
Commit-Queue: danakj <danakj@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: danakj <danakj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#826289}
2020-11-11 16:01:35 +00:00
Guido Urdaneta
ef4e919472 Reland "Move base/test/bind_test_util.h to base/test/bind.h"
This reverts commit 8bd07a6cf9.

Reason for revert: This revert was incorrect and breaks the build.

Original change's description:
> Revert "Move base/test/bind_test_util.h to base/test/bind.h"
>
> This reverts commit a4493a6f80.
>
> Reason for revert: This CL breaks internal builds (e.g. /chrome/browser/media/kaleidoscope/internal/kaleidoscope_browsertest.cc).
>
> Original change's description:
> > Move base/test/bind_test_util.h to base/test/bind.h
> >
> > Stop relying on us to remember arcane file names when writing tests,
> > and repeating the directory hierarchy into the file name.
> >
> > R=​dcheng@chromium.org
> > TBR=
> > NOPRESUBMIT=true
> >
> > Change-Id: I49c951162939c7dcef44883bee740f94b2f49e09
> > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2523099
> > Commit-Queue: danakj <danakj@chromium.org>
> > Reviewed-by: Daniel Cheng <dcheng@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#825145}
>
> TBR=danakj@chromium.org,dcheng@chromium.org
>
> # Not skipping CQ checks because original CL landed > 1 day ago.
>
> Change-Id: If165b8443662baa564895e994ea0d772348e6da6
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2526102
> Reviewed-by: Denis Kuznetsov [CET] <antrim@chromium.org>
> Commit-Queue: Denis Kuznetsov [CET] <antrim@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#825328}

TBR=danakj@chromium.org,dcheng@chromium.org,antrim@chromium.org

# Not skipping CQ checks because this is a reland.
NOPRESUBMIT=true
NOTREECHECK=true

No-Try: True
Change-Id: I6a8c0c8bbb1c8f87cc7f2df7a8b3388971292975
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2526683
Commit-Queue: Guido Urdaneta <guidou@chromium.org>
Reviewed-by: Guido Urdaneta <guidou@chromium.org>
Cr-Commit-Position: refs/heads/master@{#825329}
2020-11-09 15:06:24 +00:00
Denis Kuznetsov [CET]
8bd07a6cf9 Revert "Move base/test/bind_test_util.h to base/test/bind.h"
This reverts commit a4493a6f80.

Reason for revert: This CL breaks internal builds (e.g. /chrome/browser/media/kaleidoscope/internal/kaleidoscope_browsertest.cc).

Original change's description:
> Move base/test/bind_test_util.h to base/test/bind.h
>
> Stop relying on us to remember arcane file names when writing tests,
> and repeating the directory hierarchy into the file name.
>
> R=​dcheng@chromium.org
> TBR=
> NOPRESUBMIT=true
>
> Change-Id: I49c951162939c7dcef44883bee740f94b2f49e09
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2523099
> Commit-Queue: danakj <danakj@chromium.org>
> Reviewed-by: Daniel Cheng <dcheng@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#825145}

TBR=danakj@chromium.org,dcheng@chromium.org

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

Change-Id: If165b8443662baa564895e994ea0d772348e6da6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2526102
Reviewed-by: Denis Kuznetsov [CET] <antrim@chromium.org>
Commit-Queue: Denis Kuznetsov [CET] <antrim@chromium.org>
Cr-Commit-Position: refs/heads/master@{#825328}
2020-11-09 14:21:28 +00:00
danakj
a4493a6f80 Move base/test/bind_test_util.h to base/test/bind.h
Stop relying on us to remember arcane file names when writing tests,
and repeating the directory hierarchy into the file name.

R=dcheng@chromium.org
TBR=
NOPRESUBMIT=true

Change-Id: I49c951162939c7dcef44883bee740f94b2f49e09
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2523099
Commit-Queue: danakj <danakj@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#825145}
2020-11-07 01:53:08 +00:00
danakj
9335cb1c0f Add docs for using IgnoreResult() to wrap a callback, and with Then()
R=gab@chromium.org

Bug: 1140582
Change-Id: I214c5b4e4f4b2ccd145027316cdd58feeb220481
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2505465
Reviewed-by: Gabriel Charette <gab@chromium.org>
Commit-Queue: danakj <danakj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#821870}
2020-10-28 20:21:21 +00:00
danakj
fcc5e7c295 Add *Callback::Then() to chain 2 callbacks together
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}
2020-10-23 17:43:27 +00:00
Erik Chen
9425c0f9dc Update documentation for binding lambda that take parameters.
Change-Id: I5856d1b98ef0a143d4924c64d9eca279ffe6e8e0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2406541
Commit-Queue: Erik Chen <erikchen@chromium.org>
Auto-Submit: Erik Chen <erikchen@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#806347}
2020-09-11 21:41:09 +00:00
Matt Giuca
7e81b22e7d Fixed docs/callback.md: partial application is not currying.
Removed incorrect mentions of currying, replacing with the correct term,
partial application.

For the difference between the two terms, see:
https://en.wikipedia.org/wiki/Currying#Contrast_with_partial_function_application

Change-Id: I14477be17687cad8b2773391c1f92fc52938c2b4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1870156
Commit-Queue: Matt Giuca <mgiuca@chromium.org>
Reviewed-by: Gabriel Charette <gab@chromium.org>
Reviewed-by: Alex Clarke <alexclarke@chromium.org>
Reviewed-by: François Doray <fdoray@chromium.org>
Cr-Commit-Position: refs/heads/master@{#724118}
2019-12-12 02:41:21 +00:00
Jeremy Roman
0dd0b2ff12 Update WeakPtrFactory examples to use in-class initializers.
This is now the more common, and simpler, pattern.

Bug: 981415
Change-Id: I082e75425a33f6256c2ddc3228d61f8b6fe8bc58
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1704677
Reviewed-by: Gabriel Charette <gab@chromium.org>
Commit-Queue: Jeremy Roman <jbroman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#677960}
2019-07-16 21:00:43 +00:00
Wez
33276265b6 [docs] Tidy up docs/callback.md wording around use of WeakPtr.
The documentation for Bind() made misleading statements about WeakPtr
thread-safety, leading to confusion over correct usage.

Change-Id: I8d4226e789150e56e994d3491db0b1ef3d2881dd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1652552
Reviewed-by: Albert J. Wong <ajwong@chromium.org>
Commit-Queue: Wez <wez@chromium.org>
Auto-Submit: Wez <wez@chromium.org>
Cr-Commit-Position: refs/heads/master@{#671139}
2019-06-21 00:11:20 +00:00
danakj
e26d7cf316 Improve callback docs about passing them as function arguments.
Pass by value to give ownership, pass by reference to not.

R=dcheng@chromium.org

Change-Id: I6e8756a31997101b5808fb6a7c494436d4c1ddb3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1635549
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Commit-Queue: danakj <danakj@chromium.org>
Cr-Commit-Position: refs/heads/master@{#664419}
2019-05-29 20:04:14 +00:00
Raphael Kubo da Costa
17c1618c40 callbacks.md: Document base::BindLambdaForTesting
Bug: 789805
Change-Id: I646566939599da1edc5ff7665da9634fc8a2169a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1543792
Auto-Submit: Raphael Kubo da Costa <raphael.kubo.da.costa@intel.com>
Commit-Queue: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#645447}
2019-03-28 19:30:44 +00:00
jdoerrie
9d7236f690 [base] Remove base::ConstRef in favor of std::cref
This change removes base::ConstRef from the codebase and replaces
previous usages with the equivalent std::cref.

TBR=tzik@chromium.org

Bug: 934808
Change-Id: Idbdd1e8b5ea29aaaa0e85067923d3e61edb0d3f4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1484291
Commit-Queue: Jan Wilken Dörrie <jdoerrie@chromium.org>
Reviewed-by: Taiju Tsuiki <tzik@chromium.org>
Cr-Commit-Position: refs/heads/master@{#637663}
2019-03-05 13:00:23 +00:00
Armando Miraglia
cce1eb41b0 Address a typo in callback documentation.
FYI: I am using this opportunity to test the submission flow on
Chrome/Gerrit & co :)

R=ossu@chromium.org

Bug: None
Change-Id: I6d5897a3e64160843d80b423f02c91d68430cb82
Reviewed-on: https://chromium-review.googlesource.com/1177718
Reviewed-by: Oskar Sundbom <ossu@chromium.org>
Commit-Queue: Armando Miraglia <armax@chromium.org>
Cr-Commit-Position: refs/heads/master@{#583645}
2018-08-16 14:35:44 +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
Gayane Petrosyan
7f71698beb Add Missing Functionality in callback.md
Change-Id: I662bce08782a154da3971f6046b40570c103fa35
Reviewed-on: https://chromium-review.googlesource.com/886825
Commit-Queue: Gayane Petrosyan <gayane@chromium.org>
Reviewed-by: Taiju Tsuiki <tzik@chromium.org>
Cr-Commit-Position: refs/heads/master@{#542115}
2018-03-09 15:17:34 +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
Max Morin
b51cf51f61 Discourage use of base::Passed().
See discussion thread: https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/8PJU6CEyGwg

No-Try: true
Bug: 812523
Change-Id: Ie021ad6803dbbaf02a4caba37c6b8a50a006b251
Reviewed-on: https://chromium-review.googlesource.com/919066
Commit-Queue: Max Morin <maxmorin@chromium.org>
Reviewed-by: Gabriel Charette <gab@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#537637}
2018-02-19 12:49:49 +00:00
Gabriel Charette
9048031298 Bring useful paragraphs from old threading docs into new threading docs.
As requested @ https://chromium-review.googlesource.com/c/chromium/src/+/738469/8/docs/design/threading.md#b122

Already had "Keep the Browser Responsive" and "Use Sequences instead of Locks"
sections, but amended them with a bit more text from the old docs.

R=jam@chromium.org

Bug: 752144
Change-Id: I67857ad21f8cc5884aeb65fe08fe184f63deed44
Reviewed-on: https://chromium-review.googlesource.com/921041
Reviewed-by: John Abd-El-Malek <jam@chromium.org>
Commit-Queue: Gabriel Charette <gab@chromium.org>
Cr-Commit-Position: refs/heads/master@{#537307}
2018-02-16 15:10:05 +00:00
Brett Wilson
61fb339bda Add example for move version of base::Passed.
The documentation only gave examples of calling base::Passed
with a pointer.

Change-Id: I86c516546b55e6dcd62f8c83cdff859cba64578d
Reviewed-on: https://chromium-review.googlesource.com/688685
Commit-Queue: Albert J. Wong <ajwong@chromium.org>
Reviewed-by: Albert J. Wong <ajwong@chromium.org>
Cr-Commit-Position: refs/heads/master@{#505808}
2017-10-02 22:02:49 +00:00
Brett Wilson
508162c316 Add base:: qualification to callback examples.
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}
2017-09-27 22:24:46 +00:00
Yuri Wiitala
b8d22ce2a6 Docs: Add note about std::move() resetting a Callback.
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}
2017-07-14 21:29:32 +00:00
tzik
298f67afd0 Update //docs/callback.md for OnceCallback support of PostTask impls
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}
2017-04-24 06:14:13 +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
michaelpg
126f704d1c Fix OnceCallback example in docs/callback.md
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}
2017-03-14 23:22:53 +00:00
tzik
7c0c0cf17a Update //docs/callback.md for OnceCallback and RepeatingCallback
Review-Url: https://codereview.chromium.org/2318113002
Cr-Commit-Position: refs/heads/master@{#423110}
2016-10-05 08:15:59 +00:00
tzik
a431351621 Fix docs/callback.md style
* Add document title
* Fix line wrapping

Review-Url: https://codereview.chromium.org/2314463002
Cr-Commit-Position: refs/heads/master@{#416597}
2016-09-06 06:52:51 +00:00
tzik
703f156dc1 Move documentation of base::Callback from base/callback.h to docs/callback.md
BUG=554299

Review-Url: https://codereview.chromium.org/2300983004
Cr-Commit-Position: refs/heads/master@{#416208}
2016-09-02 07:38:56 +00:00