Fix layout of the Connection Tab of the Origin Info Bubble.
[chromium-blink-merge.git] / mojo / runner / child_process_host.h
blob8ab3147992b82e3faab43bde95d7ebf0b0e68b5c
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/files/file_path.h"
9 #include "base/macros.h"
10 #include "base/process/process.h"
11 #include "mojo/edk/embedder/channel_info_forward.h"
12 #include "mojo/edk/embedder/platform_channel_pair.h"
13 #include "mojo/edk/embedder/scoped_platform_handle.h"
14 #include "mojo/runner/child_process.mojom.h"
15 #include "mojo/runner/child_process_host.h"
17 namespace mojo {
18 namespace runner {
20 class Context;
22 // This class represents a "child process host". Handles launching and
23 // connecting a platform-specific "pipe" to the child, and supports joining the
24 // child process. Currently runs a single app (loaded from the file system).
26 // This class is not thread-safe. It should be created/used/destroyed on a
27 // single thread.
29 // Note: Does not currently work on Windows before Vista.
30 // Note: After |Start()|, |StartApp| must be called and this object must
31 // remained alive until the |on_app_complete| callback is called.
32 class ChildProcessHost {
33 public:
34 // |name| is just for debugging ease. We will spawn off a process so that it
35 // can be sandboxed if |start_sandboxed| is true. |app_path| is a path to the
36 // mojo application we wish to start.
37 ChildProcessHost(Context* context,
38 bool start_sandboxed,
39 const base::FilePath& app_path);
40 virtual ~ChildProcessHost();
42 // |Start()|s the child process; calls |DidStart()| (on the thread on which
43 // |Start()| was called) when the child has been started (or failed to start).
44 // After calling |Start()|, this object must not be destroyed until
45 // |DidStart()| has been called.
46 // TODO(vtl): Consider using weak pointers and removing this requirement.
47 void Start();
49 // Waits for the child process to terminate, and returns its exit code.
50 // Note: If |Start()| has been called, this must not be called until the
51 // callback has been called.
52 int Join();
54 // See |ChildController|:
55 void StartApp(InterfaceRequest<Application> application_request,
56 const ChildController::StartAppCallback& on_app_complete);
57 void ExitNow(int32_t exit_code);
59 protected:
60 // virtual for testing.
61 virtual void DidStart(bool success);
63 private:
64 bool DoLaunch();
66 void AppCompleted(int32_t result);
68 // Callback for |embedder::CreateChannel()|.
69 void DidCreateChannel(embedder::ChannelInfo* channel_info);
71 Context* const context_;
72 bool start_sandboxed_;
73 const base::FilePath app_path_;
74 base::Process child_process_;
75 embedder::PlatformChannelPair platform_channel_pair_;
76 ChildControllerPtr controller_;
77 embedder::ChannelInfo* channel_info_;
78 ChildController::StartAppCallback on_app_complete_;
80 // Platform-specific "pipe" to the child process. Valid immediately after
81 // creation.
82 embedder::ScopedPlatformHandle platform_channel_;
84 DISALLOW_COPY_AND_ASSIGN(ChildProcessHost);
87 } // namespace runner
88 } // namespace mojo
90 #endif // MOJO_RUNNER_CHILD_PROCESS_HOST_H_