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 MOJO_SHELL_CHILD_PROCESS_HOST_H_
6 #define MOJO_SHELL_CHILD_PROCESS_HOST_H_
8 #include "base/macros.h"
9 #include "base/process/process_handle.h"
10 #include "mojo/embedder/platform_channel_pair.h"
11 #include "mojo/embedder/scoped_platform_handle.h"
12 #include "mojo/shell/child_process.h" // For |ChildProcess::Type|.
19 // (Base) class for a "child process host". Handles launching and connecting a
20 // platform-specific "pipe" to the child, and supports joining the child
21 // process. Intended for use as a base class, but may be used on its own in
24 // This class is not thread-safe. It should be created/used/destroyed on a
27 // Note: Does not currently work on Windows before Vista.
28 class ChildProcessHost
{
32 virtual void WillStart() = 0;
33 virtual void DidStart(bool success
) = 0;
36 ChildProcessHost(Context
* context
,
38 ChildProcess::Type type
);
39 virtual ~ChildProcessHost();
41 // |Start()|s the child process; calls the delegate's |DidStart()| (on the
42 // thread on which |Start()| was called) when the child has been started (or
43 // failed to start). After calling |Start()|, this object must not be
44 // destroyed until |DidStart()| has been called.
45 // TODO(vtl): Consider using weak pointers and removing this requirement.
48 // Waits for the child process to terminate, and returns its exit code.
49 // Note: If |Start()| has been called, this must not be called until the
50 // callback has been called.
53 embedder::ScopedPlatformHandle
* platform_channel() {
54 return &platform_channel_
;
58 Context
* context() const {
64 void DidLaunch(bool success
);
66 Context
* const context_
;
67 Delegate
* const delegate_
;
68 const ChildProcess::Type type_
;
70 base::ProcessHandle child_process_handle_
;
72 embedder::PlatformChannelPair platform_channel_pair_
;
74 // Platform-specific "pipe" to the child process. Valid immediately after
76 embedder::ScopedPlatformHandle platform_channel_
;
78 DISALLOW_COPY_AND_ASSIGN(ChildProcessHost
);
84 #endif // MOJO_SHELL_CHILD_PROCESS_HOST_H_