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 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> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/process/process.h" | 11 #include "base/process/process.h" |
12 #include "mojo/edk/embedder/channel_info_forward.h" | 12 #include "mojo/edk/embedder/channel_info_forward.h" |
13 #include "mojo/edk/embedder/platform_channel_pair.h" | 13 #include "mojo/edk/embedder/platform_channel_pair.h" |
14 #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" | 15 #include "mojo/public/cpp/bindings/error_handler.h" |
16 #include "shell/child_controller.mojom.h" | 16 #include "shell/child_controller.mojom.h" |
17 | 17 |
18 namespace mojo { | |
19 namespace shell { | 18 namespace shell { |
20 | 19 |
21 class Context; | 20 class Context; |
22 | 21 |
23 // Child process host: parent-process representation of a child process, which | 22 // Child process host: parent-process representation of a child process, which |
24 // hosts/runs a native Mojo application loaded from the file system. This class | 23 // hosts/runs a native Mojo application loaded from the file system. This class |
25 // handles launching and communicating with the child process. | 24 // handles launching and communicating with the child process. |
26 // | 25 // |
27 // This class is not thread-safe. It should be created/used/destroyed on a | 26 // This class is not thread-safe. It should be created/used/destroyed on a |
28 // single thread. | 27 // single thread. |
29 class ChildProcessHost : public ErrorHandler { | 28 class ChildProcessHost : public mojo::ErrorHandler { |
30 public: | 29 public: |
31 explicit ChildProcessHost(Context* context); | 30 explicit ChildProcessHost(Context* context); |
32 ~ChildProcessHost() override; | 31 ~ChildProcessHost() override; |
33 | 32 |
34 // |Start()|s the child process; calls |DidStart()| (on the thread on which | 33 // |Start()|s the child process; calls |DidStart()| (on the thread on which |
35 // |Start()| was called) when the child has been started (or failed to start). | 34 // |Start()| was called) when the child has been started (or failed to start). |
36 // After calling |Start()|, this object must not be destroyed until | 35 // After calling |Start()|, this object must not be destroyed until |
37 // |DidStart()| has been called. | 36 // |DidStart()| has been called. |
38 // TODO(vtl): Consider using weak pointers and removing this requirement. | 37 // TODO(vtl): Consider using weak pointers and removing this requirement. |
39 // TODO(vtl): This should probably take a callback instead. | 38 // TODO(vtl): This should probably take a callback instead. |
40 // TODO(vtl): Consider merging this with |StartApp()|. | 39 // TODO(vtl): Consider merging this with |StartApp()|. |
41 void Start(); | 40 void Start(); |
42 | 41 |
43 // Waits for the child process to terminate, and returns its exit code. | 42 // Waits for the child process to terminate, and returns its exit code. |
44 // Note: If |Start()| has been called, this must not be called until the | 43 // Note: If |Start()| has been called, this must not be called until the |
45 // callback has been called. | 44 // callback has been called. |
46 int Join(); | 45 int Join(); |
47 | 46 |
48 // Methods relayed to the |ChildController|. These methods may be only be | 47 // Methods relayed to the |ChildController|. These methods may be only be |
49 // called after |Start()|, but may be called immediately (without waiting for | 48 // called after |Start()|, but may be called immediately (without waiting for |
50 // |DidStart()|). | 49 // |DidStart()|). |
51 | 50 |
52 // Like |ChildController::StartApp()|, but with one difference: | 51 // Like |ChildController::StartApp()|, but with one difference: |
53 // |on_app_complete| will *always* get called, even on connection error (or | 52 // |on_app_complete| will *always* get called, even on connection error (or |
54 // even if the child process failed to start at all). | 53 // even if the child process failed to start at all). |
55 void StartApp(const String& app_path, | 54 void StartApp(const mojo::String& app_path, |
56 bool clean_app_path, | 55 bool clean_app_path, |
57 InterfaceRequest<Application> application_request, | 56 mojo::InterfaceRequest<mojo::Application> application_request, |
58 const ChildController::StartAppCallback& on_app_complete); | 57 const ChildController::StartAppCallback& on_app_complete); |
59 void ExitNow(int32_t exit_code); | 58 void ExitNow(int32_t exit_code); |
60 | 59 |
61 // TODO(vtl): This is virtual, so tests can override it, but really |Start()| | 60 // TODO(vtl): This is virtual, so tests can override it, but really |Start()| |
62 // should take a callback (see above) and this should be private. | 61 // should take a callback (see above) and this should be private. |
63 virtual void DidStart(bool success); | 62 virtual void DidStart(bool success); |
64 | 63 |
65 private: | 64 private: |
66 // Callback for |embedder::CreateChannel()|. | 65 // Callback for |mojo::embedder::CreateChannel()|. |
67 void DidCreateChannel(embedder::ChannelInfo* channel_info); | 66 void DidCreateChannel(mojo::embedder::ChannelInfo* channel_info); |
68 | 67 |
69 bool DoLaunch(); | 68 bool DoLaunch(); |
70 | 69 |
71 void AppCompleted(int32_t result); | 70 void AppCompleted(int32_t result); |
72 | 71 |
73 // |ErrorHandler| methods: | 72 // |mojo::ErrorHandler| methods: |
74 void OnConnectionError() override; | 73 void OnConnectionError() override; |
75 | 74 |
76 Context* const context_; | 75 Context* const context_; |
77 embedder::PlatformChannelPair platform_channel_pair_; | 76 mojo::embedder::PlatformChannelPair platform_channel_pair_; |
78 | 77 |
79 ChildControllerPtr controller_; | 78 ChildControllerPtr controller_; |
80 embedder::ChannelInfo* channel_info_; | 79 mojo::embedder::ChannelInfo* channel_info_; |
81 ChildController::StartAppCallback on_app_complete_; | 80 ChildController::StartAppCallback on_app_complete_; |
82 | 81 |
83 base::Process child_process_; | 82 base::Process child_process_; |
84 | 83 |
85 DISALLOW_COPY_AND_ASSIGN(ChildProcessHost); | 84 DISALLOW_COPY_AND_ASSIGN(ChildProcessHost); |
86 }; | 85 }; |
87 | 86 |
88 } // namespace shell | 87 } // namespace shell |
89 } // namespace mojo | |
90 | 88 |
91 #endif // SHELL_CHILD_PROCESS_HOST_H_ | 89 #endif // SHELL_CHILD_PROCESS_HOST_H_ |
OLD | NEW |