Skip to content

Commit

Permalink
Introduce ChannelMojo
Browse files Browse the repository at this point in the history
This CL introduces ChannelMojo IPC::Channel implementation
and optionally applies it for renderer-browser IPC channel.

Current stability is like 5-seconds browser and There are rough edges.
It often closes the channel so needs to be more robust.
Even though the level of stability, having it in the tree will helps
team to try and improve it.

BUG=377980
R=darin@chromium.org,jam@chromium.org,viettrungluu@chromium.org
TEST=ipc_channel_mojo_unittest.cc

Review URL: https://codereview.chromium.org/382333002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@287402 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
morrita@chromium.org committed Aug 4, 2014
1 parent d93dbd1 commit 6486088
Show file tree
Hide file tree
Showing 49 changed files with 1,848 additions and 126 deletions.
1 change: 1 addition & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ group("root") {
"//google_apis",
"//google_apis/gcm",
"//ipc",
"//ipc/mojo",
"//media",
"//media/cast",
"//mojo",
Expand Down
6 changes: 6 additions & 0 deletions build/all.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
'../gpu/gpu.gyp:*',
'../gpu/tools/tools.gyp:*',
'../ipc/ipc.gyp:*',
'../ipc/mojo/ipc_mojo.gyp:*',
'../jingle/jingle.gyp:*',
'../media/cast/cast.gyp:*',
'../media/media.gyp:*',
Expand Down Expand Up @@ -291,6 +292,7 @@
'../gpu/gles2_conform_support/gles2_conform_support.gyp:gles2_conform_support',
'../gpu/gpu.gyp:gpu_unittests',
'../ipc/ipc.gyp:ipc_tests',
'../ipc/mojo/ipc_mojo.gyp:ipc_mojo_unittests',
'../jingle/jingle.gyp:jingle_unittests',
'../media/cast/cast.gyp:cast_unittests',
'../media/media.gyp:media_unittests',
Expand Down Expand Up @@ -849,6 +851,7 @@
'../google_apis/gcm/gcm.gyp:gcm_unit_tests',
'../gpu/gpu.gyp:gpu_unittests',
'../ipc/ipc.gyp:ipc_tests',
'../ipc/mojo/ipc_mojo.gyp:ipc_mojo_unittests',
'../jingle/jingle.gyp:jingle_unittests',
'../media/media.gyp:media_unittests',
'../ppapi/ppapi_internal.gyp:ppapi_unittests',
Expand Down Expand Up @@ -885,6 +888,7 @@
'../google_apis/gcm/gcm.gyp:gcm_unit_tests',
'../gpu/gpu.gyp:gpu_unittests',
'../ipc/ipc.gyp:ipc_tests',
'../ipc/mojo/ipc_mojo.gyp:ipc_mojo_unittests',
'../jingle/jingle.gyp:jingle_unittests',
'../media/media.gyp:media_unittests',
'../ppapi/ppapi_internal.gyp:ppapi_unittests',
Expand Down Expand Up @@ -982,6 +986,7 @@
'../google_apis/gcm/gcm.gyp:gcm_unit_tests',
'../gpu/gpu.gyp:gpu_unittests',
'../ipc/ipc.gyp:ipc_tests',
'../ipc/mojo/ipc_mojo.gyp:ipc_mojo_unittests',
'../jingle/jingle.gyp:jingle_unittests',
'../media/media.gyp:media_unittests',
'../ppapi/ppapi_internal.gyp:ppapi_unittests',
Expand Down Expand Up @@ -1077,6 +1082,7 @@
'../gpu/gpu.gyp:angle_unittests',
'../gpu/gpu.gyp:gpu_unittests',
'../ipc/ipc.gyp:ipc_tests',
'../ipc/mojo/ipc_mojo.gyp:ipc_mojo_unittests',
'../jingle/jingle.gyp:jingle_unittests',
'../media/cast/cast.gyp:cast_unittests',
'../media/media.gyp:media_unittests',
Expand Down
29 changes: 24 additions & 5 deletions content/browser/renderer_host/render_process_host_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
#include "ipc/ipc_channel.h"
#include "ipc/ipc_logging.h"
#include "ipc/ipc_switches.h"
#include "ipc/mojo/ipc_channel_mojo.h"
#include "media/base/media_switches.h"
#include "net/url_request/url_request_context_getter.h"
#include "ppapi/shared_impl/ppapi_switches.h"
Expand Down Expand Up @@ -594,11 +595,7 @@ bool RenderProcessHostImpl::Init() {
// Setup the IPC channel.
const std::string channel_id =
IPC::Channel::GenerateVerifiedChannelID(std::string());
channel_ = IPC::ChannelProxy::Create(
channel_id,
IPC::Channel::MODE_SERVER,
this,
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO).get());
channel_ = CreateChannelProxy(channel_id);

// Setup the Mojo channel.
mojo_application_host_->Init();
Expand Down Expand Up @@ -678,6 +675,27 @@ void RenderProcessHostImpl::MaybeActivateMojo() {
mojo_application_host_->Activate(this, GetHandle());
}

bool RenderProcessHostImpl::ShouldUseMojoChannel() const {
const CommandLine& command_line = *CommandLine::ForCurrentProcess();
return command_line.HasSwitch(switches::kEnableRendererMojoChannel);
}

scoped_ptr<IPC::ChannelProxy> RenderProcessHostImpl::CreateChannelProxy(
const std::string& channel_id) {
scoped_refptr<base::SingleThreadTaskRunner> runner =
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO);
if (ShouldUseMojoChannel()) {
VLOG(1) << "Mojo Channel is enabled on host";
return IPC::ChannelProxy::Create(
IPC::ChannelMojo::CreateFactory(
channel_id, IPC::Channel::MODE_SERVER, runner),
this, runner.get());
}

return IPC::ChannelProxy::Create(
channel_id, IPC::Channel::MODE_SERVER, this, runner.get());
}

