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