net: Fix proxy_start times to include full resolution time.
[chromium-blink-merge.git] / mojo / runner / child_process_host.h
blobcbc3d644850e9a18f81b91fa965dd4c15e3a2828
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_RUNNER_CHILD_PROCESS_HOST_H_
6 #define MOJO_RUNNER_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/runner/child_process.mojom.h"
14 #include "mojo/runner/child_process_host.h"
16 namespace mojo {
17 namespace runner {
19 class Context;
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
26 // single thread.
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 {
32 public:
33 // |name| is just for debugging ease.
34 ChildProcessHost(Context* context, const std::string& name);
35 virtual ~ChildProcessHost();
37 // |Start()|s the child process; calls |DidStart()| (on the thread on which
38 // |Start()| was called) when the child has been started (or failed to start).
39 // After calling |Start()|, this object must not be destroyed until
40 // |DidStart()| has been called.
41 // TODO(vtl): Consider using weak pointers and removing this requirement.
42 void Start();
44 // Waits for the child process to terminate, and returns its exit code.
45 // Note: If |Start()| has been called, this must not be called until the
46 // callback has been called.
47 int Join();
49 // See |ChildController|:
50 void StartApp(const String& app_path,
51 bool clean_app_path,
52 InterfaceRequest<Application> application_request,
53 const ChildController::StartAppCallback& on_app_complete);
54 void ExitNow(int32_t exit_code);
56 protected:
57 // virtual for testing.
58 virtual void DidStart(bool success);
60 private:
61 bool DoLaunch();
63 void AppCompleted(int32_t result);
65 // Callback for |embedder::CreateChannel()|.
66 void DidCreateChannel(embedder::ChannelInfo* channel_info);
68 Context* const context_;
69 const std::string name_;
70 base::Process child_process_;
71 embedder::PlatformChannelPair platform_channel_pair_;
72 ChildControllerPtr controller_;
73 embedder::ChannelInfo* channel_info_;
74 ChildController::StartAppCallback on_app_complete_;
76 // Platform-specific "pipe" to the child process. Valid immediately after
77 // creation.
78 embedder::ScopedPlatformHandle platform_channel_;
80 DISALLOW_COPY_AND_ASSIGN(ChildProcessHost);
83 } // namespace runner
84 } // namespace mojo
86 #endif // MOJO_RUNNER_CHILD_PROCESS_HOST_H_