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

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

Issue 2566663004: Revert of Build services as standalone executables (Closed)
Patch Set: 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 service, loaded from a standalone 39 // child process. Currently runs a single app (loaded from the file system).
40 // service executable on 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.
45 // Note: After |Start()|, |StartApp| must be called and this object must
46 // remained alive until the |on_app_complete| callback is called.
46 class ChildProcessHost { 47 class ChildProcessHost {
47 public: 48 public:
48 using ProcessReadyCallback = base::Callback<void(base::ProcessId)>; 49 using ProcessReadyCallback = base::Callback<void(base::ProcessId)>;
49 50
50 // |name| is just for debugging ease. We will spawn off a process so that it 51 // |name| is just for debugging ease. We will spawn off a process so that it
51 // can be sandboxed if |start_sandboxed| is true. |service_path| is a path to 52 // can be sandboxed if |start_sandboxed| is true. |app_path| is a path to the
52 // the service executable we wish to start. 53 // service we wish to start.
53 ChildProcessHost(base::TaskRunner* launch_process_runner, 54 ChildProcessHost(base::TaskRunner* launch_process_runner,
54 NativeRunnerDelegate* delegate, 55 NativeRunnerDelegate* delegate,
55 bool start_sandboxed, 56 bool start_sandboxed,
56 const Identity& target, 57 const Identity& target,
57 const base::FilePath& service_path); 58 const base::FilePath& app_path);
58 virtual ~ChildProcessHost(); 59 virtual ~ChildProcessHost();
59 60
60 // |Start()|s the child process; calls |DidStart()| (on the thread on which 61 // |Start()|s the child process; calls |DidStart()| (on the thread on which
61 // |Start()| was called) when the child has been started (or failed to start). 62 // |Start()| was called) when the child has been started (or failed to start).
62 mojom::ServicePtr Start(const Identity& target, 63 mojom::ServicePtr Start(const Identity& target,
63 const ProcessReadyCallback& callback, 64 const ProcessReadyCallback& callback,
64 const base::Closure& quit_closure); 65 const base::Closure& quit_closure);
65 66
66 // Waits for the child process to terminate. 67 // Waits for the child process to terminate.
67 void Join(); 68 void Join();
68 69
69 protected: 70 protected:
70 void DidStart(const ProcessReadyCallback& callback); 71 void DidStart(const ProcessReadyCallback& callback);
71 72
72 private: 73 private:
73 void DoLaunch(std::unique_ptr<base::CommandLine> child_command_line); 74 void DoLaunch(std::unique_ptr<base::CommandLine> child_command_line);
74 75
75 scoped_refptr<base::TaskRunner> launch_process_runner_; 76 scoped_refptr<base::TaskRunner> launch_process_runner_;
76 NativeRunnerDelegate* delegate_ = nullptr; 77 NativeRunnerDelegate* delegate_ = nullptr;
77 bool start_sandboxed_ = false; 78 bool start_sandboxed_ = false;
78 Identity target_; 79 Identity target_;
79 base::FilePath service_path_; 80 const base::FilePath app_path_;
80 base::Process child_process_; 81 base::Process child_process_;
81 82
82 // Used to initialize the Mojo IPC channel between parent and child. 83 // Used to initialize the Mojo IPC channel between parent and child.
83 std::unique_ptr<mojo::edk::PlatformChannelPair> mojo_ipc_channel_; 84 std::unique_ptr<mojo::edk::PlatformChannelPair> mojo_ipc_channel_;
84 mojo::edk::HandlePassingInformation handle_passing_info_; 85 mojo::edk::HandlePassingInformation handle_passing_info_;
85 const std::string child_token_; 86 const std::string child_token_;
86 87
87 // Since Start() calls a method on another thread, we use an event to block 88 // Since Start() calls a method on another thread, we use an event to block
88 // the main thread if it tries to destruct |this| while launching the process. 89 // the main thread if it tries to destruct |this| while launching the process.
89 base::WaitableEvent start_child_process_event_; 90 base::WaitableEvent start_child_process_event_;
90 91
91 base::WeakPtrFactory<ChildProcessHost> weak_factory_; 92 base::WeakPtrFactory<ChildProcessHost> weak_factory_;
92 93
93 DISALLOW_COPY_AND_ASSIGN(ChildProcessHost); 94 DISALLOW_COPY_AND_ASSIGN(ChildProcessHost);
94 }; 95 };
95 96
96 } // namespace service_manager 97 } // namespace service_manager
97 98
98 #endif // SERVICES_SERVICE_MANAGER_RUNNER_HOST_CHILD_PROCESS_HOST_H_ 99 #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