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

Side by Side Diff: shell/child_process_host.h

Issue 1056593002: Merge AppChildProcessHost into ChildProcessHost. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 8 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
« no previous file with comments | « shell/app_child_process_host_unittest.cc ('k') | shell/child_process_host.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 SHELL_CHILD_PROCESS_HOST_H_ 5 #ifndef SHELL_CHILD_PROCESS_HOST_H_
6 #define SHELL_CHILD_PROCESS_HOST_H_ 6 #define SHELL_CHILD_PROCESS_HOST_H_
7 7
8 #include <stdint.h>
9
8 #include "base/macros.h" 10 #include "base/macros.h"
9 #include "base/process/process.h" 11 #include "base/process/process.h"
12 #include "mojo/edk/embedder/channel_info_forward.h"
10 #include "mojo/edk/embedder/platform_channel_pair.h" 13 #include "mojo/edk/embedder/platform_channel_pair.h"
11 #include "mojo/edk/embedder/scoped_platform_handle.h" 14 #include "mojo/edk/embedder/scoped_platform_handle.h"
15 #include "mojo/public/cpp/bindings/error_handler.h"
16 #include "shell/app_child_process.mojom.h"
12 17
13 namespace mojo { 18 namespace mojo {
14 namespace shell { 19 namespace shell {
15 20
16 class Context; 21 class Context;
17 22
18 // (Base) class for a "child process host". Handles launching and connecting a 23 // Child process host: parent-process representation of a child process, which
19 // platform-specific "pipe" to the child, and supports joining the child 24 // hosts/runs a native Mojo application loaded from the file system. This class
20 // process. 25 // handles launching and communicating with the child process.
21 // 26 //
22 // This class is not thread-safe. It should be created/used/destroyed on a 27 // This class is not thread-safe. It should be created/used/destroyed on a
23 // single thread. 28 // single thread.
24 // 29 class ChildProcessHost : public ErrorHandler {
25 // Note: Does not currently work on Windows before Vista.
26 class ChildProcessHost {
27 public: 30 public:
28 explicit ChildProcessHost(Context* context); 31 explicit ChildProcessHost(Context* context);
29 virtual ~ChildProcessHost(); 32 virtual ~ChildProcessHost();
30 33
31 // |Start()|s the child process; calls |DidStart()| (on the thread on which 34 // |Start()|s the child process; calls |DidStart()| (on the thread on which
32 // |Start()| was called) when the child has been started (or failed to start). 35 // |Start()| was called) when the child has been started (or failed to start).
33 // After calling |Start()|, this object must not be destroyed until 36 // After calling |Start()|, this object must not be destroyed until
34 // |DidStart()| has been called. 37 // |DidStart()| has been called.
35 // TODO(vtl): Consider using weak pointers and removing this requirement. 38 // TODO(vtl): Consider using weak pointers and removing this requirement.
39 // TODO(vtl): This should probably take a callback instead.
40 // TODO(vtl): Consider merging this with |StartApp()|.
36 void Start(); 41 void Start();
37 42
38 // Waits for the child process to terminate, and returns its exit code. 43 // Waits for the child process to terminate, and returns its exit code.
39 // Note: If |Start()| has been called, this must not be called until the 44 // Note: If |Start()| has been called, this must not be called until the
40 // callback has been called. 45 // callback has been called.
41 int Join(); 46 int Join();
42 47
43 embedder::ScopedPlatformHandle* platform_channel() { 48 // Methods relayed to the |AppChildController|. These methods may be only be
44 return &platform_channel_; 49 // called after |Start()|, but may be called immediately (without waiting for
45 } 50 // |DidStart()|).
46 51
47 virtual void WillStart() = 0; 52 // Like |AppChildController::StartApp()|, but with one difference:
48 virtual void DidStart(bool success) = 0; 53 // |on_app_complete| will *always* get called, even on connection error (or
54 // even if the child process failed to start at all).
55 void StartApp(const String& app_path,
56 bool clean_app_path,
57 InterfaceRequest<Application> application_request,
58 const AppChildController::StartAppCallback& on_app_complete);
59 void ExitNow(int32_t exit_code);
49 60
50 protected: 61 // TODO(vtl): This is virtual, so tests can override it, but really |Start()|
51 Context* context() const { return context_; } 62 // should take a callback (see above) and this should be private.
63 virtual void DidStart(bool success);
52 64
53 private: 65 private:
66 // Callback for |embedder::CreateChannel()|.
67 void DidCreateChannel(embedder::ChannelInfo* channel_info);
68
54 bool DoLaunch(); 69 bool DoLaunch();
55 70
71 void AppCompleted(int32_t result);
72
73 // |ErrorHandler| methods:
74 void OnConnectionError() override;
75
56 Context* const context_; 76 Context* const context_;
77 embedder::PlatformChannelPair platform_channel_pair_;
78
79 AppChildControllerPtr controller_;
80 embedder::ChannelInfo* channel_info_;
81 AppChildController::StartAppCallback on_app_complete_;
57 82
58 base::Process child_process_; 83 base::Process child_process_;
59 84
60 embedder::PlatformChannelPair platform_channel_pair_;
61
62 // Platform-specific "pipe" to the child process. Valid immediately after
63 // creation.
64 embedder::ScopedPlatformHandle platform_channel_;
65
66 DISALLOW_COPY_AND_ASSIGN(ChildProcessHost); 85 DISALLOW_COPY_AND_ASSIGN(ChildProcessHost);
67 }; 86 };
68 87
69 } // namespace shell 88 } // namespace shell
70 } // namespace mojo 89 } // namespace mojo
71 90
72 #endif // SHELL_CHILD_PROCESS_HOST_H_ 91 #endif // SHELL_CHILD_PROCESS_HOST_H_
OLDNEW
« no previous file with comments | « shell/app_child_process_host_unittest.cc ('k') | shell/child_process_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698