OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CONTENT_PUBLIC_BROWSER_RENDER_PROCESS_HOST_H_ |
| 6 #define CONTENT_PUBLIC_BROWSER_RENDER_PROCESS_HOST_H_ |
| 7 |
| 8 #include "base/basictypes.h" |
| 9 #include "base/id_map.h" |
| 10 #include "base/process.h" |
| 11 #include "base/process_util.h" |
| 12 #include "content/common/content_export.h" |
| 13 #include "ipc/ipc_channel_proxy.h" |
| 14 #include "ipc/ipc_message.h" |
| 15 #include "ui/gfx/native_widget_types.h" |
| 16 #include "ui/gfx/surface/transport_dib.h" |
| 17 |
| 18 class GURL; |
| 19 struct ViewMsg_SwapOut_Params; |
| 20 |
| 21 namespace content { |
| 22 class BrowserContext; |
| 23 } |
| 24 |
| 25 namespace base { |
| 26 class TimeDelta; |
| 27 } |
| 28 |
| 29 namespace content { |
| 30 |
| 31 // Interface that represents the browser side of the browser <-> renderer |
| 32 // communication channel. There will generally be one RenderProcessHost per |
| 33 // renderer process. |
| 34 class CONTENT_EXPORT RenderProcessHost : public IPC::Message::Sender, |
| 35 public IPC::Channel::Listener { |
| 36 public: |
| 37 typedef IDMap<RenderProcessHost>::iterator iterator; |
| 38 typedef IDMap<IPC::Channel::Listener>::const_iterator listeners_iterator; |
| 39 |
| 40 // Details for RENDERER_PROCESS_CLOSED notifications. |
| 41 struct RendererClosedDetails { |
| 42 RendererClosedDetails(base::ProcessHandle handle, |
| 43 base::TerminationStatus status, |
| 44 int exit_code, |
| 45 bool was_alive) { |
| 46 this->handle = handle; |
| 47 this->status = status; |
| 48 this->exit_code = exit_code; |
| 49 this->was_alive = was_alive; |
| 50 } |
| 51 base::ProcessHandle handle; |
| 52 base::TerminationStatus status; |
| 53 int exit_code; |
| 54 bool was_alive; |
| 55 }; |
| 56 |
| 57 virtual ~RenderProcessHost() {} |
| 58 |
| 59 // Initialize the new renderer process, returning true on success. This must |
| 60 // be called once before the object can be used, but can be called after |
| 61 // that with no effect. Therefore, if the caller isn't sure about whether |
| 62 // the process has been created, it should just call Init(). |
| 63 virtual bool Init(bool is_accessibility_enabled) = 0; |
| 64 |
| 65 // Gets the next available routing id. |
| 66 virtual int GetNextRoutingID() = 0; |
| 67 |
| 68 // Called on the UI thread to cancel any outstanding resource requests for |
| 69 // the specified render widget. |
| 70 virtual void CancelResourceRequests(int render_widget_id) = 0; |
| 71 |
| 72 // Called on the UI thread to simulate a SwapOut_ACK message to the |
| 73 // ResourceDispatcherHost. Necessary for a cross-site request, in the case |
| 74 // that the original RenderViewHost is not live and thus cannot run an |
| 75 // unload handler. |
| 76 virtual void CrossSiteSwapOutACK( |
| 77 const ViewMsg_SwapOut_Params& params) = 0; |
| 78 |
| 79 // Called to wait for the next UpdateRect message for the specified render |
| 80 // widget. Returns true if successful, and the msg out-param will contain a |
| 81 // copy of the received UpdateRect message. |
| 82 virtual bool WaitForUpdateMsg(int render_widget_id, |
| 83 const base::TimeDelta& max_delay, |
| 84 IPC::Message* msg) = 0; |
| 85 |
| 86 // Called when a received message cannot be decoded. |
| 87 virtual void ReceivedBadMessage() = 0; |
| 88 |
| 89 // Track the count of visible widgets. Called by listeners to register and |
| 90 // unregister visibility. |
| 91 virtual void WidgetRestored() = 0; |
| 92 virtual void WidgetHidden() = 0; |
| 93 virtual int VisibleWidgetCount() const = 0; |
| 94 |
| 95 // Try to shutdown the associated renderer process as fast as possible. |
| 96 // If this renderer has any RenderViews with unload handlers, then this |
| 97 // function does nothing. The current implementation uses TerminateProcess. |
| 98 // Returns True if it was able to do fast shutdown. |
| 99 virtual bool FastShutdownIfPossible() = 0; |
| 100 |
| 101 // Returns true if fast shutdown was started for the renderer. |
| 102 virtual bool FastShutdownStarted() const = 0; |
| 103 |
| 104 // Dump the child process' handle table before shutting down. |
| 105 virtual void DumpHandles() = 0; |
| 106 |
| 107 // Returns the process object associated with the child process. In certain |
| 108 // tests or single-process mode, this will actually represent the current |
| 109 // process. |
| 110 // |
| 111 // NOTE: this is not necessarily valid immediately after calling Init, as |
| 112 // Init starts the process asynchronously. It's guaranteed to be valid after |
| 113 // the first IPC arrives. |
| 114 virtual base::ProcessHandle GetHandle() = 0; |
| 115 |
| 116 // Transport DIB functions --------------------------------------------------- |
| 117 |
| 118 // Return the TransportDIB for the given id. On Linux, this can involve |
| 119 // mapping shared memory. On Mac, the shared memory is created in the browser |
| 120 // process and the cached metadata is returned. On Windows, this involves |
| 121 // duplicating the handle from the remote process. The RenderProcessHost |
| 122 // still owns the returned DIB. |
| 123 virtual TransportDIB* GetTransportDIB(TransportDIB::Id dib_id) = 0; |
| 124 |
| 125 // RenderWidgetHost / compositing surface mapping functions ------------------ |
| 126 |
| 127 // Set a mapping from a RenderWidgetHost to a compositing surface. Pass a null |
| 128 // handle to remove the mapping. |
| 129 virtual void SetCompositingSurface( |
| 130 int render_widget_id, |
| 131 gfx::PluginWindowHandle compositing_surface) = 0; |
| 132 |
| 133 // Returns the user browser context associated with this renderer process. |
| 134 virtual content::BrowserContext* GetBrowserContext() const = 0; |
| 135 |
| 136 // Returns the unique ID for this child process. This can be used later in |
| 137 // a call to FromID() to get back to this object (this is used to avoid |
| 138 // sending non-threadsafe pointers to other threads). |
| 139 // |
| 140 // This ID will be unique for all child processes, including workers, plugins, |
| 141 // etc. It is generated by ChildProcessInfo. |
| 142 virtual int GetID() const = 0; |
| 143 |
| 144 // Called to inform the render process host of a new "max page id" for a |
| 145 // render view host. The render process host computes the largest page id |
| 146 // across all render view hosts and uses the value when it needs to |
| 147 // initialize a new renderer in place of the current one. |
| 148 virtual void UpdateMaxPageID(int32 page_id) = 0; |
| 149 |
| 150 // Returns the listener for the routing id passed in. |
| 151 virtual IPC::Channel::Listener* GetListenerByID(int routing_id) = 0; |
| 152 |
| 153 // Returns true iff channel_ has been set to non-NULL. Use this for checking |
| 154 // if there is connection or not. Virtual for mocking out for tests. |
| 155 virtual bool HasConnection() const = 0; |
| 156 |
| 157 // Call this to allow queueing of IPC messages that are sent before the |
| 158 // process is launched. |
| 159 virtual void EnableSendQueue() = 0; |
| 160 |
| 161 // Returns the renderer channel. |
| 162 virtual IPC::ChannelProxy* GetChannel() = 0; |
| 163 |
| 164 virtual listeners_iterator ListenersIterator() = 0; |
| 165 |
| 166 // Try to shutdown the associated render process as fast as possible |
| 167 virtual bool FastShutdownForPageCount(size_t count) = 0; |
| 168 |
| 169 // Update the max page ID and send the update to the renderer process as well |
| 170 virtual void UpdateAndSendMaxPageID(int32 page_id) = 0; |
| 171 |
| 172 // TODO(ananta) |
| 173 // Revisit whether the virtual functions declared from here on need to be |
| 174 // part of the interface. |
| 175 virtual void SetIgnoreInputEvents(bool ignore_input_events) = 0; |
| 176 virtual bool IgnoreInputEvents() const = 0; |
| 177 |
| 178 // Used for refcounting, each holder of this object must Attach and Release |
| 179 // just like it would for a COM object. This object should be allocated on |
| 180 // the heap; when no listeners own it any more, it will delete itself. |
| 181 virtual void Attach(IPC::Channel::Listener* listener, int routing_id) = 0; |
| 182 |
| 183 // See Attach() |
| 184 virtual void Release(int listener_id) = 0; |
| 185 |
| 186 // Schedules the host for deletion and removes it from the all_hosts list. |
| 187 virtual void Cleanup() = 0; |
| 188 |
| 189 // Listeners should call this when they've sent a "Close" message and |
| 190 // they're waiting for a "Close_ACK", so that if the renderer process |
| 191 // goes away we'll know that it was intentional rather than a crash. |
| 192 virtual void ReportExpectingClose(int32 listener_id) = 0; |
| 193 |
| 194 // Track the count of pending views that are being swapped back in. Called |
| 195 // by listeners to register and unregister pending views to prevent the |
| 196 // process from exiting. |
| 197 virtual void AddPendingView() = 0; |
| 198 virtual void RemovePendingView() = 0; |
| 199 |
| 200 // Sets a flag indicating that the process can be abnormally terminated. |
| 201 virtual void SetSuddenTerminationAllowed(bool allowed) = 0; |
| 202 // Returns true if the process can be abnormally terminated. |
| 203 virtual bool SuddenTerminationAllowed() const = 0; |
| 204 |
| 205 // Returns how long the child has been idle. The definition of idle |
| 206 // depends on when a derived class calls mark_child_process_activity_time(). |
| 207 // This is a rough indicator and its resolution should not be better than |
| 208 // 10 milliseconds. |
| 209 virtual base::TimeDelta GetChildProcessIdleTime() const = 0; |
| 210 |
| 211 // Static management functions ----------------------------------------------- |
| 212 |
| 213 // Flag to run the renderer in process. This is primarily |
| 214 // for debugging purposes. When running "in process", the |
| 215 // browser maintains a single RenderProcessHost which communicates |
| 216 // to a RenderProcess which is instantiated in the same process |
| 217 // with the Browser. All IPC between the Browser and the |
| 218 // Renderer is the same, it's just not crossing a process boundary. |
| 219 |
| 220 static bool run_renderer_in_process(); |
| 221 static void set_run_renderer_in_process(bool value); |
| 222 |
| 223 // Allows iteration over all the RenderProcessHosts in the browser. Note |
| 224 // that each host may not be active, and therefore may have NULL channels. |
| 225 static iterator AllHostsIterator(); |
| 226 |
| 227 // Returns the RenderProcessHost given its ID. Returns NULL if the ID does |
| 228 // not correspond to a live RenderProcessHost. |
| 229 static RenderProcessHost* FromID(int render_process_id); |
| 230 |
| 231 // Returns true if the caller should attempt to use an existing |
| 232 // RenderProcessHost rather than creating a new one. |
| 233 static bool ShouldTryToUseExistingProcessHost(); |
| 234 |
| 235 // Get an existing RenderProcessHost associated with the given browser |
| 236 // context, if possible. The renderer process is chosen randomly from |
| 237 // suitable renderers that share the same context and type (determined by the |
| 238 // site url). |
| 239 // Returns NULL if no suitable renderer process is available, in which case |
| 240 // the caller is free to create a new renderer. |
| 241 static RenderProcessHost* GetExistingProcessHost( |
| 242 content::BrowserContext* browser_context, const GURL& site_url); |
| 243 |
| 244 // Overrides the default heuristic for limiting the max renderer process |
| 245 // count. This is useful for unit testing process limit behaviors. |
| 246 // A value of zero means to use the default heuristic. |
| 247 static void SetMaxRendererProcessCountForTest(size_t count); |
| 248 }; |
| 249 |
| 250 } // namespace content. |
| 251 |
| 252 #endif // CONTENT_PUBLIC_BROWSER_RENDER_PROCESS_HOST_H_ |
| 253 |
OLD | NEW |