[SyncFS] Build indexes from FileTracker entries on disk.
[chromium-blink-merge.git] / mojo / shell / child_process_host.h
blobd3c7669a1b4ba171980a05128cb4d1b43144c08e
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|.
14 namespace mojo {
15 namespace shell {
17 class Context;
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
22 // simple cases.
24 // This class is not thread-safe. It should be created/used/destroyed on a
25 // single thread.
27 // Note: Does not currently work on Windows before Vista.
28 class ChildProcessHost {
29 public:
30 class Delegate {
31 public:
32 virtual void WillStart() = 0;
33 virtual void DidStart(bool success) = 0;
36 ChildProcessHost(Context* context,
37 Delegate* delegate,
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.
46 void Start();
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.
51 int Join();
53 embedder::ScopedPlatformHandle* platform_channel() {
54 return &platform_channel_;
57 protected:
58 Context* context() const {
59 return context_;
62 private:
63 bool DoLaunch();
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
75 // creation.
76 embedder::ScopedPlatformHandle platform_channel_;
78 DISALLOW_COPY_AND_ASSIGN(ChildProcessHost);
81 } // namespace shell
82 } // namespace mojo
84 #endif // MOJO_SHELL_CHILD_PROCESS_HOST_H_