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
3 // found in the LICENSE file.
5 #ifndef SHELL_CHILD_PROCESS_HOST_H_
6 #define SHELL_CHILD_PROCESS_HOST_H_
8 #include "base/macros.h"
9 #include "base/process/process.h"
10 #include "mojo/edk/embedder/channel_info_forward.h"
11 #include "mojo/edk/embedder/platform_channel_pair.h"
12 #include "mojo/edk/embedder/scoped_platform_handle.h"
13 #include "mojo/shell/child_process.mojom.h"
14 #include "mojo/shell/child_process_host.h"
21 // This class represents a "child process host". Handles launching and
22 // connecting a platform-specific "pipe" to the child, and supports joining the
23 // child process. Currently runs a single app (loaded from the file system).
25 // This class is not thread-safe. It should be created/used/destroyed on a
28 // Note: Does not currently work on Windows before Vista.
29 // Note: After |Start()|, |StartApp| must be called and this object must
30 // remained alive until the |on_app_complete| callback is called.
31 class ChildProcessHost
{
33 explicit ChildProcessHost(Context
* context
);
34 virtual ~ChildProcessHost();
36 // |Start()|s the child process; calls |DidStart()| (on the thread on which
37 // |Start()| was called) when the child has been started (or failed to start).
38 // After calling |Start()|, this object must not be destroyed until
39 // |DidStart()| has been called.
40 // TODO(vtl): Consider using weak pointers and removing this requirement.
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
45 // callback has been called.
48 // See |ChildController|:
49 void StartApp(const String
& app_path
,
51 InterfaceRequest
<Application
> application_request
,
52 const ChildController::StartAppCallback
& on_app_complete
);
53 void ExitNow(int32_t exit_code
);
56 // virtual for testing.
57 virtual void DidStart(bool success
);
62 void AppCompleted(int32_t result
);
64 // Callback for |embedder::CreateChannel()|.
65 void DidCreateChannel(embedder::ChannelInfo
* channel_info
);
67 Context
* const context_
;
68 base::Process child_process_
;
69 embedder::PlatformChannelPair platform_channel_pair_
;
70 ChildControllerPtr controller_
;
71 embedder::ChannelInfo
* channel_info_
;
72 ChildController::StartAppCallback on_app_complete_
;
74 // Platform-specific "pipe" to the child process. Valid immediately after
76 embedder::ScopedPlatformHandle platform_channel_
;
78 DISALLOW_COPY_AND_ASSIGN(ChildProcessHost
);
84 #endif // SHELL_CHILD_PROCESS_HOST_H_