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 #ifndef SERVICES_SHELL_RUNNER_HOST_CHILD_PROCESS_HOST_H_ | 5 #ifndef SERVICES_SHELL_RUNNER_HOST_CHILD_PROCESS_HOST_H_ |
6 #define SERVICES_SHELL_RUNNER_HOST_CHILD_PROCESS_HOST_H_ | 6 #define SERVICES_SHELL_RUNNER_HOST_CHILD_PROCESS_HOST_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
| 10 #include <memory> |
10 #include <string> | 11 #include <string> |
11 | 12 |
12 #include "base/callback.h" | 13 #include "base/callback.h" |
13 #include "base/command_line.h" | 14 #include "base/command_line.h" |
14 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
15 #include "base/macros.h" | 16 #include "base/macros.h" |
16 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
17 #include "base/memory/scoped_ptr.h" | |
18 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
19 #include "base/process/process.h" | 19 #include "base/process/process.h" |
20 #include "base/synchronization/lock.h" | 20 #include "base/synchronization/lock.h" |
21 #include "base/synchronization/waitable_event.h" | 21 #include "base/synchronization/waitable_event.h" |
22 #include "mojo/edk/embedder/platform_channel_pair.h" | 22 #include "mojo/edk/embedder/platform_channel_pair.h" |
23 #include "mojo/public/cpp/system/message_pipe.h" | 23 #include "mojo/public/cpp/system/message_pipe.h" |
24 #include "services/shell/public/cpp/identity.h" | 24 #include "services/shell/public/cpp/identity.h" |
25 #include "services/shell/public/interfaces/shell_client_factory.mojom.h" | 25 #include "services/shell/public/interfaces/shell_client_factory.mojom.h" |
26 #include "services/shell/runner/host/child_process_host.h" | 26 #include "services/shell/runner/host/child_process_host.h" |
27 | 27 |
28 namespace base { | 28 namespace base { |
29 class TaskRunner; | 29 class TaskRunner; |
30 } | 30 } |
31 | 31 |
32 namespace mojo { | |
33 class Identity; | |
34 namespace shell { | 32 namespace shell { |
35 | 33 |
| 34 class Identity; |
36 class NativeRunnerDelegate; | 35 class NativeRunnerDelegate; |
37 | 36 |
38 // This class represents a "child process host". Handles launching and | 37 // This class represents a "child process host". Handles launching and |
39 // connecting a platform-specific "pipe" to the child, and supports joining the | 38 // connecting a platform-specific "pipe" to the child, and supports joining the |
40 // child process. Currently runs a single app (loaded from the file system). | 39 // child process. Currently runs a single app (loaded from the file system). |
41 // | 40 // |
42 // This class is not thread-safe. It should be created/used/destroyed on a | 41 // This class is not thread-safe. It should be created/used/destroyed on a |
43 // single thread. | 42 // single thread. |
44 // | 43 // |
45 // Note: Does not currently work on Windows before Vista. | 44 // Note: Does not currently work on Windows before Vista. |
(...skipping 19 matching lines...) Expand all Loading... |
65 const ProcessReadyCallback& callback, | 64 const ProcessReadyCallback& callback, |
66 const base::Closure& quit_closure); | 65 const base::Closure& quit_closure); |
67 | 66 |
68 // Waits for the child process to terminate. | 67 // Waits for the child process to terminate. |
69 void Join(); | 68 void Join(); |
70 | 69 |
71 protected: | 70 protected: |
72 void DidStart(const ProcessReadyCallback& callback); | 71 void DidStart(const ProcessReadyCallback& callback); |
73 | 72 |
74 private: | 73 private: |
75 void DoLaunch(scoped_ptr<base::CommandLine> child_command_line); | 74 void DoLaunch(std::unique_ptr<base::CommandLine> child_command_line); |
76 | 75 |
77 scoped_refptr<base::TaskRunner> launch_process_runner_; | 76 scoped_refptr<base::TaskRunner> launch_process_runner_; |
78 NativeRunnerDelegate* delegate_ = nullptr; | 77 NativeRunnerDelegate* delegate_ = nullptr; |
79 bool start_sandboxed_ = false; | 78 bool start_sandboxed_ = false; |
80 Identity target_; | 79 Identity target_; |
81 const base::FilePath app_path_; | 80 const base::FilePath app_path_; |
82 base::Process child_process_; | 81 base::Process child_process_; |
83 | 82 |
84 // Used to initialize the Mojo IPC channel between parent and child. | 83 // Used to initialize the Mojo IPC channel between parent and child. |
85 scoped_ptr<edk::PlatformChannelPair> mojo_ipc_channel_; | 84 std::unique_ptr<mojo::edk::PlatformChannelPair> mojo_ipc_channel_; |
86 edk::HandlePassingInformation handle_passing_info_; | 85 mojo::edk::HandlePassingInformation handle_passing_info_; |
87 | 86 |
88 // Since Start() calls a method on another thread, we use an event to block | 87 // Since Start() calls a method on another thread, we use an event to block |
89 // the main thread if it tries to destruct |this| while launching the process. | 88 // the main thread if it tries to destruct |this| while launching the process. |
90 base::WaitableEvent start_child_process_event_; | 89 base::WaitableEvent start_child_process_event_; |
91 | 90 |
92 base::WeakPtrFactory<ChildProcessHost> weak_factory_; | 91 base::WeakPtrFactory<ChildProcessHost> weak_factory_; |
93 | 92 |
94 DISALLOW_COPY_AND_ASSIGN(ChildProcessHost); | 93 DISALLOW_COPY_AND_ASSIGN(ChildProcessHost); |
95 }; | 94 }; |
96 | 95 |
97 } // namespace shell | 96 } // namespace shell |
98 } // namespace mojo | |
99 | 97 |
100 #endif // SERVICES_SHELL_RUNNER_HOST_CHILD_PROCESS_HOST_H_ | 98 #endif // SERVICES_SHELL_RUNNER_HOST_CHILD_PROCESS_HOST_H_ |
OLD | NEW |