| 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/app_child_process.mojom.h" | 16 #include "shell/child_controller.mojom.h" |
| 17 | 17 |
| 18 namespace mojo { | 18 namespace mojo { |
| 19 namespace shell { | 19 namespace shell { |
| 20 | 20 |
| 21 class Context; | 21 class Context; |
| 22 | 22 |
| 23 // Child process host: parent-process representation of a child process, which | 23 // 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 | 24 // hosts/runs a native Mojo application loaded from the file system. This class |
| 25 // handles launching and communicating with the child process. | 25 // handles launching and communicating with the child process. |
| 26 // | 26 // |
| (...skipping 11 matching lines...) Expand all Loading... |
| 38 // 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. | 39 // TODO(vtl): This should probably take a callback instead. |
| 40 // TODO(vtl): Consider merging this with |StartApp()|. | 40 // TODO(vtl): Consider merging this with |StartApp()|. |
| 41 void Start(); | 41 void Start(); |
| 42 | 42 |
| 43 // 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. |
| 44 // 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 |
| 45 // callback has been called. | 45 // callback has been called. |
| 46 int Join(); | 46 int Join(); |
| 47 | 47 |
| 48 // Methods relayed to the |AppChildController|. These methods may be only be | 48 // Methods relayed to the |ChildController|. These methods may be only be |
| 49 // called after |Start()|, but may be called immediately (without waiting for | 49 // called after |Start()|, but may be called immediately (without waiting for |
| 50 // |DidStart()|). | 50 // |DidStart()|). |
| 51 | 51 |
| 52 // Like |AppChildController::StartApp()|, but with one difference: | 52 // Like |ChildController::StartApp()|, but with one difference: |
| 53 // |on_app_complete| will *always* get called, even on connection error (or | 53 // |on_app_complete| will *always* get called, even on connection error (or |
| 54 // even if the child process failed to start at all). | 54 // even if the child process failed to start at all). |
| 55 void StartApp(const String& app_path, | 55 void StartApp(const String& app_path, |
| 56 bool clean_app_path, | 56 bool clean_app_path, |
| 57 InterfaceRequest<Application> application_request, | 57 InterfaceRequest<Application> application_request, |
| 58 const AppChildController::StartAppCallback& on_app_complete); | 58 const ChildController::StartAppCallback& on_app_complete); |
| 59 void ExitNow(int32_t exit_code); | 59 void ExitNow(int32_t exit_code); |
| 60 | 60 |
| 61 // TODO(vtl): This is virtual, so tests can override it, but really |Start()| | 61 // 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. | 62 // should take a callback (see above) and this should be private. |
| 63 virtual void DidStart(bool success); | 63 virtual void DidStart(bool success); |
| 64 | 64 |
| 65 private: | 65 private: |
| 66 // Callback for |embedder::CreateChannel()|. | 66 // Callback for |embedder::CreateChannel()|. |
| 67 void DidCreateChannel(embedder::ChannelInfo* channel_info); | 67 void DidCreateChannel(embedder::ChannelInfo* channel_info); |
| 68 | 68 |
| 69 bool DoLaunch(); | 69 bool DoLaunch(); |
| 70 | 70 |
| 71 void AppCompleted(int32_t result); | 71 void AppCompleted(int32_t result); |
| 72 | 72 |
| 73 // |ErrorHandler| methods: | 73 // |ErrorHandler| methods: |
| 74 void OnConnectionError() override; | 74 void OnConnectionError() override; |
| 75 | 75 |
| 76 Context* const context_; | 76 Context* const context_; |
| 77 embedder::PlatformChannelPair platform_channel_pair_; | 77 embedder::PlatformChannelPair platform_channel_pair_; |
| 78 | 78 |
| 79 AppChildControllerPtr controller_; | 79 ChildControllerPtr controller_; |
| 80 embedder::ChannelInfo* channel_info_; | 80 embedder::ChannelInfo* channel_info_; |
| 81 AppChildController::StartAppCallback on_app_complete_; | 81 ChildController::StartAppCallback on_app_complete_; |
| 82 | 82 |
| 83 base::Process child_process_; | 83 base::Process child_process_; |
| 84 | 84 |
| 85 DISALLOW_COPY_AND_ASSIGN(ChildProcessHost); | 85 DISALLOW_COPY_AND_ASSIGN(ChildProcessHost); |
| 86 }; | 86 }; |
| 87 | 87 |
| 88 } // namespace shell | 88 } // namespace shell |
| 89 } // namespace mojo | 89 } // namespace mojo |
| 90 | 90 |
| 91 #endif // SHELL_CHILD_PROCESS_HOST_H_ | 91 #endif // SHELL_CHILD_PROCESS_HOST_H_ |
| OLD | NEW |