From 1022458f506270ac5f1ac260916313847f7b54c3 Mon Sep 17 00:00:00 2001 From: fdoray Date: Thu, 30 Jun 2016 11:17:39 -0700 Subject: [PATCH] Remove calls to deprecated MessageLoop methods in base. This CL makes the following replacements in base: Before After ---------------------------------------------------------- x.PostTask() x.task_runner()->PostTask() PostDelayedTask() PostDelayedTask() ReleaseSoon() ReleaseSoon() DeleteSoon() DeleteSoon() x->PostTask() y->task_runner()->PostTask() PostDelayedTask() PostDelayedTask() ReleaseSoon() ReleaseSoon() DeleteSoon() DeleteSoon() x.Run() RunLoop().Run() x.RunUntilIdle() RunLoop().RunUntilIdle() x->Run() RunLoop().Run() x->RunUntilIdle() RunLoop().RunUntilIdle() If |x| isn't MessageLoopForUI::current() or MessageLoopForIO::current() ---------------------------------------------------------- |x| is a base::MessageLoop(ForUI|ForIO) or a pointer to a base::MessageLoop(ForUI|ForIO). This CL was generated using the MessageLoopDeprecatedMethods clang-tidy fix available on the associated bug. Only files that compile on Mac are affected. Follow-up CLs will make these replacements for other platforms. This CL doesn't change code behavior. BUG=616447 Review-Url: https://codereview.chromium.org/2103333006 Cr-Commit-Position: refs/heads/master@{#403224} --- ...deferred_sequenced_task_runner_unittest.cc | 19 +- base/files/file_path_watcher_unittest.cc | 8 +- base/files/file_proxy_unittest.cc | 31 +- base/files/file_util_proxy_unittest.cc | 7 +- base/files/important_file_writer_unittest.cc | 6 +- base/mac/libdispatch_task_runner_unittest.cc | 20 +- .../message_loop_task_runner_unittest.cc | 13 +- base/message_loop/message_loop_test.cc | 341 +++++++++--------- base/message_loop/message_loop_unittest.cc | 25 +- .../message_pump_libevent_unittest.cc | 25 +- base/message_loop/message_pump_perftest.cc | 10 +- base/observer_list_unittest.cc | 2 +- base/sequence_checker_unittest.cc | 5 +- .../waitable_event_watcher_unittest.cc | 2 +- base/test/launcher/test_launcher.cc | 3 +- base/test/power_monitor_test_base.cc | 7 +- base/test/sequenced_worker_pool_owner.cc | 3 +- base/test/test_message_loop.cc | 3 +- base/threading/thread.cc | 3 +- base/timer/timer_unittest.cc | 21 +- ...ace_event_system_stats_monitor_unittest.cc | 5 +- 21 files changed, 282 insertions(+), 277 deletions(-) diff --git a/base/deferred_sequenced_task_runner_unittest.cc b/base/deferred_sequenced_task_runner_unittest.cc index 1ddc3542496cac..e34827ab9eee31 100644 --- a/base/deferred_sequenced_task_runner_unittest.cc +++ b/base/deferred_sequenced_task_runner_unittest.cc @@ -8,6 +8,7 @@ #include "base/bind_helpers.h" #include "base/location.h" #include "base/memory/ref_counted.h" +#include "base/run_loop.h" #include "base/single_thread_task_runner.h" #include "base/threading/non_thread_safe.h" #include "base/threading/thread.h" @@ -69,14 +70,14 @@ class DeferredSequencedTaskRunnerTest : public testing::Test, TEST_F(DeferredSequencedTaskRunnerTest, Stopped) { PostExecuteTask(1); - loop_.RunUntilIdle(); + base::RunLoop().RunUntilIdle(); EXPECT_THAT(executed_task_ids_, testing::ElementsAre()); } TEST_F(DeferredSequencedTaskRunnerTest, Start) { StartRunner(); PostExecuteTask(1); - loop_.RunUntilIdle(); + base::RunLoop().RunUntilIdle(); EXPECT_THAT(executed_task_ids_, testing::ElementsAre(1)); } @@ -85,34 +86,34 @@ TEST_F(DeferredSequencedTaskRunnerTest, StartWithMultipleElements) { for (int i = 1; i < 5; ++i) PostExecuteTask(i); - loop_.RunUntilIdle(); + base::RunLoop().RunUntilIdle(); EXPECT_THAT(executed_task_ids_, testing::ElementsAre(1, 2, 3, 4)); } TEST_F(DeferredSequencedTaskRunnerTest, DeferredStart) { PostExecuteTask(1); - loop_.RunUntilIdle(); + base::RunLoop().RunUntilIdle(); EXPECT_THAT(executed_task_ids_, testing::ElementsAre()); StartRunner(); - loop_.RunUntilIdle(); + base::RunLoop().RunUntilIdle(); EXPECT_THAT(executed_task_ids_, testing::ElementsAre(1)); PostExecuteTask(2); - loop_.RunUntilIdle(); + base::RunLoop().RunUntilIdle(); EXPECT_THAT(executed_task_ids_, testing::ElementsAre(1, 2)); } TEST_F(DeferredSequencedTaskRunnerTest, DeferredStartWithMultipleElements) { for (int i = 1; i < 5; ++i) PostExecuteTask(i); - loop_.RunUntilIdle(); + base::RunLoop().RunUntilIdle(); EXPECT_THAT(executed_task_ids_, testing::ElementsAre()); StartRunner(); for (int i = 5; i < 9; ++i) PostExecuteTask(i); - loop_.RunUntilIdle(); + base::RunLoop().RunUntilIdle(); EXPECT_THAT(executed_task_ids_, testing::ElementsAre(1, 2, 3, 4, 5, 6, 7, 8)); } @@ -139,7 +140,7 @@ TEST_F(DeferredSequencedTaskRunnerTest, DeferredStartWithMultipleThreads) { } } - loop_.RunUntilIdle(); + base::RunLoop().RunUntilIdle(); EXPECT_THAT(executed_task_ids_, testing::WhenSorted(testing::ElementsAre(0, 1, 2, 3, 4, 5, 6, 7, 8, 9))); } diff --git a/base/files/file_path_watcher_unittest.cc b/base/files/file_path_watcher_unittest.cc index c35d4cf311003e..6bfa71f0545c43 100644 --- a/base/files/file_path_watcher_unittest.cc +++ b/base/files/file_path_watcher_unittest.cc @@ -196,7 +196,7 @@ class FilePathWatcherTest : public testing::Test { bool WaitForEvents() WARN_UNUSED_RESULT { collector_->Reset(); - loop_.Run(); + RunLoop().Run(); return collector_->Success(); } @@ -890,9 +890,9 @@ TEST_F(FilePathWatcherTest, DirAttributesChanged) { // We should not get notified in this case as it hasn't affected our ability // to access the file. ASSERT_TRUE(ChangeFilePermissions(test_dir1, Read, false)); - loop_.PostDelayedTask(FROM_HERE, - MessageLoop::QuitWhenIdleClosure(), - TestTimeouts::tiny_timeout()); + loop_.task_runner()->PostDelayedTask(FROM_HERE, + MessageLoop::QuitWhenIdleClosure(), + TestTimeouts::tiny_timeout()); ASSERT_FALSE(WaitForEvents()); ASSERT_TRUE(ChangeFilePermissions(test_dir1, Read, true)); diff --git a/base/files/file_proxy_unittest.cc b/base/files/file_proxy_unittest.cc index 2562208b270752..d6a4a1edbfcf01 100644 --- a/base/files/file_proxy_unittest.cc +++ b/base/files/file_proxy_unittest.cc @@ -15,6 +15,7 @@ #include "base/files/scoped_temp_dir.h" #include "base/macros.h" #include "base/memory/weak_ptr.h" +#include "base/run_loop.h" #include "base/threading/thread.h" #include "base/threading/thread_restrictions.h" #include "build/build_config.h" @@ -80,7 +81,7 @@ class FileProxyTest : public testing::Test { proxy->CreateOrOpen( test_path(), flags, Bind(&FileProxyTest::DidCreateOrOpen, weak_factory_.GetWeakPtr())); - MessageLoop::current()->Run(); + RunLoop().Run(); EXPECT_TRUE(proxy->IsValid()); } @@ -108,7 +109,7 @@ TEST_F(FileProxyTest, CreateOrOpen_Create) { test_path(), File::FLAG_CREATE | File::FLAG_READ, Bind(&FileProxyTest::DidCreateOrOpen, weak_factory_.GetWeakPtr())); - MessageLoop::current()->Run(); + RunLoop().Run(); EXPECT_EQ(File::FILE_OK, error_); EXPECT_TRUE(proxy.IsValid()); @@ -127,7 +128,7 @@ TEST_F(FileProxyTest, CreateOrOpen_Open) { test_path(), File::FLAG_OPEN | File::FLAG_READ, Bind(&FileProxyTest::DidCreateOrOpen, weak_factory_.GetWeakPtr())); - MessageLoop::current()->Run(); + RunLoop().Run(); EXPECT_EQ(File::FILE_OK, error_); EXPECT_TRUE(proxy.IsValid()); @@ -140,7 +141,7 @@ TEST_F(FileProxyTest, CreateOrOpen_OpenNonExistent) { test_path(), File::FLAG_OPEN | File::FLAG_READ, Bind(&FileProxyTest::DidCreateOrOpen, weak_factory_.GetWeakPtr())); - MessageLoop::current()->Run(); + RunLoop().Run(); EXPECT_EQ(File::FILE_ERROR_NOT_FOUND, error_); EXPECT_FALSE(proxy.IsValid()); EXPECT_FALSE(proxy.created()); @@ -156,7 +157,7 @@ TEST_F(FileProxyTest, CreateOrOpen_AbandonedCreate) { File::FLAG_CREATE | File::FLAG_READ, Bind(&FileProxyTest::DidCreateOrOpen, weak_factory_.GetWeakPtr())); } - MessageLoop::current()->Run(); + RunLoop().Run(); ThreadRestrictions::SetIOAllowed(prev); EXPECT_TRUE(PathExists(test_path())); @@ -173,7 +174,7 @@ TEST_F(FileProxyTest, Close) { #endif proxy.Close(Bind(&FileProxyTest::DidFinish, weak_factory_.GetWeakPtr())); - MessageLoop::current()->Run(); + RunLoop().Run(); EXPECT_EQ(File::FILE_OK, error_); EXPECT_FALSE(proxy.IsValid()); @@ -187,7 +188,7 @@ TEST_F(FileProxyTest, CreateTemporary) { proxy.CreateTemporary( 0 /* additional_file_flags */, Bind(&FileProxyTest::DidCreateTemporary, weak_factory_.GetWeakPtr())); - MessageLoop::current()->Run(); + RunLoop().Run(); EXPECT_TRUE(proxy.IsValid()); EXPECT_EQ(File::FILE_OK, error_); @@ -196,7 +197,7 @@ TEST_F(FileProxyTest, CreateTemporary) { // The file should be writable. proxy.Write(0, "test", 4, Bind(&FileProxyTest::DidWrite, weak_factory_.GetWeakPtr())); - MessageLoop::current()->Run(); + RunLoop().Run(); EXPECT_EQ(File::FILE_OK, error_); EXPECT_EQ(4, bytes_written_); } @@ -235,7 +236,7 @@ TEST_F(FileProxyTest, GetInfo) { CreateProxy(File::FLAG_OPEN | File::FLAG_READ, &proxy); proxy.GetInfo( Bind(&FileProxyTest::DidGetFileInfo, weak_factory_.GetWeakPtr())); - MessageLoop::current()->Run(); + RunLoop().Run(); // Verify. EXPECT_EQ(File::FILE_OK, error_); @@ -258,7 +259,7 @@ TEST_F(FileProxyTest, Read) { CreateProxy(File::FLAG_OPEN | File::FLAG_READ, &proxy); proxy.Read(0, 128, Bind(&FileProxyTest::DidRead, weak_factory_.GetWeakPtr())); - MessageLoop::current()->Run(); + RunLoop().Run(); // Verify. EXPECT_EQ(File::FILE_OK, error_); @@ -276,14 +277,14 @@ TEST_F(FileProxyTest, WriteAndFlush) { int data_bytes = arraysize(data); proxy.Write(0, data, data_bytes, Bind(&FileProxyTest::DidWrite, weak_factory_.GetWeakPtr())); - MessageLoop::current()->Run(); + RunLoop().Run(); EXPECT_EQ(File::FILE_OK, error_); EXPECT_EQ(data_bytes, bytes_written_); // Flush the written data. (So that the following read should always // succeed. On some platforms it may work with or without this flush.) proxy.Flush(Bind(&FileProxyTest::DidFinish, weak_factory_.GetWeakPtr())); - MessageLoop::current()->Run(); + RunLoop().Run(); EXPECT_EQ(File::FILE_OK, error_); // Verify the written data. @@ -311,7 +312,7 @@ TEST_F(FileProxyTest, MAYBE_SetTimes) { proxy.SetTimes(last_accessed_time, last_modified_time, Bind(&FileProxyTest::DidFinish, weak_factory_.GetWeakPtr())); - MessageLoop::current()->Run(); + RunLoop().Run(); EXPECT_EQ(File::FILE_OK, error_); File::Info info; @@ -338,7 +339,7 @@ TEST_F(FileProxyTest, SetLength_Shrink) { CreateProxy(File::FLAG_OPEN | File::FLAG_WRITE, &proxy); proxy.SetLength(7, Bind(&FileProxyTest::DidFinish, weak_factory_.GetWeakPtr())); - MessageLoop::current()->Run(); + RunLoop().Run(); // Verify. GetFileInfo(test_path(), &info); @@ -364,7 +365,7 @@ TEST_F(FileProxyTest, SetLength_Expand) { CreateProxy(File::FLAG_OPEN | File::FLAG_WRITE, &proxy); proxy.SetLength(53, Bind(&FileProxyTest::DidFinish, weak_factory_.GetWeakPtr())); - MessageLoop::current()->Run(); + RunLoop().Run(); // Verify. GetFileInfo(test_path(), &info); diff --git a/base/files/file_util_proxy_unittest.cc b/base/files/file_util_proxy_unittest.cc index 74083699f00f8f..a01aa4e4f23547 100644 --- a/base/files/file_util_proxy_unittest.cc +++ b/base/files/file_util_proxy_unittest.cc @@ -8,6 +8,7 @@ #include "base/files/file_util.h" #include "base/files/scoped_temp_dir.h" #include "base/memory/weak_ptr.h" +#include "base/run_loop.h" #include "base/threading/thread.h" #include "testing/gtest/include/gtest/gtest.h" @@ -67,7 +68,7 @@ TEST_F(FileUtilProxyTest, GetFileInfo_File) { file_task_runner(), test_path(), Bind(&FileUtilProxyTest::DidGetFileInfo, weak_factory_.GetWeakPtr())); - MessageLoop::current()->Run(); + RunLoop().Run(); // Verify. EXPECT_EQ(File::FILE_OK, error_); @@ -90,7 +91,7 @@ TEST_F(FileUtilProxyTest, GetFileInfo_Directory) { file_task_runner(), test_path(), Bind(&FileUtilProxyTest::DidGetFileInfo, weak_factory_.GetWeakPtr())); - MessageLoop::current()->Run(); + RunLoop().Run(); // Verify. EXPECT_EQ(File::FILE_OK, error_); @@ -113,7 +114,7 @@ TEST_F(FileUtilProxyTest, Touch) { last_accessed_time, last_modified_time, Bind(&FileUtilProxyTest::DidFinish, weak_factory_.GetWeakPtr())); - MessageLoop::current()->Run(); + RunLoop().Run(); EXPECT_EQ(File::FILE_OK, error_); File::Info info; diff --git a/base/files/important_file_writer_unittest.cc b/base/files/important_file_writer_unittest.cc index ba1d4d3f9324e7..43e051ebcfadf1 100644 --- a/base/files/important_file_writer_unittest.cc +++ b/base/files/important_file_writer_unittest.cc @@ -157,7 +157,7 @@ TEST_F(ImportantFileWriterTest, ScheduleWrite) { ThreadTaskRunnerHandle::Get()->PostDelayedTask( FROM_HERE, MessageLoop::QuitWhenIdleClosure(), TimeDelta::FromMilliseconds(100)); - MessageLoop::current()->Run(); + RunLoop().Run(); EXPECT_FALSE(writer.HasPendingWrite()); ASSERT_TRUE(PathExists(writer.path())); EXPECT_EQ("foo", GetFileContent(writer.path())); @@ -173,7 +173,7 @@ TEST_F(ImportantFileWriterTest, DoScheduledWrite) { ThreadTaskRunnerHandle::Get()->PostDelayedTask( FROM_HERE, MessageLoop::QuitWhenIdleClosure(), TimeDelta::FromMilliseconds(100)); - MessageLoop::current()->Run(); + RunLoop().Run(); EXPECT_FALSE(writer.HasPendingWrite()); ASSERT_TRUE(PathExists(writer.path())); EXPECT_EQ("foo", GetFileContent(writer.path())); @@ -190,7 +190,7 @@ TEST_F(ImportantFileWriterTest, BatchingWrites) { ThreadTaskRunnerHandle::Get()->PostDelayedTask( FROM_HERE, MessageLoop::QuitWhenIdleClosure(), TimeDelta::FromMilliseconds(100)); - MessageLoop::current()->Run(); + RunLoop().Run(); ASSERT_TRUE(PathExists(writer.path())); EXPECT_EQ("baz", GetFileContent(writer.path())); } diff --git a/base/mac/libdispatch_task_runner_unittest.cc b/base/mac/libdispatch_task_runner_unittest.cc index bfe776c69708f4..a7bc92820845c0 100644 --- a/base/mac/libdispatch_task_runner_unittest.cc +++ b/base/mac/libdispatch_task_runner_unittest.cc @@ -10,6 +10,8 @@ #include "base/mac/bind_objc_block.h" #include "base/macros.h" #include "base/message_loop/message_loop.h" +#include "base/run_loop.h" +#include "base/single_thread_task_runner.h" #include "base/strings/stringprintf.h" #include "testing/gtest/include/gtest/gtest.h" @@ -24,10 +26,10 @@ class LibDispatchTaskRunnerTest : public testing::Test { // all non-delayed tasks are run on the LibDispatchTaskRunner. void DispatchLastTask() { dispatch_async(task_runner_->GetDispatchQueue(), ^{ - message_loop_.PostTask(FROM_HERE, - base::MessageLoop::QuitWhenIdleClosure()); + message_loop_.task_runner()->PostTask( + FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); }); - message_loop_.Run(); + base::RunLoop().Run(); task_runner_->Shutdown(); } @@ -160,11 +162,11 @@ TEST_F(LibDispatchTaskRunnerTest, NonNestable) { TaskOrderMarker marker(this, "First"); task_runner_->PostNonNestableTask(FROM_HERE, base::BindBlock(^{ TaskOrderMarker marker(this, "Second NonNestable"); - message_loop_.PostTask(FROM_HERE, - base::MessageLoop::QuitWhenIdleClosure()); + message_loop_.task_runner()->PostTask( + FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); })); })); - message_loop_.Run(); + base::RunLoop().Run(); task_runner_->Shutdown(); const char* const expectations[] = { @@ -186,11 +188,11 @@ TEST_F(LibDispatchTaskRunnerTest, PostDelayed) { task_runner_->PostDelayedTask(FROM_HERE, base::BindBlock(^{ TaskOrderMarker marker(this, "Timed"); run_time = base::TimeTicks::Now(); - message_loop_.PostTask(FROM_HERE, - base::MessageLoop::QuitWhenIdleClosure()); + message_loop_.task_runner()->PostTask( + FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); }), delta); task_runner_->PostTask(FROM_HERE, BoundRecordTaskOrder(this, "Second")); - message_loop_.Run(); + base::RunLoop().Run(); task_runner_->Shutdown(); const char* const expectations[] = { diff --git a/base/message_loop/message_loop_task_runner_unittest.cc b/base/message_loop/message_loop_task_runner_unittest.cc index 60eef4c0e40581..cabd25013bc12e 100644 --- a/base/message_loop/message_loop_task_runner_unittest.cc +++ b/base/message_loop/message_loop_task_runner_unittest.cc @@ -11,6 +11,8 @@ #include "base/debug/leak_annotations.h" #include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop_task_runner.h" +#include "base/run_loop.h" +#include "base/single_thread_task_runner.h" #include "base/synchronization/waitable_event.h" #include "base/threading/thread.h" #include "base/threading/thread_task_runner_handle.h" @@ -36,7 +38,7 @@ class MessageLoopTaskRunnerTest : public testing::Test { task_thread_.Start(); // Allow us to pause the |task_thread_|'s MessageLoop. - task_thread_.message_loop()->PostTask( + task_thread_.message_loop()->task_runner()->PostTask( FROM_HERE, Bind(&MessageLoopTaskRunnerTest::BlockTaskThreadHelper, Unretained(this))); } @@ -258,7 +260,8 @@ class MessageLoopTaskRunnerThreadingTest : public testing::Test { } void Quit() const { - loop_.PostTask(FROM_HERE, MessageLoop::QuitWhenIdleClosure()); + loop_.task_runner()->PostTask(FROM_HERE, + MessageLoop::QuitWhenIdleClosure()); } void AssertOnIOThread() const { @@ -314,21 +317,21 @@ class MessageLoopTaskRunnerThreadingTest : public testing::Test { TEST_F(MessageLoopTaskRunnerThreadingTest, Release) { EXPECT_TRUE(io_thread_->task_runner()->ReleaseSoon(FROM_HERE, this)); - MessageLoop::current()->Run(); + RunLoop().Run(); } TEST_F(MessageLoopTaskRunnerThreadingTest, Delete) { DeletedOnFile* deleted_on_file = new DeletedOnFile(this); EXPECT_TRUE( file_thread_->task_runner()->DeleteSoon(FROM_HERE, deleted_on_file)); - MessageLoop::current()->Run(); + RunLoop().Run(); } TEST_F(MessageLoopTaskRunnerThreadingTest, PostTask) { EXPECT_TRUE(file_thread_->task_runner()->PostTask( FROM_HERE, Bind(&MessageLoopTaskRunnerThreadingTest::BasicFunction, Unretained(this)))); - MessageLoop::current()->Run(); + RunLoop().Run(); } TEST_F(MessageLoopTaskRunnerThreadingTest, PostTaskAfterThreadExits) { diff --git a/base/message_loop/message_loop_test.cc b/base/message_loop/message_loop_test.cc index 4e45acbbf02218..1ab946f9e242a8 100644 --- a/base/message_loop/message_loop_test.cc +++ b/base/message_loop/message_loop_test.cc @@ -12,6 +12,7 @@ #include "base/macros.h" #include "base/memory/ref_counted.h" #include "base/run_loop.h" +#include "base/single_thread_task_runner.h" #include "base/synchronization/waitable_event.h" #include "base/threading/thread.h" @@ -96,25 +97,25 @@ void RunTest_PostTask(MessagePumpFactory factory) { // Add tests to message loop scoped_refptr foo(new Foo()); std::string a("a"), b("b"), c("c"), d("d"); - MessageLoop::current()->PostTask(FROM_HERE, Bind( - &Foo::Test0, foo.get())); - MessageLoop::current()->PostTask(FROM_HERE, Bind( - &Foo::Test1ConstRef, foo.get(), a)); - MessageLoop::current()->PostTask(FROM_HERE, Bind( - &Foo::Test1Ptr, foo.get(), &b)); - MessageLoop::current()->PostTask(FROM_HERE, Bind( - &Foo::Test1Int, foo.get(), 100)); - MessageLoop::current()->PostTask(FROM_HERE, Bind( - &Foo::Test2Ptr, foo.get(), &a, &c)); - MessageLoop::current()->PostTask(FROM_HERE, Bind( - &Foo::Test2Mixed, foo.get(), a, &d)); + MessageLoop::current()->task_runner()->PostTask(FROM_HERE, + Bind(&Foo::Test0, foo.get())); + MessageLoop::current()->task_runner()->PostTask( + FROM_HERE, Bind(&Foo::Test1ConstRef, foo.get(), a)); + MessageLoop::current()->task_runner()->PostTask( + FROM_HERE, Bind(&Foo::Test1Ptr, foo.get(), &b)); + MessageLoop::current()->task_runner()->PostTask( + FROM_HERE, Bind(&Foo::Test1Int, foo.get(), 100)); + MessageLoop::current()->task_runner()->PostTask( + FROM_HERE, Bind(&Foo::Test2Ptr, foo.get(), &a, &c)); + MessageLoop::current()->task_runner()->PostTask( + FROM_HERE, Bind(&Foo::Test2Mixed, foo.get(), a, &d)); // After all tests, post a message that will shut down the message loop - MessageLoop::current()->PostTask( + MessageLoop::current()->task_runner()->PostTask( FROM_HERE, Bind(&MessageLoop::QuitWhenIdle, Unretained(MessageLoop::current()))); // Now kick things off - MessageLoop::current()->Run(); + RunLoop().Run(); EXPECT_EQ(foo->test_count(), 105); EXPECT_EQ(foo->result(), "abacad"); @@ -131,12 +132,11 @@ void RunTest_PostDelayedTask_Basic(MessagePumpFactory factory) { int num_tasks = 1; Time run_time; - loop.PostDelayedTask( - FROM_HERE, Bind(&RecordRunTimeFunc, &run_time, &num_tasks), - kDelay); + loop.task_runner()->PostDelayedTask( + FROM_HERE, Bind(&RecordRunTimeFunc, &run_time, &num_tasks), kDelay); Time time_before_run = Time::Now(); - loop.Run(); + RunLoop().Run(); Time time_after_run = Time::Now(); EXPECT_EQ(0, num_tasks); @@ -151,18 +151,16 @@ void RunTest_PostDelayedTask_InDelayOrder(MessagePumpFactory factory) { int num_tasks = 2; Time run_time1, run_time2; - loop.PostDelayedTask( - FROM_HERE, - Bind(&RecordRunTimeFunc, &run_time1, &num_tasks), + loop.task_runner()->PostDelayedTask( + FROM_HERE, Bind(&RecordRunTimeFunc, &run_time1, &num_tasks), TimeDelta::FromMilliseconds(200)); // If we get a large pause in execution (due to a context switch) here, this // test could fail. - loop.PostDelayedTask( - FROM_HERE, - Bind(&RecordRunTimeFunc, &run_time2, &num_tasks), + loop.task_runner()->PostDelayedTask( + FROM_HERE, Bind(&RecordRunTimeFunc, &run_time2, &num_tasks), TimeDelta::FromMilliseconds(10)); - loop.Run(); + RunLoop().Run(); EXPECT_EQ(0, num_tasks); EXPECT_TRUE(run_time2 < run_time1); @@ -185,14 +183,12 @@ void RunTest_PostDelayedTask_InPostOrder(MessagePumpFactory factory) { int num_tasks = 2; Time run_time1, run_time2; - loop.PostDelayedTask( - FROM_HERE, - Bind(&RecordRunTimeFunc, &run_time1, &num_tasks), kDelay); - loop.PostDelayedTask( - FROM_HERE, - Bind(&RecordRunTimeFunc, &run_time2, &num_tasks), kDelay); + loop.task_runner()->PostDelayedTask( + FROM_HERE, Bind(&RecordRunTimeFunc, &run_time1, &num_tasks), kDelay); + loop.task_runner()->PostDelayedTask( + FROM_HERE, Bind(&RecordRunTimeFunc, &run_time2, &num_tasks), kDelay); - loop.Run(); + RunLoop().Run(); EXPECT_EQ(0, num_tasks); EXPECT_TRUE(run_time1 < run_time2); @@ -210,14 +206,13 @@ void RunTest_PostDelayedTask_InPostOrder_2(MessagePumpFactory factory) { int num_tasks = 2; Time run_time; - loop.PostTask(FROM_HERE, Bind(&SlowFunc, kPause, &num_tasks)); - loop.PostDelayedTask( - FROM_HERE, - Bind(&RecordRunTimeFunc, &run_time, &num_tasks), + loop.task_runner()->PostTask(FROM_HERE, Bind(&SlowFunc, kPause, &num_tasks)); + loop.task_runner()->PostDelayedTask( + FROM_HERE, Bind(&RecordRunTimeFunc, &run_time, &num_tasks), TimeDelta::FromMilliseconds(10)); Time time_before_run = Time::Now(); - loop.Run(); + RunLoop().Run(); Time time_after_run = Time::Now(); EXPECT_EQ(0, num_tasks); @@ -240,14 +235,14 @@ void RunTest_PostDelayedTask_InPostOrder_3(MessagePumpFactory factory) { // Clutter the ML with tasks. for (int i = 1; i < num_tasks; ++i) - loop.PostTask(FROM_HERE, - Bind(&RecordRunTimeFunc, &run_time1, &num_tasks)); + loop.task_runner()->PostTask( + FROM_HERE, Bind(&RecordRunTimeFunc, &run_time1, &num_tasks)); - loop.PostDelayedTask( + loop.task_runner()->PostDelayedTask( FROM_HERE, Bind(&RecordRunTimeFunc, &run_time2, &num_tasks), TimeDelta::FromMilliseconds(1)); - loop.Run(); + RunLoop().Run(); EXPECT_EQ(0, num_tasks); EXPECT_TRUE(run_time2 > run_time1); @@ -265,18 +260,16 @@ void RunTest_PostDelayedTask_SharedTimer(MessagePumpFactory factory) { int num_tasks = 1; Time run_time1, run_time2; - loop.PostDelayedTask( - FROM_HERE, - Bind(&RecordRunTimeFunc, &run_time1, &num_tasks), + loop.task_runner()->PostDelayedTask( + FROM_HERE, Bind(&RecordRunTimeFunc, &run_time1, &num_tasks), TimeDelta::FromSeconds(1000)); - loop.PostDelayedTask( - FROM_HERE, - Bind(&RecordRunTimeFunc, &run_time2, &num_tasks), + loop.task_runner()->PostDelayedTask( + FROM_HERE, Bind(&RecordRunTimeFunc, &run_time2, &num_tasks), TimeDelta::FromMilliseconds(10)); Time start_time = Time::Now(); - loop.Run(); + RunLoop().Run(); EXPECT_EQ(0, num_tasks); // Ensure that we ran in far less time than the slower timer. @@ -309,7 +302,7 @@ class RecordDeletionProbe : public RefCounted { ~RecordDeletionProbe() { *was_deleted_ = true; if (post_on_delete_.get()) - MessageLoop::current()->PostTask( + MessageLoop::current()->task_runner()->PostTask( FROM_HERE, Bind(&RecordDeletionProbe::Run, post_on_delete_.get())); } @@ -323,13 +316,13 @@ void RunTest_EnsureDeletion(MessagePumpFactory factory) { { std::unique_ptr pump(factory()); MessageLoop loop(std::move(pump)); - loop.PostTask( + loop.task_runner()->PostTask( FROM_HERE, Bind(&RecordDeletionProbe::Run, - new RecordDeletionProbe(NULL, &a_was_deleted))); + new RecordDeletionProbe(NULL, &a_was_deleted))); // TODO(ajwong): Do we really need 1000ms here? - loop.PostDelayedTask( + loop.task_runner()->PostDelayedTask( FROM_HERE, Bind(&RecordDeletionProbe::Run, - new RecordDeletionProbe(NULL, &b_was_deleted)), + new RecordDeletionProbe(NULL, &b_was_deleted)), TimeDelta::FromMilliseconds(1000)); } EXPECT_TRUE(a_was_deleted); @@ -348,7 +341,7 @@ void RunTest_EnsureDeletion_Chain(MessagePumpFactory factory) { RecordDeletionProbe* a = new RecordDeletionProbe(NULL, &a_was_deleted); RecordDeletionProbe* b = new RecordDeletionProbe(a, &b_was_deleted); RecordDeletionProbe* c = new RecordDeletionProbe(b, &c_was_deleted); - loop.PostTask(FROM_HERE, Bind(&RecordDeletionProbe::Run, c)); + loop.task_runner()->PostTask(FROM_HERE, Bind(&RecordDeletionProbe::Run, c)); } EXPECT_TRUE(a_was_deleted); EXPECT_TRUE(b_was_deleted); @@ -358,11 +351,11 @@ void RunTest_EnsureDeletion_Chain(MessagePumpFactory factory) { void NestingFunc(int* depth) { if (*depth > 0) { *depth -= 1; - MessageLoop::current()->PostTask(FROM_HERE, - Bind(&NestingFunc, depth)); + MessageLoop::current()->task_runner()->PostTask(FROM_HERE, + Bind(&NestingFunc, depth)); MessageLoop::current()->SetNestableTasksAllowed(true); - MessageLoop::current()->Run(); + RunLoop().Run(); } MessageLoop::current()->QuitWhenIdle(); } @@ -372,9 +365,9 @@ void RunTest_Nesting(MessagePumpFactory factory) { MessageLoop loop(std::move(pump)); int depth = 100; - MessageLoop::current()->PostTask(FROM_HERE, - Bind(&NestingFunc, &depth)); - MessageLoop::current()->Run(); + MessageLoop::current()->task_runner()->PostTask(FROM_HERE, + Bind(&NestingFunc, &depth)); + RunLoop().Run(); EXPECT_EQ(depth, 0); } @@ -410,9 +403,10 @@ void RunNestedLoop(TestNestingObserver* observer, RunLoop nested_loop; // Verify that by the time the first task is run the observer has seen the // message loop begin. - MessageLoop::current()->PostTask(FROM_HERE, - Bind(&ExpectOneBeginNestedLoop, observer)); - MessageLoop::current()->PostTask(FROM_HERE, nested_loop.QuitClosure()); + MessageLoop::current()->task_runner()->PostTask( + FROM_HERE, Bind(&ExpectOneBeginNestedLoop, observer)); + MessageLoop::current()->task_runner()->PostTask(FROM_HERE, + nested_loop.QuitClosure()); nested_loop.Run(); // Quitting message loops doesn't change the begin count. @@ -431,9 +425,10 @@ void RunTest_NestingObserver(MessagePumpFactory factory) { outer_loop.AddNestingObserver(&nesting_observer); // Post a task that runs a nested message loop. - outer_loop.PostTask(FROM_HERE, Bind(&RunNestedLoop, &nesting_observer, - outer_loop.QuitWhenIdleClosure())); - outer_loop.Run(); + outer_loop.task_runner()->PostTask(FROM_HERE, + Bind(&RunNestedLoop, &nesting_observer, + outer_loop.QuitWhenIdleClosure())); + RunLoop().Run(); outer_loop.RemoveNestingObserver(&nesting_observer); } @@ -523,7 +518,7 @@ void RecursiveFunc(TaskList* order, int cookie, int depth, if (depth > 0) { if (is_reentrant) MessageLoop::current()->SetNestableTasksAllowed(true); - MessageLoop::current()->PostTask( + MessageLoop::current()->task_runner()->PostTask( FROM_HERE, Bind(&RecursiveFunc, order, cookie, depth - 1, is_reentrant)); } @@ -541,17 +536,14 @@ void RunTest_RecursiveDenial1(MessagePumpFactory factory) { EXPECT_TRUE(MessageLoop::current()->NestableTasksAllowed()); TaskList order; - MessageLoop::current()->PostTask( - FROM_HERE, - Bind(&RecursiveFunc, &order, 1, 2, false)); - MessageLoop::current()->PostTask( - FROM_HERE, - Bind(&RecursiveFunc, &order, 2, 2, false)); - MessageLoop::current()->PostTask( - FROM_HERE, - Bind(&QuitFunc, &order, 3)); + MessageLoop::current()->task_runner()->PostTask( + FROM_HERE, Bind(&RecursiveFunc, &order, 1, 2, false)); + MessageLoop::current()->task_runner()->PostTask( + FROM_HERE, Bind(&RecursiveFunc, &order, 2, 2, false)); + MessageLoop::current()->task_runner()->PostTask(FROM_HERE, + Bind(&QuitFunc, &order, 3)); - MessageLoop::current()->Run(); + RunLoop().Run(); // FIFO order. ASSERT_EQ(14U, order.Size()); @@ -588,20 +580,16 @@ void RunTest_RecursiveDenial3(MessagePumpFactory factory) { EXPECT_TRUE(MessageLoop::current()->NestableTasksAllowed()); TaskList order; - MessageLoop::current()->PostTask( + MessageLoop::current()->task_runner()->PostTask( FROM_HERE, Bind(&RecursiveSlowFunc, &order, 1, 2, false)); - MessageLoop::current()->PostTask( + MessageLoop::current()->task_runner()->PostTask( FROM_HERE, Bind(&RecursiveSlowFunc, &order, 2, 2, false)); - MessageLoop::current()->PostDelayedTask( - FROM_HERE, - Bind(&OrderedFunc, &order, 3), - TimeDelta::FromMilliseconds(5)); - MessageLoop::current()->PostDelayedTask( - FROM_HERE, - Bind(&QuitFunc, &order, 4), - TimeDelta::FromMilliseconds(5)); + MessageLoop::current()->task_runner()->PostDelayedTask( + FROM_HERE, Bind(&OrderedFunc, &order, 3), TimeDelta::FromMilliseconds(5)); + MessageLoop::current()->task_runner()->PostDelayedTask( + FROM_HERE, Bind(&QuitFunc, &order, 4), TimeDelta::FromMilliseconds(5)); - MessageLoop::current()->Run(); + RunLoop().Run(); // FIFO order. ASSERT_EQ(16U, order.Size()); @@ -628,14 +616,14 @@ void RunTest_RecursiveSupport1(MessagePumpFactory factory) { MessageLoop loop(std::move(pump)); TaskList order; - MessageLoop::current()->PostTask( + MessageLoop::current()->task_runner()->PostTask( FROM_HERE, Bind(&RecursiveFunc, &order, 1, 2, true)); - MessageLoop::current()->PostTask( + MessageLoop::current()->task_runner()->PostTask( FROM_HERE, Bind(&RecursiveFunc, &order, 2, 2, true)); - MessageLoop::current()->PostTask( - FROM_HERE, Bind(&QuitFunc, &order, 3)); + MessageLoop::current()->task_runner()->PostTask(FROM_HERE, + Bind(&QuitFunc, &order, 3)); - MessageLoop::current()->Run(); + RunLoop().Run(); // FIFO order. ASSERT_EQ(14U, order.Size()); @@ -670,7 +658,7 @@ void RunTest_NonNestableWithNoNesting(MessagePumpFactory factory) { Bind(&OrderedFunc, &order, 2)); MessageLoop::current()->task_runner()->PostTask(FROM_HERE, Bind(&QuitFunc, &order, 3)); - MessageLoop::current()->Run(); + RunLoop().Run(); // FIFO order. ASSERT_EQ(6U, order.Size()); @@ -723,7 +711,7 @@ void RunTest_NonNestableInNestedLoop(MessagePumpFactory factory) { FROM_HERE, Bind(&QuitFunc, &order, 6)); - MessageLoop::current()->Run(); + RunLoop().Run(); // FIFO order. ASSERT_EQ(12U, order.Size()); @@ -762,20 +750,20 @@ void RunTest_QuitNow(MessagePumpFactory factory) { RunLoop run_loop; - MessageLoop::current()->PostTask(FROM_HERE, - Bind(&FuncThatRuns, &order, 1, Unretained(&run_loop))); - MessageLoop::current()->PostTask( + MessageLoop::current()->task_runner()->PostTask( + FROM_HERE, Bind(&FuncThatRuns, &order, 1, Unretained(&run_loop))); + MessageLoop::current()->task_runner()->PostTask( FROM_HERE, Bind(&OrderedFunc, &order, 2)); - MessageLoop::current()->PostTask( - FROM_HERE, Bind(&FuncThatQuitsNow)); - MessageLoop::current()->PostTask( + MessageLoop::current()->task_runner()->PostTask(FROM_HERE, + Bind(&FuncThatQuitsNow)); + MessageLoop::current()->task_runner()->PostTask( FROM_HERE, Bind(&OrderedFunc, &order, 3)); - MessageLoop::current()->PostTask( - FROM_HERE, Bind(&FuncThatQuitsNow)); - MessageLoop::current()->PostTask( - FROM_HERE, Bind(&OrderedFunc, &order, 4)); // never runs + MessageLoop::current()->task_runner()->PostTask(FROM_HERE, + Bind(&FuncThatQuitsNow)); + MessageLoop::current()->task_runner()->PostTask( + FROM_HERE, Bind(&OrderedFunc, &order, 4)); // never runs - MessageLoop::current()->Run(); + RunLoop().Run(); ASSERT_EQ(6U, order.Size()); int task_index = 0; @@ -798,13 +786,13 @@ void RunTest_RunLoopQuitTop(MessagePumpFactory factory) { RunLoop outer_run_loop; RunLoop nested_run_loop; - MessageLoop::current()->PostTask(FROM_HERE, - Bind(&FuncThatRuns, &order, 1, Unretained(&nested_run_loop))); - MessageLoop::current()->PostTask( - FROM_HERE, outer_run_loop.QuitClosure()); - MessageLoop::current()->PostTask( + MessageLoop::current()->task_runner()->PostTask( + FROM_HERE, Bind(&FuncThatRuns, &order, 1, Unretained(&nested_run_loop))); + MessageLoop::current()->task_runner()->PostTask(FROM_HERE, + outer_run_loop.QuitClosure()); + MessageLoop::current()->task_runner()->PostTask( FROM_HERE, Bind(&OrderedFunc, &order, 2)); - MessageLoop::current()->PostTask( + MessageLoop::current()->task_runner()->PostTask( FROM_HERE, nested_run_loop.QuitClosure()); outer_run_loop.Run(); @@ -828,14 +816,14 @@ void RunTest_RunLoopQuitNested(MessagePumpFactory factory) { RunLoop outer_run_loop; RunLoop nested_run_loop; - MessageLoop::current()->PostTask(FROM_HERE, - Bind(&FuncThatRuns, &order, 1, Unretained(&nested_run_loop))); - MessageLoop::current()->PostTask( + MessageLoop::current()->task_runner()->PostTask( + FROM_HERE, Bind(&FuncThatRuns, &order, 1, Unretained(&nested_run_loop))); + MessageLoop::current()->task_runner()->PostTask( FROM_HERE, nested_run_loop.QuitClosure()); - MessageLoop::current()->PostTask( + MessageLoop::current()->task_runner()->PostTask( FROM_HERE, Bind(&OrderedFunc, &order, 2)); - MessageLoop::current()->PostTask( - FROM_HERE, outer_run_loop.QuitClosure()); + MessageLoop::current()->task_runner()->PostTask(FROM_HERE, + outer_run_loop.QuitClosure()); outer_run_loop.Run(); @@ -859,15 +847,15 @@ void RunTest_RunLoopQuitBogus(MessagePumpFactory factory) { RunLoop nested_run_loop; RunLoop bogus_run_loop; - MessageLoop::current()->PostTask(FROM_HERE, - Bind(&FuncThatRuns, &order, 1, Unretained(&nested_run_loop))); - MessageLoop::current()->PostTask( - FROM_HERE, bogus_run_loop.QuitClosure()); - MessageLoop::current()->PostTask( + MessageLoop::current()->task_runner()->PostTask( + FROM_HERE, Bind(&FuncThatRuns, &order, 1, Unretained(&nested_run_loop))); + MessageLoop::current()->task_runner()->PostTask(FROM_HERE, + bogus_run_loop.QuitClosure()); + MessageLoop::current()->task_runner()->PostTask( FROM_HERE, Bind(&OrderedFunc, &order, 2)); - MessageLoop::current()->PostTask( - FROM_HERE, outer_run_loop.QuitClosure()); - MessageLoop::current()->PostTask( + MessageLoop::current()->task_runner()->PostTask(FROM_HERE, + outer_run_loop.QuitClosure()); + MessageLoop::current()->task_runner()->PostTask( FROM_HERE, nested_run_loop.QuitClosure()); outer_run_loop.Run(); @@ -894,35 +882,35 @@ void RunTest_RunLoopQuitDeep(MessagePumpFactory factory) { RunLoop nested_loop3; RunLoop nested_loop4; - MessageLoop::current()->PostTask(FROM_HERE, - Bind(&FuncThatRuns, &order, 1, Unretained(&nested_loop1))); - MessageLoop::current()->PostTask(FROM_HERE, - Bind(&FuncThatRuns, &order, 2, Unretained(&nested_loop2))); - MessageLoop::current()->PostTask(FROM_HERE, - Bind(&FuncThatRuns, &order, 3, Unretained(&nested_loop3))); - MessageLoop::current()->PostTask(FROM_HERE, - Bind(&FuncThatRuns, &order, 4, Unretained(&nested_loop4))); - MessageLoop::current()->PostTask( + MessageLoop::current()->task_runner()->PostTask( + FROM_HERE, Bind(&FuncThatRuns, &order, 1, Unretained(&nested_loop1))); + MessageLoop::current()->task_runner()->PostTask( + FROM_HERE, Bind(&FuncThatRuns, &order, 2, Unretained(&nested_loop2))); + MessageLoop::current()->task_runner()->PostTask( + FROM_HERE, Bind(&FuncThatRuns, &order, 3, Unretained(&nested_loop3))); + MessageLoop::current()->task_runner()->PostTask( + FROM_HERE, Bind(&FuncThatRuns, &order, 4, Unretained(&nested_loop4))); + MessageLoop::current()->task_runner()->PostTask( FROM_HERE, Bind(&OrderedFunc, &order, 5)); - MessageLoop::current()->PostTask( - FROM_HERE, outer_run_loop.QuitClosure()); - MessageLoop::current()->PostTask( + MessageLoop::current()->task_runner()->PostTask(FROM_HERE, + outer_run_loop.QuitClosure()); + MessageLoop::current()->task_runner()->PostTask( FROM_HERE, Bind(&OrderedFunc, &order, 6)); - MessageLoop::current()->PostTask( - FROM_HERE, nested_loop1.QuitClosure()); - MessageLoop::current()->PostTask( + MessageLoop::current()->task_runner()->PostTask(FROM_HERE, + nested_loop1.QuitClosure()); + MessageLoop::current()->task_runner()->PostTask( FROM_HERE, Bind(&OrderedFunc, &order, 7)); - MessageLoop::current()->PostTask( - FROM_HERE, nested_loop2.QuitClosure()); - MessageLoop::current()->PostTask( + MessageLoop::current()->task_runner()->PostTask(FROM_HERE, + nested_loop2.QuitClosure()); + MessageLoop::current()->task_runner()->PostTask( FROM_HERE, Bind(&OrderedFunc, &order, 8)); - MessageLoop::current()->PostTask( - FROM_HERE, nested_loop3.QuitClosure()); - MessageLoop::current()->PostTask( + MessageLoop::current()->task_runner()->PostTask(FROM_HERE, + nested_loop3.QuitClosure()); + MessageLoop::current()->task_runner()->PostTask( FROM_HERE, Bind(&OrderedFunc, &order, 9)); - MessageLoop::current()->PostTask( - FROM_HERE, nested_loop4.QuitClosure()); - MessageLoop::current()->PostTask( + MessageLoop::current()->task_runner()->PostTask(FROM_HERE, + nested_loop4.QuitClosure()); + MessageLoop::current()->task_runner()->PostTask( FROM_HERE, Bind(&OrderedFunc, &order, 10)); outer_run_loop.Run(); @@ -961,10 +949,10 @@ void RunTest_RunLoopQuitOrderBefore(MessagePumpFactory factory) { run_loop.Quit(); - MessageLoop::current()->PostTask( - FROM_HERE, Bind(&OrderedFunc, &order, 1)); // never runs - MessageLoop::current()->PostTask( - FROM_HERE, Bind(&FuncThatQuitsNow)); // never runs + MessageLoop::current()->task_runner()->PostTask( + FROM_HERE, Bind(&OrderedFunc, &order, 1)); // never runs + MessageLoop::current()->task_runner()->PostTask( + FROM_HERE, Bind(&FuncThatQuitsNow)); // never runs run_loop.Run(); @@ -980,14 +968,14 @@ void RunTest_RunLoopQuitOrderDuring(MessagePumpFactory factory) { RunLoop run_loop; - MessageLoop::current()->PostTask( + MessageLoop::current()->task_runner()->PostTask( FROM_HERE, Bind(&OrderedFunc, &order, 1)); - MessageLoop::current()->PostTask( - FROM_HERE, run_loop.QuitClosure()); - MessageLoop::current()->PostTask( - FROM_HERE, Bind(&OrderedFunc, &order, 2)); // never runs - MessageLoop::current()->PostTask( - FROM_HERE, Bind(&FuncThatQuitsNow)); // never runs + MessageLoop::current()->task_runner()->PostTask(FROM_HERE, + run_loop.QuitClosure()); + MessageLoop::current()->task_runner()->PostTask( + FROM_HERE, Bind(&OrderedFunc, &order, 2)); // never runs + MessageLoop::current()->task_runner()->PostTask( + FROM_HERE, Bind(&FuncThatQuitsNow)); // never runs run_loop.Run(); @@ -1007,20 +995,20 @@ void RunTest_RunLoopQuitOrderAfter(MessagePumpFactory factory) { RunLoop run_loop; - MessageLoop::current()->PostTask(FROM_HERE, - Bind(&FuncThatRuns, &order, 1, Unretained(&run_loop))); - MessageLoop::current()->PostTask( + MessageLoop::current()->task_runner()->PostTask( + FROM_HERE, Bind(&FuncThatRuns, &order, 1, Unretained(&run_loop))); + MessageLoop::current()->task_runner()->PostTask( FROM_HERE, Bind(&OrderedFunc, &order, 2)); - MessageLoop::current()->PostTask( - FROM_HERE, Bind(&FuncThatQuitsNow)); - MessageLoop::current()->PostTask( + MessageLoop::current()->task_runner()->PostTask(FROM_HERE, + Bind(&FuncThatQuitsNow)); + MessageLoop::current()->task_runner()->PostTask( FROM_HERE, Bind(&OrderedFunc, &order, 3)); - MessageLoop::current()->PostTask( - FROM_HERE, run_loop.QuitClosure()); // has no affect - MessageLoop::current()->PostTask( + MessageLoop::current()->task_runner()->PostTask( + FROM_HERE, run_loop.QuitClosure()); // has no affect + MessageLoop::current()->task_runner()->PostTask( FROM_HERE, Bind(&OrderedFunc, &order, 4)); - MessageLoop::current()->PostTask( - FROM_HERE, Bind(&FuncThatQuitsNow)); + MessageLoop::current()->task_runner()->PostTask(FROM_HERE, + Bind(&FuncThatQuitsNow)); RunLoop outer_run_loop; outer_run_loop.Run(); @@ -1040,9 +1028,8 @@ void RunTest_RunLoopQuitOrderAfter(MessagePumpFactory factory) { void PostNTasksThenQuit(int posts_remaining) { if (posts_remaining > 1) { - MessageLoop::current()->PostTask( - FROM_HERE, - Bind(&PostNTasksThenQuit, posts_remaining - 1)); + MessageLoop::current()->task_runner()->PostTask( + FROM_HERE, Bind(&PostNTasksThenQuit, posts_remaining - 1)); } else { MessageLoop::current()->QuitWhenIdle(); } @@ -1060,8 +1047,8 @@ void RunTest_RecursivePosts(MessagePumpFactory factory) { const int kNumTimes = 1 << 17; std::unique_ptr pump(factory()); MessageLoop loop(std::move(pump)); - loop.PostTask(FROM_HERE, Bind(&PostNTasksThenQuit, kNumTimes)); - loop.Run(); + loop.task_runner()->PostTask(FROM_HERE, Bind(&PostNTasksThenQuit, kNumTimes)); + RunLoop().Run(); } } // namespace test diff --git a/base/message_loop/message_loop_unittest.cc b/base/message_loop/message_loop_unittest.cc index c4855816737e38..52337e31a8c3ea 100644 --- a/base/message_loop/message_loop_unittest.cc +++ b/base/message_loop/message_loop_unittest.cc @@ -18,6 +18,7 @@ #include "base/pending_task.h" #include "base/posix/eintr_wrapper.h" #include "base/run_loop.h" +#include "base/single_thread_task_runner.h" #include "base/synchronization/waitable_event.h" #include "base/test/test_simple_task_runner.h" #include "base/threading/platform_thread.h" @@ -416,9 +417,8 @@ void RunTest_RecursiveSupport2(MessageLoop::Type message_loop_type) { void PostNTasksThenQuit(int posts_remaining) { if (posts_remaining > 1) { - MessageLoop::current()->PostTask( - FROM_HERE, - Bind(&PostNTasksThenQuit, posts_remaining - 1)); + MessageLoop::current()->task_runner()->PostTask( + FROM_HERE, Bind(&PostNTasksThenQuit, posts_remaining - 1)); } else { MessageLoop::current()->QuitWhenIdle(); } @@ -639,8 +639,8 @@ TEST(MessageLoopTest, TaskObserver) { MessageLoop loop; loop.AddTaskObserver(&observer); - loop.PostTask(FROM_HERE, Bind(&PostNTasksThenQuit, kNumPosts)); - loop.Run(); + loop.task_runner()->PostTask(FROM_HERE, Bind(&PostNTasksThenQuit, kNumPosts)); + RunLoop().Run(); loop.RemoveTaskObserver(&observer); EXPECT_EQ(kNumPosts, observer.num_tasks_started()); @@ -815,11 +815,10 @@ TEST(MessageLoopTest, DestructionObserverTest) { MLDestructionObserver observer(&task_destroyed, &destruction_observer_called); loop->AddDestructionObserver(&observer); - loop->PostDelayedTask( - FROM_HERE, - Bind(&DestructionObserverProbe::Run, - new DestructionObserverProbe(&task_destroyed, - &destruction_observer_called)), + loop->task_runner()->PostDelayedTask( + FROM_HERE, Bind(&DestructionObserverProbe::Run, + new DestructionObserverProbe( + &task_destroyed, &destruction_observer_called)), kDelay); delete loop; EXPECT_TRUE(observer.task_destroyed_before_message_loop()); @@ -840,12 +839,12 @@ TEST(MessageLoopTest, ThreadMainTaskRunner) { &Foo::Test1ConstRef, foo.get(), a)); // Post quit task; - MessageLoop::current()->PostTask( + MessageLoop::current()->task_runner()->PostTask( FROM_HERE, Bind(&MessageLoop::QuitWhenIdle, Unretained(MessageLoop::current()))); // Now kick things off - MessageLoop::current()->Run(); + RunLoop().Run(); EXPECT_EQ(foo->test_count(), 1); EXPECT_EQ(foo->result(), "a"); @@ -964,7 +963,7 @@ TEST(MessageLoopTest, OriginalRunnerWorks) { scoped_refptr foo(new Foo()); original_runner->PostTask(FROM_HERE, Bind(&Foo::Test1ConstRef, foo.get(), "a")); - loop.RunUntilIdle(); + RunLoop().RunUntilIdle(); EXPECT_EQ(1, foo->test_count()); } diff --git a/base/message_loop/message_pump_libevent_unittest.cc b/base/message_loop/message_pump_libevent_unittest.cc index 6a5a1f36235786..6d1cf7ef31f9a9 100644 --- a/base/message_loop/message_pump_libevent_unittest.cc +++ b/base/message_loop/message_pump_libevent_unittest.cc @@ -15,6 +15,7 @@ #include "base/message_loop/message_loop.h" #include "base/posix/eintr_wrapper.h" #include "base/run_loop.h" +#include "base/single_thread_task_runner.h" #include "base/synchronization/waitable_event.h" #include "base/synchronization/waitable_event_watcher.h" #include "base/third_party/libevent/event.h" @@ -177,7 +178,8 @@ void QuitMessageLoopAndStart(const Closure& quit_closure) { MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current()); RunLoop runloop; - MessageLoop::current()->PostTask(FROM_HERE, runloop.QuitClosure()); + MessageLoop::current()->task_runner()->PostTask(FROM_HERE, + runloop.QuitClosure()); runloop.Run(); } @@ -188,8 +190,8 @@ class NestedPumpWatcher : public MessagePumpLibevent::Watcher { void OnFileCanReadWithoutBlocking(int /* fd */) override { RunLoop runloop; - MessageLoop::current()->PostTask(FROM_HERE, Bind(&QuitMessageLoopAndStart, - runloop.QuitClosure())); + MessageLoop::current()->task_runner()->PostTask( + FROM_HERE, Bind(&QuitMessageLoopAndStart, runloop.QuitClosure())); runloop.Run(); } @@ -220,7 +222,8 @@ class QuitWatcher : public BaseWatcher { void OnFileCanReadWithoutBlocking(int /* fd */) override { // Post a fatal closure to the MessageLoop before we quit it. - MessageLoop::current()->PostTask(FROM_HERE, Bind(&FatalClosure)); + MessageLoop::current()->task_runner()->PostTask(FROM_HERE, + Bind(&FatalClosure)); // Now quit the MessageLoop. run_loop_->Quit(); @@ -260,19 +263,21 @@ TEST_F(MessagePumpLibeventTest, QuitWatcher) { const char buf = 0; const WaitableEventWatcher::EventCallback write_fd_task = Bind(&WriteFDWrapper, pipefds_[1], &buf, 1); - io_loop()->PostTask(FROM_HERE, - Bind(IgnoreResult(&WaitableEventWatcher::StartWatching), - Unretained(watcher.get()), &event, write_fd_task)); + io_loop()->task_runner()->PostTask( + FROM_HERE, Bind(IgnoreResult(&WaitableEventWatcher::StartWatching), + Unretained(watcher.get()), &event, write_fd_task)); // Queue |event| to signal on |loop|. - loop.PostTask(FROM_HERE, Bind(&WaitableEvent::Signal, Unretained(&event))); + loop.task_runner()->PostTask( + FROM_HERE, Bind(&WaitableEvent::Signal, Unretained(&event))); // Now run the MessageLoop. run_loop.Run(); // StartWatching can move |watcher| to IO thread. Release on IO thread. - io_loop()->PostTask(FROM_HERE, Bind(&WaitableEventWatcher::StopWatching, - Owned(watcher.release()))); + io_loop()->task_runner()->PostTask( + FROM_HERE, + Bind(&WaitableEventWatcher::StopWatching, Owned(watcher.release()))); } } // namespace diff --git a/base/message_loop/message_pump_perftest.cc b/base/message_loop/message_pump_perftest.cc index edaf2068ff6ec1..7bb942fa657707 100644 --- a/base/message_loop/message_pump_perftest.cc +++ b/base/message_loop/message_pump_perftest.cc @@ -9,6 +9,7 @@ #include "base/format_macros.h" #include "base/memory/ptr_util.h" #include "base/memory/scoped_vector.h" +#include "base/single_thread_task_runner.h" #include "base/strings/stringprintf.h" #include "base/synchronization/condition_variable.h" #include "base/synchronization/lock.h" @@ -63,10 +64,9 @@ class ScheduleWorkTest : public testing::Test { base::ThreadTicks::Now() - thread_start; min_batch_times_[index] = minimum; max_batch_times_[index] = maximum; - target_message_loop()->PostTask(FROM_HERE, - base::Bind(&ScheduleWorkTest::Increment, - base::Unretained(this), - schedule_calls)); + target_message_loop()->task_runner()->PostTask( + FROM_HERE, base::Bind(&ScheduleWorkTest::Increment, + base::Unretained(this), schedule_calls)); } void ScheduleWork(MessageLoop::Type target_type, int num_scheduling_threads) { @@ -101,7 +101,7 @@ class ScheduleWorkTest : public testing::Test { } for (int i = 0; i < num_scheduling_threads; ++i) { - scheduling_threads[i]->message_loop()->PostTask( + scheduling_threads[i]->message_loop()->task_runner()->PostTask( FROM_HERE, base::Bind(&ScheduleWorkTest::Schedule, base::Unretained(this), i)); } diff --git a/base/observer_list_unittest.cc b/base/observer_list_unittest.cc index 2e51e455216b96..097a2ed28b1549 100644 --- a/base/observer_list_unittest.cc +++ b/base/observer_list_unittest.cc @@ -111,7 +111,7 @@ class AddRemoveThread : public PlatformThread::Delegate, loop_->task_runner()->PostTask( FROM_HERE, base::Bind(&AddRemoveThread::AddTask, weak_factory_.GetWeakPtr())); - loop_->Run(); + RunLoop().Run(); //LOG(ERROR) << "Loop 0x" << std::hex << loop_ << " done. " << // count_observes_ << ", " << count_addtask_; delete loop_; diff --git a/base/sequence_checker_unittest.cc b/base/sequence_checker_unittest.cc index 1e89a5f4b48f14..196bb1cc797230 100644 --- a/base/sequence_checker_unittest.cc +++ b/base/sequence_checker_unittest.cc @@ -95,9 +95,8 @@ class SequenceCheckerTest : public testing::Test { void PostDeleteToOtherThread( std::unique_ptr sequence_checked_object) { - other_thread()->message_loop()->DeleteSoon( - FROM_HERE, - sequence_checked_object.release()); + other_thread()->message_loop()->task_runner()->DeleteSoon( + FROM_HERE, sequence_checked_object.release()); } // Destroys the SequencedWorkerPool instance, blocking until it is fully shut diff --git a/base/synchronization/waitable_event_watcher_unittest.cc b/base/synchronization/waitable_event_watcher_unittest.cc index 6ec55cedea94ad..8b76da58158497 100644 --- a/base/synchronization/waitable_event_watcher_unittest.cc +++ b/base/synchronization/waitable_event_watcher_unittest.cc @@ -59,7 +59,7 @@ void RunTest_BasicSignal(MessageLoop::Type message_loop_type) { event.Signal(); - MessageLoop::current()->Run(); + RunLoop().Run(); EXPECT_TRUE(watcher.GetWatchedEvent() == NULL); } diff --git a/base/test/launcher/test_launcher.cc b/base/test/launcher/test_launcher.cc index cfd08fbc49ca6d..6f8776ad0cb9b8 100644 --- a/base/test/launcher/test_launcher.cc +++ b/base/test/launcher/test_launcher.cc @@ -22,6 +22,7 @@ #include "base/message_loop/message_loop.h" #include "base/process/kill.h" #include "base/process/launch.h" +#include "base/run_loop.h" #include "base/single_thread_task_runner.h" #include "base/strings/pattern.h" #include "base/strings/string_number_conversions.h" @@ -535,7 +536,7 @@ bool TestLauncher::Run() { ThreadTaskRunnerHandle::Get()->PostTask( FROM_HERE, Bind(&TestLauncher::RunTestIteration, Unretained(this))); - MessageLoop::current()->Run(); + RunLoop().Run(); if (requested_cycles != 1) results_tracker_.PrintSummaryOfAllIterations(); diff --git a/base/test/power_monitor_test_base.cc b/base/test/power_monitor_test_base.cc index 73438ea3e94958..8e8b9124b018ba 100644 --- a/base/test/power_monitor_test_base.cc +++ b/base/test/power_monitor_test_base.cc @@ -7,6 +7,7 @@ #include "base/message_loop/message_loop.h" #include "base/power_monitor/power_monitor.h" #include "base/power_monitor/power_monitor_source.h" +#include "base/run_loop.h" namespace base { @@ -20,17 +21,17 @@ PowerMonitorTestSource::~PowerMonitorTestSource() { void PowerMonitorTestSource::GeneratePowerStateEvent(bool on_battery_power) { test_on_battery_power_ = on_battery_power; ProcessPowerEvent(POWER_STATE_EVENT); - message_loop_.RunUntilIdle(); + RunLoop().RunUntilIdle(); } void PowerMonitorTestSource::GenerateSuspendEvent() { ProcessPowerEvent(SUSPEND_EVENT); - message_loop_.RunUntilIdle(); + RunLoop().RunUntilIdle(); } void PowerMonitorTestSource::GenerateResumeEvent() { ProcessPowerEvent(RESUME_EVENT); - message_loop_.RunUntilIdle(); + RunLoop().RunUntilIdle(); } bool PowerMonitorTestSource::IsOnBatteryPowerImpl() { diff --git a/base/test/sequenced_worker_pool_owner.cc b/base/test/sequenced_worker_pool_owner.cc index 37bad2b29d25c5..8781495d7d381d 100644 --- a/base/test/sequenced_worker_pool_owner.cc +++ b/base/test/sequenced_worker_pool_owner.cc @@ -54,7 +54,8 @@ void SequencedWorkerPoolOwner::WillWaitForShutdown() { } void SequencedWorkerPoolOwner::OnDestruct() { - constructor_message_loop_->PostTask(FROM_HERE, exit_loop_.QuitClosure()); + constructor_message_loop_->task_runner()->PostTask(FROM_HERE, + exit_loop_.QuitClosure()); } } // namespace base diff --git a/base/test/test_message_loop.cc b/base/test/test_message_loop.cc index cc6a00073d8372..7283a8799294d3 100644 --- a/base/test/test_message_loop.cc +++ b/base/test/test_message_loop.cc @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/run_loop.h" #include "base/test/test_message_loop.h" namespace base { @@ -11,7 +12,7 @@ TestMessageLoop::TestMessageLoop() {} TestMessageLoop::TestMessageLoop(MessageLoop::Type type) : loop_(type) {} TestMessageLoop::~TestMessageLoop() { - loop_.RunUntilIdle(); + RunLoop().RunUntilIdle(); } } // namespace base diff --git a/base/threading/thread.cc b/base/threading/thread.cc index 10e7206b5c0e17..11aaea1d7f8af1 100644 --- a/base/threading/thread.cc +++ b/base/threading/thread.cc @@ -7,6 +7,7 @@ #include "base/bind.h" #include "base/lazy_instance.h" #include "base/location.h" +#include "base/run_loop.h" #include "base/synchronization/waitable_event.h" #include "base/third_party/dynamic_annotations/dynamic_annotations.h" #include "base/threading/thread_id_name_manager.h" @@ -201,7 +202,7 @@ bool Thread::IsRunning() const { } void Thread::Run(MessageLoop* message_loop) { - message_loop->Run(); + RunLoop().Run(); } void Thread::SetThreadWasQuitProperly(bool flag) { diff --git a/base/timer/timer_unittest.cc b/base/timer/timer_unittest.cc index 2263a09f896506..6fcd25b93a3af6 100644 --- a/base/timer/timer_unittest.cc +++ b/base/timer/timer_unittest.cc @@ -10,6 +10,7 @@ #include "base/macros.h" #include "base/message_loop/message_loop.h" +#include "base/run_loop.h" #include "base/test/test_simple_task_runner.h" #include "base/threading/thread_task_runner_handle.h" #include "build/build_config.h" @@ -116,7 +117,7 @@ void RunTest_OneShotTimer(base::MessageLoop::Type message_loop_type) { OneShotTimerTester f(&did_run); f.Start(); - base::MessageLoop::current()->Run(); + base::RunLoop().Run(); EXPECT_TRUE(did_run); } @@ -137,7 +138,7 @@ void RunTest_OneShotTimer_Cancel(base::MessageLoop::Type message_loop_type) { OneShotTimerTester b(&did_run_b); b.Start(); - base::MessageLoop::current()->Run(); + base::RunLoop().Run(); EXPECT_FALSE(did_run_a); EXPECT_TRUE(did_run_b); @@ -151,7 +152,7 @@ void RunTest_OneShotSelfDeletingTimer( OneShotSelfDeletingTimerTester f(&did_run); f.Start(); - base::MessageLoop::current()->Run(); + base::RunLoop().Run(); EXPECT_TRUE(did_run); } @@ -164,7 +165,7 @@ void RunTest_RepeatingTimer(base::MessageLoop::Type message_loop_type, RepeatingTimerTester f(&did_run, delay); f.Start(); - base::MessageLoop::current()->Run(); + base::RunLoop().Run(); EXPECT_TRUE(did_run); } @@ -186,7 +187,7 @@ void RunTest_RepeatingTimer_Cancel(base::MessageLoop::Type message_loop_type, RepeatingTimerTester b(&did_run_b, delay); b.Start(); - base::MessageLoop::current()->Run(); + base::RunLoop().Run(); EXPECT_FALSE(did_run_a); EXPECT_TRUE(did_run_b); @@ -216,7 +217,7 @@ void RunTest_DelayTimer_NoCall(base::MessageLoop::Type message_loop_type) { bool did_run = false; OneShotTimerTester tester(&did_run); tester.Start(); - base::MessageLoop::current()->Run(); + base::RunLoop().Run(); ASSERT_FALSE(target.signaled()); } @@ -232,7 +233,7 @@ void RunTest_DelayTimer_OneCall(base::MessageLoop::Type message_loop_type) { bool did_run = false; OneShotTimerTester tester(&did_run, 100 /* milliseconds */); tester.Start(); - base::MessageLoop::current()->Run(); + base::RunLoop().Run(); ASSERT_TRUE(target.signaled()); } @@ -271,7 +272,7 @@ void RunTest_DelayTimer_Reset(base::MessageLoop::Type message_loop_type) { bool did_run = false; OneShotTimerTester tester(&did_run, 300); tester.Start(); - base::MessageLoop::current()->Run(); + base::RunLoop().Run(); ASSERT_TRUE(target.signaled()); } @@ -514,7 +515,7 @@ TEST(TimerTest, ContinuationStopStart) { timer.Stop(); timer.Start(FROM_HERE, TimeDelta::FromMilliseconds(40), base::Bind(&SetCallbackHappened2)); - base::MessageLoop::current()->Run(); + base::RunLoop().Run(); EXPECT_FALSE(g_callback_happened1); EXPECT_TRUE(g_callback_happened2); } @@ -530,7 +531,7 @@ TEST(TimerTest, ContinuationReset) { timer.Reset(); // Since Reset happened before task ran, the user_task must not be cleared: ASSERT_FALSE(timer.user_task().is_null()); - base::MessageLoop::current()->Run(); + base::RunLoop().Run(); EXPECT_TRUE(g_callback_happened1); } } diff --git a/base/trace_event/trace_event_system_stats_monitor_unittest.cc b/base/trace_event/trace_event_system_stats_monitor_unittest.cc index e834ded370003c..3ec6eab81634c3 100644 --- a/base/trace_event/trace_event_system_stats_monitor_unittest.cc +++ b/base/trace_event/trace_event_system_stats_monitor_unittest.cc @@ -8,6 +8,7 @@ #include #include "base/macros.h" +#include "base/run_loop.h" #include "base/trace_event/trace_event_impl.h" #include "build/build_config.h" #include "testing/gtest/include/gtest/gtest.h" @@ -48,12 +49,12 @@ TEST_F(TraceSystemStatsMonitorTest, TraceEventSystemStatsMonitor) { // Simulate enabling tracing. system_stats_monitor->StartProfiling(); - message_loop.RunUntilIdle(); + RunLoop().RunUntilIdle(); EXPECT_TRUE(system_stats_monitor->IsTimerRunningForTest()); // Simulate disabling tracing. system_stats_monitor->StopProfiling(); - message_loop.RunUntilIdle(); + RunLoop().RunUntilIdle(); EXPECT_FALSE(system_stats_monitor->IsTimerRunningForTest()); // Deleting the observer removes it from the TraceLog observer list.