Roll src/third_party/WebKit a05b987:7eb2976 (svn 202510:202511)
[chromium-blink-merge.git] / mojo / runner / out_of_process_native_runner.cc
blob1e92cc8e7d82c6cfcb7faca5f78935408a09572b
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/runner/out_of_process_native_runner.h"
7 #include "base/bind.h"
8 #include "base/callback_helpers.h"
9 #include "base/files/file_util.h"
10 #include "base/logging.h"
11 #include "mojo/runner/child_process.mojom.h"
12 #include "mojo/runner/child_process_host.h"
13 #include "mojo/runner/in_process_native_runner.h"
15 namespace mojo {
16 namespace runner {
18 OutOfProcessNativeRunner::OutOfProcessNativeRunner(Context* context)
19 : context_(context) {
22 OutOfProcessNativeRunner::~OutOfProcessNativeRunner() {
23 if (child_process_host_) {
24 // TODO(vtl): Race condition: If |ChildProcessHost::DidStart()| hasn't been
25 // called yet, we shouldn't call |Join()| here. (Until |DidStart()|, we may
26 // not have a child process to wait on.) Probably we should fix |Join()|.
27 child_process_host_->Join();
31 void OutOfProcessNativeRunner::Start(
32 const base::FilePath& app_path,
33 bool start_sandboxed,
34 InterfaceRequest<Application> application_request,
35 const base::Closure& app_completed_callback) {
36 app_path_ = app_path;
38 DCHECK(app_completed_callback_.is_null());
39 app_completed_callback_ = app_completed_callback;
41 child_process_host_.reset(
42 new ChildProcessHost(context_, start_sandboxed, app_path));
43 child_process_host_->Start();
45 child_process_host_->StartApp(
46 application_request.Pass(),
47 base::Bind(&OutOfProcessNativeRunner::AppCompleted,
48 base::Unretained(this)));
51 void OutOfProcessNativeRunner::AppCompleted(int32_t result) {
52 DVLOG(2) << "OutOfProcessNativeRunner::AppCompleted(" << result << ")";
54 child_process_host_.reset();
55 // This object may be deleted by this callback.
56 base::Closure app_completed_callback = app_completed_callback_;
57 app_completed_callback_.Reset();
58 app_completed_callback.Run();
61 scoped_ptr<shell::NativeRunner> OutOfProcessNativeRunnerFactory::Create() {
62 return make_scoped_ptr(new OutOfProcessNativeRunner(context_));
65 } // namespace runner
66 } // namespace mojo