OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_RENDERER_HOST_BROWSER_RENDER_PROCESS_HOST_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_BROWSER_RENDER_PROCESS_HOST_IMPL_H_ |
6 #define CONTENT_BROWSER_RENDERER_HOST_BROWSER_RENDER_PROCESS_HOST_IMPL_H_ | 6 #define CONTENT_BROWSER_RENDERER_HOST_BROWSER_RENDER_PROCESS_HOST_IMPL_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <queue> | 10 #include <queue> |
11 #include <string> | 11 #include <string> |
12 | 12 |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/process.h" | 14 #include "base/process.h" |
15 #include "base/synchronization/waitable_event_watcher.h" | |
16 #include "base/timer.h" | 15 #include "base/timer.h" |
17 #include "content/browser/child_process_launcher.h" | 16 #include "content/browser/child_process_launcher.h" |
18 #include "content/common/content_export.h" | 17 #include "content/common/content_export.h" |
19 #include "content/public/browser/render_process_host.h" | 18 #include "content/public/browser/render_process_host.h" |
20 #include "ipc/ipc_channel_proxy.h" | 19 #include "ipc/ipc_channel_proxy.h" |
21 #include "ui/surface/transport_dib.h" | 20 #include "ui/surface/transport_dib.h" |
22 | 21 |
23 class CommandLine; | 22 class CommandLine; |
24 class GpuMessageFilter; | 23 class GpuMessageFilter; |
25 class RenderWidgetHelper; | 24 class RenderWidgetHelper; |
26 | 25 |
27 namespace base { | |
28 class WaitableEvent; | |
29 } | |
30 | |
31 namespace content { | 26 namespace content { |
32 class RendererMainThread; | 27 class RendererMainThread; |
33 class RenderWidgetHost; | 28 class RenderWidgetHost; |
34 class RenderWidgetHostImpl; | 29 class RenderWidgetHostImpl; |
35 | 30 |
36 // Implements a concrete RenderProcessHost for the browser process for talking | 31 // Implements a concrete RenderProcessHost for the browser process for talking |
37 // to actual renderer processes (as opposed to mocks). | 32 // to actual renderer processes (as opposed to mocks). |
38 // | 33 // |
39 // Represents the browser side of the browser <--> renderer communication | 34 // Represents the browser side of the browser <--> renderer communication |
40 // channel. There will be one RenderProcessHost per renderer process. | 35 // channel. There will be one RenderProcessHost per renderer process. |
41 // | 36 // |
42 // This object is refcounted so that it can release its resources when all | 37 // This object is refcounted so that it can release its resources when all |
43 // hosts using it go away. | 38 // hosts using it go away. |
44 // | 39 // |
45 // This object communicates back and forth with the RenderProcess object | 40 // This object communicates back and forth with the RenderProcess object |
46 // running in the renderer process. Each RenderProcessHost and RenderProcess | 41 // running in the renderer process. Each RenderProcessHost and RenderProcess |
47 // keeps a list of RenderView (renderer) and WebContentsImpl (browser) which | 42 // keeps a list of RenderView (renderer) and WebContentsImpl (browser) which |
48 // are correlated with IDs. This way, the Views and the corresponding ViewHosts | 43 // are correlated with IDs. This way, the Views and the corresponding ViewHosts |
49 // communicate through the two process objects. | 44 // communicate through the two process objects. |
50 class CONTENT_EXPORT RenderProcessHostImpl | 45 class CONTENT_EXPORT RenderProcessHostImpl |
51 : public RenderProcessHost, | 46 : public RenderProcessHost, |
52 public ChildProcessLauncher::Client, | 47 public ChildProcessLauncher::Client { |
53 public base::WaitableEventWatcher::Delegate { | |
54 public: | 48 public: |
55 RenderProcessHostImpl(BrowserContext* browser_context, bool is_guest); | 49 RenderProcessHostImpl(BrowserContext* browser_context, bool is_guest); |
56 virtual ~RenderProcessHostImpl(); | 50 virtual ~RenderProcessHostImpl(); |
57 | 51 |
58 // RenderProcessHost implementation (public portion). | 52 // RenderProcessHost implementation (public portion). |
59 virtual void EnableSendQueue() OVERRIDE; | 53 virtual void EnableSendQueue() OVERRIDE; |
60 virtual bool Init() OVERRIDE; | 54 virtual bool Init() OVERRIDE; |
61 virtual int GetNextRoutingID() OVERRIDE; | 55 virtual int GetNextRoutingID() OVERRIDE; |
62 virtual void CancelResourceRequests(int render_widget_id) OVERRIDE; | 56 virtual void CancelResourceRequests(int render_widget_id) OVERRIDE; |
63 virtual void CrossSiteSwapOutACK(const ViewMsg_SwapOut_Params& params) | 57 virtual void CrossSiteSwapOutACK(const ViewMsg_SwapOut_Params& params) |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 virtual bool Send(IPC::Message* msg) OVERRIDE; | 94 virtual bool Send(IPC::Message* msg) OVERRIDE; |
101 | 95 |
102 // IPC::Listener via RenderProcessHost. | 96 // IPC::Listener via RenderProcessHost. |
103 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; | 97 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; |
104 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; | 98 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; |
105 virtual void OnChannelError() OVERRIDE; | 99 virtual void OnChannelError() OVERRIDE; |
106 | 100 |
107 // ChildProcessLauncher::Client implementation. | 101 // ChildProcessLauncher::Client implementation. |
108 virtual void OnProcessLaunched() OVERRIDE; | 102 virtual void OnProcessLaunched() OVERRIDE; |
109 | 103 |
110 // base::WaitableEventWatcher::Delegate implementation. | |
111 virtual void OnWaitableEventSignaled( | |
112 base::WaitableEvent* waitable_event) OVERRIDE; | |
113 | |
114 // Call this function when it is evident that the child process is actively | 104 // Call this function when it is evident that the child process is actively |
115 // performing some operation, for example if we just received an IPC message. | 105 // performing some operation, for example if we just received an IPC message. |
116 void mark_child_process_activity_time() { | 106 void mark_child_process_activity_time() { |
117 child_process_activity_time_ = base::TimeTicks::Now(); | 107 child_process_activity_time_ = base::TimeTicks::Now(); |
118 } | 108 } |
119 | 109 |
120 // Returns the current number of active views in this process. Excludes | 110 // Returns the current number of active views in this process. Excludes |
121 // any RenderViewHosts that are swapped out. | 111 // any RenderViewHosts that are swapped out. |
122 int GetActiveViewCount(); | 112 int GetActiveViewCount(); |
123 | 113 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 | 193 |
204 // Copies applicable command line switches from the given |browser_cmd| line | 194 // Copies applicable command line switches from the given |browser_cmd| line |
205 // flags to the output |renderer_cmd| line flags. Not all switches will be | 195 // flags to the output |renderer_cmd| line flags. Not all switches will be |
206 // copied over. | 196 // copied over. |
207 void PropagateBrowserCommandLineToRenderer(const CommandLine& browser_cmd, | 197 void PropagateBrowserCommandLineToRenderer(const CommandLine& browser_cmd, |
208 CommandLine* renderer_cmd) const; | 198 CommandLine* renderer_cmd) const; |
209 | 199 |
210 // Callers can reduce the RenderProcess' priority. | 200 // Callers can reduce the RenderProcess' priority. |
211 void SetBackgrounded(bool backgrounded); | 201 void SetBackgrounded(bool backgrounded); |
212 | 202 |
213 // Handle termination of our process. |was_alive| indicates that when we | 203 // Handle termination of our process. |
214 // tried to retrieve the exit code the process had not finished yet. | 204 void ProcessDied(); |
215 void ProcessDied(base::ProcessHandle handle, | |
216 base::TerminationStatus status, | |
217 int exit_code, | |
218 bool was_alive); | |
219 | 205 |
220 // The count of currently visible widgets. Since the host can be a container | 206 // The count of currently visible widgets. Since the host can be a container |
221 // for multiple widgets, it uses this count to determine when it should be | 207 // for multiple widgets, it uses this count to determine when it should be |
222 // backgrounded. | 208 // backgrounded. |
223 int32 visible_widgets_; | 209 int32 visible_widgets_; |
224 | 210 |
225 // Does this process have backgrounded priority. | 211 // Does this process have backgrounded priority. |
226 bool backgrounded_; | 212 bool backgrounded_; |
227 | 213 |
228 // Used to allow a RenderWidgetHost to intercept various messages on the | 214 // Used to allow a RenderWidgetHost to intercept various messages on the |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 | 247 |
262 // Used to launch and terminate the process without blocking the UI thread. | 248 // Used to launch and terminate the process without blocking the UI thread. |
263 scoped_ptr<ChildProcessLauncher> child_process_launcher_; | 249 scoped_ptr<ChildProcessLauncher> child_process_launcher_; |
264 | 250 |
265 // Messages we queue while waiting for the process handle. We queue them here | 251 // Messages we queue while waiting for the process handle. We queue them here |
266 // instead of in the channel so that we ensure they're sent after init related | 252 // instead of in the channel so that we ensure they're sent after init related |
267 // messages that are sent once the process handle is available. This is | 253 // messages that are sent once the process handle is available. This is |
268 // because the queued messages may have dependencies on the init messages. | 254 // because the queued messages may have dependencies on the init messages. |
269 std::queue<IPC::Message*> queued_messages_; | 255 std::queue<IPC::Message*> queued_messages_; |
270 | 256 |
271 #if defined(OS_WIN) | |
272 // Used to wait until the renderer dies to get an accurrate exit code. | |
273 base::WaitableEventWatcher child_process_watcher_; | |
274 #endif | |
275 | |
276 // The globally-unique identifier for this RPH. | 257 // The globally-unique identifier for this RPH. |
277 int id_; | 258 int id_; |
278 | 259 |
279 BrowserContext* browser_context_; | 260 BrowserContext* browser_context_; |
280 | 261 |
281 // True if the process can be shut down suddenly. If this is true, then we're | 262 // True if the process can be shut down suddenly. If this is true, then we're |
282 // sure that all the RenderViews in the process can be shutdown suddenly. If | 263 // sure that all the RenderViews in the process can be shutdown suddenly. If |
283 // it's false, then specific RenderViews might still be allowed to be shutdown | 264 // it's false, then specific RenderViews might still be allowed to be shutdown |
284 // suddenly by checking their SuddenTerminationAllowed() flag. This can occur | 265 // suddenly by checking their SuddenTerminationAllowed() flag. This can occur |
285 // if one WebContents has an unload event listener but another WebContents in | 266 // if one WebContents has an unload event listener but another WebContents in |
(...skipping 10 matching lines...) Expand all Loading... |
296 // Indicates whether this is a RenderProcessHost of a Browser Plugin guest | 277 // Indicates whether this is a RenderProcessHost of a Browser Plugin guest |
297 // renderer. | 278 // renderer. |
298 bool is_guest_; | 279 bool is_guest_; |
299 | 280 |
300 DISALLOW_COPY_AND_ASSIGN(RenderProcessHostImpl); | 281 DISALLOW_COPY_AND_ASSIGN(RenderProcessHostImpl); |
301 }; | 282 }; |
302 | 283 |
303 } // namespace content | 284 } // namespace content |
304 | 285 |
305 #endif // CONTENT_BROWSER_RENDERER_HOST_BROWSER_RENDER_PROCESS_HOST_IMPL_H_ | 286 #endif // CONTENT_BROWSER_RENDERER_HOST_BROWSER_RENDER_PROCESS_HOST_IMPL_H_ |
OLD | NEW |