Skip to content

Commit

Permalink
Remove calls to deprecated MessageLoop methods in jingle.
Browse files Browse the repository at this point in the history
This CL makes the following replacements in
jingle:

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 |y| isn't MessageLoopForUI::current() or
    MessageLoopForIO::current()

 y.message_loop()->task_runner()
                      y.task_runner()
y->message_loop()->task_runner()
                      y->task_runner()
----------------------------------------------------------

|x| is a base::MessageLoop(ForUI|ForIO) or a pointer to
a base::MessageLoop(ForUI|ForIO). |y| is a base::Thread
or a pointer to a base::Thread.

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
R=sergeyu@chromium.org

Review-Url: https://codereview.chromium.org/2082353002
Cr-Commit-Position: refs/heads/master@{#401400}
  • Loading branch information
fdoray authored and Commit bot committed Jun 22, 2016
1 parent 3af175c commit 83f4a1a
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 57 deletions.
34 changes: 11 additions & 23 deletions jingle/glue/chrome_async_socket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "base/bind.h"
#include "base/compiler_specific.h"
#include "base/logging.h"
#include "base/message_loop/message_loop.h"
#include "base/threading/thread_task_runner_handle.h"
#include "jingle/glue/resolving_client_socket_factory.h"
#include "net/base/address_list.h"
#include "net/base/host_port_pair.h"
Expand Down Expand Up @@ -117,12 +117,9 @@ bool ChromeAsyncSocket::Connect(const rtc::SocketAddress& address) {
// directly here as the caller may not expect an error/close to
// happen here. This is okay, as from the caller's point of view,
// the connect always happens asynchronously.
base::MessageLoop* message_loop = base::MessageLoop::current();
CHECK(message_loop);
message_loop->PostTask(
FROM_HERE,
base::Bind(&ChromeAsyncSocket::ProcessConnectDone,
weak_ptr_factory_.GetWeakPtr(), status));
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::Bind(&ChromeAsyncSocket::ProcessConnectDone,
weak_ptr_factory_.GetWeakPtr(), status));
}
return true;
}
Expand Down Expand Up @@ -154,12 +151,9 @@ void ChromeAsyncSocket::PostDoRead() {
DCHECK_EQ(read_state_, IDLE);
DCHECK_EQ(read_start_, 0U);
DCHECK_EQ(read_end_, 0U);
base::MessageLoop* message_loop = base::MessageLoop::current();
CHECK(message_loop);
message_loop->PostTask(
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
base::Bind(&ChromeAsyncSocket::DoRead,
weak_ptr_factory_.GetWeakPtr()));
base::Bind(&ChromeAsyncSocket::DoRead, weak_ptr_factory_.GetWeakPtr()));
read_state_ = POSTED;
}

Expand Down Expand Up @@ -288,12 +282,9 @@ void ChromeAsyncSocket::PostDoWrite() {
DCHECK(IsOpen());
DCHECK_EQ(write_state_, IDLE);
DCHECK_GT(write_end_, 0U);
base::MessageLoop* message_loop = base::MessageLoop::current();
CHECK(message_loop);
message_loop->PostTask(
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
base::Bind(&ChromeAsyncSocket::DoWrite,
weak_ptr_factory_.GetWeakPtr()));
base::Bind(&ChromeAsyncSocket::DoWrite, weak_ptr_factory_.GetWeakPtr()));
write_state_ = POSTED;
}

