OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef SHELL_CHILD_PROCESS_HOST_H_ | 5 #ifndef SHELL_CHILD_PROCESS_HOST_H_ |
6 #define SHELL_CHILD_PROCESS_HOST_H_ | 6 #define SHELL_CHILD_PROCESS_HOST_H_ |
7 | 7 |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/process/process.h" | 9 #include "base/process/process.h" |
10 #include "mojo/edk/embedder/platform_channel_pair.h" | 10 #include "mojo/edk/embedder/platform_channel_pair.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 // | 26 // |
27 // Note: Does not currently work on Windows before Vista. | 27 // Note: Does not currently work on Windows before Vista. |
28 class ChildProcessHost { | 28 class ChildProcessHost { |
29 public: | 29 public: |
30 class Delegate { | 30 class Delegate { |
31 public: | 31 public: |
32 virtual void WillStart() = 0; | 32 virtual void WillStart() = 0; |
33 virtual void DidStart(bool success) = 0; | 33 virtual void DidStart(bool success) = 0; |
34 }; | 34 }; |
35 | 35 |
36 ChildProcessHost(Context* context, | 36 ChildProcessHost(Context* context, Delegate* delegate); |
37 Delegate* delegate, | |
38 ChildProcess::Type type); | |
39 virtual ~ChildProcessHost(); | 37 virtual ~ChildProcessHost(); |
40 | 38 |
41 // |Start()|s the child process; calls the delegate's |DidStart()| (on the | 39 // |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 | 40 // 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 | 41 // failed to start). After calling |Start()|, this object must not be |
44 // destroyed until |DidStart()| has been called. | 42 // destroyed until |DidStart()| has been called. |
45 // TODO(vtl): Consider using weak pointers and removing this requirement. | 43 // TODO(vtl): Consider using weak pointers and removing this requirement. |
46 void Start(); | 44 void Start(); |
47 | 45 |
48 // Waits for the child process to terminate, and returns its exit code. | 46 // 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 | 47 // Note: If |Start()| has been called, this must not be called until the |
50 // callback has been called. | 48 // callback has been called. |
51 int Join(); | 49 int Join(); |
52 | 50 |
53 embedder::ScopedPlatformHandle* platform_channel() { | 51 embedder::ScopedPlatformHandle* platform_channel() { |
54 return &platform_channel_; | 52 return &platform_channel_; |
55 } | 53 } |
56 | 54 |
57 protected: | 55 protected: |
58 Context* context() const { return context_; } | 56 Context* context() const { return context_; } |
59 | 57 |
60 private: | 58 private: |
61 bool DoLaunch(); | 59 bool DoLaunch(); |
62 void DidLaunch(bool success); | 60 void DidLaunch(bool success); |
63 | 61 |
64 Context* const context_; | 62 Context* const context_; |
65 Delegate* const delegate_; | 63 Delegate* const delegate_; |
66 const ChildProcess::Type type_; | |
67 | 64 |
68 base::Process child_process_; | 65 base::Process child_process_; |
69 | 66 |
70 embedder::PlatformChannelPair platform_channel_pair_; | 67 embedder::PlatformChannelPair platform_channel_pair_; |
71 | 68 |
72 // Platform-specific "pipe" to the child process. Valid immediately after | 69 // Platform-specific "pipe" to the child process. Valid immediately after |
73 // creation. | 70 // creation. |
74 embedder::ScopedPlatformHandle platform_channel_; | 71 embedder::ScopedPlatformHandle platform_channel_; |
75 | 72 |
76 DISALLOW_COPY_AND_ASSIGN(ChildProcessHost); | 73 DISALLOW_COPY_AND_ASSIGN(ChildProcessHost); |
77 }; | 74 }; |
78 | 75 |
79 } // namespace shell | 76 } // namespace shell |
80 } // namespace mojo | 77 } // namespace mojo |
81 | 78 |
82 #endif // SHELL_CHILD_PROCESS_HOST_H_ | 79 #endif // SHELL_CHILD_PROCESS_HOST_H_ |
OLD | NEW |