Commit bbede16b authored by Gabriel Charette's avatar Gabriel Charette Committed by Commit Bot

Cleanup MessageLoop::current() usage /content/child

Changes in patch set 1 were scripted as part of the effort to restrict exposure of the
raw MessageLoop*.

I've manually cleaned it up in the latest patch set to remove usage of MessageLoop*
another level.

This CL was uploaded by git cl split (initially).

R=haraken@chromium.org
TBR=piman@chromium.org (naming side-effect in ppapi_plugin/)

Bug: 825327
Change-Id: Id2c1dcb68c7a8fccafa5e0eee86fb5db82939a2f
Reviewed-on: https://chromium-review.googlesource.com/1024654
Commit-Queue: Gabriel Charette <gab@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#553539}
parent 4f9ee5fb
......@@ -101,13 +101,13 @@ void ChildProcess::set_main_thread(ChildThreadImpl* thread) {
void ChildProcess::AddRefProcess() {
DCHECK(!main_thread_.get() || // null in unittests.
main_thread_->message_loop()->task_runner()->BelongsToCurrentThread());
main_thread_->main_thread_runner()->BelongsToCurrentThread());
ref_count_++;
}
void ChildProcess::ReleaseProcess() {
DCHECK(!main_thread_.get() || // null in unittests.
main_thread_->message_loop()->task_runner()->BelongsToCurrentThread());
main_thread_->main_thread_runner()->BelongsToCurrentThread());
DCHECK(ref_count_);
if (--ref_count_)
return;
......
......@@ -17,7 +17,7 @@
#include "base/location.h"
#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/message_loop/timer_slack.h"
#include "base/metrics/field_trial.h"
#include "base/metrics/histogram_macros.h"
......@@ -208,7 +208,7 @@ void QuitClosure::BindToMainThread() {
scoped_refptr<base::SingleThreadTaskRunner> task_runner(
base::ThreadTaskRunnerHandle::Get());
base::Closure quit_closure =
base::MessageLoop::current()->QuitWhenIdleClosure();
base::MessageLoopCurrent::Get()->QuitWhenIdleClosure();
closure_ = base::Bind(&QuitClosure::PostClosure, task_runner, quit_closure);
cond_var_.Signal();
}
......@@ -428,7 +428,7 @@ void ChildThreadImpl::Init(const Options& options) {
TRACE_EVENT0("startup", "ChildThreadImpl::Init");
g_lazy_tls.Pointer()->Set(this);
on_channel_error_called_ = false;
message_loop_ = base::MessageLoop::current();
main_thread_runner_ = base::ThreadTaskRunnerHandle::Get();
#if BUILDFLAG(IPC_MESSAGE_LOG_ENABLED)
// We must make sure to instantiate the IPC Logger *before* we create the
// channel, otherwise we can get a callback on the IO thread which creates
......@@ -472,8 +472,8 @@ void ChildThreadImpl::Init(const Options& options) {
}
sync_message_filter_ = channel_->CreateSyncMessageFilter();
thread_safe_sender_ = new ThreadSafeSender(
message_loop_->task_runner(), sync_message_filter_.get());
thread_safe_sender_ =
new ThreadSafeSender(main_thread_runner_, sync_message_filter_.get());
auto registry = std::make_unique<service_manager::BinderRegistry>();
registry->AddInterface(base::Bind(&ChildHistogramFetcherFactoryImpl::Create),
......@@ -558,7 +558,7 @@ void ChildThreadImpl::Init(const Options& options) {
connection_timeout = temp;
}
message_loop_->task_runner()->PostDelayedTask(
main_thread_runner_->PostDelayedTask(
FROM_HERE,
base::BindOnce(&ChildThreadImpl::EnsureConnected,
channel_connected_factory_->GetWeakPtr()),
......@@ -641,7 +641,7 @@ void ChildThreadImpl::OnChannelError() {
}
bool ChildThreadImpl::Send(IPC::Message* msg) {
DCHECK(message_loop_->task_runner()->BelongsToCurrentThread());
DCHECK(main_thread_runner_->BelongsToCurrentThread());
if (!channel_) {
delete msg;
return false;
......@@ -701,7 +701,7 @@ service_manager::Connector* ChildThreadImpl::GetConnector() {
}
IPC::MessageRouter* ChildThreadImpl::GetRouter() {
DCHECK(message_loop_->task_runner()->BelongsToCurrentThread());
DCHECK(main_thread_runner_->BelongsToCurrentThread());
return &router_;
}
......
......@@ -12,6 +12,7 @@
#include <string>
#include "base/macros.h"
#include "base/memory/scoped_refptr.h"
#include "base/memory/shared_memory.h"
#include "base/memory/weak_ptr.h"
#include "base/metrics/field_trial.h"
......@@ -37,10 +38,6 @@
#include "content/common/font_loader_mac.mojom.h"
#endif
namespace base {
class MessageLoop;
} // namespace base
namespace IPC {
class MessageFilter;
class SyncChannel;
......@@ -132,7 +129,9 @@ class CONTENT_EXPORT ChildThreadImpl
return thread_safe_sender_.get();
}
base::MessageLoop* message_loop() const { return message_loop_; }
scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner() const {
return main_thread_runner_;
}
// Returns the one child thread. Can only be called on the main thread.
static ChildThreadImpl* current();
......@@ -248,7 +247,8 @@ class CONTENT_EXPORT ChildThreadImpl
// attempt to communicate.
bool on_channel_error_called_;
base::MessageLoop* message_loop_;
// TaskRunner to post tasks to the main thread.
scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner_;
std::unique_ptr<base::PowerMonitor> power_monitor_;
......
......@@ -148,7 +148,7 @@ void PpapiThread::Shutdown() {
bool PpapiThread::Send(IPC::Message* msg) {
// Allow access from multiple threads.
if (message_loop()->task_runner()->BelongsToCurrentThread())
if (main_thread_runner()->BelongsToCurrentThread())
return ChildThreadImpl::Send(msg);
return sync_message_filter()->Send(msg);
......
......@@ -801,7 +801,7 @@ void RenderThreadImpl::Init(
metrics::InitializeSingleSampleMetricsFactory(
base::BindRepeating(&CreateSingleSampleMetricsProvider,
message_loop()->task_runner(), GetConnector()));
main_thread_runner(), GetConnector()));
gpu_ = ui::Gpu::Create(GetConnector(),
base::FeatureList::IsEnabled(features::kMash)
......@@ -853,14 +853,13 @@ void RenderThreadImpl::Init(
peer_connection_factory_.reset(
new PeerConnectionDependencyFactory(p2p_socket_dispatcher_.get()));
aec_dump_message_filter_ = new AecDumpMessageFilter(
GetIOTaskRunner(), message_loop()->task_runner());
aec_dump_message_filter_ =
new AecDumpMessageFilter(GetIOTaskRunner(), main_thread_runner());
AddFilter(aec_dump_message_filter_.get());
#endif // BUILDFLAG(ENABLE_WEBRTC)
audio_input_ipc_factory_.emplace(message_loop()->task_runner(),
GetIOTaskRunner());
audio_input_ipc_factory_.emplace(main_thread_runner(), GetIOTaskRunner());
audio_output_ipc_factory_.emplace(GetIOTaskRunner());
......@@ -2397,7 +2396,7 @@ void RenderThreadImpl::RecordPurgeMemory(RendererMemoryMetrics before) {
scoped_refptr<base::SingleThreadTaskRunner>
RenderThreadImpl::GetMediaThreadTaskRunner() {
DCHECK(message_loop()->task_runner()->BelongsToCurrentThread());
DCHECK(main_thread_runner()->BelongsToCurrentThread());
if (!media_thread_) {
media_thread_.reset(new base::Thread("Media"));
media_thread_->Start();
......
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