OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "services/service_manager/runner/host/out_of_process_native_runner.h" | |
6 | |
7 #include <stdint.h> | |
8 | |
9 #include <utility> | |
10 | |
11 #include "base/bind.h" | |
12 #include "base/callback_helpers.h" | |
13 #include "base/files/file_util.h" | |
14 #include "base/logging.h" | |
15 #include "base/memory/ptr_util.h" | |
16 #include "base/task_runner.h" | |
17 #include "services/service_manager/runner/common/client_util.h" | |
18 #include "services/service_manager/runner/host/child_process_host.h" | |
19 | |
20 namespace service_manager { | |
21 | |
22 OutOfProcessNativeRunner::OutOfProcessNativeRunner( | |
23 const base::FilePath& service_path, | |
24 base::TaskRunner* launch_process_runner, | |
25 NativeRunnerDelegate* delegate) | |
26 : launch_process_runner_(launch_process_runner), | |
27 delegate_(delegate), | |
28 service_path_(service_path) {} | |
29 | |
30 OutOfProcessNativeRunner::~OutOfProcessNativeRunner() { | |
31 if (child_process_host_ && !service_path_.empty()) | |
32 child_process_host_->Join(); | |
33 } | |
34 | |
35 mojom::ServicePtr OutOfProcessNativeRunner::Start( | |
36 const Identity& target, | |
37 bool start_sandboxed, | |
38 const base::Callback<void(base::ProcessId)>& pid_available_callback, | |
39 const base::Closure& app_completed_callback) { | |
40 DCHECK(app_completed_callback_.is_null()); | |
41 app_completed_callback_ = app_completed_callback; | |
42 | |
43 child_process_host_.reset(new ChildProcessHost( | |
44 launch_process_runner_, delegate_, start_sandboxed, target, | |
45 service_path_)); | |
46 return child_process_host_->Start( | |
47 target, pid_available_callback, | |
48 base::Bind(&OutOfProcessNativeRunner::AppCompleted, | |
49 base::Unretained(this))); | |
50 } | |
51 | |
52 void OutOfProcessNativeRunner::AppCompleted() { | |
53 if (child_process_host_) | |
54 child_process_host_->Join(); | |
55 child_process_host_.reset(); | |
56 // This object may be deleted by this callback. | |
57 base::Closure app_completed_callback = app_completed_callback_; | |
58 app_completed_callback_.Reset(); | |
59 if (!app_completed_callback.is_null()) | |
60 app_completed_callback.Run(); | |
61 } | |
62 | |
63 OutOfProcessNativeRunnerFactory::OutOfProcessNativeRunnerFactory( | |
64 base::TaskRunner* launch_process_runner, | |
65 NativeRunnerDelegate* delegate) | |
66 : launch_process_runner_(launch_process_runner), delegate_(delegate) {} | |
67 | |
68 OutOfProcessNativeRunnerFactory::~OutOfProcessNativeRunnerFactory() {} | |
69 | |
70 std::unique_ptr<NativeRunner> OutOfProcessNativeRunnerFactory::Create( | |
71 const base::FilePath& service_path) { | |
72 return base::MakeUnique<OutOfProcessNativeRunner>( | |
73 service_path, launch_process_runner_, delegate_); | |
74 } | |
75 | |
76 } // namespace service_manager | |
OLD | NEW |