Commit 32044bca authored by Gabriel Charette's avatar Gabriel Charette Committed by Commit Bot

Migrate MessageLoop::current() to MessageLoopCurrent in /mojo

These changes were scripted as part of the effort to restrict exposure of the
raw MessageLoop*.

Note that many static methods exposed on MessageLoopCurrent are also deprecated
so it is very well possible that this is migrating to an already deprecated
method.

The goal of this pass is to reduce usage of MessageLoop::current() (and
ultimately make it impossible to obtain the MessageLoop* statically).

As such I will not edit this CL unless the script did something logically wrong.
I defer to owners to fix highlighted usage of already deprecated APIs.

Possible script screw ups / things to look out for in this review:
 - Storing MessageLoopCurrent in a MessageLoop* variable or comparing it against
   one (I will go over that in a separate pass).

Includes should have been stripped if that was the last usage of message_loop.h
in that file.

Please CQ if LGTY

This CL was uploaded by git cl split.

R=sky@chromium.org

Bug: 825327
Change-Id: Ieae521d62d35bae3cd5c54309796f2b0c702679c
Reviewed-on: https://chromium-review.googlesource.com/1024378Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Gabriel Charette <gab@chromium.org>
Cr-Commit-Position: refs/heads/master@{#553454}
parent dc53a1b2
...@@ -32,7 +32,7 @@ BrokerHost::BrokerHost(base::ProcessHandle client_process, ...@@ -32,7 +32,7 @@ BrokerHost::BrokerHost(base::ProcessHandle client_process,
{ {
CHECK(platform_handle.is_valid()); CHECK(platform_handle.is_valid());
base::MessageLoop::current()->AddDestructionObserver(this); base::MessageLoopCurrent::Get()->AddDestructionObserver(this);
channel_ = Channel::Create( channel_ = Channel::Create(
this, this,
...@@ -43,7 +43,7 @@ BrokerHost::BrokerHost(base::ProcessHandle client_process, ...@@ -43,7 +43,7 @@ BrokerHost::BrokerHost(base::ProcessHandle client_process,
BrokerHost::~BrokerHost() { BrokerHost::~BrokerHost() {
// We're always destroyed on the creation thread, which is the IO thread. // We're always destroyed on the creation thread, which is the IO thread.
base::MessageLoop::current()->RemoveDestructionObserver(this); base::MessageLoopCurrent::Get()->RemoveDestructionObserver(this);
if (channel_) if (channel_)
channel_->ShutDown(); channel_->ShutDown();
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
#include "base/message_loop/message_loop_current.h"
#include "base/process/process_handle.h" #include "base/process/process_handle.h"
#include "base/strings/string_piece.h" #include "base/strings/string_piece.h"
#include "mojo/edk/embedder/process_error_callback.h" #include "mojo/edk/embedder/process_error_callback.h"
...@@ -22,7 +23,7 @@ namespace edk { ...@@ -22,7 +23,7 @@ namespace edk {
// The BrokerHost is a channel to a broker client process, servicing synchronous // The BrokerHost is a channel to a broker client process, servicing synchronous
// IPCs issued by the client. // IPCs issued by the client.
class BrokerHost : public Channel::Delegate, class BrokerHost : public Channel::Delegate,
public base::MessageLoop::DestructionObserver { public base::MessageLoopCurrent::DestructionObserver {
public: public:
BrokerHost(base::ProcessHandle client_process, BrokerHost(base::ProcessHandle client_process,
ScopedPlatformHandle handle, ScopedPlatformHandle handle,
...@@ -47,7 +48,7 @@ class BrokerHost : public Channel::Delegate, ...@@ -47,7 +48,7 @@ class BrokerHost : public Channel::Delegate,
std::vector<ScopedPlatformHandle> handles) override; std::vector<ScopedPlatformHandle> handles) override;
void OnChannelError(Channel::Error error) override; void OnChannelError(Channel::Error error) override;
// base::MessageLoop::DestructionObserver: // base::MessageLoopCurrent::DestructionObserver:
void WillDestroyCurrentMessageLoop() override; void WillDestroyCurrentMessageLoop() override;
void OnBufferRequest(uint32_t num_bytes); void OnBufferRequest(uint32_t num_bytes);
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
#include "base/message_loop/message_loop_current.h"
#include "base/message_loop/message_pump_for_io.h" #include "base/message_loop/message_pump_for_io.h"
#include "base/synchronization/lock.h" #include "base/synchronization/lock.h"
#include "base/task_runner.h" #include "base/task_runner.h"
...@@ -87,7 +88,7 @@ class MessageView { ...@@ -87,7 +88,7 @@ class MessageView {
}; };
class ChannelPosix : public Channel, class ChannelPosix : public Channel,
public base::MessageLoop::DestructionObserver, public base::MessageLoopCurrent::DestructionObserver,
public base::MessagePumpForIO::FdWatcher { public base::MessagePumpForIO::FdWatcher {
public: public:
ChannelPosix(Delegate* delegate, ChannelPosix(Delegate* delegate,
...@@ -211,15 +212,15 @@ class ChannelPosix : public Channel, ...@@ -211,15 +212,15 @@ class ChannelPosix : public Channel,
DCHECK(!write_watcher_); DCHECK(!write_watcher_);
read_watcher_.reset( read_watcher_.reset(
new base::MessagePumpForIO::FdWatchController(FROM_HERE)); new base::MessagePumpForIO::FdWatchController(FROM_HERE));
base::MessageLoop::current()->AddDestructionObserver(this); base::MessageLoopCurrent::Get()->AddDestructionObserver(this);
if (handle_.get().needs_connection) { if (handle_.get().needs_connection) {
base::MessageLoopForIO::current()->WatchFileDescriptor( base::MessageLoopCurrentForIO::Get()->WatchFileDescriptor(
handle_.get().handle, false /* persistent */, handle_.get().handle, false /* persistent */,
base::MessagePumpForIO::WATCH_READ, read_watcher_.get(), this); base::MessagePumpForIO::WATCH_READ, read_watcher_.get(), this);
} else { } else {
write_watcher_.reset( write_watcher_.reset(
new base::MessagePumpForIO::FdWatchController(FROM_HERE)); new base::MessagePumpForIO::FdWatchController(FROM_HERE));
base::MessageLoopForIO::current()->WatchFileDescriptor( base::MessageLoopCurrentForIO::Get()->WatchFileDescriptor(
handle_.get().handle, true /* persistent */, handle_.get().handle, true /* persistent */,
base::MessagePumpForIO::WATCH_READ, read_watcher_.get(), this); base::MessagePumpForIO::WATCH_READ, read_watcher_.get(), this);
base::AutoLock lock(write_lock_); base::AutoLock lock(write_lock_);
...@@ -239,7 +240,7 @@ class ChannelPosix : public Channel, ...@@ -239,7 +240,7 @@ class ChannelPosix : public Channel,
return; return;
if (io_task_runner_->RunsTasksInCurrentSequence()) { if (io_task_runner_->RunsTasksInCurrentSequence()) {
pending_write_ = true; pending_write_ = true;
base::MessageLoopForIO::current()->WatchFileDescriptor( base::MessageLoopCurrentForIO::Get()->WatchFileDescriptor(
handle_.get().handle, false /* persistent */, handle_.get().handle, false /* persistent */,
base::MessagePumpForIO::WATCH_WRITE, write_watcher_.get(), this); base::MessagePumpForIO::WATCH_WRITE, write_watcher_.get(), this);
} else { } else {
...@@ -250,7 +251,7 @@ class ChannelPosix : public Channel, ...@@ -250,7 +251,7 @@ class ChannelPosix : public Channel,
} }
void ShutDownOnIOThread() { void ShutDownOnIOThread() {
base::MessageLoop::current()->RemoveDestructionObserver(this); base::MessageLoopCurrent::Get()->RemoveDestructionObserver(this);
read_watcher_.reset(); read_watcher_.reset();
write_watcher_.reset(); write_watcher_.reset();
...@@ -265,7 +266,7 @@ class ChannelPosix : public Channel, ...@@ -265,7 +266,7 @@ class ChannelPosix : public Channel,
self_ = nullptr; self_ = nullptr;
} }
// base::MessageLoop::DestructionObserver: // base::MessageLoopCurrent::DestructionObserver:
void WillDestroyCurrentMessageLoop() override { void WillDestroyCurrentMessageLoop() override {
DCHECK(io_task_runner_->RunsTasksInCurrentSequence()); DCHECK(io_task_runner_->RunsTasksInCurrentSequence());
if (self_) if (self_)
...@@ -278,7 +279,7 @@ class ChannelPosix : public Channel, ...@@ -278,7 +279,7 @@ class ChannelPosix : public Channel,
if (handle_.get().needs_connection) { if (handle_.get().needs_connection) {
#if !defined(OS_NACL) #if !defined(OS_NACL)
read_watcher_.reset(); read_watcher_.reset();
base::MessageLoop::current()->RemoveDestructionObserver(this); base::MessageLoopCurrent::Get()->RemoveDestructionObserver(this);
ScopedPlatformHandle accept_fd; ScopedPlatformHandle accept_fd;
ServerAcceptConnection(handle_, &accept_fd); ServerAcceptConnection(handle_, &accept_fd);
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
#include "base/message_loop/message_loop_current.h"
#include "base/message_loop/message_pump_for_io.h" #include "base/message_loop/message_pump_for_io.h"
#include "base/synchronization/lock.h" #include "base/synchronization/lock.h"
#include "base/task_runner.h" #include "base/task_runner.h"
...@@ -29,7 +30,7 @@ namespace edk { ...@@ -29,7 +30,7 @@ namespace edk {
namespace { namespace {
class ChannelWin : public Channel, class ChannelWin : public Channel,
public base::MessageLoop::DestructionObserver, public base::MessageLoopCurrent::DestructionObserver,
public base::MessagePumpForIO::IOHandler { public base::MessagePumpForIO::IOHandler {
public: public:
ChannelWin(Delegate* delegate, ChannelWin(Delegate* delegate,
...@@ -106,8 +107,8 @@ class ChannelWin : public Channel, ...@@ -106,8 +107,8 @@ class ChannelWin : public Channel,
~ChannelWin() override {} ~ChannelWin() override {}
void StartOnIOThread() { void StartOnIOThread() {
base::MessageLoop::current()->AddDestructionObserver(this); base::MessageLoopCurrent::Get()->AddDestructionObserver(this);
base::MessageLoopForIO::current()->RegisterIOHandler( base::MessageLoopCurrentForIO::Get()->RegisterIOHandler(
handle_.get().handle, this); handle_.get().handle, this);
if (handle_.get().needs_connection) { if (handle_.get().needs_connection) {
...@@ -150,7 +151,7 @@ class ChannelWin : public Channel, ...@@ -150,7 +151,7 @@ class ChannelWin : public Channel,
} }
void ShutDownOnIOThread() { void ShutDownOnIOThread() {
base::MessageLoop::current()->RemoveDestructionObserver(this); base::MessageLoopCurrent::Get()->RemoveDestructionObserver(this);
// BUG(crbug.com/583525): This function is expected to be called once, and // BUG(crbug.com/583525): This function is expected to be called once, and
// |handle_| should be valid at this point. // |handle_| should be valid at this point.
...@@ -164,7 +165,7 @@ class ChannelWin : public Channel, ...@@ -164,7 +165,7 @@ class ChannelWin : public Channel,
self_ = nullptr; self_ = nullptr;
} }
// base::MessageLoop::DestructionObserver: // base::MessageLoopCurrent::DestructionObserver:
void WillDestroyCurrentMessageLoop() override { void WillDestroyCurrentMessageLoop() override {
DCHECK(io_task_runner_->RunsTasksInCurrentSequence()); DCHECK(io_task_runner_->RunsTasksInCurrentSequence());
if (self_) if (self_)
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
#include "base/message_loop/message_loop_current.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/process/process_handle.h" #include "base/process/process_handle.h"
#include "base/rand_util.h" #include "base/rand_util.h"
...@@ -103,8 +104,8 @@ ports::ScopedEvent DeserializeEventMessage( ...@@ -103,8 +104,8 @@ ports::ScopedEvent DeserializeEventMessage(
// Used by NodeController to watch for shutdown. Since no IO can happen once // Used by NodeController to watch for shutdown. Since no IO can happen once
// the IO thread is killed, the NodeController can cleanly drop all its peers // the IO thread is killed, the NodeController can cleanly drop all its peers
// at that time. // at that time.
class ThreadDestructionObserver : class ThreadDestructionObserver
public base::MessageLoop::DestructionObserver { : public base::MessageLoopCurrent::DestructionObserver {
public: public:
static void Create(scoped_refptr<base::TaskRunner> task_runner, static void Create(scoped_refptr<base::TaskRunner> task_runner,
const base::Closure& callback) { const base::Closure& callback) {
...@@ -120,14 +121,14 @@ class ThreadDestructionObserver : ...@@ -120,14 +121,14 @@ class ThreadDestructionObserver :
private: private:
explicit ThreadDestructionObserver(const base::Closure& callback) explicit ThreadDestructionObserver(const base::Closure& callback)
: callback_(callback) { : callback_(callback) {
base::MessageLoop::current()->AddDestructionObserver(this); base::MessageLoopCurrent::Get()->AddDestructionObserver(this);
} }
~ThreadDestructionObserver() override { ~ThreadDestructionObserver() override {
base::MessageLoop::current()->RemoveDestructionObserver(this); base::MessageLoopCurrent::Get()->RemoveDestructionObserver(this);
} }
// base::MessageLoop::DestructionObserver: // base::MessageLoopCurrent::DestructionObserver:
void WillDestroyCurrentMessageLoop() override { void WillDestroyCurrentMessageLoop() override {
callback_.Run(); callback_.Run();
delete this; delete this;
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
#include "base/message_loop/message_loop_current.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/synchronization/lock.h" #include "base/synchronization/lock.h"
#include "base/threading/thread_local.h" #include "base/threading/thread_local.h"
...@@ -64,11 +65,11 @@ class Connector::ActiveDispatchTracker { ...@@ -64,11 +65,11 @@ class Connector::ActiveDispatchTracker {
// ActiveDispatchTrackers when a nested run loop is started. // ActiveDispatchTrackers when a nested run loop is started.
class Connector::RunLoopNestingObserver class Connector::RunLoopNestingObserver
: public base::RunLoop::NestingObserver, : public base::RunLoop::NestingObserver,
public base::MessageLoop::DestructionObserver { public base::MessageLoopCurrent::DestructionObserver {
public: public:
RunLoopNestingObserver() { RunLoopNestingObserver() {
base::RunLoop::AddNestingObserverOnCurrentThread(this); base::RunLoop::AddNestingObserverOnCurrentThread(this);
base::MessageLoop::current()->AddDestructionObserver(this); base::MessageLoopCurrent::Get()->AddDestructionObserver(this);
} }
~RunLoopNestingObserver() override {} ~RunLoopNestingObserver() override {}
...@@ -79,17 +80,17 @@ class Connector::RunLoopNestingObserver ...@@ -79,17 +80,17 @@ class Connector::RunLoopNestingObserver
top_tracker_->NotifyBeginNesting(); top_tracker_->NotifyBeginNesting();
} }
// base::MessageLoop::DestructionObserver: // base::MessageLoopCurrent::DestructionObserver:
void WillDestroyCurrentMessageLoop() override { void WillDestroyCurrentMessageLoop() override {
base::RunLoop::RemoveNestingObserverOnCurrentThread(this); base::RunLoop::RemoveNestingObserverOnCurrentThread(this);
base::MessageLoop::current()->RemoveDestructionObserver(this); base::MessageLoopCurrent::Get()->RemoveDestructionObserver(this);
DCHECK_EQ(this, g_tls_nesting_observer.Get().Get()); DCHECK_EQ(this, g_tls_nesting_observer.Get().Get());
g_tls_nesting_observer.Get().Set(nullptr); g_tls_nesting_observer.Get().Set(nullptr);
delete this; delete this;
} }
static RunLoopNestingObserver* GetForThread() { static RunLoopNestingObserver* GetForThread() {
if (!base::MessageLoop::current()) if (!base::MessageLoopCurrent::Get())
return nullptr; return nullptr;
auto* observer = static_cast<RunLoopNestingObserver*>( auto* observer = static_cast<RunLoopNestingObserver*>(
g_tls_nesting_observer.Get().Get()); g_tls_nesting_observer.Get().Get());
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/callback.h" #include "base/callback.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
#include "base/message_loop/message_loop_current.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/test/perf_time_logger.h" #include "base/test/perf_time_logger.h"
...@@ -82,7 +83,7 @@ void PingPongTest::RunTest(int iterations, int batch_size, int message_size) { ...@@ -82,7 +83,7 @@ void PingPongTest::RunTest(int iterations, int batch_size, int message_size) {
current_iterations_ = 0; current_iterations_ = 0;
calls_outstanding_ = 0; calls_outstanding_ = 0;
base::MessageLoop::current()->SetNestableTasksAllowed(true); base::MessageLoopCurrent::Get()->SetNestableTasksAllowed(true);
base::RunLoop run_loop; base::RunLoop run_loop;
quit_closure_ = run_loop.QuitClosure(); quit_closure_ = run_loop.QuitClosure();
base::ThreadTaskRunnerHandle::Get()->PostTask( base::ThreadTaskRunnerHandle::Get()->PostTask(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment