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

Side by Side Diff: mojo/shell/runner/host/child_process_host.h

Issue 1761153002: Replace ChildController with ShellClientFactory (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@29binding
Patch Set: . Created 4 years, 9 months 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 MOJO_SHELL_RUNNER_HOST_CHILD_PROCESS_HOST_H_ 5 #ifndef MOJO_SHELL_RUNNER_HOST_CHILD_PROCESS_HOST_H_
6 #define MOJO_SHELL_RUNNER_HOST_CHILD_PROCESS_HOST_H_ 6 #define MOJO_SHELL_RUNNER_HOST_CHILD_PROCESS_HOST_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <string> 10 #include <string>
11 11
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
16 #include "base/memory/weak_ptr.h" 16 #include "base/memory/weak_ptr.h"
17 #include "base/process/process.h" 17 #include "base/process/process.h"
18 #include "base/synchronization/lock.h" 18 #include "base/synchronization/lock.h"
19 #include "base/synchronization/waitable_event.h" 19 #include "base/synchronization/waitable_event.h"
20 #include "mojo/edk/embedder/platform_channel_pair.h" 20 #include "mojo/edk/embedder/platform_channel_pair.h"
21 #include "mojo/public/cpp/system/message_pipe.h" 21 #include "mojo/public/cpp/system/message_pipe.h"
22 #include "mojo/shell/identity.h" 22 #include "mojo/shell/identity.h"
23 #include "mojo/shell/runner/child/child_controller.mojom.h" 23 #include "mojo/shell/public/interfaces/shell_client_factory.mojom.h"
24 #include "mojo/shell/runner/host/child_process_host.h" 24 #include "mojo/shell/runner/host/child_process_host.h"
25 25
26 namespace base { 26 namespace base {
27 class TaskRunner; 27 class TaskRunner;
28 } 28 }
29 29
30 namespace mojo { 30 namespace mojo {
31 namespace shell { 31 namespace shell {
32 32
33 class Identity; 33 class Identity;
(...skipping 16 matching lines...) Expand all
50 // |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
51 // can be sandboxed if |start_sandboxed| is true. |app_path| is a path to the 51 // can be sandboxed if |start_sandboxed| is true. |app_path| is a path to the
52 // mojo application we wish to start. 52 // mojo application we wish to start.
53 ChildProcessHost(base::TaskRunner* launch_process_runner, 53 ChildProcessHost(base::TaskRunner* launch_process_runner,
54 NativeRunnerDelegate* delegate, 54 NativeRunnerDelegate* delegate,
55 bool start_sandboxed, 55 bool start_sandboxed,
56 const Identity& target, 56 const Identity& target,
57 const base::FilePath& app_path); 57 const base::FilePath& app_path);
58 // Allows a ChildProcessHost to be instantiated for an existing channel 58 // Allows a ChildProcessHost to be instantiated for an existing channel
59 // created by someone else (e.g. an app that launched its own process). 59 // created by someone else (e.g. an app that launched its own process).
60 explicit ChildProcessHost(ScopedHandle channel); 60 explicit ChildProcessHost(mojom::ShellClientFactoryPtr factory);
61 virtual ~ChildProcessHost(); 61 virtual ~ChildProcessHost();
62 62
63 // |Start()|s the child process; calls |DidStart()| (on the thread on which 63 // |Start()|s the child process; calls |DidStart()| (on the thread on which
64 // |Start()| was called) when the child has been started (or failed to start). 64 // |Start()| was called) when the child has been started (or failed to start).
65 void Start(const ProcessReadyCallback& callback); 65 void Start(const ProcessReadyCallback& callback);
66 66
67 // Waits for the child process to terminate, and returns its exit code. 67 // Waits for the child process to terminate.
68 int Join(); 68 void Join();
69 69
70 // See |mojom::ChildController|: 70 void StartChild(mojom::ShellClientRequest request,
71 void StartApp( 71 const String& name,
72 InterfaceRequest<mojom::ShellClient> request, 72 const base::Closure& quit_closure);
73 const mojom::ChildController::StartAppCallback& on_app_complete);
74 void ExitNow(int32_t exit_code);
75 73
76 protected: 74 protected:
77 void DidStart(const ProcessReadyCallback& callback); 75 void DidStart(const ProcessReadyCallback& callback);
78 76
79 private: 77 private:
80 void DoLaunch(); 78 void DoLaunch();
81 79
82 void AppCompleted(int32_t result);
83
84 // If |true|, the hosted process is neither launched nor owned by this 80 // If |true|, the hosted process is neither launched nor owned by this
85 // ChildProcessHost. 81 // ChildProcessHost.
86 bool external_process_ = false; 82 bool external_process_ = false;
87 83
88 scoped_refptr<base::TaskRunner> launch_process_runner_; 84 scoped_refptr<base::TaskRunner> launch_process_runner_;
89 NativeRunnerDelegate* delegate_; 85 NativeRunnerDelegate* delegate_ = nullptr;
90 bool start_sandboxed_; 86 bool start_sandboxed_ = false;
91 Identity target_; 87 Identity target_;
92 const base::FilePath app_path_; 88 const base::FilePath app_path_;
93 base::Process child_process_; 89 base::Process child_process_;
94 // Used for the ChildController binding. 90 // Used for the ShellClientFactory binding.
95 edk::PlatformChannelPair platform_channel_pair_; 91 edk::PlatformChannelPair platform_channel_pair_;
96 mojom::ChildControllerPtr controller_; 92 mojom::ShellClientFactoryPtr factory_;
97 mojom::ChildController::StartAppCallback on_app_complete_;
98 edk::HandlePassingInformation handle_passing_info_; 93 edk::HandlePassingInformation handle_passing_info_;
99 94
100 // Used to back the NodeChannel between the parent and child node. 95 // Used to back the NodeChannel between the parent and child node.
101 scoped_ptr<edk::PlatformChannelPair> node_channel_; 96 scoped_ptr<edk::PlatformChannelPair> node_channel_;
102 97
103 // Since Start() calls a method on another thread, we use an event to block 98 // Since Start() calls a method on another thread, we use an event to block
104 // the main thread if it tries to destruct |this| while launching the process. 99 // the main thread if it tries to destruct |this| while launching the process.
105 base::WaitableEvent start_child_process_event_; 100 base::WaitableEvent start_child_process_event_;
106 101
107 // A token the child can use to connect a primordial pipe to the host. 102 // A token the child can use to connect a primordial pipe to the host.
108 std::string primordial_pipe_token_; 103 std::string primordial_pipe_token_;
109 104
110 base::WeakPtrFactory<ChildProcessHost> weak_factory_; 105 base::WeakPtrFactory<ChildProcessHost> weak_factory_;
111 106
112 DISALLOW_COPY_AND_ASSIGN(ChildProcessHost); 107 DISALLOW_COPY_AND_ASSIGN(ChildProcessHost);
113 }; 108 };
114 109
115 } // namespace shell 110 } // namespace shell
116 } // namespace mojo 111 } // namespace mojo
117 112
118 #endif // MOJO_SHELL_RUNNER_HOST_CHILD_PROCESS_HOST_H_ 113 #endif // MOJO_SHELL_RUNNER_HOST_CHILD_PROCESS_HOST_H_
OLDNEW
« no previous file with comments | « mojo/shell/runner/host/child_process_base.cc ('k') | mojo/shell/runner/host/child_process_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698