Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(427)

Unified Diff: base/message_loop/message_pump_glib_unittest.cc

Issue 2824533002: Migrate Bind to BindOnce or BindRepeating in //base/message_loop (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/message_loop/message_pump_glib_unittest.cc
diff --git a/base/message_loop/message_pump_glib_unittest.cc b/base/message_loop/message_pump_glib_unittest.cc
index bef0c8f63e122ef62c180291a31af381bb47b803..564de7d83f549eb09dfa186989b6096907acb1d1 100644
--- a/base/message_loop/message_pump_glib_unittest.cc
+++ b/base/message_loop/message_pump_glib_unittest.cc
@@ -59,27 +59,27 @@ class EventInjector {
void HandleDispatch() {
if (events_.empty())
return;
- Event event = events_[0];
+ Event event = std::move(events_[0]);
events_.erase(events_.begin());
++processed_events_;
if (!event.callback.is_null())
- event.callback.Run();
+ std::move(event.callback).Run();
else if (!event.task.is_null())
- event.task.Run();
+ std::move(event.task).Run();
}
// Adds an event to the queue. When "handled", executes |callback|.
// delay_ms is relative to the last event if any, or to Now() otherwise.
- void AddEvent(int delay_ms, const Closure& callback) {
- AddEventHelper(delay_ms, callback, Closure());
+ void AddEvent(int delay_ms, OnceClosure callback) {
+ AddEventHelper(delay_ms, std::move(callback), OnceClosure());
}
void AddDummyEvent(int delay_ms) {
- AddEventHelper(delay_ms, Closure(), Closure());
+ AddEventHelper(delay_ms, OnceClosure(), OnceClosure());
}
- void AddEventAsTask(int delay_ms, const Closure& task) {
- AddEventHelper(delay_ms, Closure(), task);
+ void AddEventAsTask(int delay_ms, OnceClosure task) {
+ AddEventHelper(delay_ms, OnceClosure(), std::move(task));
}
void Reset() {
@@ -92,16 +92,15 @@ class EventInjector {
private:
struct Event {
Time time;
- Closure callback;
- Closure task;
+ OnceClosure callback;
+ OnceClosure task;
};
struct Source : public GSource {
EventInjector* injector;
};
- void AddEventHelper(
- int delay_ms, const Closure& callback, const Closure& task) {
+ void AddEventHelper(int delay_ms, OnceClosure callback, OnceClosure task) {
Time last_time;
if (!events_.empty())
last_time = (events_.end()-1)->time;
@@ -109,8 +108,8 @@ class EventInjector {
last_time = Time::NowFromSystemTime();
Time future = last_time + TimeDelta::FromMilliseconds(delay_ms);
- EventInjector::Event event = {future, callback, task};
- events_.push_back(event);
+ EventInjector::Event event = {future, std::move(callback), std::move(task)};
+ events_.push_back(std::move(event));
}
static gboolean Prepare(GSource* source, gint* timeout_ms) {
@@ -154,8 +153,8 @@ void ExpectProcessedEvents(EventInjector* injector, int count) {
// Posts a task on the current message loop.
void PostMessageLoopTask(const tracked_objects::Location& from_here,
- const Closure& task) {
- ThreadTaskRunnerHandle::Get()->PostTask(from_here, task);
+ OnceClosure task) {
+ ThreadTaskRunnerHandle::Get()->PostTask(from_here, std::move(task));
}
// Test fixture.
@@ -208,24 +207,24 @@ TEST_F(MessagePumpGLibTest, TestEventTaskInterleave) {
// If changes cause this test to fail, it is reasonable to change it, but
// TestWorkWhileWaitingForEvents and TestEventsWhileWaitingForWork have to be
// changed accordingly, otherwise they can become flaky.
- injector()->AddEventAsTask(0, Bind(&DoNothing));
- Closure check_task =
- Bind(&ExpectProcessedEvents, Unretained(injector()), 2);
- Closure posted_task =
- Bind(&PostMessageLoopTask, FROM_HERE, check_task);
- injector()->AddEventAsTask(0, posted_task);
- injector()->AddEventAsTask(0, Bind(&DoNothing));
+ injector()->AddEventAsTask(0, BindOnce(&DoNothing));
+ OnceClosure check_task =
+ BindOnce(&ExpectProcessedEvents, Unretained(injector()), 2);
+ OnceClosure posted_task =
+ BindOnce(&PostMessageLoopTask, FROM_HERE, std::move(check_task));
+ injector()->AddEventAsTask(0, std::move(posted_task));
+ injector()->AddEventAsTask(0, BindOnce(&DoNothing));
injector()->AddEvent(0, MessageLoop::QuitWhenIdleClosure());
RunLoop().Run();
EXPECT_EQ(4, injector()->processed_events());
injector()->Reset();
- injector()->AddEventAsTask(0, Bind(&DoNothing));
- check_task =
- Bind(&ExpectProcessedEvents, Unretained(injector()), 2);
- posted_task = Bind(&PostMessageLoopTask, FROM_HERE, check_task);
- injector()->AddEventAsTask(0, posted_task);
- injector()->AddEventAsTask(10, Bind(&DoNothing));
+ injector()->AddEventAsTask(0, BindOnce(&DoNothing));
+ check_task = BindOnce(&ExpectProcessedEvents, Unretained(injector()), 2);
+ posted_task =
+ BindOnce(&PostMessageLoopTask, FROM_HERE, std::move(check_task));
+ injector()->AddEventAsTask(0, std::move(posted_task));
+ injector()->AddEventAsTask(10, BindOnce(&DoNothing));
injector()->AddEvent(0, MessageLoop::QuitWhenIdleClosure());
RunLoop().Run();
EXPECT_EQ(4, injector()->processed_events());
@@ -279,11 +278,11 @@ TEST_F(MessagePumpGLibTest, TestEventsWhileWaitingForWork) {
// After all the events have been processed, post a task that will check that
// the events have been processed (note: the task executes after the event
// that posted it has been handled, so we expect 11 at that point).
- Closure check_task =
- Bind(&ExpectProcessedEvents, Unretained(injector()), 11);
- Closure posted_task =
- Bind(&PostMessageLoopTask, FROM_HERE, check_task);
- injector()->AddEventAsTask(10, posted_task);
+ OnceClosure check_task =
+ BindOnce(&ExpectProcessedEvents, Unretained(injector()), 11);
+ OnceClosure posted_task =
+ BindOnce(&PostMessageLoopTask, FROM_HERE, std::move(check_task));
+ injector()->AddEventAsTask(10, std::move(posted_task));
// And then quit (relies on the condition tested by TestEventTaskInterleave).
injector()->AddEvent(10, MessageLoop::QuitWhenIdleClosure());
@@ -324,8 +323,8 @@ class ConcurrentHelper : public RefCounted<ConcurrentHelper> {
if (task_count_ == 0 && event_count_ == 0) {
MessageLoop::current()->QuitWhenIdle();
} else {
- injector_->AddEventAsTask(
- 0, Bind(&ConcurrentHelper::FromEvent, this));
+ injector_->AddEventAsTask(0,
+ BindOnce(&ConcurrentHelper::FromEvent, this));
}
}
@@ -357,10 +356,8 @@ TEST_F(MessagePumpGLibTest, TestConcurrentEventPostedTask) {
// Add 2 events to the queue to make sure it is always full (when we remove
// the event before processing it).
- injector()->AddEventAsTask(
- 0, Bind(&ConcurrentHelper::FromEvent, helper));
- injector()->AddEventAsTask(
- 0, Bind(&ConcurrentHelper::FromEvent, helper));
+ injector()->AddEventAsTask(0, BindOnce(&ConcurrentHelper::FromEvent, helper));
+ injector()->AddEventAsTask(0, BindOnce(&ConcurrentHelper::FromEvent, helper));
// Similarly post 2 tasks.
loop()->task_runner()->PostTask(

Powered by Google App Engine
This is Rietveld 408576698