Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / mojo / shell / out_of_process_dynamic_service_runner.cc
blob5f21d409f7668d95ab3cd302bf256f7821f3c7cb
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "mojo/shell/out_of_process_dynamic_service_runner.h"
7 #include "base/bind.h"
8 #include "base/callback_helpers.h"
9 #include "base/file_util.h"
10 #include "base/logging.h"
11 #include "base/scoped_native_library.h"
13 namespace mojo {
14 namespace shell {
16 OutOfProcessDynamicServiceRunner::OutOfProcessDynamicServiceRunner(
17 Context* context)
18 : context_(context) {
21 OutOfProcessDynamicServiceRunner::~OutOfProcessDynamicServiceRunner() {
22 if (app_child_process_host_) {
23 // TODO(vtl): Race condition: If |AppChildProcessHost::DidStart()| hasn't
24 // been called yet, we shouldn't call |Join()| here. (Until |DidStart()|, we
25 // may not have a child process to wait on.) Probably we should fix
26 // |Join()|.
27 app_child_process_host_->Join();
31 void OutOfProcessDynamicServiceRunner::Start(
32 const base::FilePath& app_path,
33 ScopedMessagePipeHandle service_handle,
34 const base::Closure& app_completed_callback) {
35 app_path_ = app_path;
37 DCHECK(!service_handle_.is_valid());
38 service_handle_ = service_handle.Pass();
40 DCHECK(app_completed_callback_.is_null());
41 app_completed_callback_ = app_completed_callback;
43 app_child_process_host_.reset(new AppChildProcessHost(context_, this));
44 app_child_process_host_->Start();
46 // TODO(vtl): |app_path.AsUTF8Unsafe()| is unsafe.
47 app_child_process_host_->controller()->StartApp(
48 app_path.AsUTF8Unsafe(),
49 ScopedMessagePipeHandle(MessagePipeHandle(
50 service_handle.release().value())));
53 void OutOfProcessDynamicServiceRunner::AppCompleted(int32_t result) {
54 DVLOG(2) << "OutOfProcessDynamicServiceRunner::AppCompleted(" << result
55 << ")";
57 app_completed_callback_.Run();
58 app_completed_callback_.Reset();
59 app_child_process_host_.reset();
62 } // namespace shell
63 } // namespace mojo