Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / content / child / child_thread.cc
index 3222b41..34e7491 100644 (file)
@@ -37,7 +37,6 @@
 #include "content/child/quota_dispatcher.h"
 #include "content/child/quota_message_filter.h"
 #include "content/child/resource_dispatcher.h"
-#include "content/child/service_worker/service_worker_dispatcher.h"
 #include "content/child/service_worker/service_worker_message_filter.h"
 #include "content/child/socket_stream_dispatcher.h"
 #include "content/child/thread_safe_sender.h"
@@ -48,6 +47,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"
@@ -192,6 +192,17 @@ void QuitMainThreadMessageLoop() {
 
 }  // namespace
 
+ChildThread::Options::Options()
+    : channel_name(base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
+          switches::kProcessChannelID)),
+      use_mojo_channel(false) {}
+
+ChildThread::Options::Options(bool mojo)
+    : channel_name(base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
+          switches::kProcessChannelID)),
+      use_mojo_channel(mojo) {}
+
+
 ChildThread::ChildThreadMessageRouter::ChildThreadMessageRouter(
     IPC::Sender* sender)
     : sender_(sender) {}
@@ -202,22 +213,42 @@ bool ChildThread::ChildThreadMessageRouter::Send(IPC::Message* msg) {
 
 ChildThread::ChildThread()
     : router_(this),
-      channel_connected_factory_(this),
-      in_browser_process_(false) {
-  channel_name_ = CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
-      switches::kProcessChannelID);
-  Init();
+      in_browser_process_(false),
+      channel_connected_factory_(this) {
+  Init(Options());
+}
+
+ChildThread::ChildThread(const Options& options)
+    : router_(this),
+      in_browser_process_(true),
+      channel_connected_factory_(this) {
+  Init(options);
 }
 
-ChildThread::ChildThread(const std::string& channel_name)
-    : channel_name_(channel_name),
-      router_(this),
-      channel_connected_factory_(this),
-      in_browser_process_(true) {
-  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::CreateClientFactory(channel_name_),
+        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() {
+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();
@@ -227,19 +258,13 @@ 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);
 #endif
 
-  mojo_application_.reset(new MojoApplication(this));
+  mojo_application_.reset(new MojoApplication);
 
   sync_message_filter_ =
       new IPC::SyncMessageFilter(ChildProcess::current()->GetShutDownEvent());
@@ -257,8 +282,6 @@ void ChildThread::Init() {
 
   service_worker_message_filter_ =
       new ServiceWorkerMessageFilter(thread_safe_sender_.get());
-  service_worker_dispatcher_.reset(
-      new ServiceWorkerDispatcher(thread_safe_sender_.get()));
 
   quota_message_filter_ =
       new QuotaMessageFilter(thread_safe_sender_.get());
@@ -271,7 +294,8 @@ void ChildThread::Init() {
   channel_->AddFilter(quota_message_filter_->GetFilter());
   channel_->AddFilter(service_worker_message_filter_->GetFilter());
 
-  if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess)) {
+  if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
+          switches::kSingleProcess)) {
     // In single process mode, browser-side tracing will cover the whole
     // process including renderers.
     channel_->AddFilter(new tracing::ChildTraceMessageFilter(
@@ -291,13 +315,13 @@ void ChildThread::Init() {
 #if defined(OS_POSIX)
   // Check that --process-type is specified so we don't do this in unit tests
   // and single-process mode.
-  if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kProcessType))
+  if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kProcessType))
     channel_->AddFilter(new SuicideOnChannelErrorFilter());
 #endif
 
   int connection_timeout = kConnectionTimeoutS;
   std::string connection_override =
-      CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
+      base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
           switches::kIPCConnectionTimeout);
   if (!connection_override.empty()) {
     int temp;
@@ -370,15 +394,6 @@ void ChildThread::OnChannelError() {
   base::MessageLoop::current()->Quit();
 }
 
-void ChildThread::ConnectToService(
-    const mojo::String& service_url,
-    const mojo::String& service_name,
-    mojo::ScopedMessagePipeHandle message_pipe,
-    const mojo::String& requestor_url) {
-  // By default, we don't expect incoming connections.
-  NOTREACHED();
-}
-
 bool ChildThread::Send(IPC::Message* msg) {
   DCHECK(base::MessageLoop::current() == message_loop());
   if (!channel_) {
@@ -509,7 +524,7 @@ void ChildThread::OnDumpHandles() {
 #if defined(OS_WIN)
   scoped_refptr<HandleEnumerator> handle_enum(
       new HandleEnumerator(
-          CommandLine::ForCurrentProcess()->HasSwitch(
+          base::CommandLine::ForCurrentProcess()->HasSwitch(
               switches::kAuditAllHandles)));
   handle_enum->EnumerateHandles();
   Send(new ChildProcessHostMsg_DumpHandlesDone);
@@ -575,14 +590,6 @@ void ChildThread::OnProcessBackgrounded(bool background) {
   if (background)
     timer_slack = base::TIMER_SLACK_MAXIMUM;
   base::MessageLoop::current()->SetTimerSlack(timer_slack);
-
-#ifdef OS_WIN
-  // Windows Vista+ has a fancy process backgrounding mode that can only be set
-  // from within the process.
-  // TODO(wfh) Do not set background from within process until the issue with
-  // white tabs is resolved.  See http://crbug.com/398103.
-  // base::Process::Current().SetProcessBackgrounded(background);
-#endif  // OS_WIN
 }
 
 }  // namespace content