diff options
author | cmasone@chromium.org <cmasone@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-16 23:27:07 +0000 |
---|---|---|
committer | cmasone@chromium.org <cmasone@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-16 23:27:07 +0000 |
commit | 6d77881320023a8ed096644024db22696c30c146 (patch) | |
tree | 9bce91b96f4adc9c2c61d5af9dd7979b2855e5e9 /content | |
parent | 08bdf1b7a457f3ad5db55b43fb7e0ed0abaf9d2b (diff) | |
download | chromium_src-6d77881320023a8ed096644024db22696c30c146.zip chromium_src-6d77881320023a8ed096644024db22696c30c146.tar.gz chromium_src-6d77881320023a8ed096644024db22696c30c146.tar.bz2 |
Move MojoChannelInit to mojo/common
This class has general utility for bootstrapping mojo
services over a variety of communication channels,
so pull it into mojo itself.
BUG=None
TEST=None
R=sky@chromium.org
Review URL: https://codereview.chromium.org/232073002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@264342 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r-- | content/DEPS | 1 | ||||
-rw-r--r-- | content/browser/renderer_host/render_process_host_mojo_impl.cc | 4 | ||||
-rw-r--r-- | content/browser/renderer_host/render_process_host_mojo_impl.h | 9 | ||||
-rw-r--r-- | content/browser/webui/web_ui_mojo_browsertest.cc | 1 | ||||
-rw-r--r-- | content/common/mojo/mojo_channel_init.cc | 58 | ||||
-rw-r--r-- | content/common/mojo/mojo_channel_init.h | 66 | ||||
-rw-r--r-- | content/content_common.gypi | 2 | ||||
-rw-r--r-- | content/renderer/mojo/mojo_render_process_observer.cc | 4 | ||||
-rw-r--r-- | content/renderer/mojo/mojo_render_process_observer.h | 8 |
9 files changed, 17 insertions, 136 deletions
diff --git a/content/DEPS b/content/DEPS index 56a4ab6..11f13d0 100644 --- a/content/DEPS +++ b/content/DEPS @@ -37,6 +37,7 @@ include_rules = [ "+gpu", "+mojo/public", "+mojo/bindings/js", + "+mojo/common", "+mojo/embedder", "+mojo/service_manager", "+net", diff --git a/content/browser/renderer_host/render_process_host_mojo_impl.cc b/content/browser/renderer_host/render_process_host_mojo_impl.cc index 16348a6..1adb4a1 100644 --- a/content/browser/renderer_host/render_process_host_mojo_impl.cc +++ b/content/browser/renderer_host/render_process_host_mojo_impl.cc @@ -5,10 +5,10 @@ #include "content/browser/renderer_host/render_process_host_mojo_impl.h" #include "base/platform_file.h" -#include "content/common/mojo/mojo_channel_init.h" #include "content/common/mojo/mojo_messages.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/render_process_host.h" +#include "mojo/common/mojo_channel_init.h" #include "mojo/embedder/platform_channel_pair.h" namespace content { @@ -73,7 +73,7 @@ void RenderProcessHostMojoImpl::CreateMojoChannel( return; mojo::embedder::PlatformChannelPair channel_pair; - mojo_channel_init_.reset(new MojoChannelInit); + mojo_channel_init_.reset(new mojo::common::MojoChannelInit); mojo_channel_init_->Init( PlatformFileFromScopedPlatformHandle(channel_pair.PassServerHandle()), BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)); diff --git a/content/browser/renderer_host/render_process_host_mojo_impl.h b/content/browser/renderer_host/render_process_host_mojo_impl.h index e9ce29a..f55268d 100644 --- a/content/browser/renderer_host/render_process_host_mojo_impl.h +++ b/content/browser/renderer_host/render_process_host_mojo_impl.h @@ -10,9 +10,14 @@ #include "content/common/mojo/render_process.mojom.h" #include "mojo/public/cpp/bindings/remote_ptr.h" +namespace mojo { +namespace common { +class MojoChannelInit; +} +} + namespace content { -class MojoChannelInit; class RenderProcessHost; // RenderProcessHostMojoImpl is responsible for initiating and maintaining the @@ -37,7 +42,7 @@ private: RenderProcessHost* host_; // Used to establish the connection. - scoped_ptr<MojoChannelInit> mojo_channel_init_; + scoped_ptr<mojo::common::MojoChannelInit> mojo_channel_init_; mojo::RemotePtr<content::RenderProcessMojo> render_process_mojo_; diff --git a/content/browser/webui/web_ui_mojo_browsertest.cc b/content/browser/webui/web_ui_mojo_browsertest.cc index 61a0b3d..4aeda16 100644 --- a/content/browser/webui/web_ui_mojo_browsertest.cc +++ b/content/browser/webui/web_ui_mojo_browsertest.cc @@ -9,7 +9,6 @@ #include "base/run_loop.h" #include "base/strings/string_util.h" #include "content/browser/webui/web_ui_controller_factory_registry.h" -#include "content/common/mojo/mojo_channel_init.h" #include "content/public/browser/browser_context.h" #include "content/public/browser/render_view_host.h" #include "content/public/browser/web_contents.h" diff --git a/content/common/mojo/mojo_channel_init.cc b/content/common/mojo/mojo_channel_init.cc deleted file mode 100644 index 16661ab..0000000 --- a/content/common/mojo/mojo_channel_init.cc +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (c) 2014 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/mojo/mojo_channel_init.h" - -#include "base/bind.h" -#include "base/message_loop/message_loop.h" -#include "mojo/embedder/embedder.h" - -namespace content { - -MojoChannelInit::MojoChannelInit() - : channel_info_(NULL), - weak_factory_(this) { -} - -MojoChannelInit::~MojoChannelInit() { - bootstrap_message_pipe_.reset(); - if (channel_info_) { - io_thread_task_runner_->PostTask( - FROM_HERE, - base::Bind(&mojo::embedder::DestroyChannelOnIOThread, channel_info_)); - } -} - -void MojoChannelInit::Init( - base::PlatformFile file, - scoped_refptr<base::TaskRunner> io_thread_task_runner) { - DCHECK(!io_thread_task_runner_.get()); // Should only init once. - io_thread_task_runner_ = io_thread_task_runner; - bootstrap_message_pipe_ = mojo::embedder::CreateChannel( - mojo::embedder::ScopedPlatformHandle( - mojo::embedder::PlatformHandle(file)), - io_thread_task_runner, - base::Bind(&MojoChannelInit::OnCreatedChannel, weak_factory_.GetWeakPtr(), - io_thread_task_runner), - base::MessageLoop::current()->message_loop_proxy()).Pass(); -} - -// static -void MojoChannelInit::OnCreatedChannel( - base::WeakPtr<MojoChannelInit> host, - scoped_refptr<base::TaskRunner> io_thread, - mojo::embedder::ChannelInfo* channel) { - // By the time we get here |host| may have been destroyed. If so, shutdown the - // channel. - if (!host.get()) { - io_thread->PostTask( - FROM_HERE, - base::Bind(&mojo::embedder::DestroyChannelOnIOThread, channel)); - return; - } - host->channel_info_ = channel; -} - - -} // namespace content diff --git a/content/common/mojo/mojo_channel_init.h b/content/common/mojo/mojo_channel_init.h deleted file mode 100644 index 05b4e0c..0000000 --- a/content/common/mojo/mojo_channel_init.h +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright 2014 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_MOJO_MOJO_CHANNEL_INIT_H_ -#define CONTENT_COMMON_MOJO_MOJO_CHANNEL_INIT_H_ - -#include "base/memory/ref_counted.h" -#include "base/memory/weak_ptr.h" -#include "base/platform_file.h" -#include "content/common/content_export.h" -#include "mojo/public/cpp/system/core.h" - -namespace base { -class MessageLoopProxy; -class TaskRunner; -} - -namespace mojo { -namespace embedder { -struct ChannelInfo; -} -} - -namespace content { - -// MojoChannelInit handle creation (and destruction) of the mojo channel. It is -// expected that this class is created and destroyed on the main thread. -class CONTENT_EXPORT MojoChannelInit { - public: - MojoChannelInit(); - ~MojoChannelInit(); - - // Inits the channel. This takes ownership of |file|. - void Init(base::PlatformFile file, - scoped_refptr<base::TaskRunner> io_thread_task_runner); - - bool is_handle_valid() const { return bootstrap_message_pipe_.is_valid(); } - - mojo::ScopedMessagePipeHandle bootstrap_message_pipe() { - return bootstrap_message_pipe_.Pass(); - } - - private: - // Invoked on the main thread once the channel has been established. - static void OnCreatedChannel( - base::WeakPtr<MojoChannelInit> host, - scoped_refptr<base::TaskRunner> io_thread, - mojo::embedder::ChannelInfo* channel); - - scoped_refptr<base::TaskRunner> io_thread_task_runner_; - - // If non-null the channel has been established. - mojo::embedder::ChannelInfo* channel_info_; - - // The handle from channel creation. - mojo::ScopedMessagePipeHandle bootstrap_message_pipe_; - - base::WeakPtrFactory<MojoChannelInit> weak_factory_; - - DISALLOW_COPY_AND_ASSIGN(MojoChannelInit); -}; - -} // namespace content - -#endif // CONTENT_COMMON_MOJO_MOJO_CHANNEL_INIT_H_ diff --git a/content/content_common.gypi b/content/content_common.gypi index 24b95d1..45e9d2c 100644 --- a/content/content_common.gypi +++ b/content/content_common.gypi @@ -351,8 +351,6 @@ 'common/message_router.cc', 'common/message_router.h', 'common/mime_registry_messages.h', - 'common/mojo/mojo_channel_init.cc', - 'common/mojo/mojo_channel_init.h', 'common/mojo/mojo_messages.h', 'common/navigation_gesture.h', 'common/net/url_fetcher.cc', diff --git a/content/renderer/mojo/mojo_render_process_observer.cc b/content/renderer/mojo/mojo_render_process_observer.cc index 7f01d3f..9790787 100644 --- a/content/renderer/mojo/mojo_render_process_observer.cc +++ b/content/renderer/mojo/mojo_render_process_observer.cc @@ -6,11 +6,11 @@ #include "base/message_loop/message_loop.h" #include "content/child/child_process.h" -#include "content/common/mojo/mojo_channel_init.h" #include "content/common/mojo/mojo_messages.h" #include "content/public/renderer/render_thread.h" #include "content/public/renderer/render_view.h" #include "content/renderer/web_ui_mojo.h" +#include "mojo/common/mojo_channel_init.h" namespace content { @@ -46,7 +46,7 @@ void MojoRenderProcessObserver::OnChannelCreated( base::PlatformFile handle = file; #endif DCHECK(!channel_init_.get()); - channel_init_.reset(new MojoChannelInit); + channel_init_.reset(new mojo::common::MojoChannelInit); channel_init_->Init(handle, ChildProcess::current()->io_message_loop_proxy()); if (!channel_init_->is_handle_valid()) return; diff --git a/content/renderer/mojo/mojo_render_process_observer.h b/content/renderer/mojo/mojo_render_process_observer.h index 2bee59d..a66a98d 100644 --- a/content/renderer/mojo/mojo_render_process_observer.h +++ b/content/renderer/mojo/mojo_render_process_observer.h @@ -12,14 +12,16 @@ #include "mojo/public/cpp/bindings/remote_ptr.h" namespace mojo { -namespace embedder{ +namespace common { +class MojoChannelInit; +} +namespace embedder { struct ChannelInfo; } } namespace content { -class MojoChannelInit; class RenderThread; // RenderProcessObserver implementation that initializes the mojo channel when @@ -47,7 +49,7 @@ class MojoRenderProcessObserver content::RenderThread* render_thread_; - scoped_ptr<MojoChannelInit> channel_init_; + scoped_ptr<mojo::common::MojoChannelInit> channel_init_; mojo::RemotePtr<content::RenderProcessHostMojo> render_process_host_mojo_; |