void RenderProcessHostImpl::CreateMessageFilters() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
AddFilter(new ResourceSchedulerFilter(GetID()));
Expand Down Expand Up @@ -1128,6 +1146,7 @@ void RenderProcessHostImpl::PropagateBrowserCommandLineToRenderer(
switches::kEnablePinch,
switches::kEnablePreciseMemoryInfo,
switches::kEnablePreparsedJsCaching,
switches::kEnableRendererMojoChannel,
switches::kEnableSeccompFilterSandbox,
switches::kEnableSkiaBenchmarking,
switches::kEnableSmoothScrolling,
Expand Down
3 changes: 3 additions & 0 deletions content/browser/renderer_host/render_process_host_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,9 @@ class CONTENT_EXPORT RenderProcessHostImpl
friend class VisitRelayingRenderProcessHost;

void MaybeActivateMojo();
bool ShouldUseMojoChannel() const;
scoped_ptr<IPC::ChannelProxy> CreateChannelProxy(
const std::string& channel_id);

// Creates and adds the IO thread message filters.
void CreateMessageFilters();
Expand Down
59 changes: 44 additions & 15 deletions content/child/child_thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include "ipc/ipc_switches.h"
#include "ipc/ipc_sync_channel.h"
#include "ipc/ipc_sync_message_filter.h"
#include "ipc/mojo/ipc_channel_mojo.h"

#if defined(OS_WIN)
#include "content/common/handle_enumerator_win.h"
Expand Down Expand Up @@ -192,6 +193,17 @@ void QuitMainThreadMessageLoop() {

} // namespace

ChildThread::Options::Options()
: channel_name(CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
switches::kProcessChannelID)),
use_mojo_channel(false) {}

ChildThread::Options::Options(bool mojo)
: channel_name(CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
switches::kProcessChannelID)),
use_mojo_channel(mojo) {}


ChildThread::ChildThreadMessageRouter::ChildThreadMessageRouter(
IPC::Sender* sender)
: sender_(sender) {}
Expand All @@ -204,20 +216,43 @@ ChildThread::ChildThread()
: router_(this),
channel_connected_factory_(this),
in_browser_process_(false) {
channel_name_ = CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
switches::kProcessChannelID);
Init();
Init(Options());
}

ChildThread::ChildThread(const std::string& channel_name)
: channel_name_(channel_name),
router_(this),
ChildThread::ChildThread(const Options& options)
: router_(this),
channel_connected_factory_(this),
in_browser_process_(true) {
Init();
Init(options);
}