Expand Down Expand Up @@ -411,12 +402,9 @@ bool ChromeAsyncSocket::StartTls(const std::string& domain_name) {
base::Bind(&ChromeAsyncSocket::ProcessSSLConnectDone,
weak_ptr_factory_.GetWeakPtr()));
if (status != net::ERR_IO_PENDING) {
base::MessageLoop* message_loop = base::MessageLoop::current();
CHECK(message_loop);
message_loop->PostTask(
FROM_HERE,
base::Bind(&ChromeAsyncSocket::ProcessSSLConnectDone,
weak_ptr_factory_.GetWeakPtr(), status));
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::Bind(&ChromeAsyncSocket::ProcessSSLConnectDone,
weak_ptr_factory_.GetWeakPtr(), status));
}
return true;
}
Expand Down
3 changes: 2 additions & 1 deletion jingle/glue/proxy_resolving_client_socket_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "base/compiler_specific.h"
#include "base/macros.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/threading/thread_task_runner_handle.h"
#include "net/base/test_completion_callback.h"
#include "net/dns/mock_host_resolver.h"
Expand Down Expand Up @@ -46,7 +47,7 @@ class ProxyResolvingClientSocketTest : public testing::Test {
void TearDown() override {
// Clear out any messages posted by ProxyResolvingClientSocket's
// destructor.
message_loop_.RunUntilIdle();
base::RunLoop().RunUntilIdle();
}

base::MessageLoop message_loop_;
Expand Down
6 changes: 2 additions & 4 deletions jingle/glue/task_pump.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <stdint.h>

#include "base/bind.h"
#include "base/message_loop/message_loop.h"
#include "base/threading/thread_task_runner_handle.h"
#include "jingle/glue/task_pump.h"

namespace jingle_glue {
Expand All @@ -23,10 +23,8 @@ TaskPump::~TaskPump() {
void TaskPump::WakeTasks() {
DCHECK(CalledOnValidThread());
if (!stopped_ && !posted_wake_) {
base::MessageLoop* current_message_loop = base::MessageLoop::current();
CHECK(current_message_loop);
// Do the requested wake up.
current_message_loop->PostTask(
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
base::Bind(&TaskPump::CheckAndRunTasks, weak_factory_.GetWeakPtr()));
posted_wake_ = true;
Expand Down
28 changes: 15 additions & 13 deletions jingle/glue/thread_wrapper_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "base/bind.h"
#include "base/compiler_specific.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/single_thread_task_runner.h"
#include "base/threading/thread.h"
#include "jingle/glue/thread_wrapper.h"
#include "testing/gmock/include/gmock/gmock.h"
Expand Down Expand Up @@ -120,7 +122,7 @@ TEST_F(ThreadWrapperTest, Post) {
MatchMessage(&handler2_, kTestMessage1, data4)))
.WillOnce(DeleteMessageData());

message_loop_.RunUntilIdle();
base::RunLoop().RunUntilIdle();
}

TEST_F(ThreadWrapperTest, PostDelayed) {
Expand Down Expand Up @@ -153,10 +155,10 @@ TEST_F(ThreadWrapperTest, PostDelayed) {
MatchMessage(&handler2_, kTestMessage1, data4)))
.WillOnce(DeleteMessageData());

message_loop_.PostDelayedTask(
message_loop_.task_runner()->PostDelayedTask(
FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(),
base::TimeDelta::FromMilliseconds(kMaxTestDelay));
message_loop_.Run();
base::RunLoop().Run();
}

TEST_F(ThreadWrapperTest, Clear) {
Expand All @@ -180,7 +182,7 @@ TEST_F(ThreadWrapperTest, Clear) {
MatchMessage(&handler2_, kTestMessage2, null_data)))
.WillOnce(DeleteMessageData());

message_loop_.RunUntilIdle();
base::RunLoop().RunUntilIdle();
}

TEST_F(ThreadWrapperTest, ClearDelayed) {
Expand Down Expand Up @@ -208,10 +210,10 @@ TEST_F(ThreadWrapperTest, ClearDelayed) {
MatchMessage(&handler2_, kTestMessage1, null_data)))
.WillOnce(DeleteMessageData());

message_loop_.PostDelayedTask(
message_loop_.task_runner()->PostDelayedTask(
FROM_HERE, base::MessageLoop::QuitWhenIdleClosure(),
base::TimeDelta::FromMilliseconds(kMaxTestDelay));
message_loop_.Run();
base::RunLoop().Run();
}

// Verify that the queue is cleared when a handler is destroyed.
Expand Down Expand Up @@ -258,9 +260,9 @@ TEST_F(ThreadWrapperTest, SendToOtherThread) {
base::WaitableEvent::ResetPolicy::MANUAL,
base::WaitableEvent::InitialState::NOT_SIGNALED);
rtc::Thread* target;
second_thread.message_loop()->PostTask(
FROM_HERE, base::Bind(&InitializeWrapperForNewThread,
&target, &initialized_event));
second_thread.task_runner()->PostTask(
FROM_HERE,
base::Bind(&InitializeWrapperForNewThread, &target, &initialized_event));
initialized_event.Wait();

ASSERT_TRUE(target != NULL);
Expand Down Expand Up @@ -289,9 +291,9 @@ TEST_F(ThreadWrapperTest, SendDuringSend) {
base::WaitableEvent::ResetPolicy::MANUAL,
base::WaitableEvent::InitialState::NOT_SIGNALED);
rtc::Thread* target;
second_thread.message_loop()->PostTask(
FROM_HERE, base::Bind(&InitializeWrapperForNewThread,
&target, &initialized_event));
second_thread.task_runner()->PostTask(
FROM_HERE,
base::Bind(&InitializeWrapperForNewThread, &target, &initialized_event));
initialized_event.Wait();

ASSERT_TRUE(target != NULL);
Expand All @@ -313,7 +315,7 @@ TEST_F(ThreadWrapperTest, Dispose) {
bool deleted_ = false;
thread_->Dispose(new DeletableObject(&deleted_));
EXPECT_FALSE(deleted_);
message_loop_.RunUntilIdle();
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(deleted_);
}

Expand Down
5 changes: 3 additions & 2 deletions jingle/notifier/communicator/single_login_attempt_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "base/compiler_specific.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/threading/thread_task_runner_handle.h"
#include "jingle/notifier/base/const_communicator.h"
#include "jingle/notifier/base/fake_base_task.h"
Expand Down Expand Up @@ -93,15 +94,15 @@ class SingleLoginAttemptTest : public ::testing::Test {
"auth_mechanism"),
attempt_(new SingleLoginAttempt(login_settings_, &fake_delegate_)) {}

void TearDown() override { message_loop_.RunUntilIdle(); }
void TearDown() override { base::RunLoop().RunUntilIdle(); }

void FireRedirect(buzz::XmlElement* redirect_error) {
attempt_->OnError(buzz::XmppEngine::ERROR_STREAM, 0, redirect_error);
}

~SingleLoginAttemptTest() override {
attempt_.reset();
message_loop_.RunUntilIdle();
base::RunLoop().RunUntilIdle();
}

private:
Expand Down
21 changes: 11 additions & 10 deletions jingle/notifier/listener/non_blocking_push_client_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "base/compiler_specific.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/threading/thread_task_runner_handle.h"
#include "jingle/notifier/base/fake_base_task.h"
#include "jingle/notifier/listener/fake_push_client.h"
Expand All @@ -35,17 +36,17 @@ class NonBlockingPushClientTest : public testing::Test {
base::Unretained(this))));
push_client_->AddObserver(&fake_observer_);
// Pump message loop to run CreateFakePushClient.
message_loop_.RunUntilIdle();
base::RunLoop().RunUntilIdle();
}

