diff options
author | viettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-20 17:37:19 +0000 |
---|---|---|
committer | viettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-20 17:37:19 +0000 |
commit | 5dcd57c3f8a07a6dadee280e0031b576277b0af5 (patch) | |
tree | a68edf86af447bd791ae0f4857baf0c4d95bed01 /mojo/shell | |
parent | 0ed2f78e683a3695c80932792f771397278b56cd (diff) | |
download | chromium_src-5dcd57c3f8a07a6dadee280e0031b576277b0af5.zip chromium_src-5dcd57c3f8a07a6dadee280e0031b576277b0af5.tar.gz chromium_src-5dcd57c3f8a07a6dadee280e0031b576277b0af5.tar.bz2 |
Mojo: Add a mojom interface between the app child process and the parent.
Do some plumbing.
R=sky@chromium.org
Review URL: https://codereview.chromium.org/205733002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@258325 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'mojo/shell')
-rw-r--r-- | mojo/shell/app_child_process.cc | 23 | ||||
-rw-r--r-- | mojo/shell/app_child_process.mojom | 19 | ||||
-rw-r--r-- | mojo/shell/app_child_process_host.cc | 31 | ||||
-rw-r--r-- | mojo/shell/app_child_process_host.h | 24 | ||||
-rw-r--r-- | mojo/shell/child_process_host.cc | 15 | ||||
-rw-r--r-- | mojo/shell/child_process_host.h | 7 | ||||
-rw-r--r-- | mojo/shell/desktop/mojo_main.cc | 5 | ||||
-rw-r--r-- | mojo/shell/out_of_process_dynamic_service_runner.cc | 15 | ||||
-rw-r--r-- | mojo/shell/out_of_process_dynamic_service_runner.h | 7 |
9 files changed, 105 insertions, 41 deletions
diff --git a/mojo/shell/app_child_process.cc b/mojo/shell/app_child_process.cc index 0105aca..0ba6188 100644 --- a/mojo/shell/app_child_process.cc +++ b/mojo/shell/app_child_process.cc @@ -15,7 +15,9 @@ #include "base/threading/thread_checker.h" #include "mojo/common/message_pump_mojo.h" #include "mojo/embedder/embedder.h" +#include "mojo/public/bindings/remote_ptr.h" #include "mojo/public/system/core_cpp.h" +#include "mojo/shell/app_child_process.mojom.h" namespace mojo { namespace shell { @@ -86,10 +88,9 @@ class AppContext { // AppChildControllerImpl ------------------------------------------------------ -// TODO(vtl): This will inherit from an |AppChildController| interface. -class AppChildControllerImpl { +class AppChildControllerImpl : public mojo_shell::AppChildController { public: - ~AppChildControllerImpl() { + virtual ~AppChildControllerImpl() { DCHECK(thread_checker_.CalledOnValidThread()); } @@ -108,6 +109,14 @@ class AppChildControllerImpl { make_scoped_ptr(new AppChildControllerImpl(app_context))); app_context->controller()->CreateChannel(platform_channel.Pass(), main_thread_runner); + + } + + // |AppChildController| method: + virtual void StartApp(const String& app_path, + ScopedMessagePipeHandle service) OVERRIDE { + DVLOG(2) << "AppChildControllerImpl::StartApp(" + << app_path.To<std::string>() << ", ...)"; } private: @@ -128,8 +137,10 @@ class AppChildControllerImpl { base::Bind(&AppChildControllerImpl::DidCreateChannel, base::Unretained(this), main_thread_runner), base::MessageLoopProxy::current())); - - // TODO(vtl): Set up RemotePtr here. + controller_client_.reset( + mojo_shell::ScopedAppChildControllerClientHandle( + mojo_shell::AppChildControllerClientHandle( + host_message_pipe.release().value())), this); } // Callback for |embedder::CreateChannel()|. @@ -143,6 +154,8 @@ class AppChildControllerImpl { base::ThreadChecker thread_checker_; AppContext* const app_context_; + + RemotePtr<mojo_shell::AppChildControllerClient> controller_client_; embedder::ChannelInfo* channel_info_; DISALLOW_COPY_AND_ASSIGN(AppChildControllerImpl); diff --git a/mojo/shell/app_child_process.mojom b/mojo/shell/app_child_process.mojom new file mode 100644 index 0000000..feb9ece --- /dev/null +++ b/mojo/shell/app_child_process.mojom @@ -0,0 +1,19 @@ +// 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. + +// TODO(vtl): mojom currently doesn't support nested modules. :( +module mojo_shell { + +[Peer=AppChildControllerClient] +interface AppChildController { + // TODO(vtl): |service| should be of a more specific type. + StartApp(string app_path, handle<message_pipe> service); +}; + +[Peer=AppChildController] +interface AppChildControllerClient { + AppCompleted(int32 result); +}; + +} // module mojo_shell diff --git a/mojo/shell/app_child_process_host.cc b/mojo/shell/app_child_process_host.cc index 9f14532..42e5d82 100644 --- a/mojo/shell/app_child_process_host.cc +++ b/mojo/shell/app_child_process_host.cc @@ -4,6 +4,7 @@ #include "mojo/shell/app_child_process_host.h" +#include "base/logging.h" #include "base/message_loop/message_loop.h" #include "mojo/embedder/embedder.h" #include "mojo/public/system/core_cpp.h" @@ -13,23 +14,19 @@ namespace mojo { namespace shell { -AppChildProcessHost::AppChildProcessHost(Context* context, - AppDelegate* app_delegate) +AppChildProcessHost::AppChildProcessHost( + Context* context, + mojo_shell::AppChildControllerClient* controller_client) : ChildProcessHost(context, this, ChildProcess::TYPE_APP), - app_delegate_(app_delegate), + controller_client_(controller_client), channel_info_(NULL) { } AppChildProcessHost::~AppChildProcessHost() { } -void AppChildProcessHost::DidStart(bool success) { - DVLOG(2) << "AppChildProcessHost::DidStart()"; - - if (!success) { - app_delegate_->DidTerminate(); - return; - } +void AppChildProcessHost::WillStart() { + DCHECK(platform_channel()->is_valid()); mojo::ScopedMessagePipeHandle child_message_pipe(embedder::CreateChannel( platform_channel()->Pass(), @@ -37,8 +34,20 @@ void AppChildProcessHost::DidStart(bool success) { base::Bind(&AppChildProcessHost::DidCreateChannel, base::Unretained(this)), base::MessageLoop::current()->message_loop_proxy())); + controller_.reset( + mojo_shell::ScopedAppChildControllerHandle( + mojo_shell::AppChildControllerHandle( + child_message_pipe.release().value())), controller_client_); +} - // TODO(vtl): Hook up a RemotePtr, etc. +void AppChildProcessHost::DidStart(bool success) { + DVLOG(2) << "AppChildProcessHost::DidStart()"; + + if (!success) { + LOG(ERROR) << "Failed to start app child process"; + controller_client_->AppCompleted(MOJO_RESULT_UNKNOWN); + return; + } } // Callback for |embedder::CreateChannel()|. diff --git a/mojo/shell/app_child_process_host.h b/mojo/shell/app_child_process_host.h index 2ddd276..263b408 100644 --- a/mojo/shell/app_child_process_host.h +++ b/mojo/shell/app_child_process_host.h @@ -6,6 +6,8 @@ #define MOJO_SHELL_APP_CHILD_PROCESS_HOST_H_ #include "base/macros.h" +#include "mojo/public/bindings/remote_ptr.h" +#include "mojo/shell/app_child_process.mojom.h" #include "mojo/shell/child_process_host.h" namespace mojo { @@ -16,28 +18,30 @@ struct ChannelInfo; namespace shell { -// Note: After |Start()|, this object must remain alive until the delegate's -// |DidTerminate()| is called. +// Note: After |Start()|, this object must remain alive until the controller +// client's |AppCompleted()| is called. class AppChildProcessHost : public ChildProcessHost, public ChildProcessHost::Delegate { public: - class AppDelegate { - public: - virtual void DidTerminate() = 0; - }; - - AppChildProcessHost(Context* context, AppDelegate* app_delegate); + AppChildProcessHost(Context* context, + mojo_shell::AppChildControllerClient* controller_client); virtual ~AppChildProcessHost(); + mojo_shell::AppChildController* controller() { + return controller_.get(); + } + private: - // |ChildProcessHost::Delegate| method: + // |ChildProcessHost::Delegate| methods: + virtual void WillStart() OVERRIDE; virtual void DidStart(bool success) OVERRIDE; // Callback for |embedder::CreateChannel()|. void DidCreateChannel(embedder::ChannelInfo* channel_info); - AppDelegate* const app_delegate_; + mojo_shell::AppChildControllerClient* const controller_client_; + RemotePtr<mojo_shell::AppChildController> controller_; embedder::ChannelInfo* channel_info_; DISALLOW_COPY_AND_ASSIGN(AppChildProcessHost); diff --git a/mojo/shell/child_process_host.cc b/mojo/shell/child_process_host.cc index 34aa69e..98674c0 100644 --- a/mojo/shell/child_process_host.cc +++ b/mojo/shell/child_process_host.cc @@ -15,7 +15,6 @@ #include "base/strings/string_number_conversions.h" #include "base/task_runner.h" #include "base/task_runner_util.h" -#include "mojo/embedder/platform_channel_pair.h" #include "mojo/shell/context.h" #include "mojo/shell/switches.h" @@ -30,6 +29,8 @@ ChildProcessHost::ChildProcessHost(Context* context, type_(type), child_process_handle_(base::kNullProcessHandle) { DCHECK(delegate); + platform_channel_ = platform_channel_pair_.PassServerHandle(); + CHECK(platform_channel_.is_valid()); } ChildProcessHost::~ChildProcessHost() { @@ -42,13 +43,14 @@ ChildProcessHost::~ChildProcessHost() { void ChildProcessHost::Start() { DCHECK_EQ(child_process_handle_, base::kNullProcessHandle); + + delegate_->WillStart(); + CHECK(base::PostTaskAndReplyWithResult( context_->task_runners()->blocking_pool(), FROM_HERE, base::Bind(&ChildProcessHost::DoLaunch, base::Unretained(this)), base::Bind(&ChildProcessHost::DidLaunch, base::Unretained(this)))); -//FIXME move the platform channel pair to here, so we get the server channel -// immediately } int ChildProcessHost::Join() { @@ -75,9 +77,8 @@ bool ChildProcessHost::DoLaunch() { child_command_line.AppendSwitchASCII( switches::kChildProcessType, base::IntToString(static_cast<int>(type_))); - embedder::PlatformChannelPair platform_channel_pair; embedder::HandlePassingInformation handle_passing_info; - platform_channel_pair.PrepareToPassClientHandleToChildProcess( + platform_channel_pair_.PrepareToPassClientHandleToChildProcess( &child_command_line, &handle_passing_info); base::LaunchOptions options; @@ -91,9 +92,7 @@ bool ChildProcessHost::DoLaunch() { if (!base::LaunchProcess(child_command_line, options, &child_process_handle_)) return false; - platform_channel_pair.ChildProcessLaunched(); - platform_channel_ = platform_channel_pair.PassServerHandle(); - CHECK(platform_channel_.is_valid()); + platform_channel_pair_.ChildProcessLaunched(); return true; } diff --git a/mojo/shell/child_process_host.h b/mojo/shell/child_process_host.h index da428be..d3c7669 100644 --- a/mojo/shell/child_process_host.h +++ b/mojo/shell/child_process_host.h @@ -7,6 +7,7 @@ #include "base/macros.h" #include "base/process/process_handle.h" +#include "mojo/embedder/platform_channel_pair.h" #include "mojo/embedder/scoped_platform_handle.h" #include "mojo/shell/child_process.h" // For |ChildProcess::Type|. @@ -28,6 +29,7 @@ class ChildProcessHost { public: class Delegate { public: + virtual void WillStart() = 0; virtual void DidStart(bool success) = 0; }; @@ -67,7 +69,10 @@ class ChildProcessHost { base::ProcessHandle child_process_handle_; - // Platform-specific "pipe" to the child process. Valid after |Start()|. + embedder::PlatformChannelPair platform_channel_pair_; + + // Platform-specific "pipe" to the child process. Valid immediately after + // creation. embedder::ScopedPlatformHandle platform_channel_; DISALLOW_COPY_AND_ASSIGN(ChildProcessHost); diff --git a/mojo/shell/desktop/mojo_main.cc b/mojo/shell/desktop/mojo_main.cc index 42b94a2..9591ae8 100644 --- a/mojo/shell/desktop/mojo_main.cc +++ b/mojo/shell/desktop/mojo_main.cc @@ -23,8 +23,11 @@ class TestChildProcessHostDelegate public: TestChildProcessHostDelegate() {} virtual ~TestChildProcessHostDelegate() {} + virtual void WillStart() OVERRIDE { + VLOG(2) << "TestChildProcessHostDelegate::WillStart()"; + } virtual void DidStart(bool success) OVERRIDE { - VLOG(2) << "TestChildProcessHostDelegate::DidStart: success = " << success; + VLOG(2) << "TestChildProcessHostDelegate::DidStart(" << success << ")"; base::MessageLoop::current()->QuitWhenIdle(); } }; diff --git a/mojo/shell/out_of_process_dynamic_service_runner.cc b/mojo/shell/out_of_process_dynamic_service_runner.cc index 9c085c1..05a898b 100644 --- a/mojo/shell/out_of_process_dynamic_service_runner.cc +++ b/mojo/shell/out_of_process_dynamic_service_runner.cc @@ -9,6 +9,7 @@ #include "base/file_util.h" #include "base/logging.h" #include "base/scoped_native_library.h" +#include "mojo/public/bindings/allocation_scope.h" namespace mojo { namespace shell { @@ -42,10 +43,20 @@ void OutOfProcessDynamicServiceRunner::Start( app_child_process_host_.reset(new AppChildProcessHost(context_, this)); app_child_process_host_->Start(); -//FIXME app_child_process_host_->StartApp(); + + // TODO(vtl): Where should my allocation scope be? + AllocationScope scope; + // TODO(vtl): |app_path.AsUTF8Unsafe()| is unsafe. + app_child_process_host_->controller()->StartApp( + app_path.AsUTF8Unsafe(), + ScopedMessagePipeHandle(MessagePipeHandle( + service_handle.release().value()))); } -void OutOfProcessDynamicServiceRunner::DidTerminate() { +void OutOfProcessDynamicServiceRunner::AppCompleted(int32_t result) { + DVLOG(2) << "OutOfProcessDynamicServiceRunner::AppCompleted(" << result + << ")"; + app_completed_callback_.Run(); app_completed_callback_.Reset(); app_child_process_host_.reset(); diff --git a/mojo/shell/out_of_process_dynamic_service_runner.h b/mojo/shell/out_of_process_dynamic_service_runner.h index 0970acd..073cc0a 100644 --- a/mojo/shell/out_of_process_dynamic_service_runner.h +++ b/mojo/shell/out_of_process_dynamic_service_runner.h @@ -8,6 +8,7 @@ #include "base/callback.h" #include "base/files/file_path.h" #include "base/macros.h" +#include "mojo/shell/app_child_process.mojom.h" #include "mojo/shell/app_child_process_host.h" #include "mojo/shell/dynamic_service_runner.h" @@ -16,7 +17,7 @@ namespace shell { class OutOfProcessDynamicServiceRunner : public DynamicServiceRunner, - public AppChildProcessHost::AppDelegate { + public mojo_shell::AppChildControllerClient { public: explicit OutOfProcessDynamicServiceRunner(Context* context); virtual ~OutOfProcessDynamicServiceRunner(); @@ -27,8 +28,8 @@ class OutOfProcessDynamicServiceRunner const base::Closure& app_completed_callback) OVERRIDE; private: - // |AppChildProcessHost::AppDelegate| method: - virtual void DidTerminate() OVERRIDE; + // |mojo_shell::AppChildControllerClient| method: + virtual void AppCompleted(int32_t result) OVERRIDE; Context* const context_; |