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,
{
CHECK(platform_handle.is_valid());
base::MessageLoop::current()->AddDestructionObserver(this);
base::MessageLoopCurrent::Get()->AddDestructionObserver(this);
channel_ = Channel::Create(
this,
......@@ -43,7 +43,7 @@ BrokerHost::BrokerHost(base::ProcessHandle client_process,
BrokerHost::~BrokerHost() {
// 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_)
channel_->ShutDown();
......
......@@ -10,6 +10,7 @@
#include "base/macros.h"
#include "base/message_loop/message_loop.h"
#include "base/message_loop/message_loop_current.h"
#include "base/process/process_handle.h"
#include "base/strings/string_piece.h"
#include "mojo/edk/embedder/process_error_callback.h"
......@@ -22,7 +23,7 @@ namespace edk {
// The BrokerHost is a channel to a broker client process, servicing synchronous
// IPCs issued by the client.
class BrokerHost : public Channel::Delegate,
public base::MessageLoop::DestructionObserver {
public base::MessageLoopCurrent::DestructionObserver {
public:
BrokerHost(base::ProcessHandle client_process,
ScopedPlatformHandle handle,
......@@ -47,7 +48,7 @@ class BrokerHost : public Channel::Delegate,
std::vector<ScopedPlatformHandle> handles) override;
void OnChannelError(Channel::Error error) override;
// base::MessageLoop::DestructionObserver:
// base::MessageLoopCurrent::DestructionObserver:
void WillDestroyCurrentMessageLoop() override;
void OnBufferRequest(uint32_t num_bytes);
......
......@@ -17,6 +17,7 @@
#include "base/macros.h"
#include "base/memory/ref_counted.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/synchronization/lock.h"
#include "base/task_runner.h"
......@@ -87,7 +88,7 @@ class MessageView {
};
class ChannelPosix : public Channel,
public base::MessageLoop::DestructionObserver,
public base::MessageLoopCurrent::DestructionObserver,
public base::MessagePumpForIO::FdWatcher {
public:
ChannelPosix(Delegate* delegate,
......@@ -211,15 +212,15 @@ class ChannelPosix : public Channel,
DCHECK(!write_watcher_);
read_watcher_.reset(
new base::MessagePumpForIO::FdWatchController(FROM_HERE));
base::MessageLoop::current()->AddDestructionObserver(this);
base::MessageLoopCurrent::Get()->AddDestructionObserver(this);
if (handle_.get().needs_connection) {
base::MessageLoopForIO::current()->WatchFileDescriptor(
base::MessageLoopCurrentForIO::Get()->WatchFileDescriptor(
handle_.get().handle, false /* persistent */,
base::MessagePumpForIO::WATCH_READ, read_watcher_.get(), this);
} else {
write_watcher_.reset(
new base::MessagePumpForIO::FdWatchController(FROM_HERE));
base::MessageLoopForIO::current()->WatchFileDescriptor(
base::MessageLoopCurrentForIO::Get()->WatchFileDescriptor(
handle_.get().handle, true /* persistent */,
base::MessagePumpForIO::WATCH_READ, read_watcher_.get(), this);
base::AutoLock lock(write_lock_);
......@@ -239,7 +240,7 @@ class ChannelPosix : public Channel,
return;
if (io_task_runner_->RunsTasksInCurrentSequence()) {
pending_write_ = true;
base::MessageLoopForIO::current()->WatchFileDescriptor(
base::MessageLoopCurrentForIO::Get()->WatchFileDescriptor(
handle_.get().handle, false /* persistent */,
base::MessagePumpForIO::WATCH_WRITE, write_watcher_.get(), this);
} else {
......@@ -250,7 +251,7 @@ class ChannelPosix : public Channel,
}
void ShutDownOnIOThread() {
base::MessageLoop::current()->RemoveDestructionObserver(this);
base::MessageLoopCurrent::Get()->RemoveDestructionObserver(this);
read_watcher_.reset();
write_watcher_.reset();
......@@ -265,7 +266,7 @@ class ChannelPosix : public Channel,
self_ = nullptr;
}
// base::MessageLoop::DestructionObserver:
// base::MessageLoopCurrent::DestructionObserver:
void WillDestroyCurrentMessageLoop() override {
DCHECK(io_task_runner_->RunsTasksInCurrentSequence());
if (self_)
......@@ -278,7 +279,7 @@ class ChannelPosix : public Channel,
if (handle_.get().needs_connection) {
#if !defined(OS_NACL)
read_watcher_.reset();
base::MessageLoop::current()->RemoveDestructionObserver(this);
base::MessageLoopCurrent::Get()->RemoveDestructionObserver(this);
ScopedPlatformHandle accept_fd;
ServerAcceptConnection(handle_, &accept_fd);
......
......@@ -17,6 +17,7 @@
#include "base/macros.h"
#include "base/memory/ref_counted.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/synchronization/lock.h"
#include "base/task_runner.h"
......@@ -29,7 +30,7 @@ namespace edk {
namespace {
class ChannelWin : public Channel,
public base::MessageLoop::DestructionObserver,
public base::MessageLoopCurrent::DestructionObserver,
public base::MessagePumpForIO::IOHandler {
public:
ChannelWin(Delegate* delegate,
......@@ -106,8 +107,8 @@ class ChannelWin : public Channel,
~ChannelWin() override {}
void StartOnIOThread() {
base::MessageLoop::current()->AddDestructionObserver(this);
base::MessageLoopForIO::current()->RegisterIOHandler(
base::MessageLoopCurrent::Get()->AddDestructionObserver(this);
base::MessageLoopCurrentForIO::Get()->RegisterIOHandler(
handle_.get().handle, this);
if (handle_.get().needs_connection) {
......@@ -150,7 +151,7 @@ class ChannelWin : public Channel,
}
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
// |handle_| should be valid at this point.
......@@ -164,7 +165,7 @@ class ChannelWin : public Channel,
self_ = nullptr;
}
// base::MessageLoop::DestructionObserver:
// base::MessageLoopCurrent::DestructionObserver:
void WillDestroyCurrentMessageLoop() override {
DCHECK(io_task_runner_->RunsTasksInCurrentSequence());
if (self_)
......
......@@ -14,6 +14,7 @@
#include "base/logging.h"
#include "base/macros.h"
#include "base/message_loop/message_loop.h"
#include "base/message_loop/message_loop_current.h"
#include "base/metrics/histogram_macros.h"
#include "base/process/process_handle.h"
#include "base/rand_util.h"
......@@ -103,8 +104,8 @@ ports::ScopedEvent DeserializeEventMessage(
// 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
// at that time.
class ThreadDestructionObserver :
public base::MessageLoop::DestructionObserver {
class ThreadDestructionObserver
: public base::MessageLoopCurrent::DestructionObserver {
public:
static void Create(scoped_refptr<base::TaskRunner> task_runner,
const base::Closure& callback) {
......@@ -120,14 +121,14 @@ class ThreadDestructionObserver :
private:
explicit ThreadDestructionObserver(const base::Closure& callback)
: callback_(callback) {
base::MessageLoop::current()->AddDestructionObserver(this);
base::MessageLoopCurrent::Get()->AddDestructionObserver(this);
}
~ThreadDestructionObserver() override {
base::MessageLoop::current()->RemoveDestructionObserver(this);
base::MessageLoopCurrent::Get()->RemoveDestructionObserver(this);
}
// base::MessageLoop::DestructionObserver:
// base::MessageLoopCurrent::DestructionObserver:
void WillDestroyCurrentMessageLoop() override {
callback_.Run();
delete this;
......
......@@ -13,6 +13,7 @@
#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "base/message_loop/message_loop.h"
#include "base/message_loop/message_loop_current.h"
#include "base/run_loop.h"
#include "base/synchronization/lock.h"
#include "base/threading/thread_local.h"
......@@ -64,11 +65,11 @@ class Connector::ActiveDispatchTracker {
// ActiveDispatchTrackers when a nested run loop is started.
class Connector::RunLoopNestingObserver
: public base::RunLoop::NestingObserver,
public base::MessageLoop::DestructionObserver {
public base::MessageLoopCurrent::DestructionObserver {
public:
RunLoopNestingObserver() {
base::RunLoop::AddNestingObserverOnCurrentThread(this);
base::MessageLoop::current()->AddDestructionObserver(this);
base::MessageLoopCurrent::Get()->AddDestructionObserver(this);
}
~RunLoopNestingObserver() override {}
......@@ -79,17 +80,17 @@ class Connector::RunLoopNestingObserver
top_tracker_->NotifyBeginNesting();
}
// base::MessageLoop::DestructionObserver:
// base::MessageLoopCurrent::DestructionObserver:
void WillDestroyCurrentMessageLoop() override {
base::RunLoop::RemoveNestingObserverOnCurrentThread(this);
base::MessageLoop::current()->RemoveDestructionObserver(this);
base::MessageLoopCurrent::Get()->RemoveDestructionObserver(this);
DCHECK_EQ(this, g_tls_nesting_observer.Get().Get());
g_tls_nesting_observer.Get().Set(nullptr);
delete this;
}
static RunLoopNestingObserver* GetForThread() {
if (!base::MessageLoop::current())
if (!base::MessageLoopCurrent::Get())
return nullptr;
auto* observer = static_cast<RunLoopNestingObserver*>(
g_tls_nesting_observer.Get().Get());
......
......@@ -9,6 +9,7 @@
#include "base/callback.h"
#include "base/memory/ptr_util.h"
#include "base/message_loop/message_loop.h"
#include "base/message_loop/message_loop_current.h"
#include "base/run_loop.h"
#include "base/strings/stringprintf.h"
#include "base/test/perf_time_logger.h"
......@@ -82,7 +83,7 @@ void PingPongTest::RunTest(int iterations, int batch_size, int message_size) {
current_iterations_ = 0;
calls_outstanding_ = 0;
base::MessageLoop::current()->SetNestableTasksAllowed(true);
base::MessageLoopCurrent::Get()->SetNestableTasksAllowed(true);
base::RunLoop run_loop;
quit_closure_ = run_loop.QuitClosure();
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