void TearDown() override {
// Clear out any pending notifications before removing observers.
message_loop_.RunUntilIdle();
base::RunLoop().RunUntilIdle();
push_client_->RemoveObserver(&fake_observer_);
push_client_.reset();
// Then pump message loop to run
// NonBlockingPushClient::DestroyOnDelegateThread().
message_loop_.RunUntilIdle();
base::RunLoop().RunUntilIdle();
}

std::unique_ptr<PushClient> CreateFakePushClient() {
Expand All @@ -72,7 +73,7 @@ TEST_F(NonBlockingPushClientTest, UpdateSubscriptions) {

push_client_->UpdateSubscriptions(subscriptions);
EXPECT_TRUE(fake_push_client_->subscriptions().empty());
message_loop_.RunUntilIdle();
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(
SubscriptionListsEqual(
fake_push_client_->subscriptions(), subscriptions));
Expand All @@ -86,7 +87,7 @@ TEST_F(NonBlockingPushClientTest, UpdateCredentials) {
push_client_->UpdateCredentials(kEmail, kToken);
EXPECT_TRUE(fake_push_client_->email().empty());
EXPECT_TRUE(fake_push_client_->token().empty());
message_loop_.RunUntilIdle();
base::RunLoop().RunUntilIdle();
EXPECT_EQ(kEmail, fake_push_client_->email());
EXPECT_EQ(kToken, fake_push_client_->token());
}
Expand All @@ -107,7 +108,7 @@ TEST_F(NonBlockingPushClientTest, SendNotification) {

push_client_->SendNotification(notification);
EXPECT_TRUE(fake_push_client_->sent_notifications().empty());
message_loop_.RunUntilIdle();
base::RunLoop().RunUntilIdle();
ASSERT_EQ(1u, fake_push_client_->sent_notifications().size());
EXPECT_TRUE(
fake_push_client_->sent_notifications()[0].Equals(notification));
Expand All @@ -117,7 +118,7 @@ TEST_F(NonBlockingPushClientTest, SendNotification) {
TEST_F(NonBlockingPushClientTest, SendPing) {
push_client_->SendPing();
EXPECT_EQ(0, fake_push_client_->sent_pings());
message_loop_.RunUntilIdle();
base::RunLoop().RunUntilIdle();
ASSERT_EQ(1, fake_push_client_->sent_pings());
}

Expand All @@ -127,12 +128,12 @@ TEST_F(NonBlockingPushClientTest, NotificationStateChange) {
EXPECT_EQ(DEFAULT_NOTIFICATION_ERROR,
fake_observer_.last_notifications_disabled_reason());
fake_push_client_->EnableNotifications();
message_loop_.RunUntilIdle();
base::RunLoop().RunUntilIdle();
EXPECT_EQ(NO_NOTIFICATION_ERROR,
fake_observer_.last_notifications_disabled_reason());
fake_push_client_->DisableNotifications(
NOTIFICATION_CREDENTIALS_REJECTED);
message_loop_.RunUntilIdle();
base::RunLoop().RunUntilIdle();
EXPECT_EQ(NOTIFICATION_CREDENTIALS_REJECTED,
fake_observer_.last_notifications_disabled_reason());
}
Expand All @@ -142,7 +143,7 @@ TEST_F(NonBlockingPushClientTest, OnIncomingNotification) {
const Notification notification = MakeTestNotification();

fake_push_client_->SimulateIncomingNotification(notification);
message_loop_.RunUntilIdle();
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(
fake_observer_.last_incoming_notification().Equals(notification));
}
Expand Down
8 changes: 4 additions & 4 deletions jingle/notifier/listener/push_client_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "base/compiler_specific.h"
#include "base/location.h"
#include "base/message_loop/message_loop.h"
#include "base/single_thread_task_runner.h"
#include "base/threading/thread.h"
#include "jingle/notifier/base/notifier_options.h"
#include "net/url_request/url_request_test_util.h"
Expand Down Expand Up @@ -44,10 +45,9 @@ TEST_F(PushClientTest, CreateDefaultOnIOThread) {
TEST_F(PushClientTest, CreateDefaultOffIOThread) {
base::Thread thread("Non-IO thread");
EXPECT_TRUE(thread.Start());
thread.message_loop()->PostTask(
FROM_HERE,
base::Bind(base::IgnoreResult(&PushClient::CreateDefault),
notifier_options_));
thread.task_runner()->PostTask(
FROM_HERE, base::Bind(base::IgnoreResult(&PushClient::CreateDefault),
notifier_options_));
thread.Stop();
}

Expand Down

0 comments on commit 83f4a1a

Please sign in to comment.