summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormorrita <morrita@chromium.org>2015-03-17 18:48:29 -0700
committerCommit bot <commit-bot@chromium.org>2015-03-18 01:49:26 +0000
commitc6238ab6b40c8f0a291f75dbceb58535cf942eac (patch)
tree00442ea1dff2879348e36399816483f374015f7c
parentc61ff5194d2d46e2302e25f2c864115cc28ac13e (diff)
downloadchromium_src-c6238ab6b40c8f0a291f75dbceb58535cf942eac.zip
chromium_src-c6238ab6b40c8f0a291f75dbceb58535cf942eac.tar.gz
chromium_src-c6238ab6b40c8f0a291f75dbceb58535cf942eac.tar.bz2
Get rid of ChannelInit::SetSingleProcessIOTaskRunner()
The globally-set TaskRunner doesn't work because some child thread can run inside the browser process even when other child threads run in their own processes. For example, there is a configuration where GpuChildThread being in-process while RenderThreadImpl isn't. It is troublesome once non-renderer child processes adopt ChannelMojo. This CL eliminates the global in-process IO task runner and instead, passes an IO runnner for each thread if it is configured as an in-process mode. Note that InProcessChildThreadParams object is introuced to clarify that the parameter is for in-process mode. This is a spin-off from https://codereview.chromium.org/960693003/. R=jamesr@chromium.org, rockot@chromium.org, jam@chromium.org BUG=377980 Review URL: https://codereview.chromium.org/987693005 Cr-Commit-Position: refs/heads/master@{#321047}
-rw-r--r--content/browser/gpu/gpu_process_host.cc6
-rw-r--r--content/browser/gpu/gpu_process_host.h4
-rw-r--r--content/browser/renderer_host/render_process_host_impl.cc9
-rw-r--r--content/browser/renderer_host/render_process_host_impl.h3
-rw-r--r--content/browser/utility_process_host_impl.cc6
-rw-r--r--content/browser/utility_process_host_impl.h3
-rw-r--r--content/child/child_thread_impl.cc48
-rw-r--r--content/child/child_thread_impl.h11
-rw-r--r--content/child/mojo/mojo_application.cc13
-rw-r--r--content/child/mojo/mojo_application.h9
-rw-r--r--content/common/in_process_child_thread_params.cc18
-rw-r--r--content/common/in_process_child_thread_params.h38
-rw-r--r--content/common/mojo/channel_init.cc18
-rw-r--r--content/common/mojo/channel_init.h5
-rw-r--r--content/content_common.gypi2
-rw-r--r--content/gpu/gpu_child_thread.cc7
-rw-r--r--content/gpu/gpu_child_thread.h3
-rw-r--r--content/gpu/in_process_gpu_thread.cc11
-rw-r--r--content/gpu/in_process_gpu_thread.h9
-rw-r--r--content/renderer/in_process_renderer_thread.cc12
-rw-r--r--content/renderer/in_process_renderer_thread.h7
-rw-r--r--content/renderer/render_thread_impl.cc19
-rw-r--r--content/renderer/render_thread_impl.h5
-rw-r--r--content/renderer/render_thread_impl_browsertest.cc11
-rw-r--r--content/test/render_thread_impl_browser_test_ipc_helper.cc6
-rw-r--r--content/test/render_thread_impl_browser_test_ipc_helper.h2
-rw-r--r--content/utility/in_process_utility_thread.cc12
-rw-r--r--content/utility/in_process_utility_thread.h7
-rw-r--r--content/utility/utility_thread_impl.cc19
-rw-r--r--content/utility/utility_thread_impl.h5
30 files changed, 197 insertions, 131 deletions
diff --git a/content/browser/gpu/gpu_process_host.cc b/content/browser/gpu/gpu_process_host.cc
index a857a9d..f0dbf33 100644
--- a/content/browser/gpu/gpu_process_host.cc
+++ b/content/browser/gpu/gpu_process_host.cc
@@ -25,6 +25,7 @@
#include "content/browser/renderer_host/render_widget_resize_helper.h"
#include "content/common/child_process_host_impl.h"
#include "content/common/gpu/gpu_messages.h"
+#include "content/common/in_process_child_thread_params.h"
#include "content/common/view_messages.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/content_browser_client.h"
@@ -503,8 +504,11 @@ bool GpuProcessHost::Init() {
return false;
if (in_process_) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
DCHECK(g_gpu_main_thread_factory);
- in_process_gpu_thread_.reset(g_gpu_main_thread_factory(channel_id));
+ in_process_gpu_thread_.reset(
+ g_gpu_main_thread_factory(InProcessChildThreadParams(
+ channel_id, base::MessageLoop::current()->task_runner())));
base::Thread::Options options;
#if defined(OS_WIN)
// WGL needs to create its own window and pump messages on it.
diff --git a/content/browser/gpu/gpu_process_host.h b/content/browser/gpu/gpu_process_host.h
index 3600de8..b7d625bb9 100644
--- a/content/browser/gpu/gpu_process_host.h
+++ b/content/browser/gpu/gpu_process_host.h
@@ -40,10 +40,12 @@ struct ChannelHandle;
namespace content {
class BrowserChildProcessHostImpl;
class GpuMainThread;
+class InProcessChildThreadParams;
class RenderWidgetHostViewFrameSubscriber;
class ShaderDiskCache;
-typedef base::Thread* (*GpuMainThreadFactoryFunction)(const std::string& id);
+typedef base::Thread* (*GpuMainThreadFactoryFunction)(
+ const InProcessChildThreadParams&);
class GpuProcessHost : public BrowserChildProcessHostDelegate,
public IPC::Sender,
diff --git a/content/browser/renderer_host/render_process_host_impl.cc b/content/browser/renderer_host/render_process_host_impl.cc
index fefede1..97bc169 100644
--- a/content/browser/renderer_host/render_process_host_impl.cc
+++ b/content/browser/renderer_host/render_process_host_impl.cc
@@ -111,6 +111,7 @@
#include "content/common/frame_messages.h"
#include "content/common/gpu/gpu_memory_buffer_factory.h"
#include "content/common/gpu/gpu_messages.h"
+#include "content/common/in_process_child_thread_params.h"
#include "content/common/mojo/channel_init.h"
#include "content/common/mojo/mojo_messages.h"
#include "content/common/resource_messages.h"
@@ -628,7 +629,10 @@ bool RenderProcessHostImpl::Init() {
// thread in the renderer process runs the WebKit code and can sometimes
// make blocking calls to the UI thread (i.e. this thread), they need to run
// on separate threads.
- in_process_renderer_.reset(g_renderer_main_thread_factory(channel_id));
+ in_process_renderer_.reset(
+ g_renderer_main_thread_factory(InProcessChildThreadParams(
+ channel_id, BrowserThread::UnsafeGetMessageLoopForThread(
+ BrowserThread::IO)->task_runner())));
base::Thread::Options options;
#if defined(OS_WIN) && !defined(OS_MACOSX)
@@ -690,9 +694,6 @@ scoped_ptr<IPC::ChannelProxy> RenderProcessHostImpl::CreateChannelProxy(
scoped_refptr<base::SequencedTaskRunner> mojo_task_runner =
BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO)
->task_runner();
- if (run_renderer_in_process()) {
- ChannelInit::SetSingleProcessIOTaskRunner(mojo_task_runner);
- }
if (ShouldUseMojoChannel()) {
VLOG(1) << "Mojo Channel is enabled on host";
if (!channel_mojo_host_) {
diff --git a/content/browser/renderer_host/render_process_host_impl.h b/content/browser/renderer_host/render_process_host_impl.h
index 03733f7..0b00d26 100644
--- a/content/browser/renderer_host/render_process_host_impl.h
+++ b/content/browser/renderer_host/render_process_host_impl.h
@@ -46,6 +46,7 @@ class AudioRendererHost;
class BrowserCdmManager;
class BrowserDemuxerAndroid;
class GpuMessageFilter;
+class InProcessChildThreadParams;
class MessagePortMessageFilter;
class MojoApplicationHost;
class NotificationMessageFilter;
@@ -63,7 +64,7 @@ class StoragePartition;
class StoragePartitionImpl;
typedef base::Thread* (*RendererMainThreadFactoryFunction)(
- const std::string& id);
+ const InProcessChildThreadParams& params);
// Implements a concrete RenderProcessHost for the browser process for talking
// to actual renderer processes (as opposed to mocks).
diff --git a/content/browser/utility_process_host_impl.cc b/content/browser/utility_process_host_impl.cc
index 9df2a0ca..39dfe22 100644
--- a/content/browser/utility_process_host_impl.cc
+++ b/content/browser/utility_process_host_impl.cc
@@ -20,6 +20,7 @@
#include "content/browser/mojo/mojo_application_host.h"
#include "content/browser/renderer_host/render_process_host_impl.h"
#include "content/common/child_process_host_impl.h"
+#include "content/common/in_process_child_thread_params.h"
#include "content/common/utility_messages.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/content_browser_client.h"
@@ -211,7 +212,10 @@ bool UtilityProcessHostImpl::StartProcess() {
DCHECK(g_utility_main_thread_factory);
// See comment in RenderProcessHostImpl::Init() for the background on why we
// support single process mode this way.
- in_process_thread_.reset(g_utility_main_thread_factory(channel_id));
+ in_process_thread_.reset(
+ g_utility_main_thread_factory(InProcessChildThreadParams(
+ channel_id, BrowserThread::UnsafeGetMessageLoopForThread(
+ BrowserThread::IO)->task_runner())));
in_process_thread_->Start();
} else {
const base::CommandLine& browser_command_line =
diff --git a/content/browser/utility_process_host_impl.h b/content/browser/utility_process_host_impl.h
index 00b72e0..e21bca4 100644
--- a/content/browser/utility_process_host_impl.h
+++ b/content/browser/utility_process_host_impl.h
@@ -24,10 +24,11 @@ class Thread;
namespace content {
class BrowserChildProcessHostImpl;
+class InProcessChildThreadParams;
class MojoApplicationHost;
typedef base::Thread* (*UtilityMainThreadFactoryFunction)(
- const std::string& id);
+ const InProcessChildThreadParams&);
class CONTENT_EXPORT UtilityProcessHostImpl
: public NON_EXPORTED_BASE(UtilityProcessHost),
diff --git a/content/child/child_thread_impl.cc b/content/child/child_thread_impl.cc
index 4aa4aa6..41c5543 100644
--- a/content/child/child_thread_impl.cc
+++ b/content/child/child_thread_impl.cc
@@ -49,7 +49,7 @@
#include "content/child/thread_safe_sender.h"
#include "content/child/websocket_dispatcher.h"
#include "content/common/child_process_messages.h"
-#include "content/common/mojo/channel_init.h"
+#include "content/common/in_process_child_thread_params.h"
#include "content/public/common/content_switches.h"
#include "ipc/ipc_logging.h"
#include "ipc/ipc_switches.h"
@@ -209,7 +209,9 @@ ChildThread* ChildThread::Get() {
class ChildThreadImpl::SingleProcessChannelDelegate
: public IPC::ChannelMojo::Delegate {
public:
- explicit SingleProcessChannelDelegate() : weak_factory_(this) {}
+ explicit SingleProcessChannelDelegate(
+ scoped_refptr<base::SequencedTaskRunner> io_runner)
+ : io_runner_(io_runner), weak_factory_(this) {}
~SingleProcessChannelDelegate() override {}
@@ -218,19 +220,20 @@ class ChildThreadImpl::SingleProcessChannelDelegate
}
scoped_refptr<base::TaskRunner> GetIOTaskRunner() override {
- return ChannelInit::GetSingleProcessIOTaskRunner();
+ return io_runner_;
}
void OnChannelCreated(base::WeakPtr<IPC::ChannelMojo> channel) override {}
void DeleteSoon() {
- ChannelInit::GetSingleProcessIOTaskRunner()->PostTask(
+ io_runner_->PostTask(
FROM_HERE,
base::Bind(&base::DeletePointer<SingleProcessChannelDelegate>,
base::Unretained(this)));
}
private:
+ scoped_refptr<base::SequencedTaskRunner> io_runner_;
base::WeakPtrFactory<IPC::ChannelMojo::Delegate> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(SingleProcessChannelDelegate);
@@ -244,8 +247,7 @@ void ChildThreadImpl::SingleProcessChannelDelegateDeleter::operator()(
ChildThreadImpl::Options::Options()
: channel_name(base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
switches::kProcessChannelID)),
- use_mojo_channel(false),
- in_browser_process(false) {
+ use_mojo_channel(false) {
}
ChildThreadImpl::Options::~Options() {
@@ -255,8 +257,10 @@ ChildThreadImpl::Options::Builder::Builder() {
}
ChildThreadImpl::Options::Builder&
-ChildThreadImpl::Options::Builder::InBrowserProcess(bool in_browser_process) {
- options_.in_browser_process = in_browser_process;
+ChildThreadImpl::Options::Builder::InBrowserProcess(
+ const InProcessChildThreadParams& params) {
+ options_.browser_process_io_runner = params.io_runner();
+ options_.channel_name = params.channel_name();
return *this;
}
@@ -294,30 +298,32 @@ bool ChildThreadImpl::ChildThreadMessageRouter::Send(IPC::Message* msg) {
ChildThreadImpl::ChildThreadImpl()
: router_(this),
- in_browser_process_(false),
channel_connected_factory_(this) {
Init(Options::Builder().Build());
}
ChildThreadImpl::ChildThreadImpl(const Options& options)
: router_(this),
- in_browser_process_(options.in_browser_process),
+ browser_process_io_runner_(options.browser_process_io_runner),
channel_connected_factory_(this) {
Init(options);
}
+scoped_refptr<base::SequencedTaskRunner> ChildThreadImpl::GetIOTaskRunner() {
+ if (IsInBrowserProcess())
+ return browser_process_io_runner_;
+ return ChildProcess::current()->io_message_loop_proxy();
+}
+
void ChildThreadImpl::ConnectChannel(bool use_mojo_channel) {
bool create_pipe_now = true;
if (use_mojo_channel) {
VLOG(1) << "Mojo is enabled on child";
- scoped_refptr<base::TaskRunner> io_task_runner =
- ChannelInit::GetSingleProcessIOTaskRunner();
- if (io_task_runner) {
- single_process_channel_delegate_.reset(new SingleProcessChannelDelegate);
- } else {
- io_task_runner = ChildProcess::current()->io_message_loop_proxy();
- }
+ scoped_refptr<base::SequencedTaskRunner> io_task_runner = GetIOTaskRunner();
DCHECK(io_task_runner);
+ if (IsInBrowserProcess())
+ single_process_channel_delegate_.reset(
+ new SingleProcessChannelDelegate(io_task_runner));
ipc_support_.reset(new IPC::ScopedIPCSupport(io_task_runner));
channel_->Init(
IPC::ChannelMojo::CreateClientFactory(
@@ -347,11 +353,11 @@ void ChildThreadImpl::Init(const Options& options) {
this, ChildProcess::current()->io_message_loop_proxy(),
ChildProcess::current()->GetShutDownEvent());
#ifdef IPC_MESSAGE_LOG_ENABLED
- if (!in_browser_process_)
+ if (!IsInBrowserProcess())
IPC::Logging::GetInstance()->SetIPCSender(this);
#endif
- mojo_application_.reset(new MojoApplication);
+ mojo_application_.reset(new MojoApplication(GetIOTaskRunner()));
sync_message_filter_ =
new IPC::SyncMessageFilter(ChildProcess::current()->GetShutDownEvent());
@@ -716,6 +722,10 @@ void ChildThreadImpl::EnsureConnected() {
base::Process::Current().Terminate(0, false);
}
+bool ChildThreadImpl::IsInBrowserProcess() const {
+ return browser_process_io_runner_;
+}
+
void ChildThreadImpl::OnProcessBackgrounded(bool background) {
// Set timer slack to maximum on main thread when in background.
base::TimerSlack timer_slack = base::TIMER_SLACK_NONE;
diff --git a/content/child/child_thread_impl.h b/content/child/child_thread_impl.h
index 03727d6..7b04d42 100644
--- a/content/child/child_thread_impl.h
+++ b/content/child/child_thread_impl.h
@@ -12,6 +12,7 @@
#include "base/memory/shared_memory.h"
#include "base/memory/weak_ptr.h"
#include "base/power_monitor/power_monitor.h"
+#include "base/sequenced_task_runner.h"
#include "base/tracked_objects.h"
#include "content/child/mojo/mojo_application.h"
#include "content/common/content_export.h"
@@ -46,6 +47,7 @@ class ChildHistogramMessageFilter;
class ChildResourceMessageFilter;
class ChildSharedBitmapManager;
class FileSystemDispatcher;
+class InProcessChildThreadParams;
class NavigatorConnectDispatcher;
class NotificationDispatcher;
class PushDispatcher;
@@ -198,6 +200,9 @@ class CONTENT_EXPORT ChildThreadImpl
void OnChannelConnected(int32 peer_pid) override;
void OnChannelError() override;
+ bool IsInBrowserProcess() const;
+ scoped_refptr<base::SequencedTaskRunner> GetIOTaskRunner();
+
private:
class ChildThreadMessageRouter : public MessageRouter {
public:
@@ -298,7 +303,7 @@ class CONTENT_EXPORT ChildThreadImpl
scoped_refptr<NavigatorConnectDispatcher> navigator_connect_dispatcher_;
- bool in_browser_process_;
+ scoped_refptr<base::SequencedTaskRunner> browser_process_io_runner_;
base::WeakPtrFactory<ChildThreadImpl> channel_connected_factory_;
@@ -312,7 +317,7 @@ struct ChildThreadImpl::Options {
std::string channel_name;
bool use_mojo_channel;
- bool in_browser_process;
+ scoped_refptr<base::SequencedTaskRunner> browser_process_io_runner;
std::vector<IPC::MessageFilter*> startup_filters;
private:
@@ -323,7 +328,7 @@ class ChildThreadImpl::Options::Builder {
public:
Builder();
- Builder& InBrowserProcess(bool in_browser_process);
+ Builder& InBrowserProcess(const InProcessChildThreadParams& params);
Builder& UseMojoChannel(bool use_mojo_channel);
Builder& WithChannelName(const std::string& channel_name);
Builder& AddStartupFilter(IPC::MessageFilter* filter);
diff --git a/content/child/mojo/mojo_application.cc b/content/child/mojo/mojo_application.cc
index f896dc6..5deee5d 100644
--- a/content/child/mojo/mojo_application.cc
+++ b/content/child/mojo/mojo_application.cc
@@ -13,7 +13,10 @@
namespace content {
-MojoApplication::MojoApplication() {
+MojoApplication::MojoApplication(
+ scoped_refptr<base::SequencedTaskRunner> io_task_runner)
+ : io_task_runner_(io_task_runner) {
+ DCHECK(io_task_runner_);
}
MojoApplication::~MojoApplication() {
@@ -35,15 +38,9 @@ void MojoApplication::OnActivate(
#elif defined(OS_WIN)
base::PlatformFile handle = file;
#endif
- scoped_refptr<base::TaskRunner> io_task_runner =
- ChannelInit::GetSingleProcessIOTaskRunner();
- if (!io_task_runner) {
- io_task_runner = ChildProcess::current()->io_message_loop_proxy();
- }
- DCHECK(io_task_runner);
mojo::ScopedMessagePipeHandle message_pipe =
- channel_init_.Init(handle, io_task_runner);
+ channel_init_.Init(handle, io_task_runner_);
DCHECK(message_pipe.is_valid());
ApplicationSetupPtr application_setup;
diff --git a/content/child/mojo/mojo_application.h b/content/child/mojo/mojo_application.h
index 5b89ddb..5c207f2 100644
--- a/content/child/mojo/mojo_application.h
+++ b/content/child/mojo/mojo_application.h
@@ -9,6 +9,10 @@
#include "content/common/mojo/service_registry_impl.h"
#include "ipc/ipc_platform_file.h"
+namespace base {
+class SequencedTaskRunner;
+}
+
namespace IPC {
class Message;
}
@@ -21,7 +25,8 @@ namespace content {
// It makes the ServiceRegistry interface available.
class MojoApplication {
public:
- MojoApplication();
+ explicit MojoApplication(
+ scoped_refptr<base::SequencedTaskRunner> io_task_runner);
virtual ~MojoApplication();
bool OnMessageReceived(const IPC::Message& msg);
@@ -31,6 +36,8 @@ class MojoApplication {
private:
void OnActivate(const IPC::PlatformFileForTransit& file);
+ scoped_refptr<base::SequencedTaskRunner> io_task_runner_;
+
ChannelInit channel_init_;
ServiceRegistryImpl service_registry_;
diff --git a/content/common/in_process_child_thread_params.cc b/content/common/in_process_child_thread_params.cc
new file mode 100644
index 0000000..13e9390
--- /dev/null
+++ b/content/common/in_process_child_thread_params.cc
@@ -0,0 +1,18 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/common/in_process_child_thread_params.h"
+
+namespace content {
+
+InProcessChildThreadParams::InProcessChildThreadParams(
+ const std::string& channel_name,
+ scoped_refptr<base::SequencedTaskRunner> io_runner)
+ : channel_name_(channel_name), io_runner_(io_runner) {
+}
+
+InProcessChildThreadParams::~InProcessChildThreadParams() {
+}
+
+} // namespace content
diff --git a/content/common/in_process_child_thread_params.h b/content/common/in_process_child_thread_params.h
new file mode 100644
index 0000000..938a6ef
--- /dev/null
+++ b/content/common/in_process_child_thread_params.h
@@ -0,0 +1,38 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_COMMON_IN_PROCESS_CHILD_THREAD_PARAMS_H_
+#define CONTENT_COMMON_IN_PROCESS_CHILD_THREAD_PARAMS_H_
+
+#include <string>
+
+#include "base/memory/ref_counted.h"
+#include "base/sequenced_task_runner.h"
+#include "content/common/content_export.h"
+
+namespace content {
+
+// Tells ChildThreadImpl to run in in-process mode. There are a couple of
+// parameters to run in the mode: An emulated io task runner used by
+// ChnanelMojo, an IPC channel name to open.
+class CONTENT_EXPORT InProcessChildThreadParams {
+ public:
+ InProcessChildThreadParams(
+ const std::string& channel_name,
+ scoped_refptr<base::SequencedTaskRunner> io_runner);
+ ~InProcessChildThreadParams();
+
+ const std::string& channel_name() const { return channel_name_; }
+ scoped_refptr<base::SequencedTaskRunner> io_runner() const {
+ return io_runner_;
+ }
+
+ private:
+ std::string channel_name_;
+ scoped_refptr<base::SequencedTaskRunner> io_runner_;
+};
+
+} // namespace content
+
+#endif // CONTENT_COMMON_IN_PROCESS_CHILD_THREAD_PARAMS_H_
diff --git a/content/common/mojo/channel_init.cc b/content/common/mojo/channel_init.cc
index 453e06a..c2d4bf2 100644
--- a/content/common/mojo/channel_init.cc
+++ b/content/common/mojo/channel_init.cc
@@ -12,13 +12,6 @@
namespace content {
-namespace {
-
-base::LazyInstance<scoped_refptr<base::TaskRunner>>
- g_single_process_task_runner = LAZY_INSTANCE_INITIALIZER;
-
-} // namespace
-
ChannelInit::ChannelInit() : channel_info_(nullptr), weak_factory_(this) {}
ChannelInit::~ChannelInit() {
@@ -57,17 +50,6 @@ void ChannelInit::ShutdownOnIOThread() {
}
// static
-scoped_refptr<base::TaskRunner> ChannelInit::GetSingleProcessIOTaskRunner() {
- return g_single_process_task_runner.Get();
-}
-
-// static
-void ChannelInit::SetSingleProcessIOTaskRunner(
- scoped_refptr<base::TaskRunner> io_task_runner) {
- g_single_process_task_runner.Get() = io_task_runner;
-}
-
-// static
void ChannelInit::OnCreatedChannel(
base::WeakPtr<ChannelInit> self,
scoped_ptr<IPC::ScopedIPCSupport> ipc_support,
diff --git a/content/common/mojo/channel_init.h b/content/common/mojo/channel_init.h
index 6706e3b5..1dd7f15 100644
--- a/content/common/mojo/channel_init.h
+++ b/content/common/mojo/channel_init.h
@@ -39,11 +39,6 @@ class CONTENT_EXPORT ChannelInit {
// Shuts down the channel. Must be called from the IO thread.
void ShutdownOnIOThread();
- // Get/Set a shared I/O TaskRunner for children to use in single process mode.
- static scoped_refptr<base::TaskRunner> GetSingleProcessIOTaskRunner();
- static void SetSingleProcessIOTaskRunner(
- scoped_refptr<base::TaskRunner> io_task_runner);
-
private:
// Invoked on the thread on which this object lives once the channel has been
// established. This is a static method that takes a weak pointer to self,
diff --git a/content/content_common.gypi b/content/content_common.gypi
index c4fb4ab..827ffc9 100644
--- a/content/content_common.gypi
+++ b/content/content_common.gypi
@@ -388,6 +388,8 @@
'common/input_messages.h',
'common/inter_process_time_ticks_converter.cc',
'common/inter_process_time_ticks_converter.h',
+ 'common/in_process_child_thread_params.cc',
+ 'common/in_process_child_thread_params.h',
'common/mac/attributed_string_coder.h',
'common/mac/attributed_string_coder.mm',
'common/mac/font_descriptor.h',
diff --git a/content/gpu/gpu_child_thread.cc b/content/gpu/gpu_child_thread.cc
index 901618e..6c34189 100644
--- a/content/gpu/gpu_child_thread.cc
+++ b/content/gpu/gpu_child_thread.cc
@@ -76,10 +76,9 @@ GpuChildThread::GpuChildThread(GpuWatchdogThread* watchdog_thread,
g_thread_safe_sender.Get() = thread_safe_sender();
}
-GpuChildThread::GpuChildThread(const std::string& channel_id)
- : ChildThreadImpl(Options::Builder()
- .InBrowserProcess(true)
- .WithChannelName(channel_id)
+GpuChildThread::GpuChildThread(const InProcessChildThreadParams& params)
+ : ChildThreadImpl(ChildThreadImpl::Options::Builder()
+ .InBrowserProcess(params)
.Build()),
dead_on_arrival_(false),
in_browser_process_(true) {
diff --git a/content/gpu/gpu_child_thread.h b/content/gpu/gpu_child_thread.h
index 7103cd3..70a6bb8 100644
--- a/content/gpu/gpu_child_thread.h
+++ b/content/gpu/gpu_child_thread.h
@@ -42,8 +42,7 @@ class GpuChildThread : public ChildThreadImpl {
const gpu::GPUInfo& gpu_info,
const DeferredMessages& deferred_messages);
- // For single-process mode.
- explicit GpuChildThread(const std::string& channel_id);
+ explicit GpuChildThread(const InProcessChildThreadParams& params);
~GpuChildThread() override;
diff --git a/content/gpu/in_process_gpu_thread.cc b/content/gpu/in_process_gpu_thread.cc
index 8a7818d..dfd9d35 100644
--- a/content/gpu/in_process_gpu_thread.cc
+++ b/content/gpu/in_process_gpu_thread.cc
@@ -9,9 +9,9 @@
namespace content {
-InProcessGpuThread::InProcessGpuThread(const std::string& channel_id)
+InProcessGpuThread::InProcessGpuThread(const InProcessChildThreadParams& params)
: base::Thread("Chrome_InProcGpuThread"),
- channel_id_(channel_id),
+ params_(params),
gpu_process_(NULL) {
}
@@ -23,7 +23,7 @@ void InProcessGpuThread::Init() {
gpu_process_ = new GpuProcess();
// The process object takes ownership of the thread object, so do not
// save and delete the pointer.
- gpu_process_->set_main_thread(new GpuChildThread(channel_id_));
+ gpu_process_->set_main_thread(new GpuChildThread(params_));
}
void InProcessGpuThread::CleanUp() {
@@ -31,8 +31,9 @@ void InProcessGpuThread::CleanUp() {
delete gpu_process_;
}
-base::Thread* CreateInProcessGpuThread(const std::string& channel_id) {
- return new InProcessGpuThread(channel_id);
+base::Thread* CreateInProcessGpuThread(
+ const InProcessChildThreadParams& params) {
+ return new InProcessGpuThread(params);
}
} // namespace content
diff --git a/content/gpu/in_process_gpu_thread.h b/content/gpu/in_process_gpu_thread.h
index e8e0140..67ba017 100644
--- a/content/gpu/in_process_gpu_thread.h
+++ b/content/gpu/in_process_gpu_thread.h
@@ -7,6 +7,8 @@
#include "base/threading/thread.h"
#include "content/common/content_export.h"
+#include "content/common/content_export.h"
+#include "content/common/in_process_child_thread_params.h"
namespace content {
@@ -16,7 +18,7 @@ class GpuProcess;
// with --in-process-gpu or --single-process.
class InProcessGpuThread : public base::Thread {
public:
- explicit InProcessGpuThread(const std::string& channel_id);
+ InProcessGpuThread(const InProcessChildThreadParams& params);
~InProcessGpuThread() override;
protected:
@@ -24,7 +26,8 @@ class InProcessGpuThread : public base::Thread {
void CleanUp() override;
private:
- std::string channel_id_;
+ InProcessChildThreadParams params_;
+
// Deleted in CleanUp() on the gpu thread, so don't use smart pointers.
GpuProcess* gpu_process_;
@@ -32,7 +35,7 @@ class InProcessGpuThread : public base::Thread {
};
CONTENT_EXPORT base::Thread* CreateInProcessGpuThread(
- const std::string& channel_id);
+ const InProcessChildThreadParams& params);
} // namespace content
diff --git a/content/renderer/in_process_renderer_thread.cc b/content/renderer/in_process_renderer_thread.cc
index fa6b834..f2eecf9 100644
--- a/content/renderer/in_process_renderer_thread.cc
+++ b/content/renderer/in_process_renderer_thread.cc
@@ -10,8 +10,9 @@
namespace content {
-InProcessRendererThread::InProcessRendererThread(const std::string& channel_id)
- : Thread("Chrome_InProcRendererThread"), channel_id_(channel_id) {
+InProcessRendererThread::InProcessRendererThread(
+ const InProcessChildThreadParams& params)
+ : Thread("Chrome_InProcRendererThread"), params_(params) {
}
InProcessRendererThread::~InProcessRendererThread() {
@@ -20,7 +21,7 @@ InProcessRendererThread::~InProcessRendererThread() {
void InProcessRendererThread::Init() {
render_process_.reset(new RenderProcessImpl());
- new RenderThreadImpl(channel_id_);
+ new RenderThreadImpl(params_);
}
void InProcessRendererThread::CleanUp() {
@@ -38,8 +39,9 @@ void InProcessRendererThread::CleanUp() {
SetThreadWasQuitProperly(true);
}
-base::Thread* CreateInProcessRendererThread(const std::string& channel_id) {
- return new InProcessRendererThread(channel_id);
+base::Thread* CreateInProcessRendererThread(
+ const InProcessChildThreadParams& params) {
+ return new InProcessRendererThread(params);
}
} // namespace content
diff --git a/content/renderer/in_process_renderer_thread.h b/content/renderer/in_process_renderer_thread.h
index 4b4bc65..1156160 100644
--- a/content/renderer/in_process_renderer_thread.h
+++ b/content/renderer/in_process_renderer_thread.h
@@ -9,6 +9,7 @@
#include "base/threading/thread.h"
#include "content/common/content_export.h"
+#include "content/common/in_process_child_thread_params.h"
namespace content {
class RenderProcess;
@@ -17,7 +18,7 @@ class RenderProcess;
// single-process mode. It's not used in multi-process mode.
class InProcessRendererThread : public base::Thread {
public:
- explicit InProcessRendererThread(const std::string& channel_id);
+ explicit InProcessRendererThread(const InProcessChildThreadParams& params);
~InProcessRendererThread() override;
protected:
@@ -25,14 +26,14 @@ class InProcessRendererThread : public base::Thread {
void CleanUp() override;
private:
- std::string channel_id_;
+ InProcessChildThreadParams params_;
scoped_ptr<RenderProcess> render_process_;
DISALLOW_COPY_AND_ASSIGN(InProcessRendererThread);
};
CONTENT_EXPORT base::Thread* CreateInProcessRendererThread(
- const std::string& channel_id);
+ const InProcessChildThreadParams& params);
} // namespace content
diff --git a/content/renderer/render_thread_impl.cc b/content/renderer/render_thread_impl.cc
index f9d02f1..00a93c5 100644
--- a/content/renderer/render_thread_impl.cc
+++ b/content/renderer/render_thread_impl.cc
@@ -425,30 +425,19 @@ RenderThreadImpl* RenderThreadImpl::current() {
return lazy_tls.Pointer()->Get();
}
-// When we run plugins in process, we actually run them on the render thread,
-// which means that we need to make the render thread pump UI events.
-RenderThreadImpl::RenderThreadImpl()
- : ChildThreadImpl(Options::Builder()
- .InBrowserProcess(true)
- .UseMojoChannel(ShouldUseMojoChannel())
- .Build()) {
- Init();
-}
-
-RenderThreadImpl::RenderThreadImpl(const std::string& channel_name)
+RenderThreadImpl::RenderThreadImpl(const InProcessChildThreadParams& params)
: ChildThreadImpl(Options::Builder()
- .InBrowserProcess(true)
+ .InBrowserProcess(params)
.UseMojoChannel(ShouldUseMojoChannel())
- .WithChannelName(channel_name)
.Build()) {
Init();
}
+// When we run plugins in process, we actually run them on the render thread,
+// which means that we need to make the render thread pump UI events.
RenderThreadImpl::RenderThreadImpl(
scoped_ptr<base::MessageLoop> main_message_loop)
: ChildThreadImpl(Options::Builder()
- // TODO(skyostil): This should be set to false.
- .InBrowserProcess(true)
.UseMojoChannel(ShouldUseMojoChannel())
.Build()),
main_message_loop_(main_message_loop.Pass()) {
diff --git a/content/renderer/render_thread_impl.h b/content/renderer/render_thread_impl.h
index 6ec87b5..32ca4ab 100644
--- a/content/renderer/render_thread_impl.h
+++ b/content/renderer/render_thread_impl.h
@@ -131,10 +131,7 @@ class CONTENT_EXPORT RenderThreadImpl
public:
static RenderThreadImpl* current();
- RenderThreadImpl();
- // Constructor that's used when running in single process mode.
- explicit RenderThreadImpl(const std::string& channel_name);
- // Constructor that's used in RendererMain.
+ explicit RenderThreadImpl(const InProcessChildThreadParams& params);
explicit RenderThreadImpl(scoped_ptr<base::MessageLoop> main_message_loop);
~RenderThreadImpl() override;
void Shutdown() override;
diff --git a/content/renderer/render_thread_impl_browsertest.cc b/content/renderer/render_thread_impl_browsertest.cc
index 87d48f3..264826d 100644
--- a/content/renderer/render_thread_impl_browsertest.cc
+++ b/content/renderer/render_thread_impl_browsertest.cc
@@ -8,6 +8,7 @@
#include "base/memory/scoped_vector.h"
#include "base/strings/string_number_conversions.h"
#include "base/thread_task_runner_handle.h"
+#include "content/common/in_process_child_thread_params.h"
#include "content/common/resource_messages.h"
#include "content/common/websocket_messages.h"
#include "content/public/browser/content_browser_client.h"
@@ -87,9 +88,9 @@ class TestTaskCounter : public base::SingleThreadTaskRunner {
class RenderThreadImplForTest : public RenderThreadImpl {
public:
- RenderThreadImplForTest(const std::string& channel_id,
+ RenderThreadImplForTest(const InProcessChildThreadParams& params,
scoped_refptr<TestTaskCounter> test_task_counter)
- : RenderThreadImpl(channel_id), test_task_counter_(test_task_counter) {}
+ : RenderThreadImpl(params), test_task_counter_(test_task_counter) {}
~RenderThreadImplForTest() override {}
@@ -159,8 +160,10 @@ class RenderThreadImplBrowserTest : public testing::Test {
cmd->AppendSwitchASCII(switches::kUseImageTextureTarget,
base::UintToString(GL_TEXTURE_2D));
- thread_ = new RenderThreadImplForTest(test_helper_->GetChannelId(),
- test_task_counter_);
+ thread_ = new RenderThreadImplForTest(
+ InProcessChildThreadParams(test_helper_->GetChannelId(),
+ test_helper_->GetIOTaskRunner()),
+ test_task_counter_);
cmd->InitFromArgv(old_argv);
thread_->EnsureWebKitInitialized();
diff --git a/content/test/render_thread_impl_browser_test_ipc_helper.cc b/content/test/render_thread_impl_browser_test_ipc_helper.cc
index 3075f75..7f03885 100644
--- a/content/test/render_thread_impl_browser_test_ipc_helper.cc
+++ b/content/test/render_thread_impl_browser_test_ipc_helper.cc
@@ -41,7 +41,6 @@ void RenderThreadImplBrowserIPCTestHelper::SetupIpcThread() {
base::Thread::Options options;
options.message_loop_type = base::MessageLoop::TYPE_IO;
ASSERT_TRUE(ipc_thread_->StartWithOptions(options));
- ChannelInit::SetSingleProcessIOTaskRunner(ipc_thread_->task_runner());
}
void RenderThreadImplBrowserIPCTestHelper::SetupMojo() {
@@ -64,4 +63,9 @@ void RenderThreadImplBrowserIPCTestHelper::SetupMojo() {
mojo_host_->OnClientLaunched(base::GetCurrentProcessHandle());
}
+scoped_refptr<base::SingleThreadTaskRunner>
+RenderThreadImplBrowserIPCTestHelper::GetIOTaskRunner() const {
+ return ipc_thread_->task_runner();
+}
+
} // namespace content
diff --git a/content/test/render_thread_impl_browser_test_ipc_helper.h b/content/test/render_thread_impl_browser_test_ipc_helper.h
index b2eebd4..0d86732 100644
--- a/content/test/render_thread_impl_browser_test_ipc_helper.h
+++ b/content/test/render_thread_impl_browser_test_ipc_helper.h
@@ -33,6 +33,8 @@ class RenderThreadImplBrowserIPCTestHelper {
const std::string& GetChannelId() const { return channel_id_; }
+ scoped_refptr<base::SingleThreadTaskRunner> GetIOTaskRunner() const;
+
private:
class DummyListener;
diff --git a/content/utility/in_process_utility_thread.cc b/content/utility/in_process_utility_thread.cc
index a91bac5..ab5a229 100644
--- a/content/utility/in_process_utility_thread.cc
+++ b/content/utility/in_process_utility_thread.cc
@@ -13,8 +13,9 @@ namespace content {
// are many globals used in the utility process.
static base::LazyInstance<base::Lock> g_one_utility_thread_lock;
-InProcessUtilityThread::InProcessUtilityThread(const std::string& channel_id)
- : Thread("Chrome_InProcUtilityThread"), channel_id_(channel_id) {
+InProcessUtilityThread::InProcessUtilityThread(
+ const InProcessChildThreadParams& params)
+ : Thread("Chrome_InProcUtilityThread"), params_(params) {
}
InProcessUtilityThread::~InProcessUtilityThread() {
@@ -44,11 +45,12 @@ void InProcessUtilityThread::CleanUp() {
void InProcessUtilityThread::InitInternal() {
g_one_utility_thread_lock.Get().Acquire();
child_process_.reset(new ChildProcess());
- child_process_->set_main_thread(new UtilityThreadImpl(channel_id_));
+ child_process_->set_main_thread(new UtilityThreadImpl(params_));
}
-base::Thread* CreateInProcessUtilityThread(const std::string& channel_id) {
- return new InProcessUtilityThread(channel_id);
+base::Thread* CreateInProcessUtilityThread(
+ const InProcessChildThreadParams& params) {
+ return new InProcessUtilityThread(params);
}
} // namespace content
diff --git a/content/utility/in_process_utility_thread.h b/content/utility/in_process_utility_thread.h
index 00c71a1..2e16d1e 100644
--- a/content/utility/in_process_utility_thread.h
+++ b/content/utility/in_process_utility_thread.h
@@ -9,6 +9,7 @@
#include "base/threading/thread.h"
#include "content/common/content_export.h"
+#include "content/common/in_process_child_thread_params.h"
namespace content {
@@ -16,7 +17,7 @@ class ChildProcess;
class InProcessUtilityThread : public base::Thread {
public:
- InProcessUtilityThread(const std::string& channel_id);
+ InProcessUtilityThread(const InProcessChildThreadParams& params);
~InProcessUtilityThread() override;
private:
@@ -26,14 +27,14 @@ class InProcessUtilityThread : public base::Thread {
void InitInternal();
- std::string channel_id_;
+ InProcessChildThreadParams params_;
scoped_ptr<ChildProcess> child_process_;
DISALLOW_COPY_AND_ASSIGN(InProcessUtilityThread);
};
CONTENT_EXPORT base::Thread* CreateInProcessUtilityThread(
- const std::string& channel_id);
+ const InProcessChildThreadParams& params);
} // namespace content
diff --git a/content/utility/utility_thread_impl.cc b/content/utility/utility_thread_impl.cc
index a22005e..7ea1a1d 100644
--- a/content/utility/utility_thread_impl.cc
+++ b/content/utility/utility_thread_impl.cc
@@ -35,16 +35,15 @@ void ConvertVector(const SRC& src, DEST* dest) {
} // namespace
-UtilityThreadImpl::UtilityThreadImpl() : single_process_(false) {
+UtilityThreadImpl::UtilityThreadImpl()
+ : ChildThreadImpl(ChildThreadImpl::Options::Builder().Build()) {
Init();
}
-UtilityThreadImpl::UtilityThreadImpl(const std::string& channel_name)
- : ChildThreadImpl(Options::Builder()
- .InBrowserProcess(true)
- .WithChannelName(channel_name)
- .Build()),
- single_process_(true) {
+UtilityThreadImpl::UtilityThreadImpl(const InProcessChildThreadParams& params)
+ : ChildThreadImpl(ChildThreadImpl::Options::Builder()
+ .InBrowserProcess(params)
+ .Build()) {
Init();
}
@@ -54,7 +53,7 @@ UtilityThreadImpl::~UtilityThreadImpl() {
void UtilityThreadImpl::Shutdown() {
ChildThreadImpl::Shutdown();
- if (!single_process_)
+ if (!IsInBrowserProcess())
blink::shutdown();
}
@@ -62,7 +61,7 @@ void UtilityThreadImpl::ReleaseProcessIfNeeded() {
if (batch_mode_)
return;
- if (single_process_) {
+ if (IsInBrowserProcess()) {
// Close the channel to cause UtilityProcessHostImpl to be deleted. We need
// to take a different code path than the multi-process case because that
// depends on the child process going away to close the channel, but that
@@ -76,7 +75,7 @@ void UtilityThreadImpl::ReleaseProcessIfNeeded() {
void UtilityThreadImpl::Init() {
batch_mode_ = false;
ChildProcess::current()->AddRefProcess();
- if (!single_process_) {
+ if (!IsInBrowserProcess()) {
// We can only initialize WebKit on one thread, and in single process mode
// we run the utility thread on separate thread. This means that if any code
// needs WebKit initialized in the utility process, they need to have
diff --git a/content/utility/utility_thread_impl.h b/content/utility/utility_thread_impl.h
index 043aea9..4f0fa3f 100644
--- a/content/utility/utility_thread_impl.h
+++ b/content/utility/utility_thread_impl.h
@@ -33,7 +33,7 @@ class UtilityThreadImpl : public UtilityThread,
public:
UtilityThreadImpl();
// Constructor that's used when running in single process mode.
- explicit UtilityThreadImpl(const std::string& channel_name);
+ explicit UtilityThreadImpl(const InProcessChildThreadParams& params);
~UtilityThreadImpl() override;
void Shutdown() override;
@@ -56,9 +56,6 @@ class UtilityThreadImpl : public UtilityThread,
// True when we're running in batch mode.
bool batch_mode_;
- // True if running in single process mode.
- bool single_process_;
-
scoped_ptr<BlinkPlatformImpl> blink_platform_impl_;
DISALLOW_COPY_AND_ASSIGN(UtilityThreadImpl);