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_RENDERER_HOST_BROWSER_RENDER_PROCESS_HOST_H_ | 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_BROWSER_RENDER_PROCESS_HOST_IMPL_H_ |
6 #define CONTENT_BROWSER_RENDERER_HOST_BROWSER_RENDER_PROCESS_HOST_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" | 15 #include "base/synchronization/waitable_event_watcher.h" |
16 #include "base/timer.h" | 16 #include "base/timer.h" |
17 #include "content/browser/child_process_launcher.h" | 17 #include "content/browser/child_process_launcher.h" |
18 #include "content/common/content_export.h" | 18 #include "content/common/content_export.h" |
19 #include "content/browser/renderer_host/render_process_host.h" | 19 #include "content/public/browser/render_process_host.h" |
| 20 #include "ipc/ipc_channel_proxy.h" |
20 #include "ui/gfx/surface/transport_dib.h" | 21 #include "ui/gfx/surface/transport_dib.h" |
21 | 22 |
22 class CommandLine; | 23 class CommandLine; |
23 class RendererMainThread; | 24 class RendererMainThread; |
24 class RenderWidgetHelper; | 25 class RenderWidgetHelper; |
25 | 26 |
26 namespace base { | 27 namespace base { |
27 class WaitableEvent; | 28 class WaitableEvent; |
28 } | 29 } |
29 | 30 |
30 // Implements a concrete RenderProcessHost for the browser process for talking | 31 // Implements a concrete RenderProcessHost for the browser process for talking |
31 // to actual renderer processes (as opposed to mocks). | 32 // to actual renderer processes (as opposed to mocks). |
32 // | 33 // |
33 // Represents the browser side of the browser <--> renderer communication | 34 // Represents the browser side of the browser <--> renderer communication |
34 // channel. There will be one RenderProcessHost per renderer process. | 35 // channel. There will be one RenderProcessHost per renderer process. |
35 // | 36 // |
36 // 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 |
37 // hosts using it go away. | 38 // hosts using it go away. |
38 // | 39 // |
39 // This object communicates back and forth with the RenderProcess object | 40 // This object communicates back and forth with the RenderProcess object |
40 // running in the renderer process. Each RenderProcessHost and RenderProcess | 41 // running in the renderer process. Each RenderProcessHost and RenderProcess |
41 // keeps a list of RenderView (renderer) and TabContents (browser) which | 42 // keeps a list of RenderView (renderer) and TabContents (browser) which |
42 // 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 |
43 // communicate through the two process objects. | 44 // communicate through the two process objects. |
44 class CONTENT_EXPORT BrowserRenderProcessHost | 45 class CONTENT_EXPORT RenderProcessHostImpl |
45 : public RenderProcessHost, | 46 : public content::RenderProcessHost, |
46 public ChildProcessLauncher::Client, | 47 public ChildProcessLauncher::Client, |
47 public base::WaitableEventWatcher::Delegate { | 48 public base::WaitableEventWatcher::Delegate { |
48 public: | 49 public: |
49 explicit BrowserRenderProcessHost(content::BrowserContext* browser_context); | 50 explicit RenderProcessHostImpl(content::BrowserContext* browser_context); |
50 virtual ~BrowserRenderProcessHost(); | 51 virtual ~RenderProcessHostImpl(); |
51 | 52 |
52 // RenderProcessHost implementation (public portion). | 53 // RenderProcessHost implementation (public portion). |
53 virtual void EnableSendQueue(); | 54 virtual void EnableSendQueue() OVERRIDE; |
54 virtual bool Init(bool is_accessibility_enabled); | 55 virtual bool Init(bool is_accessibility_enabled) OVERRIDE; |
55 virtual int GetNextRoutingID(); | 56 virtual int GetNextRoutingID() OVERRIDE; |
56 virtual void CancelResourceRequests(int render_widget_id); | 57 virtual void CancelResourceRequests(int render_widget_id) OVERRIDE; |
57 virtual void CrossSiteSwapOutACK(const ViewMsg_SwapOut_Params& params); | 58 virtual void CrossSiteSwapOutACK(const ViewMsg_SwapOut_Params& params) |
| 59 OVERRIDE; |
58 virtual bool WaitForUpdateMsg(int render_widget_id, | 60 virtual bool WaitForUpdateMsg(int render_widget_id, |
59 const base::TimeDelta& max_delay, | 61 const base::TimeDelta& max_delay, |
60 IPC::Message* msg); | 62 IPC::Message* msg) OVERRIDE; |
61 virtual void ReceivedBadMessage(); | 63 virtual void ReceivedBadMessage() OVERRIDE; |
62 virtual void WidgetRestored(); | 64 virtual void WidgetRestored() OVERRIDE; |
63 virtual void WidgetHidden(); | 65 virtual void WidgetHidden() OVERRIDE; |
64 virtual int VisibleWidgetCount() const; | 66 virtual int VisibleWidgetCount() const OVERRIDE; |
65 virtual bool FastShutdownIfPossible(); | 67 virtual bool FastShutdownIfPossible() OVERRIDE; |
66 virtual void DumpHandles(); | 68 virtual void DumpHandles() OVERRIDE; |
67 virtual base::ProcessHandle GetHandle(); | 69 virtual base::ProcessHandle GetHandle() OVERRIDE; |
68 virtual TransportDIB* GetTransportDIB(TransportDIB::Id dib_id); | 70 virtual TransportDIB* GetTransportDIB(TransportDIB::Id dib_id) OVERRIDE; |
69 virtual void SetCompositingSurface( | 71 virtual void SetCompositingSurface( |
70 int render_widget_id, | 72 int render_widget_id, |
71 gfx::PluginWindowHandle compositing_surface); | 73 gfx::PluginWindowHandle compositing_surface) OVERRIDE; |
| 74 virtual content::BrowserContext* GetBrowserContext() const OVERRIDE; |
| 75 virtual int GetID() const OVERRIDE; |
| 76 virtual bool HasConnection() const OVERRIDE; |
| 77 virtual void UpdateMaxPageID(int32 page_id) OVERRIDE; |
| 78 virtual IPC::Channel::Listener* GetListenerByID(int routing_id) OVERRIDE; |
| 79 virtual void SetIgnoreInputEvents(bool ignore_input_events) OVERRIDE; |
| 80 virtual bool IgnoreInputEvents() const OVERRIDE; |
| 81 virtual void Attach(IPC::Channel::Listener* listener, int routing_id) |
| 82 OVERRIDE; |
| 83 virtual void Release(int listener_id) OVERRIDE; |
| 84 virtual void Cleanup() OVERRIDE; |
| 85 virtual void ReportExpectingClose(int32 listener_id) OVERRIDE; |
| 86 virtual void AddPendingView() OVERRIDE; |
| 87 virtual void RemovePendingView() OVERRIDE; |
| 88 virtual void SetSuddenTerminationAllowed(bool enabled) OVERRIDE; |
| 89 virtual bool SuddenTerminationAllowed() const OVERRIDE; |
| 90 virtual IPC::ChannelProxy* GetChannel() OVERRIDE; |
| 91 virtual listeners_iterator ListenersIterator() OVERRIDE; |
| 92 virtual bool FastShutdownForPageCount(size_t count) OVERRIDE; |
| 93 virtual bool FastShutdownStarted() const OVERRIDE; |
| 94 virtual base::TimeDelta GetChildProcessIdleTime() const OVERRIDE; |
| 95 virtual void UpdateAndSendMaxPageID(int32 page_id) OVERRIDE; |
72 | 96 |
73 // IPC::Channel::Sender via RenderProcessHost. | 97 // IPC::Channel::Sender via RenderProcessHost. |
74 virtual bool Send(IPC::Message* msg); | 98 virtual bool Send(IPC::Message* msg) OVERRIDE; |
75 | 99 |
76 // IPC::Channel::Listener via RenderProcessHost. | 100 // IPC::Channel::Listener via RenderProcessHost. |
77 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; | 101 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; |
78 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; | 102 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; |
79 virtual void OnChannelError() OVERRIDE; | 103 virtual void OnChannelError() OVERRIDE; |
80 | 104 |
81 // ChildProcessLauncher::Client implementation. | 105 // ChildProcessLauncher::Client implementation. |
82 virtual void OnProcessLaunched(); | 106 virtual void OnProcessLaunched() OVERRIDE; |
83 | 107 |
84 // base::WaitableEventWatcher::Delegate implementation. | 108 // base::WaitableEventWatcher::Delegate implementation. |
85 virtual void OnWaitableEventSignaled( | 109 virtual void OnWaitableEventSignaled( |
86 base::WaitableEvent* waitable_event) OVERRIDE; | 110 base::WaitableEvent* waitable_event) OVERRIDE; |
87 | 111 |
| 112 // Call this function when it is evident that the child process is actively |
| 113 // performing some operation, for example if we just received an IPC message. |
| 114 void mark_child_process_activity_time() { |
| 115 child_process_activity_time_ = base::TimeTicks::Now(); |
| 116 } |
| 117 |
| 118 protected: |
| 119 // A proxy for our IPC::Channel that lives on the IO thread (see |
| 120 // browser_process.h) |
| 121 scoped_ptr<IPC::ChannelProxy> channel_; |
| 122 |
| 123 // The registered listeners. When this list is empty or all NULL, we should |
| 124 // delete ourselves |
| 125 IDMap<IPC::Channel::Listener> listeners_; |
| 126 |
| 127 // The maximum page ID we've ever seen from the renderer process. |
| 128 int32 max_page_id_; |
| 129 |
| 130 // True if fast shutdown has been performed on this RPH. |
| 131 bool fast_shutdown_started_; |
| 132 |
| 133 // True if we've posted a DeleteTask and will be deleted soon. |
| 134 bool deleting_soon_; |
| 135 |
| 136 // The count of currently swapped out but pending RenderViews. We have |
| 137 // started to swap these in, so the renderer process should not exit if |
| 138 // this count is non-zero. |
| 139 int32 pending_views_; |
| 140 |
88 private: | 141 private: |
89 friend class VisitRelayingRenderProcessHost; | 142 friend class VisitRelayingRenderProcessHost; |
90 | 143 |
91 // Creates and adds the IO thread message filters. | 144 // Creates and adds the IO thread message filters. |
92 void CreateMessageFilters(); | 145 void CreateMessageFilters(); |
93 | 146 |
94 // Control message handlers. | 147 // Control message handlers. |
95 void OnShutdownRequest(); | 148 void OnShutdownRequest(); |
96 void OnDumpHandlesDone(); | 149 void OnDumpHandlesDone(); |
97 void SuddenTerminationChanged(bool enabled); | 150 void SuddenTerminationChanged(bool enabled); |
(...skipping 28 matching lines...) Expand all Loading... |
126 | 179 |
127 // Does this process have backgrounded priority. | 180 // Does this process have backgrounded priority. |
128 bool backgrounded_; | 181 bool backgrounded_; |
129 | 182 |
130 // Used to allow a RenderWidgetHost to intercept various messages on the | 183 // Used to allow a RenderWidgetHost to intercept various messages on the |
131 // IO thread. | 184 // IO thread. |
132 scoped_refptr<RenderWidgetHelper> widget_helper_; | 185 scoped_refptr<RenderWidgetHelper> widget_helper_; |
133 | 186 |
134 // A map of transport DIB ids to cached TransportDIBs | 187 // A map of transport DIB ids to cached TransportDIBs |
135 std::map<TransportDIB::Id, TransportDIB*> cached_dibs_; | 188 std::map<TransportDIB::Id, TransportDIB*> cached_dibs_; |
| 189 |
136 enum { | 190 enum { |
137 // This is the maximum size of |cached_dibs_| | 191 // This is the maximum size of |cached_dibs_| |
138 MAX_MAPPED_TRANSPORT_DIBS = 3, | 192 MAX_MAPPED_TRANSPORT_DIBS = 3, |
139 }; | 193 }; |
140 | 194 |
141 // Map a transport DIB from its Id and return it. Returns NULL on error. | 195 // Map a transport DIB from its Id and return it. Returns NULL on error. |
142 TransportDIB* MapTransportDIB(TransportDIB::Id dib_id); | 196 TransportDIB* MapTransportDIB(TransportDIB::Id dib_id); |
143 | 197 |
144 void ClearTransportDIBCache(); | 198 void ClearTransportDIBCache(); |
145 // This is used to clear our cache five seconds after the last use. | 199 // This is used to clear our cache five seconds after the last use. |
146 base::DelayTimer<BrowserRenderProcessHost> cached_dibs_cleaner_; | 200 base::DelayTimer<RenderProcessHostImpl> cached_dibs_cleaner_; |
147 | 201 |
148 // Used in single-process mode. | 202 // Used in single-process mode. |
149 scoped_ptr<RendererMainThread> in_process_renderer_; | 203 scoped_ptr<RendererMainThread> in_process_renderer_; |
150 | 204 |
151 // True if this prcoess should have accessibility enabled; | 205 // True if this prcoess should have accessibility enabled; |
152 bool accessibility_enabled_; | 206 bool accessibility_enabled_; |
153 | 207 |
154 // True after Init() has been called. We can't just check channel_ because we | 208 // True after Init() has been called. We can't just check channel_ because we |
155 // also reset that in the case of process termination. | 209 // also reset that in the case of process termination. |
156 bool is_initialized_; | 210 bool is_initialized_; |
157 | 211 |
158 // Used to launch and terminate the process without blocking the UI thread. | 212 // Used to launch and terminate the process without blocking the UI thread. |
159 scoped_ptr<ChildProcessLauncher> child_process_launcher_; | 213 scoped_ptr<ChildProcessLauncher> child_process_launcher_; |
160 | 214 |
161 // Messages we queue while waiting for the process handle. We queue them here | 215 // Messages we queue while waiting for the process handle. We queue them here |
162 // instead of in the channel so that we ensure they're sent after init related | 216 // instead of in the channel so that we ensure they're sent after init related |
163 // messages that are sent once the process handle is available. This is | 217 // messages that are sent once the process handle is available. This is |
164 // because the queued messages may have dependencies on the init messages. | 218 // because the queued messages may have dependencies on the init messages. |
165 std::queue<IPC::Message*> queued_messages_; | 219 std::queue<IPC::Message*> queued_messages_; |
166 | 220 |
167 #if defined(OS_WIN) | 221 #if defined(OS_WIN) |
168 // Used to wait until the renderer dies to get an accurrate exit code. | 222 // Used to wait until the renderer dies to get an accurrate exit code. |
169 base::WaitableEventWatcher child_process_watcher_; | 223 base::WaitableEventWatcher child_process_watcher_; |
170 #endif | 224 #endif |
171 | 225 |
172 DISALLOW_COPY_AND_ASSIGN(BrowserRenderProcessHost); | 226 // The globally-unique identifier for this RPH. |
| 227 int id_; |
| 228 |
| 229 content::BrowserContext* browser_context_; |
| 230 |
| 231 // set of listeners that expect the renderer process to close |
| 232 std::set<int> listeners_expecting_close_; |
| 233 |
| 234 // True if the process can be shut down suddenly. If this is true, then we're |
| 235 // sure that all the RenderViews in the process can be shutdown suddenly. If |
| 236 // it's false, then specific RenderViews might still be allowed to be shutdown |
| 237 // suddenly by checking their SuddenTerminationAllowed() flag. This can occur |
| 238 // if one tab has an unload event listener but another tab in the same process |
| 239 // doesn't. |
| 240 bool sudden_termination_allowed_; |
| 241 |
| 242 // Set to true if we shouldn't send input events. We actually do the |
| 243 // filtering for this at the render widget level. |
| 244 bool ignore_input_events_; |
| 245 |
| 246 // Records the last time we regarded the child process active. |
| 247 base::TimeTicks child_process_activity_time_; |
| 248 |
| 249 DISALLOW_COPY_AND_ASSIGN(RenderProcessHostImpl); |
173 }; | 250 }; |
174 | 251 |
175 #endif // CONTENT_BROWSER_RENDERER_HOST_BROWSER_RENDER_PROCESS_HOST_H_ | 252 #endif // CONTENT_BROWSER_RENDERER_HOST_BROWSER_RENDER_PROCESS_HOST_IMPL_H_ |
OLD | NEW |