Skip to content

Commit

Permalink
Remove calls to deprecated MessageLoop methods in base.
Browse files Browse the repository at this point in the history
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}
  • Loading branch information
fdoray authored and Commit bot committed Jun 30, 2016
1 parent f8a7f3f commit 1022458
Show file tree
Hide file tree
Showing 21 changed files with 282 additions and 277 deletions.
19 changes: 10 additions & 9 deletions base/deferred_sequenced_task_runner_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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));
}

Expand All @@ -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));
}

Expand All @@ -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)));
}
Expand Down
8 changes: 4 additions & 4 deletions base/files/file_path_watcher_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ class FilePathWatcherTest : public testing::Test {

bool WaitForEvents() WARN_UNUSED_RESULT {
collector_->Reset();
loop_.Run();
RunLoop().Run();
return collector_->Success();
}

Expand Down Expand Up @@ -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));

Expand Down
31 changes: 16 additions & 15 deletions base/files/file_proxy_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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());
}

Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand All @@ -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());
Expand All @@ -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()));
Expand All @@ -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());

Expand All @@ -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_);
Expand All @@ -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_);
}
Expand Down Expand Up @@ -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_);
Expand All @@ -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_);
Expand All @@ -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.
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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);
Expand Down
7 changes: 4 additions & 3 deletions base/files/file_util_proxy_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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_);
Expand All @@ -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_);
Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions base/files/important_file_writer_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand All @@ -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()));
Expand All @@ -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()));
}
Expand Down
20 changes: 11 additions & 9 deletions base/mac/libdispatch_task_runner_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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();
}

Expand Down Expand Up @@ -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[] = {
Expand All @@ -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[] = {
Expand Down
Loading

0 comments on commit 1022458

Please sign in to comment.