summaryrefslogtreecommitdiffstats
path: root/content/public
diff options
context:
space:
mode:
authorananta@chromium.org <ananta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-18 00:34:30 +0000
committerananta@chromium.org <ananta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-18 00:34:30 +0000
commitf3b1a084a01ab82caf998daefcb989c66ff16135 (patch)
tree1072e46976c2fb7fa82d72c74bdc579d78f0ce01 /content/public
parent8f0633691cd10779408642e2ad5eaa9b0c190b0a (diff)
downloadchromium_src-f3b1a084a01ab82caf998daefcb989c66ff16135.zip
chromium_src-f3b1a084a01ab82caf998daefcb989c66ff16135.tar.gz
chromium_src-f3b1a084a01ab82caf998daefcb989c66ff16135.tar.bz2
Define the public interface for content browser RenderProcessHost. This interface is implemented by the RenderProcessHostImpl class which lives in content\browser\renderer_host\render_process_host_impl.cc/.h. The RenderProcessHostImpl class is a consolidation of the RenderProcessHost and BrowserRenderProcessHost classes.
The RenderProcessHost public interface was created from the now deleted RenderProcessHost class defined in content\browser\renderer_host\render_process_host.h. Additional methods have been added to the interface to ensure that it works correctly with the MockRenderProcessHost class used by unit tests. I had to implement a number of overrides in the MockRenderProcessHost class to ensure that tests work correctly. This was because of assumptions in the tests that the MockRPH class was a real RPH which it was till now. Added a TODO for the methods which could potentially be removed from this interface. Will revisit that in a subsequent CL. BUG=98716 TEST=No change in functionality. Hopefully it all compiles and works. Review URL: http://codereview.chromium.org/8515027 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@110615 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/public')
-rw-r--r--content/public/browser/content_browser_client.h13
-rw-r--r--content/public/browser/render_process_host.h253
-rw-r--r--content/public/browser/render_process_host_factory.h30
3 files changed, 289 insertions, 7 deletions
diff --git a/content/public/browser/content_browser_client.h b/content/public/browser/content_browser_client.h
index bc4c32a..4704334 100644
--- a/content/public/browser/content_browser_client.h
+++ b/content/public/browser/content_browser_client.h
@@ -15,7 +15,6 @@
#include "third_party/WebKit/Source/WebKit/chromium/public/WebNotificationPresenter.h"
class AccessTokenStore;
-class BrowserRenderProcessHost;
class BrowserURLHandler;
class CommandLine;
class DevToolsManager;
@@ -24,7 +23,6 @@ class GURL;
class MHTMLGenerationManager;
class PluginProcessHost;
class QuotaPermissionContext;
-class RenderProcessHost;
class RenderViewHost;
class RenderWidgetHost;
class RenderWidgetHostView;
@@ -42,6 +40,7 @@ namespace content {
class BrowserMainParts;
struct MainFunctionParams;
struct ShowDesktopNotificationHostMsgParams;
+class RenderProcessHost;
}
namespace crypto {
@@ -108,11 +107,11 @@ class ContentBrowserClient {
// Notifies that a new RenderHostView has been created.
virtual void RenderViewHostCreated(RenderViewHost* render_view_host) = 0;
- // Notifies that a BrowserRenderProcessHost has been created. This is called
- // before the content layer adds its own BrowserMessageFilters, so that the
+ // Notifies that a RenderProcessHost has been created. This is called before
+ // the content layer adds its own BrowserMessageFilters, so that the
// embedder's IPC filters have priority.
- virtual void BrowserRenderProcessHostCreated(
- BrowserRenderProcessHost* host) = 0;
+ virtual void RenderProcessHostCreated(
+ content::RenderProcessHost* host) = 0;
// Notifies that a PluginProcessHost has been created. This is called
// before the content layer adds its own message filters, so that the
@@ -138,7 +137,7 @@ class ContentBrowserClient {
// Returns whether a new view for a given |site_url| can be launched in a
// given |process_host|.
- virtual bool IsSuitableHost(RenderProcessHost* process_host,
+ virtual bool IsSuitableHost(content::RenderProcessHost* process_host,
const GURL& site_url) = 0;
// Called when a site instance is first associated with a process.
diff --git a/content/public/browser/render_process_host.h b/content/public/browser/render_process_host.h
new file mode 100644
index 0000000..194675b
--- /dev/null
+++ b/content/public/browser/render_process_host.h
@@ -0,0 +1,253 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_PUBLIC_BROWSER_RENDER_PROCESS_HOST_H_
+#define CONTENT_PUBLIC_BROWSER_RENDER_PROCESS_HOST_H_
+
+#include "base/basictypes.h"
+#include "base/id_map.h"
+#include "base/process.h"
+#include "base/process_util.h"
+#include "content/common/content_export.h"
+#include "ipc/ipc_channel_proxy.h"
+#include "ipc/ipc_message.h"
+#include "ui/gfx/native_widget_types.h"
+#include "ui/gfx/surface/transport_dib.h"
+
+class GURL;
+struct ViewMsg_SwapOut_Params;
+
+namespace content {
+class BrowserContext;
+}
+
+namespace base {
+class TimeDelta;
+}
+
+namespace content {
+
+// Interface that represents the browser side of the browser <-> renderer
+// communication channel. There will generally be one RenderProcessHost per
+// renderer process.
+class CONTENT_EXPORT RenderProcessHost : public IPC::Message::Sender,
+ public IPC::Channel::Listener {
+ public:
+ typedef IDMap<RenderProcessHost>::iterator iterator;
+ typedef IDMap<IPC::Channel::Listener>::const_iterator listeners_iterator;
+
+ // Details for RENDERER_PROCESS_CLOSED notifications.
+ struct RendererClosedDetails {
+ RendererClosedDetails(base::ProcessHandle handle,
+ base::TerminationStatus status,
+ int exit_code,
+ bool was_alive) {
+ this->handle = handle;
+ this->status = status;
+ this->exit_code = exit_code;
+ this->was_alive = was_alive;
+ }
+ base::ProcessHandle handle;
+ base::TerminationStatus status;
+ int exit_code;
+ bool was_alive;
+ };
+
+ virtual ~RenderProcessHost() {}
+
+ // Initialize the new renderer process, returning true on success. This must
+ // be called once before the object can be used, but can be called after
+ // that with no effect. Therefore, if the caller isn't sure about whether
+ // the process has been created, it should just call Init().
+ virtual bool Init(bool is_accessibility_enabled) = 0;
+
+ // Gets the next available routing id.
+ virtual int GetNextRoutingID() = 0;
+
+ // Called on the UI thread to cancel any outstanding resource requests for
+ // the specified render widget.
+ virtual void CancelResourceRequests(int render_widget_id) = 0;
+
+ // Called on the UI thread to simulate a SwapOut_ACK message to the
+ // ResourceDispatcherHost. Necessary for a cross-site request, in the case
+ // that the original RenderViewHost is not live and thus cannot run an
+ // unload handler.
+ virtual void CrossSiteSwapOutACK(
+ const ViewMsg_SwapOut_Params& params) = 0;
+
+ // Called to wait for the next UpdateRect message for the specified render
+ // widget. Returns true if successful, and the msg out-param will contain a
+ // copy of the received UpdateRect message.
+ virtual bool WaitForUpdateMsg(int render_widget_id,
+ const base::TimeDelta& max_delay,
+ IPC::Message* msg) = 0;
+
+ // Called when a received message cannot be decoded.
+ virtual void ReceivedBadMessage() = 0;
+
+ // Track the count of visible widgets. Called by listeners to register and
+ // unregister visibility.
+ virtual void WidgetRestored() = 0;
+ virtual void WidgetHidden() = 0;
+ virtual int VisibleWidgetCount() const = 0;
+
+ // Try to shutdown the associated renderer process as fast as possible.
+ // If this renderer has any RenderViews with unload handlers, then this
+ // function does nothing. The current implementation uses TerminateProcess.
+ // Returns True if it was able to do fast shutdown.
+ virtual bool FastShutdownIfPossible() = 0;
+
+ // Returns true if fast shutdown was started for the renderer.
+ virtual bool FastShutdownStarted() const = 0;
+
+ // Dump the child process' handle table before shutting down.
+ virtual void DumpHandles() = 0;
+
+ // Returns the process object associated with the child process. In certain
+ // tests or single-process mode, this will actually represent the current
+ // process.
+ //
+ // NOTE: this is not necessarily valid immediately after calling Init, as
+ // Init starts the process asynchronously. It's guaranteed to be valid after
+ // the first IPC arrives.
+ virtual base::ProcessHandle GetHandle() = 0;
+
+ // Transport DIB functions ---------------------------------------------------
+
+ // Return the TransportDIB for the given id. On Linux, this can involve
+ // mapping shared memory. On Mac, the shared memory is created in the browser
+ // process and the cached metadata is returned. On Windows, this involves
+ // duplicating the handle from the remote process. The RenderProcessHost
+ // still owns the returned DIB.
+ virtual TransportDIB* GetTransportDIB(TransportDIB::Id dib_id) = 0;
+
+ // RenderWidgetHost / compositing surface mapping functions ------------------
+
+ // Set a mapping from a RenderWidgetHost to a compositing surface. Pass a null
+ // handle to remove the mapping.
+ virtual void SetCompositingSurface(
+ int render_widget_id,
+ gfx::PluginWindowHandle compositing_surface) = 0;
+
+ // Returns the user browser context associated with this renderer process.
+ virtual content::BrowserContext* GetBrowserContext() const = 0;
+
+ // Returns the unique ID for this child process. This can be used later in
+ // a call to FromID() to get back to this object (this is used to avoid
+ // sending non-threadsafe pointers to other threads).
+ //
+ // This ID will be unique for all child processes, including workers, plugins,
+ // etc. It is generated by ChildProcessInfo.
+ virtual int GetID() const = 0;
+
+ // Called to inform the render process host of a new "max page id" for a
+ // render view host. The render process host computes the largest page id
+ // across all render view hosts and uses the value when it needs to
+ // initialize a new renderer in place of the current one.
+ virtual void UpdateMaxPageID(int32 page_id) = 0;
+
+ // Returns the listener for the routing id passed in.
+ virtual IPC::Channel::Listener* GetListenerByID(int routing_id) = 0;
+
+ // Returns true iff channel_ has been set to non-NULL. Use this for checking
+ // if there is connection or not. Virtual for mocking out for tests.
+ virtual bool HasConnection() const = 0;
+
+ // Call this to allow queueing of IPC messages that are sent before the
+ // process is launched.
+ virtual void EnableSendQueue() = 0;
+
+ // Returns the renderer channel.
+ virtual IPC::ChannelProxy* GetChannel() = 0;
+
+ virtual listeners_iterator ListenersIterator() = 0;
+
+ // Try to shutdown the associated render process as fast as possible
+ virtual bool FastShutdownForPageCount(size_t count) = 0;
+
+ // Update the max page ID and send the update to the renderer process as well
+ virtual void UpdateAndSendMaxPageID(int32 page_id) = 0;
+
+ // TODO(ananta)
+ // Revisit whether the virtual functions declared from here on need to be
+ // part of the interface.
+ virtual void SetIgnoreInputEvents(bool ignore_input_events) = 0;
+ virtual bool IgnoreInputEvents() const = 0;
+
+ // Used for refcounting, each holder of this object must Attach and Release
+ // just like it would for a COM object. This object should be allocated on
+ // the heap; when no listeners own it any more, it will delete itself.
+ virtual void Attach(IPC::Channel::Listener* listener, int routing_id) = 0;
+
+ // See Attach()
+ virtual void Release(int listener_id) = 0;
+
+ // Schedules the host for deletion and removes it from the all_hosts list.
+ virtual void Cleanup() = 0;
+
+ // Listeners should call this when they've sent a "Close" message and
+ // they're waiting for a "Close_ACK", so that if the renderer process
+ // goes away we'll know that it was intentional rather than a crash.
+ virtual void ReportExpectingClose(int32 listener_id) = 0;
+
+ // Track the count of pending views that are being swapped back in. Called
+ // by listeners to register and unregister pending views to prevent the
+ // process from exiting.
+ virtual void AddPendingView() = 0;
+ virtual void RemovePendingView() = 0;
+
+ // Sets a flag indicating that the process can be abnormally terminated.
+ virtual void SetSuddenTerminationAllowed(bool allowed) = 0;
+ // Returns true if the process can be abnormally terminated.
+ virtual bool SuddenTerminationAllowed() const = 0;
+
+ // Returns how long the child has been idle. The definition of idle
+ // depends on when a derived class calls mark_child_process_activity_time().
+ // This is a rough indicator and its resolution should not be better than
+ // 10 milliseconds.
+ virtual base::TimeDelta GetChildProcessIdleTime() const = 0;
+
+ // Static management functions -----------------------------------------------
+
+ // Flag to run the renderer in process. This is primarily
+ // for debugging purposes. When running "in process", the
+ // browser maintains a single RenderProcessHost which communicates
+ // to a RenderProcess which is instantiated in the same process
+ // with the Browser. All IPC between the Browser and the
+ // Renderer is the same, it's just not crossing a process boundary.
+
+ static bool run_renderer_in_process();
+ static void set_run_renderer_in_process(bool value);
+
+ // Allows iteration over all the RenderProcessHosts in the browser. Note
+ // that each host may not be active, and therefore may have NULL channels.
+ static iterator AllHostsIterator();
+
+ // Returns the RenderProcessHost given its ID. Returns NULL if the ID does
+ // not correspond to a live RenderProcessHost.
+ static RenderProcessHost* FromID(int render_process_id);
+
+ // Returns true if the caller should attempt to use an existing
+ // RenderProcessHost rather than creating a new one.
+ static bool ShouldTryToUseExistingProcessHost();
+
+ // Get an existing RenderProcessHost associated with the given browser
+ // context, if possible. The renderer process is chosen randomly from
+ // suitable renderers that share the same context and type (determined by the
+ // site url).
+ // Returns NULL if no suitable renderer process is available, in which case
+ // the caller is free to create a new renderer.
+ static RenderProcessHost* GetExistingProcessHost(
+ content::BrowserContext* browser_context, const GURL& site_url);
+
+ // Overrides the default heuristic for limiting the max renderer process
+ // count. This is useful for unit testing process limit behaviors.
+ // A value of zero means to use the default heuristic.
+ static void SetMaxRendererProcessCountForTest(size_t count);
+};
+
+} // namespace content.
+
+#endif // CONTENT_PUBLIC_BROWSER_RENDER_PROCESS_HOST_H_
+
diff --git a/content/public/browser/render_process_host_factory.h b/content/public/browser/render_process_host_factory.h
new file mode 100644
index 0000000..cd8767f
--- /dev/null
+++ b/content/public/browser/render_process_host_factory.h
@@ -0,0 +1,30 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_PUBLIC_BROWSER_RENDER_PROCESS_HOST_FACTORY_H_
+#define CONTENT_PUBLIC_BROWSER_RENDER_PROCESS_HOST_FACTORY_H_
+
+#include "base/basictypes.h"
+#include "content/common/content_export.h"
+
+namespace content {
+class BrowserContext;
+class RenderProcessHost;
+}
+
+namespace content {
+
+// Factory object for RenderProcessHosts. Using this factory allows tests to
+// swap out a different one to use a TestRenderProcessHost.
+class RenderProcessHostFactory {
+ public:
+ virtual ~RenderProcessHostFactory() {}
+ virtual RenderProcessHost* CreateRenderProcessHost(
+ content::BrowserContext* browser_context) const = 0;
+};
+
+} // namespace content
+
+#endif // CONTENT_PUBLIC_BROWSER_RENDER_PROCESS_HOST_FACTORY_H_
+