Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(248)

Side by Side Diff: content/browser/renderer_host/render_process_host_impl.h

Issue 8515027: Define the public version of the browser side RenderProcessHost interface. This interface is not ... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_H_
jam 2011/11/16 22:10:19 nit: ifdef guard
ananta 2011/11/17 13:34:45 Done.
6 #define CONTENT_BROWSER_RENDERER_HOST_BROWSER_RENDER_PROCESS_HOST_H_ 6 #define CONTENT_BROWSER_RENDERER_HOST_BROWSER_RENDER_PROCESS_HOST_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 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 // Returns the user browser context associated with this renderer process.
jam 2011/11/16 22:10:19 nit: don't duplicate comment from interface
ananta 2011/11/17 13:34:45 Done.
75 virtual content::BrowserContext* GetBrowserContext() const OVERRIDE;
76 virtual int GetID() const OVERRIDE;
77 virtual bool HasConnection() const OVERRIDE;
78 virtual void UpdateMaxPageID(int32 page_id) OVERRIDE;
79 virtual IPC::Channel::Listener* GetListenerByID(int routing_id) OVERRIDE;
80 virtual void SetIgnoreInputEvents(bool ignore_input_events) OVERRIDE;
81 virtual bool IgnoreInputEvents() const OVERRIDE;
82 virtual void Attach(IPC::Channel::Listener* listener, int routing_id)
83 OVERRIDE;
84 virtual void Release(int listener_id) OVERRIDE;
85 virtual void Cleanup() OVERRIDE;
86 virtual void ReportExpectingClose(int32 listener_id) OVERRIDE;
87 virtual void AddPendingView() OVERRIDE;
88 virtual void RemovePendingView() OVERRIDE;
89 virtual void SetSuddenTerminationAllowed(bool enabled) OVERRIDE;
90 virtual bool SuddenTerminationAllowed() const OVERRIDE;
91 virtual IPC::ChannelProxy* GetChannel() OVERRIDE;
92 virtual listeners_iterator ListenersIterator() OVERRIDE;
93 // Try to shutdown the associated render process as fast as possible, but
jam 2011/11/16 22:10:19 nit: ditto
ananta 2011/11/17 13:34:45 Done.
94 // only if |count| matches the number of render widgets that this process
95 // controls.
96 virtual bool FastShutdownForPageCount(size_t count) OVERRIDE;
97
jam 2011/11/16 22:10:19 nit: extra line
ananta 2011/11/17 13:34:45 Done.
98 virtual bool FastShutdownStarted() const OVERRIDE;
72 99
73 // IPC::Channel::Sender via RenderProcessHost. 100 // IPC::Channel::Sender via RenderProcessHost.
74 virtual bool Send(IPC::Message* msg); 101 virtual bool Send(IPC::Message* msg) OVERRIDE;
75 102
76 // IPC::Channel::Listener via RenderProcessHost. 103 // IPC::Channel::Listener via RenderProcessHost.
77 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; 104 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
78 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; 105 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE;
79 virtual void OnChannelError() OVERRIDE; 106 virtual void OnChannelError() OVERRIDE;
80 107
81 // ChildProcessLauncher::Client implementation. 108 // ChildProcessLauncher::Client implementation.
82 virtual void OnProcessLaunched(); 109 virtual void OnProcessLaunched() OVERRIDE;
83 110
84 // base::WaitableEventWatcher::Delegate implementation. 111 // base::WaitableEventWatcher::Delegate implementation.
85 virtual void OnWaitableEventSignaled( 112 virtual void OnWaitableEventSignaled(
86 base::WaitableEvent* waitable_event) OVERRIDE; 113 base::WaitableEvent* waitable_event) OVERRIDE;
87 114
115 // Returns how long the child has been idle. The definition of idle
116 // depends on when a derived class calls mark_child_process_activity_time().
117 // This is a rough indicator and its resolution should not be better than
118 // 10 milliseconds.
119 base::TimeDelta get_child_process_idle_time() const {
120 return base::TimeTicks::Now() - child_process_activity_time_;
121 }
122
123 // Call this function when it is evident that the child process is actively
124 // performing some operation, for example if we just received an IPC message.
125 void mark_child_process_activity_time() {
126 child_process_activity_time_ = base::TimeTicks::Now();
127 }
128
129 protected:
130 // A proxy for our IPC::Channel that lives on the IO thread (see
131 // browser_process.h)
132 scoped_ptr<IPC::ChannelProxy> channel_;
133
134 // The registered listeners. When this list is empty or all NULL, we should
135 // delete ourselves
136 IDMap<IPC::Channel::Listener> listeners_;
137
138 // The maximum page ID we've ever seen from the renderer process.
139 int32 max_page_id_;
140
141 // True if fast shutdown has been performed on this RPH.
142 bool fast_shutdown_started_;
143
144 // True if we've posted a DeleteTask and will be deleted soon.
145 bool deleting_soon_;
146
147 // The count of currently swapped out but pending RenderViews. We have
148 // started to swap these in, so the renderer process should not exit if
149 // this count is non-zero.
150 int32 pending_views_;
151
88 private: 152 private:
89 friend class VisitRelayingRenderProcessHost; 153 friend class VisitRelayingRenderProcessHost;
90 154
91 // Creates and adds the IO thread message filters. 155 // Creates and adds the IO thread message filters.
92 void CreateMessageFilters(); 156 void CreateMessageFilters();
93 157
94 // Control message handlers. 158 // Control message handlers.
95 void OnShutdownRequest(); 159 void OnShutdownRequest();
96 void OnDumpHandlesDone(); 160 void OnDumpHandlesDone();
97 void SuddenTerminationChanged(bool enabled); 161 void SuddenTerminationChanged(bool enabled);
(...skipping 28 matching lines...) Expand all
126 190
127 // Does this process have backgrounded priority. 191 // Does this process have backgrounded priority.
128 bool backgrounded_; 192 bool backgrounded_;
129 193
130 // Used to allow a RenderWidgetHost to intercept various messages on the 194 // Used to allow a RenderWidgetHost to intercept various messages on the
131 // IO thread. 195 // IO thread.
132 scoped_refptr<RenderWidgetHelper> widget_helper_; 196 scoped_refptr<RenderWidgetHelper> widget_helper_;
133 197
134 // A map of transport DIB ids to cached TransportDIBs 198 // A map of transport DIB ids to cached TransportDIBs
135 std::map<TransportDIB::Id, TransportDIB*> cached_dibs_; 199 std::map<TransportDIB::Id, TransportDIB*> cached_dibs_;
200
136 enum { 201 enum {
137 // This is the maximum size of |cached_dibs_| 202 // This is the maximum size of |cached_dibs_|
138 MAX_MAPPED_TRANSPORT_DIBS = 3, 203 MAX_MAPPED_TRANSPORT_DIBS = 3,
139 }; 204 };
140 205
141 // Map a transport DIB from its Id and return it. Returns NULL on error. 206 // Map a transport DIB from its Id and return it. Returns NULL on error.
142 TransportDIB* MapTransportDIB(TransportDIB::Id dib_id); 207 TransportDIB* MapTransportDIB(TransportDIB::Id dib_id);
143 208
144 void ClearTransportDIBCache(); 209 void ClearTransportDIBCache();
145 // This is used to clear our cache five seconds after the last use. 210 // This is used to clear our cache five seconds after the last use.
146 base::DelayTimer<BrowserRenderProcessHost> cached_dibs_cleaner_; 211 base::DelayTimer<RenderProcessHostImpl> cached_dibs_cleaner_;
147 212
148 // Used in single-process mode. 213 // Used in single-process mode.
149 scoped_ptr<RendererMainThread> in_process_renderer_; 214 scoped_ptr<RendererMainThread> in_process_renderer_;
150 215
151 // True if this prcoess should have accessibility enabled; 216 // True if this prcoess should have accessibility enabled;
152 bool accessibility_enabled_; 217 bool accessibility_enabled_;
153 218
154 // True after Init() has been called. We can't just check channel_ because we 219 // True after Init() has been called. We can't just check channel_ because we
155 // also reset that in the case of process termination. 220 // also reset that in the case of process termination.
156 bool is_initialized_; 221 bool is_initialized_;
157 222
158 // Used to launch and terminate the process without blocking the UI thread. 223 // Used to launch and terminate the process without blocking the UI thread.
159 scoped_ptr<ChildProcessLauncher> child_process_launcher_; 224 scoped_ptr<ChildProcessLauncher> child_process_launcher_;
160 225
161 // Messages we queue while waiting for the process handle. We queue them here 226 // 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 227 // 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 228 // messages that are sent once the process handle is available. This is
164 // because the queued messages may have dependencies on the init messages. 229 // because the queued messages may have dependencies on the init messages.
165 std::queue<IPC::Message*> queued_messages_; 230 std::queue<IPC::Message*> queued_messages_;
166 231
167 #if defined(OS_WIN) 232 #if defined(OS_WIN)
168 // Used to wait until the renderer dies to get an accurrate exit code. 233 // Used to wait until the renderer dies to get an accurrate exit code.
169 base::WaitableEventWatcher child_process_watcher_; 234 base::WaitableEventWatcher child_process_watcher_;
170 #endif 235 #endif
171 236
172 DISALLOW_COPY_AND_ASSIGN(BrowserRenderProcessHost); 237 // The globally-unique identifier for this RPH.
238 int id_;
239
240 content::BrowserContext* browser_context_;
241
242 // set of listeners that expect the renderer process to close
243 std::set<int> listeners_expecting_close_;
244
245 // True if the process can be shut down suddenly. If this is true, then we're
246 // sure that all the RenderViews in the process can be shutdown suddenly. If
247 // it's false, then specific RenderViews might still be allowed to be shutdown
248 // suddenly by checking their SuddenTerminationAllowed() flag. This can occur
249 // if one tab has an unload event listener but another tab in the same process
250 // doesn't.
251 bool sudden_termination_allowed_;
252
253 // Set to true if we shouldn't send input events. We actually do the
254 // filtering for this at the render widget level.
255 bool ignore_input_events_;
256
257 // Records the last time we regarded the child process active.
258 base::TimeTicks child_process_activity_time_;
259
260 DISALLOW_COPY_AND_ASSIGN(RenderProcessHostImpl);
173 }; 261 };
174 262
175 #endif // CONTENT_BROWSER_RENDERER_HOST_BROWSER_RENDER_PROCESS_HOST_H_ 263 #endif // CONTENT_BROWSER_RENDERER_HOST_BROWSER_RENDER_PROCESS_HOST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698