OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 CONTENT_BROWSER_BROWSER_CHILD_PROCESS_HOST_H_ | 5 #ifndef CONTENT_BROWSER_BROWSER_CHILD_PROCESS_HOST_H_ |
6 #define CONTENT_BROWSER_BROWSER_CHILD_PROCESS_HOST_H_ | 6 #define CONTENT_BROWSER_BROWSER_CHILD_PROCESS_HOST_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <list> | 9 #include <list> |
10 | 10 |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "base/process.h" | 13 #include "base/process.h" |
14 #include "base/synchronization/waitable_event_watcher.h" | 14 #include "base/synchronization/waitable_event_watcher.h" |
15 #include "content/browser/child_process_launcher.h" | 15 #include "content/browser/child_process_launcher.h" |
16 #include "content/common/content_export.h" | 16 #include "content/common/content_export.h" |
17 #include "content/public/browser/child_process_data.h" | 17 #include "content/public/browser/child_process_data.h" |
18 #include "content/public/common/child_process_host_delegate.h" | 18 #include "content/public/common/child_process_host_delegate.h" |
19 #include "ipc/ipc_message.h" | 19 #include "ipc/ipc_message.h" |
20 | 20 |
21 class ChildProcessHost; | |
22 | |
23 namespace base { | 21 namespace base { |
24 class WaitableEvent; | 22 class WaitableEvent; |
25 } | 23 } |
26 | 24 |
| 25 namespace content { |
| 26 class ChildProcessHost; |
| 27 } |
| 28 |
27 // Plugins/workers and other child processes that live on the IO thread should | 29 // Plugins/workers and other child processes that live on the IO thread should |
28 // derive from this class. | 30 // derive from this class. |
29 // | 31 // |
30 // [Browser]RenderProcessHost is the main exception that doesn't derive from | 32 // [Browser]RenderProcessHost is the main exception that doesn't derive from |
31 // this class. That project lives on the UI thread. | 33 // this class. That project lives on the UI thread. |
32 class CONTENT_EXPORT BrowserChildProcessHost : | 34 class CONTENT_EXPORT BrowserChildProcessHost : |
33 public content::ChildProcessHostDelegate, | 35 public content::ChildProcessHostDelegate, |
34 public ChildProcessLauncher::Client, | 36 public ChildProcessLauncher::Client, |
35 public base::WaitableEventWatcher::Delegate, | 37 public base::WaitableEventWatcher::Delegate, |
36 public IPC::Message::Sender { | 38 public IPC::Message::Sender { |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 // Removes this host from the host list. Calls ChildProcessHost::ForceShutdown | 122 // Removes this host from the host list. Calls ChildProcessHost::ForceShutdown |
121 void ForceShutdown(); | 123 void ForceShutdown(); |
122 | 124 |
123 // Controls whether the child process should be terminated on browser | 125 // Controls whether the child process should be terminated on browser |
124 // shutdown. Default is to always terminate. | 126 // shutdown. Default is to always terminate. |
125 void SetTerminateChildOnShutdown(bool terminate_on_shutdown); | 127 void SetTerminateChildOnShutdown(bool terminate_on_shutdown); |
126 | 128 |
127 // Sends the given notification on the UI thread. | 129 // Sends the given notification on the UI thread. |
128 void Notify(int type); | 130 void Notify(int type); |
129 | 131 |
130 ChildProcessHost* child_process_host() const { | 132 content::ChildProcessHost* child_process_host() const { |
131 return child_process_host_.get(); | 133 return child_process_host_.get(); |
132 } | 134 } |
133 void set_name(const string16& name) { data_.name = name; } | 135 void set_name(const string16& name) { data_.name = name; } |
134 void set_handle(base::ProcessHandle handle) { data_.handle = handle; } | 136 void set_handle(base::ProcessHandle handle) { data_.handle = handle; } |
135 | 137 |
136 private: | 138 private: |
137 // By using an internal class as the ChildProcessLauncher::Client, we can | 139 // By using an internal class as the ChildProcessLauncher::Client, we can |
138 // intercept OnProcessLaunched and do our own processing before | 140 // intercept OnProcessLaunched and do our own processing before |
139 // calling the subclass' implementation. | 141 // calling the subclass' implementation. |
140 class ClientHook : public ChildProcessLauncher::Client { | 142 class ClientHook : public ChildProcessLauncher::Client { |
141 public: | 143 public: |
142 explicit ClientHook(BrowserChildProcessHost* host); | 144 explicit ClientHook(BrowserChildProcessHost* host); |
143 virtual void OnProcessLaunched() OVERRIDE; | 145 virtual void OnProcessLaunched() OVERRIDE; |
144 private: | 146 private: |
145 BrowserChildProcessHost* host_; | 147 BrowserChildProcessHost* host_; |
146 }; | 148 }; |
147 | 149 |
148 content::ChildProcessData data_; | 150 content::ChildProcessData data_; |
149 scoped_ptr<ChildProcessHost> child_process_host_; | 151 scoped_ptr<content::ChildProcessHost> child_process_host_; |
150 | 152 |
151 ClientHook client_; | 153 ClientHook client_; |
152 scoped_ptr<ChildProcessLauncher> child_process_; | 154 scoped_ptr<ChildProcessLauncher> child_process_; |
153 #if defined(OS_WIN) | 155 #if defined(OS_WIN) |
154 base::WaitableEventWatcher child_watcher_; | 156 base::WaitableEventWatcher child_watcher_; |
155 #else | 157 #else |
156 base::WeakPtrFactory<BrowserChildProcessHost> task_factory_; | 158 base::WeakPtrFactory<BrowserChildProcessHost> task_factory_; |
157 #endif | 159 #endif |
158 bool disconnect_was_alive_; | 160 bool disconnect_was_alive_; |
159 }; | 161 }; |
160 | 162 |
161 #endif // CONTENT_BROWSER_BROWSER_CHILD_PROCESS_HOST_H_ | 163 #endif // CONTENT_BROWSER_BROWSER_CHILD_PROCESS_HOST_H_ |
OLD | NEW |