void ChildThread::Init() {
scoped_ptr<IPC::SyncChannel> ChildThread::CreateChannel(bool use_mojo_channel) {
if (use_mojo_channel) {
VLOG(1) << "Mojo is enabled on child";
return IPC::SyncChannel::Create(
IPC::ChannelMojo::CreateFactory(
channel_name_,
IPC::Channel::MODE_CLIENT,
ChildProcess::current()->io_message_loop_proxy()),
this,
ChildProcess::current()->io_message_loop_proxy(),
true,
ChildProcess::current()->GetShutDownEvent());
}

VLOG(1) << "Mojo is disabled on child";
return IPC::SyncChannel::Create(
channel_name_,
IPC::Channel::MODE_CLIENT,
this,
ChildProcess::current()->io_message_loop_proxy(),
true,
ChildProcess::current()->GetShutDownEvent());
}

void ChildThread::Init(const Options& options) {
channel_name_ = options.channel_name;

g_lazy_tls.Pointer()->Set(this);
on_channel_error_called_ = false;
message_loop_ = base::MessageLoop::current();
Expand All @@ -227,13 +262,7 @@ void ChildThread::Init() {
// the logger, and the logger does not like being created on the IO thread.
IPC::Logging::GetInstance();
#endif
channel_ =
IPC::SyncChannel::Create(channel_name_,
IPC::Channel::MODE_CLIENT,
this,
ChildProcess::current()->io_message_loop_proxy(),
true,
ChildProcess::current()->GetShutDownEvent());
channel_ = CreateChannel(options.use_mojo_channel);
#ifdef IPC_MESSAGE_LOG_ENABLED
if (!in_browser_process_)
IPC::Logging::GetInstance()->SetIPCSender(this);
Expand Down
15 changes: 13 additions & 2 deletions content/child/child_thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,20 @@ struct RequestInfo;
// The main thread of a child process derives from this class.
class CONTENT_EXPORT ChildThread : public IPC::Listener, public IPC::Sender {
public:
struct CONTENT_EXPORT Options {
Options();
explicit Options(bool mojo);
Options(std::string name, bool mojo)
: channel_name(name), use_mojo_channel(mojo) {}

std::string channel_name;
bool use_mojo_channel;
};

// Creates the thread.
ChildThread();
// Used for single-process mode and for in process gpu mode.
explicit ChildThread(const std::string& channel_name);
explicit ChildThread(const Options& options);
// ChildProcess::main_thread() is reset after Shutdown(), and before the
// destructor, so any subsystem that relies on ChildProcess::main_thread()
// must be terminated before Shutdown returns. In particular, if a subsystem
Expand Down Expand Up @@ -173,7 +183,8 @@ class CONTENT_EXPORT ChildThread : public IPC::Listener, public IPC::Sender {
IPC::Sender* const sender_;
};

void Init();
void Init(const Options& options);
scoped_ptr<IPC::SyncChannel> CreateChannel(bool use_mojo_channel);

// IPC message handlers.
void OnShutdown();
Expand Down
1 change: 1 addition & 0 deletions content/common/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ source_set("common") {
deps += [
"//cc",
"//ipc",
"//ipc/mojo",
"//mojo/environment:chromium",
"//mojo/system",
# TODO: the dependency on gl_in_process_context should be decoupled from
Expand Down
1 change: 1 addition & 0 deletions content/content_common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,7 @@
'../gpu/gpu.gyp:gpu_ipc',
'../gpu/skia_bindings/skia_bindings.gyp:gpu_skia_bindings',
'../ipc/ipc.gyp:ipc',
'../ipc/mojo/ipc_mojo.gyp:ipc_mojo',
'../media/media.gyp:media',
'../media/media.gyp:shared_memory_support',
'../mojo/mojo_base.gyp:mojo_application_bindings',
Expand Down
2 changes: 1 addition & 1 deletion content/gpu/gpu_child_thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ GpuChildThread::GpuChildThread(GpuWatchdogThread* watchdog_thread,
}

GpuChildThread::GpuChildThread(const std::string& channel_id)
: ChildThread(channel_id),
: ChildThread(Options(channel_id, false)),
dead_on_arrival_(false),
in_browser_process_(true) {
#if defined(OS_WIN)
Expand Down
4 changes: 4 additions & 0 deletions content/public/common/content_switches.cc
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,10 @@ const char kEnablePreparsedJsCaching[] = "enable-preparsed-js-caching";
const char kEnableRegionBasedColumns[] =
"enable-region-based-columns";

// Replaces renderer-browser IPC channel with ChnanelMojo.
const char kEnableRendererMojoChannel[] =
"enable-renderer-mojo-channel";

// Enables targeted style recalculation optimizations.
const char kEnableTargetedStyleRecalc[] =
"enable-targeted-style-recalc";
Expand Down
1 change: 1 addition & 0 deletions content/public/common/content_switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ CONTENT_EXPORT extern const char kEnablePinch[];
CONTENT_EXPORT extern const char kEnablePreciseMemoryInfo[];
extern const char kEnablePreparsedJsCaching[];
CONTENT_EXPORT extern const char kEnableRegionBasedColumns[];
CONTENT_EXPORT extern const char kEnableRendererMojoChannel[];
CONTENT_EXPORT extern const char kEnableSandboxLogging[];
extern const char kEnableSeccompFilterSandbox[];
extern const char kEnableSkiaBenchmarking[];
Expand Down
10 changes: 8 additions & 2 deletions content/renderer/render_thread_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,11 @@ void CreateRenderFrameSetup(mojo::InterfaceRequest<RenderFrameSetup> request) {
mojo::BindToRequest(new RenderFrameSetupImpl(), &request);
}

bool ShouldUseMojoChannel() {
return CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableRendererMojoChannel);
}

} // namespace

// For measuring memory usage after each task. Behind a command line flag.
Expand Down Expand Up @@ -363,12 +368,13 @@ RenderThreadImpl* RenderThreadImpl::current() {

// 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() {
RenderThreadImpl::RenderThreadImpl()
: ChildThread(Options(ShouldUseMojoChannel())) {
Init();
}

RenderThreadImpl::RenderThreadImpl(const std::string& channel_name)
: ChildThread(channel_name) {
: ChildThread(Options(channel_name, ShouldUseMojoChannel())) {
Init();
}

Expand Down
2 changes: 1 addition & 1 deletion content/utility/utility_thread_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ UtilityThreadImpl::UtilityThreadImpl() : single_process_(false) {
}

UtilityThreadImpl::UtilityThreadImpl(const std::string& channel_name)
: ChildThread(channel_name),
: ChildThread(Options(channel_name, false)),
single_process_(true) {
Init();
}
Expand Down
10 changes: 6 additions & 4 deletions ipc/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ component("ipc") {
"file_descriptor_set_posix.h",
"ipc_channel.cc",
"ipc_channel.h",
"ipc_channel_factory.cc",
"ipc_channel_factory.h",
"ipc_channel_common.cc",
"ipc_channel_handle.h",
"ipc_channel_nacl.cc",
Expand Down Expand Up @@ -95,8 +97,6 @@ if (!is_android) {
"ipc_sync_channel_unittest.cc",
"ipc_sync_message_unittest.cc",
"ipc_sync_message_unittest.h",
"ipc_test_base.cc",
"ipc_test_base.h",
"sync_socket_unittest.cc",
"unix_domain_socket_util_unittest.cc",
]
Expand Down Expand Up @@ -131,8 +131,6 @@ if (!is_android) {
test("ipc_perftests") {
sources = [
"ipc_perftests.cc",
"ipc_test_base.cc",
"ipc_test_base.h",
]

# TODO(brettw) hook up Android testing.
Expand Down Expand Up @@ -165,6 +163,10 @@ static_library("test_support") {
"ipc_multiprocess_test.h",
"ipc_test_sink.cc",
"ipc_test_sink.h",
"ipc_test_base.cc",
"ipc_test_base.h",
"ipc_test_channel_listener.h",
"ipc_test_channel_listener.cc",
]
deps = [
":ipc",
Expand Down
6 changes: 4 additions & 2 deletions ipc/ipc.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@
'ipc_sync_channel_unittest.cc',
'ipc_sync_message_unittest.cc',
'ipc_sync_message_unittest.h',
'ipc_test_base.cc',
'ipc_test_base.h',
'run_all_unittests.cc',
'sync_socket_unittest.cc',
'unix_domain_socket_util_unittest.cc',
Expand Down Expand Up @@ -132,6 +130,10 @@
'sources': [
'ipc_multiprocess_test.cc',
'ipc_multiprocess_test.h',
'ipc_test_base.cc',
'ipc_test_base.h',
'ipc_test_channel_listener.cc',
'ipc_test_channel_listener.h',
'ipc_test_sink.cc',
'ipc_test_sink.h',
],
Expand Down
2 changes: 2 additions & 0 deletions ipc/ipc.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
'file_descriptor_set_posix.h',
'ipc_channel.cc',
'ipc_channel.h',
'ipc_channel_factory.cc',
'ipc_channel_factory.h',
'ipc_channel_common.cc',
'ipc_channel_handle.h',
'ipc_channel_nacl.cc',
Expand Down
Loading

0 comments on commit 6486088

Please sign in to comment.