Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(388)

Side by Side Diff: services/service_manager/runner/host/child_process_host.h

Issue 2557213002: Build services as standalone executables (Closed)
Patch Set: remove DCHECKs with side effects -_- Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_SERVICE_MANAGER_RUNNER_HOST_CHILD_PROCESS_HOST_H_ 5 #ifndef SERVICES_SERVICE_MANAGER_RUNNER_HOST_CHILD_PROCESS_HOST_H_
6 #define SERVICES_SERVICE_MANAGER_RUNNER_HOST_CHILD_PROCESS_HOST_H_ 6 #define SERVICES_SERVICE_MANAGER_RUNNER_HOST_CHILD_PROCESS_HOST_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
(...skipping 18 matching lines...) Expand all
29 class TaskRunner; 29 class TaskRunner;
30 } 30 }
31 31
32 namespace service_manager { 32 namespace service_manager {
33 33
34 class Identity; 34 class Identity;
35 class NativeRunnerDelegate; 35 class NativeRunnerDelegate;
36 36
37 // This class represents a "child process host". Handles launching and 37 // This class represents a "child process host". Handles launching and
38 // 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
39 // child process. Currently runs a single app (loaded from the file system). 39 // child process. Currently runs a single service, loaded from a standalone
40 // service executable on the file system.
40 // 41 //
41 // This class is not thread-safe. It should be created/used/destroyed on a 42 // This class is not thread-safe. It should be created/used/destroyed on a
42 // single thread. 43 // single thread.
43 // 44 //
44 // Note: Does not currently work on Windows before Vista. 45 // Note: Does not currently work on Windows before Vista.
45 // Note: After |Start()|, |StartApp| must be called and this object must
46 // remained alive until the |on_app_complete| callback is called.
47 class ChildProcessHost { 46 class ChildProcessHost {
48 public: 47 public:
49 using ProcessReadyCallback = base::Callback<void(base::ProcessId)>; 48 using ProcessReadyCallback = base::Callback<void(base::ProcessId)>;
50 49
51 // |name| is just for debugging ease. We will spawn off a process so that it 50 // |name| is just for debugging ease. We will spawn off a process so that it
52 // can be sandboxed if |start_sandboxed| is true. |app_path| is a path to the 51 // can be sandboxed if |start_sandboxed| is true. |service_path| is a path to
53 // service we wish to start. 52 // the service executable we wish to start.
54 ChildProcessHost(base::TaskRunner* launch_process_runner, 53 ChildProcessHost(base::TaskRunner* launch_process_runner,
55 NativeRunnerDelegate* delegate, 54 NativeRunnerDelegate* delegate,
56 bool start_sandboxed, 55 bool start_sandboxed,
57 const Identity& target, 56 const Identity& target,
58 const base::FilePath& app_path); 57 const base::FilePath& service_path);
59 virtual ~ChildProcessHost(); 58 virtual ~ChildProcessHost();
60 59
61 // |Start()|s the child process; calls |DidStart()| (on the thread on which 60 // |Start()|s the child process; calls |DidStart()| (on the thread on which
62 // |Start()| was called) when the child has been started (or failed to start). 61 // |Start()| was called) when the child has been started (or failed to start).
63 mojom::ServicePtr Start(const Identity& target, 62 mojom::ServicePtr Start(const Identity& target,
64 const ProcessReadyCallback& callback, 63 const ProcessReadyCallback& callback,
65 const base::Closure& quit_closure); 64 const base::Closure& quit_closure);
66 65
67 // Waits for the child process to terminate. 66 // Waits for the child process to terminate.
68 void Join(); 67 void Join();
69 68
70 protected: 69 protected:
71 void DidStart(const ProcessReadyCallback& callback); 70 void DidStart(const ProcessReadyCallback& callback);
72 71
73 private: 72 private:
74 void DoLaunch(std::unique_ptr<base::CommandLine> child_command_line); 73 void DoLaunch(std::unique_ptr<base::CommandLine> child_command_line);
75 74
76 scoped_refptr<base::TaskRunner> launch_process_runner_; 75 scoped_refptr<base::TaskRunner> launch_process_runner_;
77 NativeRunnerDelegate* delegate_ = nullptr; 76 NativeRunnerDelegate* delegate_ = nullptr;
78 bool start_sandboxed_ = false; 77 bool start_sandboxed_ = false;
79 Identity target_; 78 Identity target_;
80 const base::FilePath app_path_; 79 base::FilePath service_path_;
81 base::Process child_process_; 80 base::Process child_process_;
82 81
83 // Used to initialize the Mojo IPC channel between parent and child. 82 // Used to initialize the Mojo IPC channel between parent and child.
84 std::unique_ptr<mojo::edk::PlatformChannelPair> mojo_ipc_channel_; 83 std::unique_ptr<mojo::edk::PlatformChannelPair> mojo_ipc_channel_;
85 mojo::edk::HandlePassingInformation handle_passing_info_; 84 mojo::edk::HandlePassingInformation handle_passing_info_;
86 const std::string child_token_; 85 const std::string child_token_;
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 service_manager 96 } // namespace service_manager
98 97
99 #endif // SERVICES_SERVICE_MANAGER_RUNNER_HOST_CHILD_PROCESS_HOST_H_ 98 #endif // SERVICES_SERVICE_MANAGER_RUNNER_HOST_CHILD_PROCESS_HOST_H_
OLDNEW
« no previous file with comments | « services/service_manager/runner/host/child_process_base.cc ('k') | services/service_manager/runner/host/child_process_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698