| 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" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 if (child_process_host_) { | 22 if (child_process_host_) { |
| 23 // TODO(vtl): Race condition: If |ChildProcessHost::DidStart()| hasn't been | 23 // TODO(vtl): Race condition: If |ChildProcessHost::DidStart()| hasn't been |
| 24 // called yet, we shouldn't call |Join()| here. (Until |DidStart()|, we may | 24 // called yet, we shouldn't call |Join()| here. (Until |DidStart()|, we may |
| 25 // not have a child process to wait on.) Probably we should fix |Join()|. | 25 // not have a child process to wait on.) Probably we should fix |Join()|. |
| 26 child_process_host_->Join(); | 26 child_process_host_->Join(); |
| 27 } | 27 } |
| 28 } | 28 } |
| 29 | 29 |
| 30 void OutOfProcessNativeRunner::Start( | 30 void OutOfProcessNativeRunner::Start( |
| 31 const base::FilePath& app_path, | 31 const base::FilePath& app_path, |
| 32 NativeApplicationCleanup cleanup, | |
| 33 mojo::InterfaceRequest<mojo::Application> application_request, | 32 mojo::InterfaceRequest<mojo::Application> application_request, |
| 34 const base::Closure& app_completed_callback) { | 33 const base::Closure& app_completed_callback) { |
| 35 app_path_ = app_path; | 34 app_path_ = app_path; |
| 36 | 35 |
| 37 DCHECK(app_completed_callback_.is_null()); | 36 DCHECK(app_completed_callback_.is_null()); |
| 38 app_completed_callback_ = app_completed_callback; | 37 app_completed_callback_ = app_completed_callback; |
| 39 | 38 |
| 40 child_process_host_.reset(new ChildProcessHost(context_)); | 39 child_process_host_.reset(new ChildProcessHost(context_)); |
| 41 child_process_host_->Start(); | 40 child_process_host_->Start(); |
| 42 | 41 |
| 43 // TODO(vtl): |app_path.AsUTF8Unsafe()| is unsafe. | 42 // TODO(vtl): |app_path.AsUTF8Unsafe()| is unsafe. |
| 44 child_process_host_->StartApp( | 43 child_process_host_->StartApp( |
| 45 app_path.AsUTF8Unsafe(), cleanup == NativeApplicationCleanup::DELETE, | 44 app_path.AsUTF8Unsafe(), application_request.Pass(), |
| 46 application_request.Pass(), | |
| 47 base::Bind(&OutOfProcessNativeRunner::AppCompleted, | 45 base::Bind(&OutOfProcessNativeRunner::AppCompleted, |
| 48 base::Unretained(this))); | 46 base::Unretained(this))); |
| 49 } | 47 } |
| 50 | 48 |
| 51 void OutOfProcessNativeRunner::AppCompleted(int32_t result) { | 49 void OutOfProcessNativeRunner::AppCompleted(int32_t result) { |
| 52 DVLOG(2) << "OutOfProcessNativeRunner::AppCompleted(" << result << ")"; | 50 DVLOG(2) << "OutOfProcessNativeRunner::AppCompleted(" << result << ")"; |
| 53 | 51 |
| 54 if (child_process_host_) { | 52 if (child_process_host_) { |
| 55 child_process_host_->Join(); | 53 child_process_host_->Join(); |
| 56 child_process_host_.reset(); | 54 child_process_host_.reset(); |
| 57 } | 55 } |
| 58 // This object may be deleted by this callback. | 56 // This object may be deleted by this callback. |
| 59 base::Closure app_completed_callback = app_completed_callback_; | 57 base::Closure app_completed_callback = app_completed_callback_; |
| 60 app_completed_callback_.Reset(); | 58 app_completed_callback_.Reset(); |
| 61 app_completed_callback.Run(); | 59 app_completed_callback.Run(); |
| 62 } | 60 } |
| 63 | 61 |
| 64 scoped_ptr<NativeRunner> OutOfProcessNativeRunnerFactory::Create( | 62 scoped_ptr<NativeRunner> OutOfProcessNativeRunnerFactory::Create( |
| 65 const Options& options) { | 63 const Options& options) { |
| 66 if (options.force_in_process) | 64 if (options.force_in_process) |
| 67 return make_scoped_ptr(new InProcessNativeRunner(context_)); | 65 return make_scoped_ptr(new InProcessNativeRunner(context_)); |
| 68 | 66 |
| 69 return make_scoped_ptr(new OutOfProcessNativeRunner(context_)); | 67 return make_scoped_ptr(new OutOfProcessNativeRunner(context_)); |
| 70 } | 68 } |
| 71 | 69 |
| 72 } // namespace shell | 70 } // namespace shell |
| OLD | NEW |