| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "shell/out_of_process_native_runner.h" | 5 #include "shell/out_of_process_native_runner.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "shell/app_child_process.mojom.h" | 11 #include "shell/app_child_process.mojom.h" |
| 12 #include "shell/app_child_process_host.h" | 12 #include "shell/child_process_host.h" |
| 13 #include "shell/in_process_native_runner.h" | 13 #include "shell/in_process_native_runner.h" |
| 14 | 14 |
| 15 namespace mojo { | 15 namespace mojo { |
| 16 namespace shell { | 16 namespace shell { |
| 17 | 17 |
| 18 OutOfProcessNativeRunner::OutOfProcessNativeRunner(Context* context) | 18 OutOfProcessNativeRunner::OutOfProcessNativeRunner(Context* context) |
| 19 : context_(context) { | 19 : context_(context) { |
| 20 } | 20 } |
| 21 | 21 |
| 22 OutOfProcessNativeRunner::~OutOfProcessNativeRunner() { | 22 OutOfProcessNativeRunner::~OutOfProcessNativeRunner() { |
| 23 if (app_child_process_host_) { | 23 if (child_process_host_) { |
| 24 // TODO(vtl): Race condition: If |AppChildProcessHost::DidStart()| hasn't | 24 // TODO(vtl): Race condition: If |ChildProcessHost::DidStart()| hasn't been |
| 25 // been called yet, we shouldn't call |Join()| here. (Until |DidStart()|, we | 25 // called yet, we shouldn't call |Join()| here. (Until |DidStart()|, we may |
| 26 // may not have a child process to wait on.) Probably we should fix | 26 // not have a child process to wait on.) Probably we should fix |Join()|. |
| 27 // |Join()|. | 27 child_process_host_->Join(); |
| 28 app_child_process_host_->Join(); | |
| 29 } | 28 } |
| 30 } | 29 } |
| 31 | 30 |
| 32 void OutOfProcessNativeRunner::Start( | 31 void OutOfProcessNativeRunner::Start( |
| 33 const base::FilePath& app_path, | 32 const base::FilePath& app_path, |
| 34 NativeApplicationCleanup cleanup, | 33 NativeApplicationCleanup cleanup, |
| 35 InterfaceRequest<Application> application_request, | 34 InterfaceRequest<Application> application_request, |
| 36 const base::Closure& app_completed_callback) { | 35 const base::Closure& app_completed_callback) { |
| 37 app_path_ = app_path; | 36 app_path_ = app_path; |
| 38 | 37 |
| 39 DCHECK(app_completed_callback_.is_null()); | 38 DCHECK(app_completed_callback_.is_null()); |
| 40 app_completed_callback_ = app_completed_callback; | 39 app_completed_callback_ = app_completed_callback; |
| 41 | 40 |
| 42 app_child_process_host_.reset(new AppChildProcessHost(context_)); | 41 child_process_host_.reset(new ChildProcessHost(context_)); |
| 43 app_child_process_host_->Start(); | 42 child_process_host_->Start(); |
| 44 | 43 |
| 45 // TODO(vtl): |app_path.AsUTF8Unsafe()| is unsafe. | 44 // TODO(vtl): |app_path.AsUTF8Unsafe()| is unsafe. |
| 46 app_child_process_host_->StartApp( | 45 child_process_host_->StartApp( |
| 47 app_path.AsUTF8Unsafe(), cleanup == NativeApplicationCleanup::DELETE, | 46 app_path.AsUTF8Unsafe(), cleanup == NativeApplicationCleanup::DELETE, |
| 48 application_request.Pass(), | 47 application_request.Pass(), |
| 49 base::Bind(&OutOfProcessNativeRunner::AppCompleted, | 48 base::Bind(&OutOfProcessNativeRunner::AppCompleted, |
| 50 base::Unretained(this))); | 49 base::Unretained(this))); |
| 51 } | 50 } |
| 52 | 51 |
| 53 void OutOfProcessNativeRunner::AppCompleted(int32_t result) { | 52 void OutOfProcessNativeRunner::AppCompleted(int32_t result) { |
| 54 DVLOG(2) << "OutOfProcessNativeRunner::AppCompleted(" << result << ")"; | 53 DVLOG(2) << "OutOfProcessNativeRunner::AppCompleted(" << result << ")"; |
| 55 | 54 |
| 56 app_child_process_host_.reset(); | 55 child_process_host_.reset(); |
| 57 // This object may be deleted by this callback. | 56 // This object may be deleted by this callback. |
| 58 base::Closure app_completed_callback = app_completed_callback_; | 57 base::Closure app_completed_callback = app_completed_callback_; |
| 59 app_completed_callback_.Reset(); | 58 app_completed_callback_.Reset(); |
| 60 app_completed_callback.Run(); | 59 app_completed_callback.Run(); |
| 61 } | 60 } |
| 62 | 61 |
| 63 scoped_ptr<NativeRunner> OutOfProcessNativeRunnerFactory::Create( | 62 scoped_ptr<NativeRunner> OutOfProcessNativeRunnerFactory::Create( |
| 64 const Options& options) { | 63 const Options& options) { |
| 65 if (options.force_in_process) | 64 if (options.force_in_process) |
| 66 return make_scoped_ptr(new InProcessNativeRunner(context_)); | 65 return make_scoped_ptr(new InProcessNativeRunner(context_)); |
| 67 | 66 |
| 68 return make_scoped_ptr(new OutOfProcessNativeRunner(context_)); | 67 return make_scoped_ptr(new OutOfProcessNativeRunner(context_)); |
| 69 } | 68 } |
| 70 | 69 |
| 71 } // namespace shell | 70 } // namespace shell |
| 72 } // namespace mojo | 71 } // namespace mojo |
| OLD | NEW |