Commit b2695fc9 authored by kylechar's avatar kylechar Committed by Commit Bot

base: Cleanup callback types (part 2).

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: Idb7bf334fb06a407bf65e4ffb4cc2e19dd8a5195
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1572809
Commit-Queue: kylechar <kylechar@chromium.org>
Reviewed-by: default avatarFrançois Doray <fdoray@chromium.org>
Cr-Commit-Position: refs/heads/master@{#653580}
parent 42e91471
...@@ -48,11 +48,11 @@ AtExitManager::~AtExitManager() { ...@@ -48,11 +48,11 @@ AtExitManager::~AtExitManager() {
// static // static
void AtExitManager::RegisterCallback(AtExitCallbackType func, void* param) { void AtExitManager::RegisterCallback(AtExitCallbackType func, void* param) {
DCHECK(func); DCHECK(func);
RegisterTask(base::Bind(func, param)); RegisterTask(base::BindOnce(func, param));
} }
// static // static
void AtExitManager::RegisterTask(base::Closure task) { void AtExitManager::RegisterTask(base::OnceClosure task) {
if (!g_top_manager) { if (!g_top_manager) {
NOTREACHED() << "Tried to RegisterCallback without an AtExitManager"; NOTREACHED() << "Tried to RegisterCallback without an AtExitManager";
return; return;
...@@ -75,7 +75,7 @@ void AtExitManager::ProcessCallbacksNow() { ...@@ -75,7 +75,7 @@ void AtExitManager::ProcessCallbacksNow() {
// Callbacks may try to add new callbacks, so run them without holding // Callbacks may try to add new callbacks, so run them without holding
// |lock_|. This is an error and caught by the DCHECK in RegisterTask(), but // |lock_|. This is an error and caught by the DCHECK in RegisterTask(), but
// handle it gracefully in release builds so we don't deadlock. // handle it gracefully in release builds so we don't deadlock.
base::stack<base::Closure> tasks; base::stack<base::OnceClosure> tasks;
{ {
AutoLock lock(g_top_manager->lock_); AutoLock lock(g_top_manager->lock_);
tasks.swap(g_top_manager->stack_); tasks.swap(g_top_manager->stack_);
...@@ -89,8 +89,7 @@ void AtExitManager::ProcessCallbacksNow() { ...@@ -89,8 +89,7 @@ void AtExitManager::ProcessCallbacksNow() {
ScopedAllowCrossThreadRefCountAccess allow_cross_thread_ref_count_access; ScopedAllowCrossThreadRefCountAccess allow_cross_thread_ref_count_access;
while (!tasks.empty()) { while (!tasks.empty()) {
base::Closure task = tasks.top(); std::move(tasks.top()).Run();
task.Run();
tasks.pop(); tasks.pop();
} }
......
...@@ -43,7 +43,7 @@ class BASE_EXPORT AtExitManager { ...@@ -43,7 +43,7 @@ class BASE_EXPORT AtExitManager {
static void RegisterCallback(AtExitCallbackType func, void* param); static void RegisterCallback(AtExitCallbackType func, void* param);
// Registers the specified task to be called at exit. // Registers the specified task to be called at exit.
static void RegisterTask(base::Closure task); static void RegisterTask(base::OnceClosure task);
// Calls the functions registered with RegisterCallback in LIFO order. It // Calls the functions registered with RegisterCallback in LIFO order. It
// is possible to register new callbacks after calling this function. // is possible to register new callbacks after calling this function.
...@@ -63,7 +63,7 @@ class BASE_EXPORT AtExitManager { ...@@ -63,7 +63,7 @@ class BASE_EXPORT AtExitManager {
private: private:
base::Lock lock_; base::Lock lock_;
base::stack<base::Closure> stack_ GUARDED_BY(lock_); base::stack<base::OnceClosure> stack_ GUARDED_BY(lock_);
#if DCHECK_IS_ON() #if DCHECK_IS_ON()
bool processing_callbacks_ GUARDED_BY(lock_) = false; bool processing_callbacks_ GUARDED_BY(lock_) = false;
......
...@@ -81,7 +81,7 @@ TEST_F(AtExitTest, Param) { ...@@ -81,7 +81,7 @@ TEST_F(AtExitTest, Param) {
TEST_F(AtExitTest, Task) { TEST_F(AtExitTest, Task) {
ZeroTestCounters(); ZeroTestCounters();
base::AtExitManager::RegisterTask(base::Bind(&ExpectParamIsCounter, base::AtExitManager::RegisterTask(
&g_test_counter_1)); base::BindOnce(&ExpectParamIsCounter, &g_test_counter_1));
base::AtExitManager::ProcessCallbacksNow(); base::AtExitManager::ProcessCallbacksNow();
} }
...@@ -16,8 +16,9 @@ class RepeatingCallback; ...@@ -16,8 +16,9 @@ class RepeatingCallback;
template <typename Signature> template <typename Signature>
using Callback = RepeatingCallback<Signature>; using Callback = RepeatingCallback<Signature>;
// Syntactic sugar to make Callback<void()> easier to declare since it // Syntactic sugar to make OnceClosure<void()> and RepeatingClosure<void()>
// will be used in a lot of APIs with delayed execution. // easier to declare since they will be used in a lot of APIs with delayed
// execution.
using OnceClosure = OnceCallback<void()>; using OnceClosure = OnceCallback<void()>;
using RepeatingClosure = RepeatingCallback<void()>; using RepeatingClosure = RepeatingCallback<void()>;
using Closure = Callback<void()>; using Closure = Callback<void()>;
......
...@@ -61,7 +61,7 @@ class Adder { ...@@ -61,7 +61,7 @@ class Adder {
if (!added_) { if (!added_) {
added_ = true; added_ = true;
subscription_ = subscription_ =
cb_reg_->Add(Bind(&Adder::IncrementTotal, Unretained(this))); cb_reg_->Add(BindRepeating(&Adder::IncrementTotal, Unretained(this)));
} }
} }
void IncrementTotal() { total_++; } void IncrementTotal() { total_++; }
...@@ -119,35 +119,38 @@ TEST(CallbackListTest, ArityTest) { ...@@ -119,35 +119,38 @@ TEST(CallbackListTest, ArityTest) {
CallbackList<void(int)> c1; CallbackList<void(int)> c1;
std::unique_ptr<CallbackList<void(int)>::Subscription> subscription1 = std::unique_ptr<CallbackList<void(int)>::Subscription> subscription1 =
c1.Add(Bind(&Summer::AddOneParam, Unretained(&s))); c1.Add(BindRepeating(&Summer::AddOneParam, Unretained(&s)));
c1.Notify(1); c1.Notify(1);
EXPECT_EQ(1, s.value()); EXPECT_EQ(1, s.value());
CallbackList<void(int, int)> c2; CallbackList<void(int, int)> c2;
std::unique_ptr<CallbackList<void(int, int)>::Subscription> subscription2 = std::unique_ptr<CallbackList<void(int, int)>::Subscription> subscription2 =
c2.Add(Bind(&Summer::AddTwoParam, Unretained(&s))); c2.Add(BindRepeating(&Summer::AddTwoParam, Unretained(&s)));
c2.Notify(1, 2); c2.Notify(1, 2);
EXPECT_EQ(3, s.value()); EXPECT_EQ(3, s.value());
CallbackList<void(int, int, int)> c3; CallbackList<void(int, int, int)> c3;
std::unique_ptr<CallbackList<void(int, int, int)>::Subscription> std::unique_ptr<CallbackList<void(int, int, int)>::Subscription>
subscription3 = c3.Add(Bind(&Summer::AddThreeParam, Unretained(&s))); subscription3 =
c3.Add(BindRepeating(&Summer::AddThreeParam, Unretained(&s)));
c3.Notify(1, 2, 3); c3.Notify(1, 2, 3);
EXPECT_EQ(6, s.value()); EXPECT_EQ(6, s.value());
CallbackList<void(int, int, int, int)> c4; CallbackList<void(int, int, int, int)> c4;
std::unique_ptr<CallbackList<void(int, int, int, int)>::Subscription> std::unique_ptr<CallbackList<void(int, int, int, int)>::Subscription>
subscription4 = c4.Add(Bind(&Summer::AddFourParam, Unretained(&s))); subscription4 =
c4.Add(BindRepeating(&Summer::AddFourParam, Unretained(&s)));
c4.Notify(1, 2, 3, 4); c4.Notify(1, 2, 3, 4);
EXPECT_EQ(10, s.value()); EXPECT_EQ(10, s.value());
CallbackList<void(int, int, int, int, int)> c5; CallbackList<void(int, int, int, int, int)> c5;
std::unique_ptr<CallbackList<void(int, int, int, int, int)>::Subscription> std::unique_ptr<CallbackList<void(int, int, int, int, int)>::Subscription>
subscription5 = c5.Add(Bind(&Summer::AddFiveParam, Unretained(&s))); subscription5 =
c5.Add(BindRepeating(&Summer::AddFiveParam, Unretained(&s)));
c5.Notify(1, 2, 3, 4, 5); c5.Notify(1, 2, 3, 4, 5);
EXPECT_EQ(15, s.value()); EXPECT_EQ(15, s.value());
...@@ -155,7 +158,8 @@ TEST(CallbackListTest, ArityTest) { ...@@ -155,7 +158,8 @@ TEST(CallbackListTest, ArityTest) {
CallbackList<void(int, int, int, int, int, int)> c6; CallbackList<void(int, int, int, int, int, int)> c6;
std::unique_ptr< std::unique_ptr<
CallbackList<void(int, int, int, int, int, int)>::Subscription> CallbackList<void(int, int, int, int, int, int)>::Subscription>
subscription6 = c6.Add(Bind(&Summer::AddSixParam, Unretained(&s))); subscription6 =
c6.Add(BindRepeating(&Summer::AddSixParam, Unretained(&s)));
c6.Notify(1, 2, 3, 4, 5, 6); c6.Notify(1, 2, 3, 4, 5, 6);
EXPECT_EQ(21, s.value()); EXPECT_EQ(21, s.value());
...@@ -168,9 +172,9 @@ TEST(CallbackListTest, BasicTest) { ...@@ -168,9 +172,9 @@ TEST(CallbackListTest, BasicTest) {
Listener a, b, c; Listener a, b, c;
std::unique_ptr<CallbackList<void(void)>::Subscription> a_subscription = std::unique_ptr<CallbackList<void(void)>::Subscription> a_subscription =
cb_reg.Add(Bind(&Listener::IncrementTotal, Unretained(&a))); cb_reg.Add(BindRepeating(&Listener::IncrementTotal, Unretained(&a)));
std::unique_ptr<CallbackList<void(void)>::Subscription> b_subscription = std::unique_ptr<CallbackList<void(void)>::Subscription> b_subscription =
cb_reg.Add(Bind(&Listener::IncrementTotal, Unretained(&b))); cb_reg.Add(BindRepeating(&Listener::IncrementTotal, Unretained(&b)));
EXPECT_TRUE(a_subscription.get()); EXPECT_TRUE(a_subscription.get());
EXPECT_TRUE(b_subscription.get()); EXPECT_TRUE(b_subscription.get());
...@@ -183,7 +187,7 @@ TEST(CallbackListTest, BasicTest) { ...@@ -183,7 +187,7 @@ TEST(CallbackListTest, BasicTest) {
b_subscription.reset(); b_subscription.reset();
std::unique_ptr<CallbackList<void(void)>::Subscription> c_subscription = std::unique_ptr<CallbackList<void(void)>::Subscription> c_subscription =
cb_reg.Add(Bind(&Listener::IncrementTotal, Unretained(&c))); cb_reg.Add(BindRepeating(&Listener::IncrementTotal, Unretained(&c)));
cb_reg.Notify(); cb_reg.Notify();
...@@ -203,9 +207,11 @@ TEST(CallbackListTest, BasicTestWithParams) { ...@@ -203,9 +207,11 @@ TEST(CallbackListTest, BasicTestWithParams) {
Listener a(1), b(-1), c(1); Listener a(1), b(-1), c(1);
std::unique_ptr<CallbackList<void(int)>::Subscription> a_subscription = std::unique_ptr<CallbackList<void(int)>::Subscription> a_subscription =
cb_reg.Add(Bind(&Listener::IncrementByMultipleOfScaler, Unretained(&a))); cb_reg.Add(BindRepeating(&Listener::IncrementByMultipleOfScaler,
Unretained(&a)));
std::unique_ptr<CallbackList<void(int)>::Subscription> b_subscription = std::unique_ptr<CallbackList<void(int)>::Subscription> b_subscription =
cb_reg.Add(Bind(&Listener::IncrementByMultipleOfScaler, Unretained(&b))); cb_reg.Add(BindRepeating(&Listener::IncrementByMultipleOfScaler,
Unretained(&b)));
EXPECT_TRUE(a_subscription.get()); EXPECT_TRUE(a_subscription.get());
EXPECT_TRUE(b_subscription.get()); EXPECT_TRUE(b_subscription.get());
...@@ -218,7 +224,8 @@ TEST(CallbackListTest, BasicTestWithParams) { ...@@ -218,7 +224,8 @@ TEST(CallbackListTest, BasicTestWithParams) {
b_subscription.reset(); b_subscription.reset();
std::unique_ptr<CallbackList<void(int)>::Subscription> c_subscription = std::unique_ptr<CallbackList<void(int)>::Subscription> c_subscription =
cb_reg.Add(Bind(&Listener::IncrementByMultipleOfScaler, Unretained(&c))); cb_reg.Add(BindRepeating(&Listener::IncrementByMultipleOfScaler,
Unretained(&c)));
cb_reg.Notify(10); cb_reg.Notify(10);
...@@ -239,15 +246,15 @@ TEST(CallbackListTest, RemoveCallbacksDuringIteration) { ...@@ -239,15 +246,15 @@ TEST(CallbackListTest, RemoveCallbacksDuringIteration) {
Remover remover_1, remover_2; Remover remover_1, remover_2;
std::unique_ptr<CallbackList<void(void)>::Subscription> remover_1_sub = std::unique_ptr<CallbackList<void(void)>::Subscription> remover_1_sub =
cb_reg.Add( cb_reg.Add(BindRepeating(&Remover::IncrementTotalAndRemove,
Bind(&Remover::IncrementTotalAndRemove, Unretained(&remover_1))); Unretained(&remover_1)));
std::unique_ptr<CallbackList<void(void)>::Subscription> remover_2_sub = std::unique_ptr<CallbackList<void(void)>::Subscription> remover_2_sub =
cb_reg.Add( cb_reg.Add(BindRepeating(&Remover::IncrementTotalAndRemove,
Bind(&Remover::IncrementTotalAndRemove, Unretained(&remover_2))); Unretained(&remover_2)));
std::unique_ptr<CallbackList<void(void)>::Subscription> a_subscription = std::unique_ptr<CallbackList<void(void)>::Subscription> a_subscription =
cb_reg.Add(Bind(&Listener::IncrementTotal, Unretained(&a))); cb_reg.Add(BindRepeating(&Listener::IncrementTotal, Unretained(&a)));
std::unique_ptr<CallbackList<void(void)>::Subscription> b_subscription = std::unique_ptr<CallbackList<void(void)>::Subscription> b_subscription =
cb_reg.Add(Bind(&Listener::IncrementTotal, Unretained(&b))); cb_reg.Add(BindRepeating(&Listener::IncrementTotal, Unretained(&b)));
// |remover_1| will remove itself. // |remover_1| will remove itself.
remover_1.SetSubscriptionToRemove(std::move(remover_1_sub)); remover_1.SetSubscriptionToRemove(std::move(remover_1_sub));
...@@ -280,9 +287,9 @@ TEST(CallbackListTest, AddCallbacksDuringIteration) { ...@@ -280,9 +287,9 @@ TEST(CallbackListTest, AddCallbacksDuringIteration) {
Adder a(&cb_reg); Adder a(&cb_reg);
Listener b; Listener b;
std::unique_ptr<CallbackList<void(void)>::Subscription> a_subscription = std::unique_ptr<CallbackList<void(void)>::Subscription> a_subscription =
cb_reg.Add(Bind(&Adder::AddCallback, Unretained(&a))); cb_reg.Add(BindRepeating(&Adder::AddCallback, Unretained(&a)));
std::unique_ptr<CallbackList<void(void)>::Subscription> b_subscription = std::unique_ptr<CallbackList<void(void)>::Subscription> b_subscription =
cb_reg.Add(Bind(&Listener::IncrementTotal, Unretained(&b))); cb_reg.Add(BindRepeating(&Listener::IncrementTotal, Unretained(&b)));
cb_reg.Notify(); cb_reg.Notify();
...@@ -307,7 +314,7 @@ TEST(CallbackList, RemovalCallback) { ...@@ -307,7 +314,7 @@ TEST(CallbackList, RemovalCallback) {
Counter remove_count; Counter remove_count;
CallbackList<void(void)> cb_reg; CallbackList<void(void)> cb_reg;
cb_reg.set_removal_callback( cb_reg.set_removal_callback(
Bind(&Counter::Increment, Unretained(&remove_count))); BindRepeating(&Counter::Increment, Unretained(&remove_count)));
std::unique_ptr<CallbackList<void(void)>::Subscription> subscription = std::unique_ptr<CallbackList<void(void)>::Subscription> subscription =
cb_reg.Add(DoNothing()); cb_reg.Add(DoNothing());
...@@ -320,11 +327,11 @@ TEST(CallbackList, RemovalCallback) { ...@@ -320,11 +327,11 @@ TEST(CallbackList, RemovalCallback) {
// Configure two subscriptions to remove themselves. // Configure two subscriptions to remove themselves.
Remover remover_1, remover_2; Remover remover_1, remover_2;
std::unique_ptr<CallbackList<void(void)>::Subscription> remover_1_sub = std::unique_ptr<CallbackList<void(void)>::Subscription> remover_1_sub =
cb_reg.Add( cb_reg.Add(BindRepeating(&Remover::IncrementTotalAndRemove,
Bind(&Remover::IncrementTotalAndRemove, Unretained(&remover_1))); Unretained(&remover_1)));
std::unique_ptr<CallbackList<void(void)>::Subscription> remover_2_sub = std::unique_ptr<CallbackList<void(void)>::Subscription> remover_2_sub =
cb_reg.Add( cb_reg.Add(BindRepeating(&Remover::IncrementTotalAndRemove,
Bind(&Remover::IncrementTotalAndRemove, Unretained(&remover_2))); Unretained(&remover_2)));
remover_1.SetSubscriptionToRemove(std::move(remover_1_sub)); remover_1.SetSubscriptionToRemove(std::move(remover_1_sub));
remover_2.SetSubscriptionToRemove(std::move(remover_2_sub)); remover_2.SetSubscriptionToRemove(std::move(remover_2_sub));
......
...@@ -47,7 +47,7 @@ void WontCompile() { ...@@ -47,7 +47,7 @@ void WontCompile() {
FooListener f; FooListener f;
CallbackList<void(std::unique_ptr<Foo>)> c1; CallbackList<void(std::unique_ptr<Foo>)> c1;
std::unique_ptr<CallbackList<void(std::unique_ptr<Foo>)>::Subscription> sub = std::unique_ptr<CallbackList<void(std::unique_ptr<Foo>)>::Subscription> sub =
c1.Add(Bind(&FooListener::GotAScopedFoo, Unretained(&f))); c1.Add(BindRepeating(&FooListener::GotAScopedFoo, Unretained(&f)));
c1.Notify(std::unique_ptr<Foo>(new Foo())); c1.Notify(std::unique_ptr<Foo>(new Foo()));
} }
......
...@@ -153,7 +153,7 @@ void FileDescriptorWatcher::Controller::Watcher:: ...@@ -153,7 +153,7 @@ void FileDescriptorWatcher::Controller::Watcher::
FileDescriptorWatcher::Controller::Controller(MessagePumpForIO::Mode mode, FileDescriptorWatcher::Controller::Controller(MessagePumpForIO::Mode mode,
int fd, int fd,
const Closure& callback) const RepeatingClosure& callback)
: callback_(callback), : callback_(callback),
io_thread_task_runner_( io_thread_task_runner_(
tls_fd_watcher.Get().Get()->io_thread_task_runner()), tls_fd_watcher.Get().Get()->io_thread_task_runner()),
...@@ -252,12 +252,12 @@ FileDescriptorWatcher::~FileDescriptorWatcher() { ...@@ -252,12 +252,12 @@ FileDescriptorWatcher::~FileDescriptorWatcher() {
} }
std::unique_ptr<FileDescriptorWatcher::Controller> std::unique_ptr<FileDescriptorWatcher::Controller>
FileDescriptorWatcher::WatchReadable(int fd, const Closure& callback) { FileDescriptorWatcher::WatchReadable(int fd, const RepeatingClosure& callback) {
return WrapUnique(new Controller(MessagePumpForIO::WATCH_READ, fd, callback)); return WrapUnique(new Controller(MessagePumpForIO::WATCH_READ, fd, callback));
} }
std::unique_ptr<FileDescriptorWatcher::Controller> std::unique_ptr<FileDescriptorWatcher::Controller>
FileDescriptorWatcher::WatchWritable(int fd, const Closure& callback) { FileDescriptorWatcher::WatchWritable(int fd, const RepeatingClosure& callback) {
return WrapUnique( return WrapUnique(
new Controller(MessagePumpForIO::WATCH_WRITE, fd, callback)); new Controller(MessagePumpForIO::WATCH_WRITE, fd, callback));
} }
......
...@@ -48,7 +48,9 @@ class BASE_EXPORT FileDescriptorWatcher { ...@@ -48,7 +48,9 @@ class BASE_EXPORT FileDescriptorWatcher {
// Registers |callback| to be invoked when |fd| is readable or writable // Registers |callback| to be invoked when |fd| is readable or writable
// without blocking (depending on |mode|). // without blocking (depending on |mode|).
Controller(MessagePumpForIO::Mode mode, int fd, const Closure& callback); Controller(MessagePumpForIO::Mode mode,
int fd,
const RepeatingClosure& callback);
// Starts watching the file descriptor. // Starts watching the file descriptor.
void StartWatching(); void StartWatching();
...@@ -58,7 +60,7 @@ class BASE_EXPORT FileDescriptorWatcher { ...@@ -58,7 +60,7 @@ class BASE_EXPORT FileDescriptorWatcher {
// The callback to run when the watched file descriptor is readable or // The callback to run when the watched file descriptor is readable or
// writable without blocking. // writable without blocking.
Closure callback_; RepeatingClosure callback_;
// TaskRunner associated with the MessageLoopForIO that watches the file // TaskRunner associated with the MessageLoopForIO that watches the file
// descriptor. // descriptor.
...@@ -100,10 +102,12 @@ class BASE_EXPORT FileDescriptorWatcher { ...@@ -100,10 +102,12 @@ class BASE_EXPORT FileDescriptorWatcher {
// must return true (these conditions are met at least on all ThreadPool // must return true (these conditions are met at least on all ThreadPool
// threads as well as on threads backed by a MessageLoopForIO). |fd| must // threads as well as on threads backed by a MessageLoopForIO). |fd| must
// outlive the returned Controller. // outlive the returned Controller.
static std::unique_ptr<Controller> WatchReadable(int fd, static std::unique_ptr<Controller> WatchReadable(
const Closure& callback); int fd,
static std::unique_ptr<Controller> WatchWritable(int fd, const RepeatingClosure& callback);
const Closure& callback); static std::unique_ptr<Controller> WatchWritable(
int fd,
const RepeatingClosure& callback);
// Asserts that usage of this API is allowed on this thread. // Asserts that usage of this API is allowed on this thread.
static void AssertAllowed() static void AssertAllowed()
......
...@@ -101,7 +101,7 @@ class FileDescriptorWatcherTest ...@@ -101,7 +101,7 @@ class FileDescriptorWatcherTest
std::unique_ptr<FileDescriptorWatcher::Controller> controller = std::unique_ptr<FileDescriptorWatcher::Controller> controller =
FileDescriptorWatcher::WatchReadable( FileDescriptorWatcher::WatchReadable(
read_file_descriptor(), read_file_descriptor(),
Bind(&Mock::ReadableCallback, Unretained(&mock_))); BindRepeating(&Mock::ReadableCallback, Unretained(&mock_)));
EXPECT_TRUE(controller); EXPECT_TRUE(controller);
// Unless read_file_descriptor() was readable before the callback was // Unless read_file_descriptor() was readable before the callback was
...@@ -117,7 +117,7 @@ class FileDescriptorWatcherTest ...@@ -117,7 +117,7 @@ class FileDescriptorWatcherTest
std::unique_ptr<FileDescriptorWatcher::Controller> controller = std::unique_ptr<FileDescriptorWatcher::Controller> controller =
FileDescriptorWatcher::WatchWritable( FileDescriptorWatcher::WatchWritable(
write_file_descriptor(), write_file_descriptor(),
Bind(&Mock::WritableCallback, Unretained(&mock_))); BindRepeating(&Mock::WritableCallback, Unretained(&mock_)));
EXPECT_TRUE(controller); EXPECT_TRUE(controller);
return controller; return controller;
} }
......
...@@ -35,7 +35,8 @@ class BASE_EXPORT FilePathWatcher { ...@@ -35,7 +35,8 @@ class BASE_EXPORT FilePathWatcher {
// Callback type for Watch(). |path| points to the file that was updated, // Callback type for Watch(). |path| points to the file that was updated,
// and |error| is true if the platform specific code detected an error. In // and |error| is true if the platform specific code detected an error. In
// that case, the callback won't be invoked again. // that case, the callback won't be invoked again.
typedef base::Callback<void(const FilePath& path, bool error)> Callback; using Callback =
base::RepeatingCallback<void(const FilePath& path, bool error)>;
// Used internally to encapsulate different members on different platforms. // Used internally to encapsulate different members on different platforms.
class PlatformDelegate { class PlatformDelegate {
......
...@@ -276,8 +276,8 @@ bool FilePathWatcherKQueue::Watch(const FilePath& path, ...@@ -276,8 +276,8 @@ bool FilePathWatcherKQueue::Watch(const FilePath& path,
// callback cannot be invoked after |kqueue_watch_controller_| (which is a // callback cannot be invoked after |kqueue_watch_controller_| (which is a
// member of |this|) has been deleted. // member of |this|) has been deleted.
kqueue_watch_controller_ = FileDescriptorWatcher::WatchReadable( kqueue_watch_controller_ = FileDescriptorWatcher::WatchReadable(
kqueue_, kqueue_, BindRepeating(&FilePathWatcherKQueue::OnKQueueReadable,
Bind(&FilePathWatcherKQueue::OnKQueueReadable, Unretained(this))); Unretained(this)));
return true; return true;
} }
......
...@@ -218,9 +218,9 @@ bool FilePathWatcherTest::SetupWatch(const FilePath& target, ...@@ -218,9 +218,9 @@ bool FilePathWatcherTest::SetupWatch(const FilePath& target,
FilePathWatcher* watcher, FilePathWatcher* watcher,
TestDelegateBase* delegate, TestDelegateBase* delegate,
bool recursive_watch) { bool recursive_watch) {
return watcher->Watch( return watcher->Watch(target, recursive_watch,
target, recursive_watch, base::BindRepeating(&TestDelegateBase::OnFileChanged,
base::Bind(&TestDelegateBase::OnFileChanged, delegate->AsWeakPtr())); delegate->AsWeakPtr()));
} }
// Basic test: Create the file and verify that we notice. // Basic test: Create the file and verify that we notice.
......
...@@ -2392,7 +2392,7 @@ TEST_F(FileUtilTest, OpenFileNoInheritance) { ...@@ -2392,7 +2392,7 @@ TEST_F(FileUtilTest, OpenFileNoInheritance) {
FILE* file = OpenFile(file_path, mode); FILE* file = OpenFile(file_path, mode);
ASSERT_NE(nullptr, file); ASSERT_NE(nullptr, file);
{ {
ScopedClosureRunner file_closer(Bind(IgnoreResult(&CloseFile), file)); ScopedClosureRunner file_closer(BindOnce(IgnoreResult(&CloseFile), file));
bool is_inheritable = true; bool is_inheritable = true;
ASSERT_NO_FATAL_FAILURE(GetIsInheritable(file, &is_inheritable)); ASSERT_NO_FATAL_FAILURE(GetIsInheritable(file, &is_inheritable));
EXPECT_FALSE(is_inheritable); EXPECT_FALSE(is_inheritable);
......
...@@ -280,7 +280,7 @@ void ImportantFileWriter::ScheduleWrite(DataSerializer* serializer) { ...@@ -280,7 +280,7 @@ void ImportantFileWriter::ScheduleWrite(DataSerializer* serializer) {
if (!timer().IsRunning()) { if (!timer().IsRunning()) {
timer().Start( timer().Start(
FROM_HERE, commit_interval_, FROM_HERE, commit_interval_,
Bind(&ImportantFileWriter::DoScheduledWrite, Unretained(this))); BindOnce(&ImportantFileWriter::DoScheduledWrite, Unretained(this)));
} }
} }
......
...@@ -93,10 +93,10 @@ class WriteCallbacksObserver { ...@@ -93,10 +93,10 @@ class WriteCallbacksObserver {
void WriteCallbacksObserver::ObserveNextWriteCallbacks( void WriteCallbacksObserver::ObserveNextWriteCallbacks(
ImportantFileWriter* writer) { ImportantFileWriter* writer) {
writer->RegisterOnNextWriteCallbacks( writer->RegisterOnNextWriteCallbacks(
base::Bind(&WriteCallbacksObserver::OnBeforeWrite, base::BindOnce(&WriteCallbacksObserver::OnBeforeWrite,
base::Unretained(this)), base::Unretained(this)),
base::Bind(&WriteCallbacksObserver::OnAfterWrite, base::BindOnce(&WriteCallbacksObserver::OnAfterWrite,
base::Unretained(this))); base::Unretained(this)));
} }
WriteCallbackObservationState WriteCallbackObservationState
......
...@@ -151,7 +151,7 @@ const TestFunctionDescription kTestFunctions[] = { ...@@ -151,7 +151,7 @@ const TestFunctionDescription kTestFunctions[] = {
// is around 16MB. // is around 16MB.
void RunSomeTests( void RunSomeTests(
const char format[], const char format[],
base::Callback<std::string(size_t length)> construct_test_string, base::RepeatingCallback<std::string(size_t length)> construct_test_string,
const TestFunctionDescription* test_functions, const TestFunctionDescription* test_functions,
size_t test_count) { size_t test_count) {
for (auto length : kTestLengths) { for (auto length : kTestLengths) {
...@@ -171,68 +171,61 @@ void RunSomeTests( ...@@ -171,68 +171,61 @@ void RunSomeTests(
} }
TEST(StreamingUtf8ValidatorPerfTest, OneByteRepeated) { TEST(StreamingUtf8ValidatorPerfTest, OneByteRepeated) {
RunSomeTests("%s: bytes=1 repeated length=%d repeat=%d", RunSomeTests(
base::Bind(ConstructRepeatedTestString, kOneByteSeqRangeStart), "%s: bytes=1 repeated length=%d repeat=%d",
kTestFunctions, base::BindRepeating(ConstructRepeatedTestString, kOneByteSeqRangeStart),
3); kTestFunctions, 3);
} }
TEST(StreamingUtf8ValidatorPerfTest, OneByteRange) { TEST(StreamingUtf8ValidatorPerfTest, OneByteRange) {
RunSomeTests("%s: bytes=1 ranged length=%d repeat=%d", RunSomeTests("%s: bytes=1 ranged length=%d repeat=%d",
base::Bind(ConstructRangedTestString, base::BindRepeating(ConstructRangedTestString,
kOneByteSeqRangeStart, kOneByteSeqRangeStart, kOneByteSeqRangeEnd),
kOneByteSeqRangeEnd), kTestFunctions, 3);
kTestFunctions,
3);
} }
TEST(StreamingUtf8ValidatorPerfTest, TwoByteRepeated) { TEST(StreamingUtf8ValidatorPerfTest, TwoByteRepeated) {
RunSomeTests("%s: bytes=2 repeated length=%d repeat=%d", RunSomeTests(
base::Bind(ConstructRepeatedTestString, kTwoByteSeqRangeStart), "%s: bytes=2 repeated length=%d repeat=%d",
kTestFunctions, base::BindRepeating(ConstructRepeatedTestString, kTwoByteSeqRangeStart),
2); kTestFunctions, 2);
} }
TEST(StreamingUtf8ValidatorPerfTest, TwoByteRange) { TEST(StreamingUtf8ValidatorPerfTest, TwoByteRange) {
RunSomeTests("%s: bytes=2 ranged length=%d repeat=%d", RunSomeTests("%s: bytes=2 ranged length=%d repeat=%d",
base::Bind(ConstructRangedTestString, base::BindRepeating(ConstructRangedTestString,
kTwoByteSeqRangeStart, kTwoByteSeqRangeStart, kTwoByteSeqRangeEnd),
kTwoByteSeqRangeEnd), kTestFunctions, 2);
kTestFunctions,
2);
} }
TEST(StreamingUtf8ValidatorPerfTest, ThreeByteRepeated) { TEST(StreamingUtf8ValidatorPerfTest, ThreeByteRepeated) {
RunSomeTests( RunSomeTests(
"%s: bytes=3 repeated length=%d repeat=%d", "%s: bytes=3 repeated length=%d repeat=%d",
base::Bind(ConstructRepeatedTestString, kThreeByteSeqRangeStart), base::BindRepeating(ConstructRepeatedTestString, kThreeByteSeqRangeStart),
kTestFunctions, kTestFunctions, 2);
2);
} }
TEST(StreamingUtf8ValidatorPerfTest, ThreeByteRange) { TEST(StreamingUtf8ValidatorPerfTest, ThreeByteRange) {
RunSomeTests("%s: bytes=3 ranged length=%d repeat=%d", RunSomeTests(
base::Bind(ConstructRangedTestString, "%s: bytes=3 ranged length=%d repeat=%d",
kThreeByteSeqRangeStart, base::BindRepeating(ConstructRangedTestString, kThreeByteSeqRangeStart,
kThreeByteSeqRangeEnd), kThreeByteSeqRangeEnd),
kTestFunctions, kTestFunctions, 2);
2);
} }
TEST(StreamingUtf8ValidatorPerfTest, FourByteRepeated) { TEST(StreamingUtf8ValidatorPerfTest, FourByteRepeated) {
RunSomeTests("%s: bytes=4 repeated length=%d repeat=%d", RunSomeTests(
base::Bind(ConstructRepeatedTestString, kFourByteSeqRangeStart), "%s: bytes=4 repeated length=%d repeat=%d",
kTestFunctions, base::BindRepeating(ConstructRepeatedTestString, kFourByteSeqRangeStart),
2); kTestFunctions, 2);
} }
TEST(StreamingUtf8ValidatorPerfTest, FourByteRange) { TEST(StreamingUtf8ValidatorPerfTest, FourByteRange) {
RunSomeTests("%s: bytes=4 ranged length=%d repeat=%d", RunSomeTests(
base::Bind(ConstructRangedTestString, "%s: bytes=4 ranged length=%d repeat=%d",
kFourByteSeqRangeStart, base::BindRepeating(ConstructRangedTestString, kFourByteSeqRangeStart,
kFourByteSeqRangeEnd), kFourByteSeqRangeEnd),
kTestFunctions, kTestFunctions, 2);
2);
} }
} // namespace } // namespace
......
...@@ -155,8 +155,8 @@ TEST_F(MessagePumpLibeventTest, StopWatcher) { ...@@ -155,8 +155,8 @@ TEST_F(MessagePumpLibeventTest, StopWatcher) {
OnLibeventNotification(pump.get(), &watcher); OnLibeventNotification(pump.get(), &watcher);
} }
void QuitMessageLoopAndStart(const Closure& quit_closure) { void QuitMessageLoopAndStart(OnceClosure quit_closure) {
quit_closure.Run(); std::move(quit_closure).Run();
RunLoop runloop(RunLoop::Type::kNestableTasksAllowed); RunLoop runloop(RunLoop::Type::kNestableTasksAllowed);
ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, runloop.QuitClosure()); ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, runloop.QuitClosure());
...@@ -196,18 +196,19 @@ void FatalClosure() { ...@@ -196,18 +196,19 @@ void FatalClosure() {
class QuitWatcher : public BaseWatcher { class QuitWatcher : public BaseWatcher {
public: public:
QuitWatcher(MessagePumpLibevent::FdWatchController* controller, QuitWatcher(MessagePumpLibevent::FdWatchController* controller,
base::Closure quit_closure) base::OnceClosure quit_closure)
: BaseWatcher(controller), quit_closure_(std::move(quit_closure)) {} : BaseWatcher(controller), quit_closure_(std::move(quit_closure)) {}
void OnFileCanReadWithoutBlocking(int /* fd */) override { void OnFileCanReadWithoutBlocking(int /* fd */) override {
// Post a fatal closure to the MessageLoop before we quit it. // Post a fatal closure to the MessageLoop before we quit it.
ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, BindOnce(&FatalClosure)); ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, BindOnce(&FatalClosure));
quit_closure_.Run(); if (quit_closure_)
std::move(quit_closure_).Run();
} }
private: private:
base::Closure quit_closure_; base::OnceClosure quit_closure_;
}; };
void WriteFDWrapper(const int fd, void WriteFDWrapper(const int fd,
......
...@@ -237,14 +237,13 @@ void StatisticsRecorder::InitLogOnShutdown() { ...@@ -237,14 +237,13 @@ void StatisticsRecorder::InitLogOnShutdown() {
} }
// static // static
bool StatisticsRecorder::SetCallback( bool StatisticsRecorder::SetCallback(const std::string& name,
const std::string& name, StatisticsRecorder::OnSampleCallback cb) {
const StatisticsRecorder::OnSampleCallback& cb) {
DCHECK(!cb.is_null()); DCHECK(!cb.is_null());
const AutoLock auto_lock(lock_.Get()); const AutoLock auto_lock(lock_.Get());
EnsureGlobalRecorderWhileLocked(); EnsureGlobalRecorderWhileLocked();
if (!top_->callbacks_.insert({name, cb}).second) if (!top_->callbacks_.insert({name, std::move(cb)}).second)
return false; return false;
const HistogramMap::const_iterator it = top_->histograms_.find(name); const HistogramMap::const_iterator it = top_->histograms_.find(name);
......
...@@ -143,7 +143,7 @@ class BASE_EXPORT StatisticsRecorder { ...@@ -143,7 +143,7 @@ class BASE_EXPORT StatisticsRecorder {
HistogramBase::Flags required_flags, HistogramBase::Flags required_flags,
HistogramSnapshotManager* snapshot_manager); HistogramSnapshotManager* snapshot_manager);
typedef base::Callback<void(HistogramBase::Sample)> OnSampleCallback; using OnSampleCallback = base::RepeatingCallback<void(HistogramBase::Sample)>;
// Sets the callback to notify when a new sample is recorded on the histogram // Sets the callback to notify when a new sample is recorded on the histogram
// referred to by |histogram_name|. Can be called before or after the // referred to by |histogram_name|. Can be called before or after the
...@@ -151,7 +151,7 @@ class BASE_EXPORT StatisticsRecorder { ...@@ -151,7 +151,7 @@ class BASE_EXPORT StatisticsRecorder {
// //
// This method is thread safe. // This method is thread safe.
static bool SetCallback(const std::string& histogram_name, static bool SetCallback(const std::string& histogram_name,
const OnSampleCallback& callback); OnSampleCallback callback);
// Clears any callback set on the histogram referred to by |histogram_name|. // Clears any callback set on the histogram referred to by |histogram_name|.
// //
......
...@@ -56,7 +56,7 @@ BASE_EXPORT void RecordAction(const UserMetricsAction& action); ...@@ -56,7 +56,7 @@ BASE_EXPORT void RecordAction(const UserMetricsAction& action);
BASE_EXPORT void RecordComputedAction(const std::string& action); BASE_EXPORT void RecordComputedAction(const std::string& action);
// Called with the action string. // Called with the action string.
typedef Callback<void(const std::string&)> ActionCallback; using ActionCallback = RepeatingCallback<void(const std::string&)>;
// Add/remove action callbacks (see above). // Add/remove action callbacks (see above).
// These functions must be called after the task runner has been set with // These functions must be called after the task runner has been set with
......
...@@ -155,9 +155,9 @@ class ObserverListThreadSafe : public internal::ObserverListThreadSafeBase { ...@@ -155,9 +155,9 @@ class ObserverListThreadSafe : public internal::ObserverListThreadSafeBase {
// delivery. // delivery.
template <typename Method, typename... Params> template <typename Method, typename... Params>
void Notify(const Location& from_here, Method m, Params&&... params) { void Notify(const Location& from_here, Method m, Params&&... params) {
Callback<void(ObserverType*)> method = RepeatingCallback<void(ObserverType*)> method =
Bind(&Dispatcher<ObserverType, Method>::Run, m, BindRepeating(&Dispatcher<ObserverType, Method>::Run, m,
std::forward<Params>(params)...); std::forward<Params>(params)...);
AutoLock lock(lock_); AutoLock lock(lock_);
for (const auto& observer : observers_) { for (const auto& observer : observers_) {
...@@ -174,11 +174,11 @@ class ObserverListThreadSafe : public internal::ObserverListThreadSafeBase { ...@@ -174,11 +174,11 @@ class ObserverListThreadSafe : public internal::ObserverListThreadSafeBase {
struct NotificationData : public NotificationDataBase { struct NotificationData : public NotificationDataBase {
NotificationData(ObserverListThreadSafe* observer_list_in, NotificationData(ObserverListThreadSafe* observer_list_in,
const Location& from_here_in, const Location& from_here_in,
const Callback<void(ObserverType*)>& method_in) const RepeatingCallback<void(ObserverType*)>& method_in)
: NotificationDataBase(observer_list_in, from_here_in), : NotificationDataBase(observer_list_in, from_here_in),
method(method_in) {} method(method_in) {}
Callback<void(ObserverType*)> method; RepeatingCallback<void(ObserverType*)> method;
}; };
~ObserverListThreadSafe() override = default; ~ObserverListThreadSafe() override = default;
......
...@@ -52,8 +52,8 @@ TEST(OneShotEventTest, CallsQueueAsDistinctTask) { ...@@ -52,8 +52,8 @@ TEST(OneShotEventTest, CallsQueueAsDistinctTask) {
scoped_refptr<base::TestSimpleTaskRunner> runner( scoped_refptr<base::TestSimpleTaskRunner> runner(
new base::TestSimpleTaskRunner); new base::TestSimpleTaskRunner);
int i = 0; int i = 0;
event.Post(FROM_HERE, base::Bind(&Increment, &i), runner); event.Post(FROM_HERE, base::BindOnce(&Increment, &i), runner);
event.Post(FROM_HERE, base::Bind(&Increment, &i), runner); event.Post(FROM_HERE, base::BindOnce(&Increment, &i), runner);
EXPECT_EQ(0U, runner->NumPendingTasks()); EXPECT_EQ(0U, runner->NumPendingTasks());
event.Signal(); event.Signal();
...@@ -69,8 +69,8 @@ TEST(OneShotEventTest, CallsQueue) { ...@@ -69,8 +69,8 @@ TEST(OneShotEventTest, CallsQueue) {
scoped_refptr<base::TestSimpleTaskRunner> runner( scoped_refptr<base::TestSimpleTaskRunner> runner(
new base::TestSimpleTaskRunner); new base::TestSimpleTaskRunner);
int i = 0; int i = 0;
event.Post(FROM_HERE, base::Bind(&Increment, &i), runner); event.Post(FROM_HERE, base::BindOnce(&Increment, &i), runner);
event.Post(FROM_HERE, base::Bind(&Increment, &i), runner); event.Post(FROM_HERE, base::BindOnce(&Increment, &i), runner);
EXPECT_EQ(0U, runner->NumPendingTasks()); EXPECT_EQ(0U, runner->NumPendingTasks());
event.Signal(); event.Signal();
ASSERT_EQ(2U, runner->NumPendingTasks()); ASSERT_EQ(2U, runner->NumPendingTasks());
...@@ -87,7 +87,7 @@ TEST(OneShotEventTest, CallsAfterSignalDontRunInline) { ...@@ -87,7 +87,7 @@ TEST(OneShotEventTest, CallsAfterSignalDontRunInline) {
int i = 0; int i = 0;
event.Signal(); event.Signal();
event.Post(FROM_HERE, base::Bind(&Increment, &i), runner); event.Post(FROM_HERE, base::BindOnce(&Increment, &i), runner);
EXPECT_EQ(1U, runner->NumPendingTasks()); EXPECT_EQ(1U, runner->NumPendingTasks());
EXPECT_EQ(0, i); EXPECT_EQ(0, i);
runner->RunPendingTasks(); runner->RunPendingTasks();
...@@ -102,8 +102,8 @@ TEST(OneShotEventTest, PostDefaultsToCurrentMessageLoop) { ...@@ -102,8 +102,8 @@ TEST(OneShotEventTest, PostDefaultsToCurrentMessageLoop) {
int runner_i = 0; int runner_i = 0;
int loop_i = 0; int loop_i = 0;
event.Post(FROM_HERE, base::Bind(&Increment, &runner_i), runner); event.Post(FROM_HERE, base::BindOnce(&Increment, &runner_i), runner);
event.Post(FROM_HERE, base::Bind(&Increment, &loop_i)); event.Post(FROM_HERE, base::BindOnce(&Increment, &loop_i));
event.Signal(); event.Signal();
EXPECT_EQ(1U, runner->NumPendingTasks()); EXPECT_EQ(1U, runner->NumPendingTasks());
EXPECT_EQ(0, runner_i); EXPECT_EQ(0, runner_i);
...@@ -119,7 +119,7 @@ void CheckSignaledAndPostIncrement( ...@@ -119,7 +119,7 @@ void CheckSignaledAndPostIncrement(
const scoped_refptr<base::SingleThreadTaskRunner>& runner, const scoped_refptr<base::SingleThreadTaskRunner>& runner,
int* i) { int* i) {
EXPECT_TRUE(event->is_signaled()); EXPECT_TRUE(event->is_signaled());
event->Post(FROM_HERE, base::Bind(&Increment, i), runner); event->Post(FROM_HERE, base::BindOnce(&Increment, i), runner);
} }
TEST(OneShotEventTest, IsSignaledAndPostsFromCallbackWork) { TEST(OneShotEventTest, IsSignaledAndPostsFromCallbackWork) {
...@@ -129,7 +129,7 @@ TEST(OneShotEventTest, IsSignaledAndPostsFromCallbackWork) { ...@@ -129,7 +129,7 @@ TEST(OneShotEventTest, IsSignaledAndPostsFromCallbackWork) {
int i = 0; int i = 0;
event.Post(FROM_HERE, event.Post(FROM_HERE,
base::Bind(&CheckSignaledAndPostIncrement, &event, runner, &i), base::BindOnce(&CheckSignaledAndPostIncrement, &event, runner, &i),
runner); runner);
EXPECT_EQ(0, i); EXPECT_EQ(0, i);
event.Signal(); event.Signal();
......
...@@ -69,8 +69,8 @@ EventLogMessage::~EventLogMessage() { ...@@ -69,8 +69,8 @@ EventLogMessage::~EventLogMessage() {
return; return;
} }
base::ScopedClosureRunner auto_deregister( base::ScopedClosureRunner auto_deregister(base::BindOnce(
base::Bind(base::IgnoreResult(&DeregisterEventSource), event_log_handle)); base::IgnoreResult(&DeregisterEventSource), event_log_handle));
std::string message(log_message_.str()); std::string message(log_message_.str());
WORD log_type = EVENTLOG_ERROR_TYPE; WORD log_type = EVENTLOG_ERROR_TYPE;
switch (log_message_.severity()) { switch (log_message_.severity()) {
......
...@@ -93,16 +93,18 @@ class BASE_EXPORT CancelableTaskTracker { ...@@ -93,16 +93,18 @@ class BASE_EXPORT CancelableTaskTracker {
std::move(reply), Owned(result))); std::move(reply), Owned(result)));
} }
// Callback version of PostTaskWithTraitsAndReplyWithResult above. // RepeatingCallback version of PostTaskWithTraitsAndReplyWithResult above.
// Though RepeatingCallback is convertible to OnceCallback, we need this since // Though RepeatingCallback is convertible to OnceCallback, we need this since
// we can not use template deduction and object conversion at once on the // we can not use template deduction and object conversion at once on the
// overload resolution. // overload resolution.
// TODO(tzik): Update all callers of the Callback version to use OnceCallback. // TODO(tzik): Update all callers of the RepeatingCallback version to use
// OnceCallback.
template <typename TaskReturnType, typename ReplyArgType> template <typename TaskReturnType, typename ReplyArgType>
TaskId PostTaskAndReplyWithResult(TaskRunner* task_runner, TaskId PostTaskAndReplyWithResult(
const Location& from_here, TaskRunner* task_runner,
Callback<TaskReturnType()> task, const Location& from_here,
Callback<void(ReplyArgType)> reply) { RepeatingCallback<TaskReturnType()> task,
RepeatingCallback<void(ReplyArgType)> reply) {
return PostTaskAndReplyWithResult( return PostTaskAndReplyWithResult(
task_runner, from_here, task_runner, from_here,
static_cast<OnceCallback<TaskReturnType()>>(std::move(task)), static_cast<OnceCallback<TaskReturnType()>>(std::move(task)),
......
...@@ -102,15 +102,16 @@ bool PostTaskAndReplyWithResult(const Location& from_here, ...@@ -102,15 +102,16 @@ bool PostTaskAndReplyWithResult(const Location& from_here,
from_here, TaskTraits(), std::move(task), std::move(reply)); from_here, TaskTraits(), std::move(task), std::move(reply));
} }
// Callback version of PostTaskAndReplyWithResult above. // RepeatingCallback version of PostTaskAndReplyWithResult above.
// Though RepeatingCallback is convertible to OnceCallback, we need this since // Though RepeatingCallback is convertible to OnceCallback, we need this since
// we can not use template deduction and object conversion at once on the // we can not use template deduction and object conversion at once on the
// overload resolution. // overload resolution.
// TODO(tzik): Update all callers of the Callback version to use OnceCallback. // TODO(tzik): Update all callers of the RepeatingCallback version to use
// OnceCallback.
template <typename TaskReturnType, typename ReplyArgType> template <typename TaskReturnType, typename ReplyArgType>
bool PostTaskAndReplyWithResult(const Location& from_here, bool PostTaskAndReplyWithResult(const Location& from_here,
Callback<TaskReturnType()> task, RepeatingCallback<TaskReturnType()> task,
Callback<void(ReplyArgType)> reply) { RepeatingCallback<void(ReplyArgType)> reply) {
return PostTaskAndReplyWithResult( return PostTaskAndReplyWithResult(
from_here, OnceCallback<TaskReturnType()>(std::move(task)), from_here, OnceCallback<TaskReturnType()>(std::move(task)),
OnceCallback<void(ReplyArgType)>(std::move(reply))); OnceCallback<void(ReplyArgType)>(std::move(reply)));
...@@ -163,16 +164,18 @@ bool PostTaskWithTraitsAndReplyWithResult( ...@@ -163,16 +164,18 @@ bool PostTaskWithTraitsAndReplyWithResult(
std::move(reply), Owned(result))); std::move(reply), Owned(result)));
} }
// Callback version of PostTaskWithTraitsAndReplyWithResult above. // RepeatingCallback version of PostTaskWithTraitsAndReplyWithResult above.
// Though RepeatingCallback is convertible to OnceCallback, we need this since // Though RepeatingCallback is convertible to OnceCallback, we need this since
// we can not use template deduction and object conversion at once on the // we can not use template deduction and object conversion at once on the
// overload resolution. // overload resolution.
// TODO(tzik): Update all callers of the Callback version to use OnceCallback. // TODO(tzik): Update all callers of the RepeatingCallback version to use
// OnceCallback.
template <typename TaskReturnType, typename ReplyArgType> template <typename TaskReturnType, typename ReplyArgType>
bool PostTaskWithTraitsAndReplyWithResult(const Location& from_here, bool PostTaskWithTraitsAndReplyWithResult(
const TaskTraits& traits, const Location& from_here,
Callback<TaskReturnType()> task, const TaskTraits& traits,
Callback<void(ReplyArgType)> reply) { RepeatingCallback<TaskReturnType()> task,
RepeatingCallback<void(ReplyArgType)> reply) {
return PostTaskWithTraitsAndReplyWithResult( return PostTaskWithTraitsAndReplyWithResult(
from_here, traits, OnceCallback<TaskReturnType()>(std::move(task)), from_here, traits, OnceCallback<TaskReturnType()>(std::move(task)),
OnceCallback<void(ReplyArgType)>(std::move(reply))); OnceCallback<void(ReplyArgType)>(std::move(reply)));
......
...@@ -48,17 +48,17 @@ bool PostTaskAndReplyWithResult(TaskRunner* task_runner, ...@@ -48,17 +48,17 @@ bool PostTaskAndReplyWithResult(TaskRunner* task_runner,
std::move(reply), Owned(result))); std::move(reply), Owned(result)));
} }
// Callback version of PostTaskAndReplyWithResult above. // RepeatingCallback version of PostTaskAndReplyWithResult above.
// Though RepeatingCallback is convertible to OnceCallback, we need this since // Though RepeatingCallback is convertible to OnceCallback, we need this since
// we cannot use template deduction and object conversion at once on the // we cannot use template deduction and object conversion at once on the
// overload resolution. // overload resolution.
// TODO(crbug.com/714018): Update all callers of the Callback version to use // TODO(crbug.com/714018): Update all callers of the RepeatingCallback version
// OnceCallback. // to use OnceCallback.
template <typename TaskReturnType, typename ReplyArgType> template <typename TaskReturnType, typename ReplyArgType>
bool PostTaskAndReplyWithResult(TaskRunner* task_runner, bool PostTaskAndReplyWithResult(TaskRunner* task_runner,
const Location& from_here, const Location& from_here,
Callback<TaskReturnType()> task, RepeatingCallback<TaskReturnType()> task,
Callback<void(ReplyArgType)> reply) { RepeatingCallback<void(ReplyArgType)> reply) {
return PostTaskAndReplyWithResult( return PostTaskAndReplyWithResult(
task_runner, from_here, OnceCallback<TaskReturnType()>(std::move(task)), task_runner, from_here, OnceCallback<TaskReturnType()>(std::move(task)),
OnceCallback<void(ReplyArgType)>(std::move(reply))); OnceCallback<void(ReplyArgType)>(std::move(reply)));
......
...@@ -26,7 +26,7 @@ struct BindLambdaHelper<F, R(Args...)> { ...@@ -26,7 +26,7 @@ struct BindLambdaHelper<F, R(Args...)> {
} // namespace internal } // namespace internal
// A variant of Bind() that can bind capturing lambdas for testing. // A variant of BindRepeating() that can bind capturing lambdas for testing.
// This doesn't support extra arguments binding as the lambda itself can do. // This doesn't support extra arguments binding as the lambda itself can do.
template <typename F> template <typename F>
decltype(auto) BindLambdaForTesting(F&& f) { decltype(auto) BindLambdaForTesting(F&& f) {
......
...@@ -486,7 +486,7 @@ void TestSuite::Initialize() { ...@@ -486,7 +486,7 @@ void TestSuite::Initialize() {
SuppressErrorDialogs(); SuppressErrorDialogs();
debug::SetSuppressDebugUI(true); debug::SetSuppressDebugUI(true);
assert_handler_ = std::make_unique<logging::ScopedLogAssertHandler>( assert_handler_ = std::make_unique<logging::ScopedLogAssertHandler>(
Bind(&TestSuite::UnitTestAssertHandler, Unretained(this))); BindRepeating(&TestSuite::UnitTestAssertHandler, Unretained(this)));
} }
test::InitializeICUForTesting(); test::InitializeICUForTesting();
......
...@@ -72,7 +72,8 @@ class BASE_EXPORT Thread : PlatformThread::Delegate { ...@@ -72,7 +72,8 @@ class BASE_EXPORT Thread : PlatformThread::Delegate {
}; };
struct BASE_EXPORT Options { struct BASE_EXPORT Options {
typedef Callback<std::unique_ptr<MessagePump>()> MessagePumpFactory; using MessagePumpFactory =
RepeatingCallback<std::unique_ptr<MessagePump>()>;
Options(); Options();
Options(MessageLoop::Type type, size_t size); Options(MessageLoop::Type type, size_t size);
......
...@@ -303,7 +303,7 @@ void TraceBufferChunk::EstimateTraceMemoryOverhead( ...@@ -303,7 +303,7 @@ void TraceBufferChunk::EstimateTraceMemoryOverhead(
TraceResultBuffer::OutputCallback TraceResultBuffer::OutputCallback
TraceResultBuffer::SimpleOutput::GetCallback() { TraceResultBuffer::SimpleOutput::GetCallback() {
return Bind(&SimpleOutput::Append, Unretained(this)); return BindRepeating(&SimpleOutput::Append, Unretained(this));
} }
void TraceResultBuffer::SimpleOutput::Append( void TraceResultBuffer::SimpleOutput::Append(
...@@ -315,9 +315,8 @@ TraceResultBuffer::TraceResultBuffer() : append_comma_(false) {} ...@@ -315,9 +315,8 @@ TraceResultBuffer::TraceResultBuffer() : append_comma_(false) {}
TraceResultBuffer::~TraceResultBuffer() = default; TraceResultBuffer::~TraceResultBuffer() = default;
void TraceResultBuffer::SetOutputCallback( void TraceResultBuffer::SetOutputCallback(OutputCallback json_chunk_callback) {
const OutputCallback& json_chunk_callback) { output_callback_ = std::move(json_chunk_callback);
output_callback_ = json_chunk_callback;
} }
void TraceResultBuffer::Start() { void TraceResultBuffer::Start() {
......
...@@ -85,7 +85,7 @@ class BASE_EXPORT TraceBuffer { ...@@ -85,7 +85,7 @@ class BASE_EXPORT TraceBuffer {
// to JSON output. // to JSON output.
class BASE_EXPORT TraceResultBuffer { class BASE_EXPORT TraceResultBuffer {
public: public:
typedef base::Callback<void(const std::string&)> OutputCallback; using OutputCallback = base::RepeatingCallback<void(const std::string&)>;
// If you don't need to stream JSON chunks out efficiently, and just want to // If you don't need to stream JSON chunks out efficiently, and just want to
// get a complete JSON string after calling Finish, use this struct to collect // get a complete JSON string after calling Finish, use this struct to collect
...@@ -106,7 +106,7 @@ class BASE_EXPORT TraceResultBuffer { ...@@ -106,7 +106,7 @@ class BASE_EXPORT TraceResultBuffer {
// JSON output and during AddFragment and Finish with following JSON output // JSON output and during AddFragment and Finish with following JSON output
// chunks. The callback target must live past the last calls to // chunks. The callback target must live past the last calls to
// TraceResultBuffer::Start/AddFragment/Finish. // TraceResultBuffer::Start/AddFragment/Finish.
void SetOutputCallback(const OutputCallback& json_chunk_callback); void SetOutputCallback(OutputCallback json_chunk_callback);
// Start JSON output. This resets all internal state, so you can reuse // Start JSON output. This resets all internal state, so you can reuse
// the TraceResultBuffer by calling Start. // the TraceResultBuffer by calling Start.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment