summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-16 18:31:26 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-16 18:31:26 +0000
commit8c8657d61fb8792985888c88730b2eb2f4fc4019 (patch)
tree73f4290e22afe39a19d64a0792a5a2ff2740a32c
parent52ef74f432e2fb08be4f7ea323244884894fc656 (diff)
downloadchromium_src-8c8657d61fb8792985888c88730b2eb2f4fc4019.zip
chromium_src-8c8657d61fb8792985888c88730b2eb2f4fc4019.tar.gz
chromium_src-8c8657d61fb8792985888c88730b2eb2f4fc4019.tar.bz2
Move functions required by the rest of the browser from RenderProcessHost to an interface and move the implementation to BrowserRenderProcessHost. This will allow me to write render view unit tests without using the actual renderer, but there are no tests yet.
Review URL: http://codereview.chromium.org/18132 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@8188 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/app/chrome_dll_main.cc2
-rw-r--r--chrome/browser/browser.scons3
-rw-r--r--chrome/browser/browser.vcproj42
-rw-r--r--chrome/browser/browser_about_handler.cc2
-rw-r--r--chrome/browser/browser_accessibility_manager.cc2
-rw-r--r--chrome/browser/browser_accessibility_manager.h30
-rw-r--r--chrome/browser/browser_prefs.cc3
-rw-r--r--chrome/browser/browser_process.h1
-rw-r--r--chrome/browser/browser_process_impl.cc2
-rw-r--r--chrome/browser/browser_shutdown.cc2
-rw-r--r--chrome/browser/cache_manager_host.cc5
-rw-r--r--chrome/browser/cache_manager_host.h1
-rw-r--r--chrome/browser/debugger/debugger_node.cc2
-rw-r--r--chrome/browser/debugger/debugger_shell.cc2
-rw-r--r--chrome/browser/download/download_manager.cc2
-rw-r--r--chrome/browser/download/save_package.cc2
-rw-r--r--chrome/browser/login_prompt.cc2
-rw-r--r--chrome/browser/memory_details.cc2
-rw-r--r--chrome/browser/metrics/metrics_service.cc2
-rw-r--r--chrome/browser/plugin_process_host.cc3
-rw-r--r--chrome/browser/plugin_service.cc2
-rw-r--r--chrome/browser/profile.cc2
-rw-r--r--chrome/browser/render_process_host.h291
-rw-r--r--chrome/browser/render_view_host.cc2
-rw-r--r--chrome/browser/render_widget_helper.cc2
-rw-r--r--chrome/browser/render_widget_helper.h17
-rw-r--r--chrome/browser/render_widget_host.cc11
-rw-r--r--chrome/browser/render_widget_host_view_win.cc2
-rw-r--r--chrome/browser/renderer_host/browser_render_process_host.cc (renamed from chrome/browser/render_process_host.cc)364
-rw-r--r--chrome/browser/renderer_host/browser_render_process_host.h160
-rw-r--r--chrome/browser/renderer_host/render_process_host.cc159
-rw-r--r--chrome/browser/renderer_host/render_process_host.h203
-rw-r--r--chrome/browser/resource_message_filter.cc6
-rw-r--r--chrome/browser/site_instance_unittest.cc7
-rw-r--r--chrome/browser/tab_contents/navigation_entry.h1
-rw-r--r--chrome/browser/tab_contents/site_instance.cc3
-rw-r--r--chrome/browser/tab_contents/site_instance.h9
-rw-r--r--chrome/browser/tab_contents/tab_contents_factory.cc2
-rw-r--r--chrome/browser/tab_contents/tab_util.cc2
-rw-r--r--chrome/browser/task_manager.cc2
-rw-r--r--chrome/browser/task_manager_resource_providers.cc2
-rw-r--r--chrome/test/testing_profile.h6
42 files changed, 733 insertions, 634 deletions
diff --git a/chrome/app/chrome_dll_main.cc b/chrome/app/chrome_dll_main.cc
index 05fd8b7..48d5b21 100644
--- a/chrome/app/chrome_dll_main.cc
+++ b/chrome/app/chrome_dll_main.cc
@@ -27,7 +27,7 @@
#include "base/string_util.h"
#if defined(OS_WIN)
#include "base/win_util.h"
-#include "chrome/browser/render_process_host.h"
+#include "chrome/browser/renderer_host/render_process_host.h"
#endif
#include "chrome/app/scoped_ole_initializer.h"
#include "chrome/common/chrome_constants.h"
diff --git a/chrome/browser/browser.scons b/chrome/browser/browser.scons
index 156903b..0d26151 100644
--- a/chrome/browser/browser.scons
+++ b/chrome/browser/browser.scons
@@ -243,7 +243,6 @@ if env.Bit('windows'):
'printing/win_printing_context.cc',
'profile.cc',
'profile_manager.cc',
- 'render_process_host.cc',
'render_view_context_menu.cc',
'render_view_context_menu_controller.cc',
'render_view_host.cc',
@@ -251,6 +250,8 @@ if env.Bit('windows'):
'render_widget_helper.cc',
'render_widget_host.cc',
'renderer_host/cross_site_resource_handler.cc',
+ 'renderer_host/render_process_host.cc',
+ 'renderer_host/browser_render_process_host.cc',
'renderer_host/resource_dispatcher_host.cc',
'repost_form_warning_dialog.cc',
'resource_message_filter.cc',
diff --git a/chrome/browser/browser.vcproj b/chrome/browser/browser.vcproj
index 8d6da23..5cc8fe9 100644
--- a/chrome/browser/browser.vcproj
+++ b/chrome/browser/browser.vcproj
@@ -482,14 +482,6 @@
>
</File>
<File
- RelativePath=".\render_process_host.cc"
- >
- </File>
- <File
- RelativePath=".\render_process_host.h"
- >
- </File>
- <File
RelativePath=".\render_view_host.cc"
>
</File>
@@ -2044,6 +2036,14 @@
>
</File>
<File
+ RelativePath=".\renderer_host\browser_render_process_host.cc"
+ >
+ </File>
+ <File
+ RelativePath=".\renderer_host\browser_render_process_host.h"
+ >
+ </File>
+ <File
RelativePath=".\renderer_host\buffered_resource_handler.cc"
>
</File>
@@ -2076,26 +2076,16 @@
>
</File>
<File
+ RelativePath=".\renderer_host\render_process_host.cc"
+ >
+ </File>
+ <File
+ RelativePath=".\renderer_host\render_process_host.h"
+ >
+ </File>
+ <File
RelativePath=".\renderer_host\resource_dispatcher_host.cc"
>
- <FileConfiguration
- Name="Debug|Win32"
- >
- <Tool
- Name="VCCLCompilerTool"
- ObjectFile="$(IntDir)\$(InputName)1.obj"
- XMLDocumentationFileName="$(IntDir)\$(InputName)1.xdc"
- />
- </FileConfiguration>
- <FileConfiguration
- Name="Release|Win32"
- >
- <Tool
- Name="VCCLCompilerTool"
- ObjectFile="$(IntDir)\$(InputName)1.obj"
- XMLDocumentationFileName="$(IntDir)\$(InputName)1.xdc"
- />
- </FileConfiguration>
</File>
<File
RelativePath=".\renderer_host\resource_dispatcher_host.h"
diff --git a/chrome/browser/browser_about_handler.cc b/chrome/browser/browser_about_handler.cc
index 0f4326b..68dd9b2 100644
--- a/chrome/browser/browser_about_handler.cc
+++ b/chrome/browser/browser_about_handler.cc
@@ -27,8 +27,8 @@
#include "chrome/browser/plugin_service.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/profile_manager.h"
-#include "chrome/browser/render_process_host.h"
#include "chrome/browser/render_view_host.h"
+#include "chrome/browser/renderer_host/render_process_host.h"
#include "chrome/browser/tab_contents/ipc_status_view.h"
#include "chrome/common/jstemplate_builder.h"
#include "chrome/common/l10n_util.h"
diff --git a/chrome/browser/browser_accessibility_manager.cc b/chrome/browser/browser_accessibility_manager.cc
index 1b533c2..0d46274 100644
--- a/chrome/browser/browser_accessibility_manager.cc
+++ b/chrome/browser/browser_accessibility_manager.cc
@@ -5,7 +5,7 @@
#include "chrome/browser/browser_accessibility_manager.h"
#include "chrome/browser/browser_accessibility.h"
-#include "chrome/browser/render_process_host.h"
+#include "chrome/browser/renderer_host/render_process_host.h"
#include "chrome/browser/render_widget_host.h"
// The time in ms after which we give up and return an error when processing an
diff --git a/chrome/browser/browser_accessibility_manager.h b/chrome/browser/browser_accessibility_manager.h
index 4d837bf..8356bc4 100644
--- a/chrome/browser/browser_accessibility_manager.h
+++ b/chrome/browser/browser_accessibility_manager.h
@@ -16,21 +16,6 @@ class BrowserAccessibility;
class RenderProcessHost;
class RenderWidgetHost;
-// Member variable structure, used in instance hashmap.
-struct UniqueMembers {
- RenderWidgetHost* render_widget_host_;
- HWND parent_hwnd_;
-
- UniqueMembers(HWND parent_hwnd, RenderWidgetHost* render_widget_host)
- : parent_hwnd_(parent_hwnd),
- render_widget_host_(render_widget_host) {
- }
-};
-
-typedef stdext::hash_map<int, UniqueMembers*> InstanceMap;
-typedef stdext::hash_map<RenderProcessHost*, BrowserAccessibility*>
- RenderProcessHostMap;
-
////////////////////////////////////////////////////////////////////////////////
//
// BrowserAccessibilityManager
@@ -91,6 +76,21 @@ class BrowserAccessibilityManager : public NotificationObserver {
~BrowserAccessibilityManager();
private:
+ // Member variable structure, used in instance hashmap.
+ struct UniqueMembers {
+ RenderWidgetHost* render_widget_host_;
+ HWND parent_hwnd_;
+
+ UniqueMembers(HWND parent_hwnd, RenderWidgetHost* render_widget_host)
+ : parent_hwnd_(parent_hwnd),
+ render_widget_host_(render_widget_host) {
+ }
+ };
+
+ typedef stdext::hash_map<int, UniqueMembers*> InstanceMap;
+ typedef stdext::hash_map<RenderProcessHost*, BrowserAccessibility*>
+ RenderProcessHostMap;
+
// Caching of the unique member variables used to handle browser accessibility
// requests from multiple processes.
InstanceMap instance_map_;
diff --git a/chrome/browser/browser_prefs.cc b/chrome/browser/browser_prefs.cc
index 2cf949b..a33c68a 100644
--- a/chrome/browser/browser_prefs.cc
+++ b/chrome/browser/browser_prefs.cc
@@ -13,6 +13,7 @@
#include "chrome/browser/google_url_tracker.h"
#include "chrome/browser/metrics/metrics_service.h"
#include "chrome/browser/password_manager/password_manager.h"
+#include "chrome/browser/renderer_host/browser_render_process_host.h"
#include "chrome/browser/safe_browsing/safe_browsing_service.h"
#include "chrome/browser/session_startup_pref.h"
#include "chrome/browser/spellchecker.h"
@@ -42,7 +43,7 @@ void RegisterAllPrefs(PrefService* user_prefs, PrefService* local_state) {
MetricsLog::RegisterPrefs(local_state);
MetricsService::RegisterPrefs(local_state);
PageInfoWindow::RegisterPrefs(local_state);
- RenderProcessHost::RegisterPrefs(local_state);
+ BrowserRenderProcessHost::RegisterPrefs(local_state);
TaskManager::RegisterPrefs(local_state);
ExternalProtocolHandler::RegisterPrefs(local_state);
SafeBrowsingService::RegisterPrefs(local_state);
diff --git a/chrome/browser/browser_process.h b/chrome/browser/browser_process.h
index adff28b..22b13d3 100644
--- a/chrome/browser/browser_process.h
+++ b/chrome/browser/browser_process.h
@@ -28,7 +28,6 @@ class MetricsService;
class NotificationService;
class PrefService;
class ProfileManager;
-class RenderProcessHost;
class DebuggerWrapper;
class ResourceDispatcherHost;
class WebAppInstallerService;
diff --git a/chrome/browser/browser_process_impl.cc b/chrome/browser/browser_process_impl.cc
index 8b98a41..20188cc1 100644
--- a/chrome/browser/browser_process_impl.cc
+++ b/chrome/browser/browser_process_impl.cc
@@ -19,7 +19,7 @@
#include "chrome/browser/plugin_service.h"
#include "chrome/browser/printing/print_job_manager.h"
#include "chrome/browser/profile_manager.h"
-#include "chrome/browser/render_process_host.h"
+#include "chrome/browser/renderer_host/render_process_host.h"
#include "chrome/browser/renderer_host/resource_dispatcher_host.h"
#include "chrome/browser/safe_browsing/safe_browsing_service.h"
#include "chrome/browser/debugger/debugger_wrapper.h"
diff --git a/chrome/browser/browser_shutdown.cc b/chrome/browser/browser_shutdown.cc
index 981737e..2815e78 100644
--- a/chrome/browser/browser_shutdown.cc
+++ b/chrome/browser/browser_shutdown.cc
@@ -16,7 +16,7 @@
#include "chrome/browser/metrics/metrics_service.h"
#include "chrome/browser/plugin_process_host.h"
#include "chrome/browser/plugin_service.h"
-#include "chrome/browser/render_process_host.h"
+#include "chrome/browser/renderer_host/render_process_host.h"
#include "chrome/browser/render_view_host.h"
#include "chrome/browser/render_widget_host.h"
#include "chrome/common/chrome_paths.h"
diff --git a/chrome/browser/cache_manager_host.cc b/chrome/browser/cache_manager_host.cc
index cc0f2e3..c295eef 100644
--- a/chrome/browser/cache_manager_host.cc
+++ b/chrome/browser/cache_manager_host.cc
@@ -9,7 +9,7 @@
#include "base/sys_info.h"
#include "base/time.h"
#include "chrome/browser/browser_process.h"
-#include "chrome/browser/render_process_host.h"
+#include "chrome/browser/renderer_host/render_process_host.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/pref_service.h"
@@ -133,8 +133,7 @@ void CacheManagerHost::ObserveStats(int renderer_id,
// See notification_types.h.
NotificationService::current()->
Notify(NOTIFY_WEB_CACHE_STATS_OBSERVED,
- Source<RenderProcessHost>(
- RenderProcessHost::FromID(renderer_id)),
+ Source<RenderProcessHost>(RenderProcessHost::FromID(renderer_id)),
Details<CacheManager::UsageStats>(&stats_details));
}
diff --git a/chrome/browser/cache_manager_host.h b/chrome/browser/cache_manager_host.h
index 5046624..d87cbf8 100644
--- a/chrome/browser/cache_manager_host.h
+++ b/chrome/browser/cache_manager_host.h
@@ -20,7 +20,6 @@
#include "webkit/glue/cache_manager.h"
class PrefService;
-class RenderProcessHost;
class CacheManagerHost {
// Unit tests are our friends.
diff --git a/chrome/browser/debugger/debugger_node.cc b/chrome/browser/debugger/debugger_node.cc
index 32e7afd..86587c5 100644
--- a/chrome/browser/debugger/debugger_node.cc
+++ b/chrome/browser/debugger/debugger_node.cc
@@ -9,7 +9,7 @@
#include "chrome/browser/browser.h"
#include "chrome/browser/browser_list.h"
#include "chrome/browser/browser_process.h"
-#include "chrome/browser/render_process_host.h"
+#include "chrome/browser/renderer_host/render_process_host.h"
#include "chrome/browser/render_view_host.h"
#include "chrome/browser/tab_contents/web_contents.h"
#include "chrome/browser/debugger/debugger_shell.h"
diff --git a/chrome/browser/debugger/debugger_shell.cc b/chrome/browser/debugger/debugger_shell.cc
index b64f083..21b1c7f 100644
--- a/chrome/browser/debugger/debugger_shell.cc
+++ b/chrome/browser/debugger/debugger_shell.cc
@@ -14,7 +14,7 @@
#include "chrome/browser/debugger/debugger_io.h"
#include "chrome/browser/debugger/debugger_node.h"
#include "chrome/browser/debugger/resources/debugger_resources.h"
-#include "chrome/browser/render_process_host.h"
+#include "chrome/browser/renderer_host/render_process_host.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/resource_bundle.h"
diff --git a/chrome/browser/download/download_manager.cc b/chrome/browser/download/download_manager.cc
index 1abfb87..d1ca5da 100644
--- a/chrome/browser/download/download_manager.cc
+++ b/chrome/browser/download/download_manager.cc
@@ -22,7 +22,7 @@
#include "chrome/browser/download/download_file.h"
#include "chrome/browser/download/download_util.h"
#include "chrome/browser/profile.h"
-#include "chrome/browser/render_process_host.h"
+#include "chrome/browser/renderer_host/render_process_host.h"
#include "chrome/browser/render_view_host.h"
#include "chrome/browser/renderer_host/resource_dispatcher_host.h"
#include "chrome/browser/tab_contents/tab_util.h"
diff --git a/chrome/browser/download/save_package.cc b/chrome/browser/download/save_package.cc
index c32c5ca..43096e0 100644
--- a/chrome/browser/download/save_package.cc
+++ b/chrome/browser/download/save_package.cc
@@ -18,7 +18,7 @@
#include "chrome/browser/download/save_file_manager.h"
#include "chrome/browser/download/save_page_model.h"
#include "chrome/browser/profile.h"
-#include "chrome/browser/render_process_host.h"
+#include "chrome/browser/renderer_host/render_process_host.h"
#include "chrome/browser/render_view_host.h"
#include "chrome/browser/render_view_host_delegate.h"
#include "chrome/browser/renderer_host/resource_dispatcher_host.h"
diff --git a/chrome/browser/login_prompt.cc b/chrome/browser/login_prompt.cc
index aaf2076..978d4dc 100644
--- a/chrome/browser/login_prompt.cc
+++ b/chrome/browser/login_prompt.cc
@@ -10,7 +10,7 @@
#include "chrome/browser/browser_process.h"
#include "chrome/browser/controller.h"
#include "chrome/browser/password_manager/password_manager.h"
-#include "chrome/browser/render_process_host.h"
+#include "chrome/browser/renderer_host/render_process_host.h"
#include "chrome/browser/renderer_host/resource_dispatcher_host.h"
#include "chrome/browser/tab_contents/constrained_window.h"
#include "chrome/browser/tab_contents/navigation_controller.h"
diff --git a/chrome/browser/memory_details.cc b/chrome/browser/memory_details.cc
index cc762f1..0a79f80 100644
--- a/chrome/browser/memory_details.cc
+++ b/chrome/browser/memory_details.cc
@@ -15,7 +15,7 @@
#include "chrome/browser/browser_trial.h"
#include "chrome/browser/plugin_process_host.h"
#include "chrome/browser/plugin_service.h"
-#include "chrome/browser/render_process_host.h"
+#include "chrome/browser/renderer_host/render_process_host.h"
#include "chrome/browser/render_view_host.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/browser/tab_contents/web_contents.h"
diff --git a/chrome/browser/metrics/metrics_service.cc b/chrome/browser/metrics/metrics_service.cc
index 399db59..e7fefe5 100644
--- a/chrome/browser/metrics/metrics_service.cc
+++ b/chrome/browser/metrics/metrics_service.cc
@@ -172,7 +172,7 @@
#include "chrome/browser/plugin_process_info.h"
#include "chrome/browser/plugin_service.h"
#include "chrome/browser/profile.h"
-#include "chrome/browser/render_process_host.h"
+#include "chrome/browser/renderer_host/render_process_host.h"
#include "chrome/browser/search_engines/template_url.h"
#include "chrome/browser/search_engines/template_url_model.h"
#include "chrome/common/chrome_paths.h"
diff --git a/chrome/browser/plugin_process_host.cc b/chrome/browser/plugin_process_host.cc
index 9249802..4607b2a 100644
--- a/chrome/browser/plugin_process_host.cc
+++ b/chrome/browser/plugin_process_host.cc
@@ -20,7 +20,8 @@
#include "chrome/browser/plugin_process_info.h"
#include "chrome/browser/plugin_service.h"
#include "chrome/browser/profile.h"
-#include "chrome/browser/render_process_host.h"
+#include "chrome/browser/renderer_host/browser_render_process_host.h"
+#include "chrome/browser/renderer_host/render_process_host.h"
#include "chrome/browser/renderer_host/resource_dispatcher_host.h"
#include "chrome/browser/sandbox_policy.h"
#include "chrome/common/chrome_paths.h"
diff --git a/chrome/browser/plugin_service.cc b/chrome/browser/plugin_service.cc
index 235ccf4..f31dc68 100644
--- a/chrome/browser/plugin_service.cc
+++ b/chrome/browser/plugin_service.cc
@@ -10,7 +10,7 @@
#include "chrome/browser/chrome_plugin_host.h"
#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/plugin_process_host.h"
-#include "chrome/browser/render_process_host.h"
+#include "chrome/browser/renderer_host/render_process_host.h"
#include "chrome/browser/resource_message_filter.h"
#include "chrome/common/chrome_plugin_lib.h"
#include "chrome/common/logging_chrome.h"
diff --git a/chrome/browser/profile.cc b/chrome/browser/profile.cc
index 7d3a947..089dd9c 100644
--- a/chrome/browser/profile.cc
+++ b/chrome/browser/profile.cc
@@ -22,7 +22,7 @@
#include "chrome/browser/history/history.h"
#include "chrome/browser/net/chrome_url_request_context.h"
#include "chrome/browser/profile_manager.h"
-#include "chrome/browser/render_process_host.h"
+#include "chrome/browser/renderer_host/render_process_host.h"
#include "chrome/browser/search_engines/template_url_fetcher.h"
#include "chrome/browser/search_engines/template_url_model.h"
#include "chrome/browser/sessions/session_service.h"
diff --git a/chrome/browser/render_process_host.h b/chrome/browser/render_process_host.h
deleted file mode 100644
index e4fea50..0000000
--- a/chrome/browser/render_process_host.h
+++ /dev/null
@@ -1,291 +0,0 @@
-// Copyright (c) 2006-2008 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 CHROME_BROWSER_RENDER_PROCESS_HOST_H_
-#define CHROME_BROWSER_RENDER_PROCESS_HOST_H_
-
-#include <limits>
-#include <set>
-#include <vector>
-#include <windows.h>
-
-#include "base/id_map.h"
-#include "base/object_watcher.h"
-#include "base/process.h"
-#include "base/rand_util.h"
-#include "base/ref_counted.h"
-#include "base/scoped_handle.h"
-#include "base/scoped_ptr.h"
-#include "chrome/common/ipc_sync_channel.h"
-#include "chrome/common/notification_service.h"
-#include "chrome/common/render_messages.h"
-
-class PrefService;
-class Profile;
-class RenderWidgetHelper;
-class WebContents;
-
-namespace base {
-class Thread;
-}
-
-// Represents the browser side of the browser <--> renderer communication
-// channel. There will be one RenderProcessHost per renderer process.
-//
-// This object is refcounted so that it can release its resources when all
-// hosts using it go away.
-//
-// This object communicates back and forth with the RenderProcess object
-// running in the renderer process. Each RenderProcessHost and RenderProcess
-// keeps a list of RenderView (renderer) and WebContents (browser) which
-// are correlated with IDs. This way, the Views and the corresponding ViewHosts
-// communicate through the two process objects.
-class RenderProcessHost : public IPC::Channel::Listener,
- public IPC::Channel::Sender,
- public base::ObjectWatcher::Delegate,
- public NotificationObserver {
- public:
- // 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);
-
- explicit RenderProcessHost(Profile* profile);
- ~RenderProcessHost();
-
- // 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() {
- return run_renderer_in_process_;
- }
- static void set_run_renderer_in_process(bool value) {
- run_renderer_in_process_ = value;
- }
-
- static void RegisterPrefs(PrefService* prefs);
-
- // If the a process has sent a message that cannot be decoded, it is deemed
- // corrupted and thus needs to be terminated using this call. This function
- // can be safely called from any thread.
- static void BadMessageTerminateProcess(uint16 msg_type, HANDLE renderer);
-
- // Called when a received message cannot be decoded.
- void ReceivedBadMessage(uint16 msg_type) {
- BadMessageTerminateProcess(msg_type, process_.handle());
- }
-
- // 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().
- bool Init();
-
- // 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.
- void Attach(IPC::Channel::Listener* listener, int routing_id);
-
- // See Attach()
- void Release(int listener_id);
-
- // 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.
- void ReportExpectingClose(int32 listener_id);
-
- // May return NULL if there is no connection.
- IPC::SyncChannel* channel() {
- return channel_.get();
- }
-
- const base::Process& process() const {
- return process_;
- }
-
- // 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.
- bool FastShutdownIfPossible();
-
- IPC::Channel::Listener* GetListenerByID(int routing_id) {
- return listeners_.Lookup(routing_id);
- }
-
- // 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.
- void UpdateMaxPageID(int32 page_id);
-
- // Called to simulate a ClosePage_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 onunload handler.
- void CrossSiteClosePageACK(int new_render_process_host_id,
- int new_request_id);
-
- // IPC channel listener
- virtual void OnMessageReceived(const IPC::Message& msg);
- virtual void OnChannelConnected(int32 peer_pid);
-
- // ObjectWatcher::Delegate
- virtual void OnObjectSignaled(HANDLE object);
-
- // IPC::Channel::Sender callback
- virtual bool Send(IPC::Message* msg);
-
- // Allows iteration over all the RenderProcessHosts in the browser. Note
- // that each host may not be active, and therefore may have NULL channels.
- // This is just a standard STL iterator, so it is not valid if the list
- // of RenderProcessHosts changes between iterations.
- typedef IDMap<RenderProcessHost>::const_iterator iterator;
- static iterator begin();
- static iterator end();
- static size_t size();
-
- // Allows iteration over this RenderProcessHost's RenderViewHost listeners.
- // Use from UI thread only.
- typedef IDMap<IPC::Channel::Listener>::const_iterator listeners_iterator;
- listeners_iterator listeners_begin() {
- return listeners_.begin();
- }
- listeners_iterator listeners_end() {
- return listeners_.end();
- }
-
- // 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 profile, if
- // possible. The renderer process is chosen randomly from the
- // processes associated with the given profile.
- // Returns NULL if no suitable renderer process is available.
- static RenderProcessHost* GetExistingProcessHost(Profile* profile);
-
- int host_id() const { return host_id_; }
-
- // Returns the user profile associated with this renderer process.
- Profile* profile() const { return profile_; }
-
- RenderWidgetHelper* widget_helper() const { return widget_helper_; }
-
- // Track the count of visible widgets. Called by listeners
- // to register/unregister visibility.
- void WidgetRestored();
- void WidgetHidden();
-
- // Add a word in the spellchecker.
- void AddWord(const std::wstring& word);
-
- // NotificationObserver implementation.
- virtual void Observe(NotificationType type,
- const NotificationSource& source,
- const NotificationDetails& details);
-
- private:
- // control message handlers
- void OnPageContents(const GURL& url, int32 page_id,
- const std::wstring& contents);
- // Clipboard messages
- void OnClipboardWriteHTML(const std::wstring& markup, const GURL& src_url);
- void OnClipboardWriteBookmark(const std::wstring& title, const GURL& url);
- void OnClipboardWriteBitmap(base::SharedMemoryHandle bitmap, gfx::Size size);
- void OnClipboardIsFormatAvailable(unsigned int format, bool* result);
- void OnClipboardReadText(std::wstring* result);
- void OnClipboardReadAsciiText(std::string* result);
- void OnClipboardReadHTML(std::wstring* markup, GURL* src_url);
- void OnUpdatedCacheStats(const CacheManager::UsageStats& stats);
-
- // Initialize support for visited links. Send the renderer process its initial
- // set of visited links.
- void InitVisitedLinks();
-
- // Initialize support for user scripts. Send the renderer process its initial
- // set of scripts and listen for updates to scripts.
- void InitUserScripts();
-
- // Sends the renderer process a new set of user scripts.
- void SendUserScriptsUpdate(base::SharedMemory* shared_memory);
-
- // Gets a handle to the renderer process, normalizing the case where we were
- // started with --single-process.
- base::ProcessHandle GetRendererProcessHandle();
-
- // Callers can reduce the RenderProcess' priority.
- // Returns true if the priority is backgrounded; false otherwise.
- void SetBackgrounded(bool boost);
-
- // Unregister this object from all globals that reference it.
- // This would naturally be part of the destructor, but we destruct
- // asynchronously.
- void Unregister();
-
- // the registered listeners. When this list is empty or all NULL, we should
- // delete ourselves
- IDMap<IPC::Channel::Listener> listeners_;
-
- // set of listeners that expect the renderer process to close
- std::set<int> listeners_expecting_close_;
-
- // A proxy for our IPC::Channel that lives on the IO thread (see
- // browser_process.h)
- scoped_ptr<IPC::SyncChannel> channel_;
-
- // Our renderer process.
- base::Process process_;
-
- // Used to watch the renderer process handle.
- base::ObjectWatcher watcher_;
-
- // The profile associated with this renderer process.
- Profile* profile_;
-
- // Our ID into the IDMap.
- int host_id_;
-
- // The maximum page ID we've ever seen from the renderer process.
- int32 max_page_id_;
-
- // The count of currently visible widgets. Since the host can be a container
- // for multiple widgets, it uses this count to determine when it should be
- // backgrounded.
- int32 visible_widgets_;
-
- // Does this process have backgrounded priority.
- bool backgrounded_;
-
- // Used to allow a RenderWidgetHost to intercept various messages on the
- // IO thread.
- scoped_refptr<RenderWidgetHelper> widget_helper_;
-
- // Whether we have notified that the process has terminated.
- bool notified_termination_;
-
- static bool run_renderer_in_process_;
-
- DISALLOW_EVIL_CONSTRUCTORS(RenderProcessHost);
-};
-
-// Generates a unique channel name for a child renderer/plugin process.
-// The "instance" pointer value is baked into the channel id.
-inline std::wstring GenerateRandomChannelID(void* instance) {
- // Note: the string must start with the current process id, this is how
- // child processes determine the pid of the parent.
- // Build the channel ID. This is composed of a unique identifier for the
- // parent browser process, an identifier for the renderer/plugin instance,
- // and a random component. We use a random component so that a hacked child
- // process can't cause denial of service by causing future named pipe creation
- // to fail.
- return StringPrintf(L"%d.%x.%d",
- GetCurrentProcessId(), instance,
- base::RandInt(0, std::numeric_limits<int>::max()));
-}
-
-
-#endif // CHROME_BROWSER_RENDER_PROCESS_HOST_H_
-
diff --git a/chrome/browser/render_view_host.cc b/chrome/browser/render_view_host.cc
index 16afeb5..15bb6b4 100644
--- a/chrome/browser/render_view_host.cc
+++ b/chrome/browser/render_view_host.cc
@@ -14,8 +14,8 @@
#include "chrome/browser/cross_site_request_manager.h"
#include "chrome/browser/debugger/debugger_wrapper.h"
#include "chrome/browser/profile.h"
+#include "chrome/browser/renderer_host/render_process_host.h"
#include "chrome/browser/metrics/user_metrics.h"
-#include "chrome/browser/render_process_host.h"
#include "chrome/browser/render_widget_host.h"
#include "chrome/browser/render_widget_host_view.h"
#include "chrome/browser/render_view_host_delegate.h"
diff --git a/chrome/browser/render_widget_helper.cc b/chrome/browser/render_widget_helper.cc
index 337f0dd..7542d27 100644
--- a/chrome/browser/render_widget_helper.cc
+++ b/chrome/browser/render_widget_helper.cc
@@ -6,7 +6,7 @@
#include "base/thread.h"
#include "chrome/browser/browser_process.h"
-#include "chrome/browser/render_process_host.h"
+#include "chrome/browser/renderer_host/render_process_host.h"
#include "chrome/browser/renderer_host/resource_dispatcher_host.h"
using base::TimeDelta;
diff --git a/chrome/browser/render_widget_helper.h b/chrome/browser/render_widget_helper.h
index 70a09ba..fe2bf08 100644
--- a/chrome/browser/render_widget_helper.h
+++ b/chrome/browser/render_widget_helper.h
@@ -86,21 +86,14 @@ class RenderWidgetHelper :
// UI THREAD ONLY -----------------------------------------------------------
- // Called on the UI thread to cancel any outstanding resource requests for
- // the specified render widget.
+ // These three functions provide the backend implementation of the
+ // corresponding functions in RenderProcessHost. See those declarations
+ // for documentation.
void CancelResourceRequests(int render_widget_id);
-
- // Called on the UI thread to simulate a ClosePage_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
- // onunload handler.
void CrossSiteClosePageACK(int new_render_process_host_id,
int new_request_id);
-
- // Called on the UI thread to wait for the next PaintRect message for the
- // specified render widget. Returns true if successful, and the msg out-
- // param will contain a copy of the received PaintRect message.
- bool WaitForPaintMsg(int render_widget_id, const base::TimeDelta& max_delay,
+ bool WaitForPaintMsg(int render_widget_id,
+ const base::TimeDelta& max_delay,
IPC::Message* msg);
diff --git a/chrome/browser/render_widget_host.cc b/chrome/browser/render_widget_host.cc
index 90aac3c..2823cba 100644
--- a/chrome/browser/render_widget_host.cc
+++ b/chrome/browser/render_widget_host.cc
@@ -7,10 +7,11 @@
#include "base/gfx/gdi_util.h"
#include "base/message_loop.h"
#include "chrome/app/chrome_dll_resource.h"
-#include "chrome/browser/render_process_host.h"
#include "chrome/browser/render_widget_helper.h"
#include "chrome/browser/render_widget_host_view.h"
+#include "chrome/browser/renderer_host/render_process_host.h"
#include "chrome/common/mru_cache.h"
+#include "chrome/common/notification_service.h"
#include "chrome/common/win_util.h"
#include "chrome/views/view.h"
#include "webkit/glue/webcursor.h"
@@ -267,7 +268,8 @@ RenderWidgetHost::BackingStoreManager::BackingStoreCache*
///////////////////////////////////////////////////////////////////////////////
// RenderWidgetHost
-RenderWidgetHost::RenderWidgetHost(RenderProcessHost* process, int routing_id)
+RenderWidgetHost::RenderWidgetHost(RenderProcessHost* process,
+ int routing_id)
: process_(process),
routing_id_(routing_id),
resize_ack_pending_(false),
@@ -281,7 +283,7 @@ RenderWidgetHost::RenderWidgetHost(RenderProcessHost* process, int routing_id)
view_being_painted_(false),
repaint_ack_pending_(false) {
if (routing_id_ == MSG_ROUTING_NONE)
- routing_id_ = process_->widget_helper()->GetNextRoutingID();
+ routing_id_ = process_->GetNextRoutingID();
process_->Attach(this, routing_id_);
// Because the widget initializes as is_hidden_ == false,
@@ -743,8 +745,7 @@ RenderWidgetHost::BackingStore* RenderWidgetHost::GetBackingStore() {
if (resize_ack_pending_ || !backing_store) {
IPC::Message msg;
TimeDelta max_delay = TimeDelta::FromMilliseconds(kPaintMsgTimeoutMS);
- if (process_->widget_helper()->WaitForPaintMsg(routing_id_, max_delay,
- &msg)) {
+ if (process_->WaitForPaintMsg(routing_id_, max_delay, &msg)) {
suppress_view_updating_ = true;
ViewHostMsg_PaintRect::Dispatch(
&msg, this, &RenderWidgetHost::OnMsgPaintRect);
diff --git a/chrome/browser/render_widget_host_view_win.cc b/chrome/browser/render_widget_host_view_win.cc
index 779d942..4fd0f18 100644
--- a/chrome/browser/render_widget_host_view_win.cc
+++ b/chrome/browser/render_widget_host_view_win.cc
@@ -12,7 +12,7 @@
#include "chrome/browser/browser_accessibility.h"
#include "chrome/browser/browser_accessibility_manager.h"
#include "chrome/browser/browser_trial.h"
-#include "chrome/browser/render_process_host.h"
+#include "chrome/browser/renderer_host/render_process_host.h"
// TODO(beng): (Cleanup) we should not need to include this file... see comment
// in |DidBecomeSelected|.
#include "chrome/browser/render_view_host.h"
diff --git a/chrome/browser/render_process_host.cc b/chrome/browser/renderer_host/browser_render_process_host.cc
index a0a8f8b..198d886 100644
--- a/chrome/browser/render_process_host.cc
+++ b/chrome/browser/renderer_host/browser_render_process_host.cc
@@ -2,13 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// Represents the browser side of the browser <--> renderer communication
-// channel. There will be one RenderProcessHost per renderer process.
+#include "chrome/browser/renderer_host/browser_render_process_host.h"
-#include "chrome/browser/render_process_host.h"
-
-#include <windows.h>
-#include <wininet.h>
#include <algorithm>
#include <sstream>
#include <vector>
@@ -19,11 +14,9 @@
#include "base/logging.h"
#include "base/path_service.h"
#include "base/process_util.h"
-#include "base/rand_util.h"
#include "base/shared_memory.h"
#include "base/singleton.h"
#include "base/string_util.h"
-#include "base/sys_info.h"
#include "base/thread.h"
#include "base/win_util.h"
#include "chrome/app/result_codes.h"
@@ -41,7 +34,6 @@
#include "chrome/browser/spellchecker.h"
#include "chrome/browser/visitedlink_master.h"
#include "chrome/browser/tab_contents/web_contents.h"
-#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/debug_flags.h"
@@ -62,29 +54,6 @@
namespace {
-unsigned int GetMaxRendererProcessCount() {
- // Defines the maximum number of renderer processes according to the amount
- // of installed memory as reported by the OS. The table values are calculated
- // by assuming that you want the renderers to use half of the installed ram
- // and assuming that each tab uses ~25MB.
- static const int kMaxRenderersByRamTier[] = {
- 4, // less than 256MB
- 8, // 256MB
- 12, // 512MB
- 16, // 768MB
- };
-
- static unsigned int max_count = 0;
- if (!max_count) {
- int memory_tier = base::SysInfo::AmountOfPhysicalMemoryMB() / 256;
- if (memory_tier >= arraysize(kMaxRenderersByRamTier))
- max_count = chrome::kMaxRendererProcessCount;
- else
- max_count = kMaxRenderersByRamTier[memory_tier];
- }
- return max_count;
-}
-
// ----------------------------------------------------------------------------
class RendererMainThread : public base::Thread {
@@ -121,9 +90,6 @@ class RendererMainThread : public base::Thread {
// Used for a View_ID where the renderer has not been attached yet
const int32 kInvalidViewID = -1;
-// the global list of all renderer processes
-IDMap<RenderProcessHost> all_hosts;
-
// Get the path to the renderer executable, which is the same as the
// current executable.
bool GetRendererPath(std::wstring* cmd_line) {
@@ -136,30 +102,20 @@ const wchar_t* const kDesktopName = L"ChromeRendererDesktop";
//------------------------------------------------------------------------------
-bool RenderProcessHost::run_renderer_in_process_ = false;
-
// static
-void RenderProcessHost::RegisterPrefs(PrefService* prefs) {
+void BrowserRenderProcessHost::RegisterPrefs(PrefService* prefs) {
prefs->RegisterBooleanPref(prefs::kStartRenderersManually, false);
}
-// static
-RenderProcessHost* RenderProcessHost::FromID(int render_process_id) {
- return all_hosts.Lookup(render_process_id);
-}
-
-RenderProcessHost::RenderProcessHost(Profile* profile)
- : profile_(profile),
- max_page_id_(-1),
+BrowserRenderProcessHost::BrowserRenderProcessHost(Profile* profile)
+ : RenderProcessHost(profile),
visible_widgets_(0),
- backgrounded_(true),
- notified_termination_(false) {
- host_id_ = all_hosts.Add(this);
- DCHECK(host_id_ >= 0); // We use a negative host_id_ in destruction.
- widget_helper_ = new RenderWidgetHelper(host_id_);
+ backgrounded_(true) {
+ DCHECK(host_id() >= 0); // We use a negative host_id_ in destruction.
+ widget_helper_ = new RenderWidgetHelper(host_id());
- CacheManagerHost::GetInstance()->Add(host_id_);
- RendererSecurityPolicy::GetInstance()->Add(host_id_);
+ CacheManagerHost::GetInstance()->Add(host_id());
+ RendererSecurityPolicy::GetInstance()->Add(host_id());
PrefService* prefs = profile->GetPrefs();
prefs->AddPrefObserver(prefs::kBlockPopups, this);
@@ -169,40 +125,31 @@ RenderProcessHost::RenderProcessHost(Profile* profile)
NotificationService::current()->AddObserver(this,
NOTIFY_USER_SCRIPTS_LOADED, NotificationService::AllSources());
- // Note: When we create the RenderProcessHost, it's technically backgrounded,
+ // Note: When we create the BrowserRenderProcessHost, it's technically backgrounded,
// because it has no visible listeners. But the process doesn't
// actually exist yet, so we'll Background it later, after creation.
}
-RenderProcessHost::~RenderProcessHost() {
- // Some tests hold RenderProcessHost in a scoped_ptr, so we must call
+BrowserRenderProcessHost::~BrowserRenderProcessHost() {
+ // Some tests hold BrowserRenderProcessHost in a scoped_ptr, so we must call
// Unregister here as well as in response to Release().
Unregister();
// We may have some unsent messages at this point, but that's OK.
channel_.reset();
- if (process_.handle() && !run_renderer_in_process_) {
+ if (process_.handle() && !run_renderer_in_process()) {
watcher_.StopWatching();
ProcessWatcher::EnsureProcessTerminated(process_.handle());
}
- profile_->GetPrefs()->RemovePrefObserver(prefs::kBlockPopups, this);
+ profile()->GetPrefs()->RemovePrefObserver(prefs::kBlockPopups, this);
NotificationService::current()->RemoveObserver(this,
NOTIFY_USER_SCRIPTS_LOADED, NotificationService::AllSources());
}
-void RenderProcessHost::Unregister() {
- if (host_id_ >= 0) {
- CacheManagerHost::GetInstance()->Remove(host_id_);
- RendererSecurityPolicy::GetInstance()->Remove(host_id_);
- all_hosts.Remove(host_id_);
- host_id_ = -1;
- }
-}
-
-bool RenderProcessHost::Init() {
+bool BrowserRenderProcessHost::Init() {
// calling Init() more than once does nothing, this makes it more convenient
// for the view host which may not be sure in some cases
if (channel_.get())
@@ -215,10 +162,10 @@ bool RenderProcessHost::Init() {
new ResourceMessageFilter(g_browser_process->resource_dispatcher_host(),
PluginService::GetInstance(),
g_browser_process->print_job_manager(),
- host_id_,
- profile_,
+ host_id(),
+ profile(),
widget_helper_,
- profile_->GetSpellChecker());
+ profile()->GetSpellChecker());
CommandLine browser_command_line;
@@ -316,7 +263,7 @@ bool RenderProcessHost::Init() {
CommandLine::AppendSwitchWithValue(&cmd_line, switches::kUserDataDir,
profile_path);
- bool run_in_process = RenderProcessHost::run_renderer_in_process();
+ bool run_in_process = run_renderer_in_process();
if (run_in_process) {
// Crank up a thread and run the initialization there. With the way that
// messages flow between the browser and renderer, this thread is required
@@ -341,7 +288,7 @@ bool RenderProcessHost::Init() {
std::wstring message =
L"Please start a renderer process using:\n" + cmd_line;
- // We don't know the owner window for RenderProcessHost and therefore we
+ // We don't know the owner window for BrowserRenderProcessHost and therefore we
// pass a NULL HWND argument.
win_util::MessageBox(NULL,
message,
@@ -391,7 +338,7 @@ bool RenderProcessHost::Init() {
if (!AddDllEvictionPolicy(policy)) {
NOTREACHED();
- return false;
+ return false;
}
result = broker_service->SpawnTarget(renderer_path.c_str(),
@@ -407,7 +354,7 @@ bool RenderProcessHost::Init() {
bool on_sandbox_desktop = (desktop != NULL);
NotificationService::current()->Notify(
- NOTIFY_RENDERER_PROCESS_IN_SBOX, Source<RenderProcessHost>(this),
+ NOTIFY_RENDERER_PROCESS_IN_SBOX, Source<BrowserRenderProcessHost>(this),
Details<bool>(&on_sandbox_desktop));
ResumeThread(target.hThread);
@@ -442,14 +389,68 @@ bool RenderProcessHost::Init() {
return true;
}
-base::ProcessHandle RenderProcessHost::GetRendererProcessHandle() {
- if (run_renderer_in_process_)
+int BrowserRenderProcessHost::GetNextRoutingID() {
+ return widget_helper_->GetNextRoutingID();
+}
+
+void BrowserRenderProcessHost::CancelResourceRequests(int render_widget_id) {
+ widget_helper_->CancelResourceRequests(render_widget_id);
+}
+
+void BrowserRenderProcessHost::CrossSiteClosePageACK(
+ int new_render_process_host_id,
+ int new_request_id) {
+ widget_helper_->CrossSiteClosePageACK(new_render_process_host_id,
+ new_request_id);
+}
+
+bool BrowserRenderProcessHost::WaitForPaintMsg(int render_widget_id,
+ const base::TimeDelta& max_delay,
+ IPC::Message* msg) {
+ return widget_helper_->WaitForPaintMsg(render_widget_id, max_delay, msg);
+}
+
+void BrowserRenderProcessHost::ReceivedBadMessage(uint16 msg_type) {
+ BadMessageTerminateProcess(msg_type, process_.handle());
+}
+
+void BrowserRenderProcessHost::WidgetRestored() {
+ // Verify we were properly backgrounded.
+ DCHECK(backgrounded_ == (visible_widgets_ == 0));
+ visible_widgets_++;
+ SetBackgrounded(false);
+}
+
+void BrowserRenderProcessHost::WidgetHidden() {
+ // On startup, the browser will call Hide
+ if (backgrounded_)
+ return;
+
+ DCHECK(backgrounded_ == (visible_widgets_ == 0));
+ visible_widgets_--;
+ DCHECK(visible_widgets_ >= 0);
+ if (visible_widgets_ == 0) {
+ DCHECK(!backgrounded_);
+ SetBackgrounded(true);
+ }
+}
+
+void BrowserRenderProcessHost::AddWord(const std::wstring& word) {
+ base::Thread* io_thread = g_browser_process->io_thread();
+ if (profile()->GetSpellChecker()) {
+ io_thread->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(
+ profile()->GetSpellChecker(), &SpellChecker::AddWord, word));
+ }
+}
+
+base::ProcessHandle BrowserRenderProcessHost::GetRendererProcessHandle() {
+ if (run_renderer_in_process())
return base::Process::Current().handle();
return process_.handle();
}
-void RenderProcessHost::InitVisitedLinks() {
- VisitedLinkMaster* visitedlink_master = profile_->GetVisitedLinkMaster();
+void BrowserRenderProcessHost::InitVisitedLinks() {
+ VisitedLinkMaster* visitedlink_master = profile()->GetVisitedLinkMaster();
if (!visitedlink_master) {
return;
}
@@ -463,7 +464,7 @@ void RenderProcessHost::InitVisitedLinks() {
}
}
-void RenderProcessHost::InitUserScripts() {
+void BrowserRenderProcessHost::InitUserScripts() {
CommandLine command_line;
if (!command_line.HasSwitch(switches::kEnableUserScripts)) {
return;
@@ -475,7 +476,7 @@ void RenderProcessHost::InitUserScripts() {
// - File IO should be asynchronous (see VisitedLinkMaster), but how do we
// get scripts to the first renderer without blocking startup? Should we
// cache some information across restarts?
- UserScriptMaster* user_script_master = profile_->GetUserScriptMaster();
+ UserScriptMaster* user_script_master = profile()->GetUserScriptMaster();
if (!user_script_master) {
return;
}
@@ -489,7 +490,7 @@ void RenderProcessHost::InitUserScripts() {
SendUserScriptsUpdate(user_script_master->GetSharedMemory());
}
-void RenderProcessHost::SendUserScriptsUpdate(
+void BrowserRenderProcessHost::SendUserScriptsUpdate(
base::SharedMemory *shared_memory) {
base::SharedMemoryHandle handle_for_process = NULL;
shared_memory->ShareToProcess(GetRendererProcessHandle(),
@@ -500,44 +501,14 @@ void RenderProcessHost::SendUserScriptsUpdate(
}
}
-void RenderProcessHost::Attach(IPC::Channel::Listener* listener,
- int routing_id) {
- listeners_.AddWithID(listener, routing_id);
-}
-
-void RenderProcessHost::Release(int listener_id) {
- DCHECK(listeners_.Lookup(listener_id) != NULL);
- listeners_.Remove(listener_id);
-
- // make sure that all associated resource requests are stopped.
- widget_helper_->CancelResourceRequests(listener_id);
-
- // when no other owners of this object, we can delete ourselves
- if (listeners_.IsEmpty()) {
- if (!notified_termination_) {
- bool close_expected = true;
- NotificationService::current()->Notify(NOTIFY_RENDERER_PROCESS_TERMINATED,
- Source<RenderProcessHost>(this),
- Details<bool>(&close_expected));
- notified_termination_ = true;
- }
- Unregister();
- MessageLoop::current()->DeleteSoon(FROM_HERE, this);
- }
-}
-
-void RenderProcessHost::ReportExpectingClose(int32 listener_id) {
- listeners_expecting_close_.insert(listener_id);
-}
-
-bool RenderProcessHost::FastShutdownIfPossible() {
+bool BrowserRenderProcessHost::FastShutdownIfPossible() {
if (!process_.handle())
return false; // Render process is probably crashed.
- if (RenderProcessHost::run_renderer_in_process())
+ if (BrowserRenderProcessHost::run_renderer_in_process())
return false; // Since process mode can't do fast shutdown.
// Test if there's an unload listener
- RenderProcessHost::listeners_iterator iter;
+ BrowserRenderProcessHost::listeners_iterator iter;
// NOTE: This is a bit dangerous. We know that for now, listeners are
// always RenderWidgetHosts. But in theory, they don't have to be.
for (iter = listeners_begin(); iter != listeners_end(); ++iter) {
@@ -561,34 +532,19 @@ bool RenderProcessHost::FastShutdownIfPossible() {
return true;
}
-// Static. This function can be called from the IO Thread or from the UI thread.
-void RenderProcessHost::BadMessageTerminateProcess(uint16 msg_type,
- HANDLE process) {
- LOG(ERROR) << "bad message " << msg_type << " terminating renderer.";
- if (RenderProcessHost::run_renderer_in_process()) {
- // In single process mode it is better if we don't suicide but just crash.
- CHECK(false);
+bool BrowserRenderProcessHost::Send(IPC::Message* msg) {
+ if (!channel_.get()) {
+ delete msg;
+ return false;
}
- NOTREACHED();
- ::TerminateProcess(process, ResultCodes::KILLED_BAD_MESSAGE);
-}
-
-void RenderProcessHost::UpdateMaxPageID(int32 page_id) {
- if (page_id > max_page_id_)
- max_page_id_ = page_id;
-}
-
-void RenderProcessHost::CrossSiteClosePageACK(int new_render_process_host_id,
- int new_request_id) {
- widget_helper_->CrossSiteClosePageACK(new_render_process_host_id,
- new_request_id);
+ return channel_->Send(msg);
}
-void RenderProcessHost::OnMessageReceived(const IPC::Message& msg) {
+void BrowserRenderProcessHost::OnMessageReceived(const IPC::Message& msg) {
if (msg.routing_id() == MSG_ROUTING_CONTROL) {
// dispatch control messages
bool msg_is_ok = true;
- IPC_BEGIN_MESSAGE_MAP_EX(RenderProcessHost, msg, msg_is_ok)
+ IPC_BEGIN_MESSAGE_MAP_EX(BrowserRenderProcessHost, msg, msg_is_ok)
IPC_MESSAGE_HANDLER(ViewHostMsg_PageContents, OnPageContents)
IPC_MESSAGE_HANDLER(ViewHostMsg_UpdatedCacheStats,
OnUpdatedCacheStats)
@@ -604,7 +560,7 @@ void RenderProcessHost::OnMessageReceived(const IPC::Message& msg) {
}
// dispatch incoming messages to the appropriate TabContents
- IPC::Channel::Listener* listener = listeners_.Lookup(msg.routing_id());
+ IPC::Channel::Listener* listener = GetListenerByID(msg.routing_id());
if (!listener) {
if (msg.is_sync()) {
// The listener has gone away, so we must respond or else the caller will
@@ -618,7 +574,7 @@ void RenderProcessHost::OnMessageReceived(const IPC::Message& msg) {
listener->OnMessageReceived(msg);
}
-void RenderProcessHost::OnChannelConnected(int32 peer_pid) {
+void BrowserRenderProcessHost::OnChannelConnected(int32 peer_pid) {
// process_ is not NULL if we created the renderer process
if (!process_.handle()) {
if (GetCurrentProcessId() == peer_pid) {
@@ -639,8 +595,20 @@ void RenderProcessHost::OnChannelConnected(int32 peer_pid) {
}
}
+// Static. This function can be called from the IO Thread or from the UI thread.
+void BrowserRenderProcessHost::BadMessageTerminateProcess(uint16 msg_type,
+ HANDLE process) {
+ LOG(ERROR) << "bad message " << msg_type << " terminating renderer.";
+ if (BrowserRenderProcessHost::run_renderer_in_process()) {
+ // In single process mode it is better if we don't suicide but just crash.
+ CHECK(false);
+ }
+ NOTREACHED();
+ ::TerminateProcess(process, ResultCodes::KILLED_BAD_MESSAGE);
+}
+
// indicates the renderer process has exited
-void RenderProcessHost::OnObjectSignaled(HANDLE object) {
+void BrowserRenderProcessHost::OnObjectSignaled(HANDLE object) {
DCHECK(process_.handle());
DCHECK(channel_.get());
DCHECK_EQ(object, process_.handle());
@@ -671,16 +639,18 @@ void RenderProcessHost::OnObjectSignaled(HANDLE object) {
// at this point, this object should be deleted
}
-// Used to send responses to resource requests
-bool RenderProcessHost::Send(IPC::Message* msg) {
- if (!channel_.get()) {
- delete msg;
- return false;
+void BrowserRenderProcessHost::Unregister() {
+ // RenderProcessHost::Unregister will clean up the host_id_, so we must
+ // do our cleanup that uses that variable before we call it.
+ if (host_id() >= 0) {
+ CacheManagerHost::GetInstance()->Remove(host_id());
+ RendererSecurityPolicy::GetInstance()->Remove(host_id());
}
- return channel_->Send(msg);
+
+ RenderProcessHost::Unregister();
}
-void RenderProcessHost::OnPageContents(const GURL& url,
+void BrowserRenderProcessHost::OnPageContents(const GURL& url,
int32 page_id,
const std::wstring& contents) {
Profile* p = profile();
@@ -692,57 +662,12 @@ void RenderProcessHost::OnPageContents(const GURL& url,
hs->SetPageContents(url, contents);
}
-void RenderProcessHost::OnUpdatedCacheStats(
+void BrowserRenderProcessHost::OnUpdatedCacheStats(
const CacheManager::UsageStats& stats) {
CacheManagerHost::GetInstance()->ObserveStats(host_id(), stats);
}
-// static
-RenderProcessHost::iterator RenderProcessHost::begin() {
- return all_hosts.begin();
-}
-
-// static
-RenderProcessHost::iterator RenderProcessHost::end() {
- return all_hosts.end();
-}
-
-// static
-size_t RenderProcessHost::size() {
- return all_hosts.size();
-}
-
-// Returns true if the given host is suitable for launching a new view
-// associated with the given profile.
-// TODO(jabdelmalek): do we want to avoid processes with hung renderers
-// or with a large memory consumption?
-static bool IsSuitableHost(Profile* profile, RenderProcessHost* host) {
- return host->profile() == profile;
-}
-
-// static
-RenderProcessHost* RenderProcessHost::GetExistingProcessHost(Profile* profile) {
- // First figure out which existing renderers we can use
- std::vector<RenderProcessHost*> suitable_renderers;
- suitable_renderers.reserve(all_hosts.size());
-
- for (IDMap<RenderProcessHost>::const_iterator iter = all_hosts.begin();
- iter != all_hosts.end(); ++iter) {
- if (IsSuitableHost(profile, iter->second))
- suitable_renderers.push_back(iter->second);
- }
-
- // Now pick a random suitable renderer, if we have any
- if (!suitable_renderers.empty()) {
- int suitable_count = static_cast<int>(suitable_renderers.size());
- int random_index = base::RandInt(0, suitable_count - 1);
- return suitable_renderers[random_index];
- }
-
- return NULL;
-}
-
-void RenderProcessHost::SetBackgrounded(bool backgrounded) {
+void BrowserRenderProcessHost::SetBackgrounded(bool backgrounded) {
// If the process_ is NULL, the process hasn't been created yet.
if (process_.handle()) {
bool rv = process_.SetProcessBackgrounded(backgrounded);
@@ -772,39 +697,10 @@ void RenderProcessHost::SetBackgrounded(bool backgrounded) {
backgrounded_ = backgrounded;
}
-void RenderProcessHost::WidgetRestored() {
- // Verify we were properly backgrounded.
- DCHECK(backgrounded_ == (visible_widgets_ == 0));
- visible_widgets_++;
- SetBackgrounded(false);
-}
-
-void RenderProcessHost::WidgetHidden() {
- // On startup, the browser will call Hide
- if (backgrounded_)
- return;
-
- DCHECK(backgrounded_ == (visible_widgets_ == 0));
- visible_widgets_--;
- DCHECK(visible_widgets_ >= 0);
- if (visible_widgets_ == 0) {
- DCHECK(!backgrounded_);
- SetBackgrounded(true);
- }
-}
-
-void RenderProcessHost::AddWord(const std::wstring& word) {
- base::Thread* io_thread = g_browser_process->io_thread();
- if (profile_->GetSpellChecker()) {
- io_thread->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(
- profile_->GetSpellChecker(), &SpellChecker::AddWord, word));
- }
-}
-
// NotificationObserver implementation.
-void RenderProcessHost::Observe(NotificationType type,
- const NotificationSource& source,
- const NotificationDetails& details) {
+void BrowserRenderProcessHost::Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
switch (type) {
case NOTIFY_PREF_CHANGED: {
std::wstring* pref_name_in = Details<std::wstring>(details).ptr();
@@ -832,19 +728,3 @@ void RenderProcessHost::Observe(NotificationType type,
}
}
}
-
-// static
-bool RenderProcessHost::ShouldTryToUseExistingProcessHost() {
- unsigned int renderer_process_count =
- static_cast<unsigned int>(all_hosts.size());
-
- // NOTE: Sometimes it's necessary to create more render processes than
- // GetMaxRendererProcessCount(), for instance when we want to create
- // a renderer process for a profile that has no existing renderers.
- // This is OK in moderation, since the GetMaxRendererProcessCount()
- // is conservative.
-
- return run_renderer_in_process() ||
- (renderer_process_count >= GetMaxRendererProcessCount());
-}
-
diff --git a/chrome/browser/renderer_host/browser_render_process_host.h b/chrome/browser/renderer_host/browser_render_process_host.h
new file mode 100644
index 0000000..2f766df
--- /dev/null
+++ b/chrome/browser/renderer_host/browser_render_process_host.h
@@ -0,0 +1,160 @@
+// Copyright (c) 2006-2008 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 CHROME_BROWSER_RENDERER_HOST_BROWSER_RENDER_PROCESS_HOST_H_
+#define CHROME_BROWSER_RENDERER_HOST_BROWSER_RENDER_PROCESS_HOST_H_
+
+#include <limits>
+#include <set>
+#include <vector>
+#include <windows.h>
+
+#include "base/id_map.h"
+#include "base/object_watcher.h"
+#include "base/rand_util.h"
+#include "base/ref_counted.h"
+#include "base/scoped_handle.h"
+#include "base/scoped_ptr.h"
+#include "chrome/browser/renderer_host/render_process_host.h"
+#include "chrome/common/notification_service.h"
+#include "chrome/common/render_messages.h"
+
+class PrefService;
+class RenderWidgetHelper;
+class WebContents;
+
+namespace base {
+class Thread;
+}
+
+// Implements a concrete RenderProcessHost for the browser process for talking
+// to actual renderer processes (as opposed to mocks).
+//
+// Represents the browser side of the browser <--> renderer communication
+// channel. There will be one RenderProcessHost per renderer process.
+//
+// This object is refcounted so that it can release its resources when all
+// hosts using it go away.
+//
+// This object communicates back and forth with the RenderProcess object
+// running in the renderer process. Each RenderProcessHost and RenderProcess
+// keeps a list of RenderView (renderer) and WebContents (browser) which
+// are correlated with IDs. This way, the Views and the corresponding ViewHosts
+// communicate through the two process objects.
+class BrowserRenderProcessHost : public RenderProcessHost,
+ public base::ObjectWatcher::Delegate,
+ public NotificationObserver {
+ public:
+ explicit BrowserRenderProcessHost(Profile* profile);
+ ~BrowserRenderProcessHost();
+
+ // RenderProcessHost implementation (public portion).
+ virtual bool Init();
+ virtual int GetNextRoutingID();
+ virtual void CancelResourceRequests(int render_widget_id);
+ virtual void CrossSiteClosePageACK(int new_render_process_host_id,
+ int new_request_id);
+ virtual bool WaitForPaintMsg(int render_widget_id,
+ const base::TimeDelta& max_delay,
+ IPC::Message* msg);
+ virtual void ReceivedBadMessage(uint16 msg_type);
+ virtual void WidgetRestored();
+ virtual void WidgetHidden();
+ virtual void AddWord(const std::wstring& word);
+ virtual bool FastShutdownIfPossible();
+
+ // IPC::Channel::Sender via RenderProcessHost.
+ virtual bool Send(IPC::Message* msg);
+
+ // IPC::Channel::Listener via RenderProcessHost.
+ virtual void OnMessageReceived(const IPC::Message& msg);
+ virtual void OnChannelConnected(int32 peer_pid);
+
+ static void RegisterPrefs(PrefService* prefs);
+
+ // If the a process has sent a message that cannot be decoded, it is deemed
+ // corrupted and thus needs to be terminated using this call. This function
+ // can be safely called from any thread.
+ static void BadMessageTerminateProcess(uint16 msg_type, HANDLE renderer);
+
+ // ObjectWatcher::Delegate
+ virtual void OnObjectSignaled(HANDLE object);
+
+ // NotificationObserver implementation.
+ virtual void Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details);
+
+ private:
+ // RenderProcessHost implementation (protected portion).
+ virtual void Unregister();
+
+ // Control message handlers.
+ void OnPageContents(const GURL& url, int32 page_id,
+ const std::wstring& contents);
+ // Clipboard messages
+ void OnClipboardWriteHTML(const std::wstring& markup, const GURL& src_url);
+ void OnClipboardWriteBookmark(const std::wstring& title, const GURL& url);
+ void OnClipboardWriteBitmap(base::SharedMemoryHandle bitmap, gfx::Size size);
+ void OnClipboardIsFormatAvailable(unsigned int format, bool* result);
+ void OnClipboardReadText(std::wstring* result);
+ void OnClipboardReadAsciiText(std::string* result);
+ void OnClipboardReadHTML(std::wstring* markup, GURL* src_url);
+ void OnUpdatedCacheStats(const CacheManager::UsageStats& stats);
+
+ // Initialize support for visited links. Send the renderer process its initial
+ // set of visited links.
+ void InitVisitedLinks();
+
+ // Initialize support for user scripts. Send the renderer process its initial
+ // set of scripts and listen for updates to scripts.
+ void InitUserScripts();
+
+ // Sends the renderer process a new set of user scripts.
+ void SendUserScriptsUpdate(base::SharedMemory* shared_memory);
+
+ // Gets a handle to the renderer process, normalizing the case where we were
+ // started with --single-process.
+ base::ProcessHandle GetRendererProcessHandle();
+
+ // Callers can reduce the RenderProcess' priority.
+ // Returns true if the priority is backgrounded; false otherwise.
+ void SetBackgrounded(bool boost);
+
+ // Used to watch the renderer process handle.
+ base::ObjectWatcher watcher_;
+
+ // The count of currently visible widgets. Since the host can be a container
+ // for multiple widgets, it uses this count to determine when it should be
+ // backgrounded.
+ int32 visible_widgets_;
+
+ // Does this process have backgrounded priority.
+ bool backgrounded_;
+
+ // Used to allow a RenderWidgetHost to intercept various messages on the
+ // IO thread.
+ scoped_refptr<RenderWidgetHelper> widget_helper_;
+
+ DISALLOW_COPY_AND_ASSIGN(BrowserRenderProcessHost);
+};
+
+// Generates a unique channel name for a child renderer/plugin process.
+// The "instance" pointer value is baked into the channel id.
+inline std::wstring GenerateRandomChannelID(void* instance) {
+ // Note: the string must start with the current process id, this is how
+ // child processes determine the pid of the parent.
+ // Build the channel ID. This is composed of a unique identifier for the
+ // parent browser process, an identifier for the renderer/plugin instance,
+ // and a random component. We use a random component so that a hacked child
+ // process can't cause denial of service by causing future named pipe creation
+ // to fail.
+ return StringPrintf(L"%d.%x.%d",
+ GetCurrentProcessId(), instance,
+ base::RandInt(0, std::numeric_limits<int>::max()));
+}
+
+
+#endif // CHROME_BROWSER_RENDERER_HOST_BROWSER_RENDER_PROCESS_HOST_H_
+
diff --git a/chrome/browser/renderer_host/render_process_host.cc b/chrome/browser/renderer_host/render_process_host.cc
new file mode 100644
index 0000000..18323f4
--- /dev/null
+++ b/chrome/browser/renderer_host/render_process_host.cc
@@ -0,0 +1,159 @@
+// Copyright (c) 2009 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.
+
+#include "chrome/browser/renderer_host/render_process_host.h"
+
+#include "base/rand_util.h"
+#include "base/sys_info.h"
+#include "chrome/common/chrome_constants.h"
+#include "chrome/common/notification_service.h"
+
+namespace {
+
+unsigned int GetMaxRendererProcessCount() {
+ // Defines the maximum number of renderer processes according to the amount
+ // of installed memory as reported by the OS. The table values are calculated
+ // by assuming that you want the renderers to use half of the installed ram
+ // and assuming that each tab uses ~25MB.
+ static const int kMaxRenderersByRamTier[] = {
+ 4, // less than 256MB
+ 8, // 256MB
+ 12, // 512MB
+ 16, // 768MB
+ };
+
+ static unsigned int max_count = 0;
+ if (!max_count) {
+ int memory_tier = base::SysInfo::AmountOfPhysicalMemoryMB() / 256;
+ if (memory_tier >= arraysize(kMaxRenderersByRamTier))
+ max_count = chrome::kMaxRendererProcessCount;
+ else
+ max_count = kMaxRenderersByRamTier[memory_tier];
+ }
+ return max_count;
+}
+
+// Returns true if the given host is suitable for launching a new view
+// associated with the given profile.
+// TODO(jabdelmalek): do we want to avoid processes with hung renderers
+// or with a large memory consumption?
+static bool IsSuitableHost(Profile* profile, RenderProcessHost* host) {
+ return host->profile() == profile;
+}
+
+// the global list of all renderer processes
+IDMap<RenderProcessHost> all_hosts;
+
+} // namespace
+
+bool RenderProcessHost::run_renderer_in_process_ = false;
+
+RenderProcessHost::RenderProcessHost(Profile* profile)
+ : max_page_id_(-1),
+ notified_termination_(false),
+ profile_(profile) {
+ host_id_ = all_hosts.Add(this);
+}
+
+RenderProcessHost::~RenderProcessHost() {
+}
+
+void RenderProcessHost::Attach(IPC::Channel::Listener* listener,
+ int routing_id) {
+ listeners_.AddWithID(listener, routing_id);
+}
+
+void RenderProcessHost::Release(int listener_id) {
+ DCHECK(listeners_.Lookup(listener_id) != NULL);
+ listeners_.Remove(listener_id);
+
+ // Make sure that all associated resource requests are stopped.
+ CancelResourceRequests(listener_id);
+
+ // When no other owners of this object, we can delete ourselves
+ if (listeners_.IsEmpty()) {
+ if (!notified_termination_) {
+ bool close_expected = true;
+ NotificationService::current()->Notify(
+ NOTIFY_RENDERER_PROCESS_TERMINATED,
+ Source<RenderProcessHost>(this),
+ Details<bool>(&close_expected));
+ notified_termination_ = true;
+ }
+ Unregister();
+ MessageLoop::current()->DeleteSoon(FROM_HERE, this);
+ }
+}
+
+void RenderProcessHost::ReportExpectingClose(int32 listener_id) {
+ listeners_expecting_close_.insert(listener_id);
+}
+
+void RenderProcessHost::UpdateMaxPageID(int32 page_id) {
+ if (page_id > max_page_id_)
+ max_page_id_ = page_id;
+}
+
+// static
+RenderProcessHost::iterator RenderProcessHost::begin() {
+ return all_hosts.begin();
+}
+
+// static
+RenderProcessHost::iterator RenderProcessHost::end() {
+ return all_hosts.end();
+}
+
+// static
+size_t RenderProcessHost::size() {
+ return all_hosts.size();
+}
+
+// static
+RenderProcessHost* RenderProcessHost::FromID(int render_process_id) {
+ return all_hosts.Lookup(render_process_id);
+}
+
+// static
+bool RenderProcessHost::ShouldTryToUseExistingProcessHost() {
+ unsigned int renderer_process_count =
+ static_cast<unsigned int>(all_hosts.size());
+
+ // NOTE: Sometimes it's necessary to create more render processes than
+ // GetMaxRendererProcessCount(), for instance when we want to create
+ // a renderer process for a profile that has no existing renderers.
+ // This is OK in moderation, since the GetMaxRendererProcessCount()
+ // is conservative.
+
+ return run_renderer_in_process() ||
+ (renderer_process_count >= GetMaxRendererProcessCount());
+}
+
+// static
+RenderProcessHost* RenderProcessHost::GetExistingProcessHost(Profile* profile) {
+ // First figure out which existing renderers we can use.
+ std::vector<RenderProcessHost*> suitable_renderers;
+ suitable_renderers.reserve(size());
+
+ for (iterator iter = begin(); iter != end(); ++iter) {
+ if (IsSuitableHost(profile, iter->second))
+ suitable_renderers.push_back(iter->second);
+ }
+
+ // Now pick a random suitable renderer, if we have any.
+ if (!suitable_renderers.empty()) {
+ int suitable_count = static_cast<int>(suitable_renderers.size());
+ int random_index = base::RandInt(0, suitable_count - 1);
+ return suitable_renderers[random_index];
+ }
+
+ return NULL;
+}
+
+void RenderProcessHost::Unregister() {
+ if (host_id_ >= 0) {
+ all_hosts.Remove(host_id_);
+ host_id_ = -1;
+ }
+}
diff --git a/chrome/browser/renderer_host/render_process_host.h b/chrome/browser/renderer_host/render_process_host.h
new file mode 100644
index 0000000..46e1353
--- /dev/null
+++ b/chrome/browser/renderer_host/render_process_host.h
@@ -0,0 +1,203 @@
+// Copyright (c) 2009 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 CHROME_BROWSER_RENDERER_HOST_RENDER_PROCESS_HOST_H_
+#define CHROME_BROWSER_RENDERER_HOST_RENDER_PROCESS_HOST_H_
+
+#include "base/basictypes.h"
+#include "base/id_map.h"
+#include "base/process.h"
+#include "base/scoped_ptr.h"
+#include "chrome/common/ipc_sync_channel.h"
+
+class Profile;
+
+// Virtual interface that represents the browser side of the browser <->
+// renderer communication channel. There will generally be one
+// RenderProcessHost per renderer process.
+//
+// The concrete implementation of this class for normal use is the
+// BrowserRenderProcessHost. It may also be implemented by a testing interface
+// for mocking purposes.
+class RenderProcessHost : public IPC::Channel::Sender,
+ public IPC::Channel::Listener {
+ public:
+ typedef IDMap<RenderProcessHost>::const_iterator iterator;
+
+ RenderProcessHost(Profile* profile);
+ virtual ~RenderProcessHost();
+
+ // Returns the user profile associated with this renderer process.
+ Profile* profile() const { return profile_; }
+
+ // Returns the unique identifier for this host. 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).
+ int host_id() const { return host_id_; }
+
+ // Returns the process object associated with the child process. In certain
+ // tests or single-process mode, this will actually represent the current
+ // process.
+ const base::Process& process() const { return process_; }
+
+ // May return NULL if there is no connection.
+ IPC::SyncChannel* channel() { return channel_.get(); }
+
+ // 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.
+ void Attach(IPC::Channel::Listener* listener, int routing_id);
+
+ // See Attach()
+ void Release(int listener_id);
+
+ // 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.
+ void ReportExpectingClose(int32 listener_id);
+
+ // Allows iteration over this RenderProcessHost's RenderViewHost listeners.
+ // Use from UI thread only.
+ typedef IDMap<IPC::Channel::Listener>::const_iterator listeners_iterator;
+ listeners_iterator listeners_begin() {
+ return listeners_.begin();
+ }
+ listeners_iterator listeners_end() {
+ return listeners_.end();
+ }
+
+ IPC::Channel::Listener* GetListenerByID(int routing_id) {
+ return listeners_.Lookup(routing_id);
+ }
+
+ // 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.
+ void UpdateMaxPageID(int32 page_id);
+
+ // Virtual interface ---------------------------------------------------------
+
+ // 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() = 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 ClosePage_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
+ // onunload handler.
+ virtual void CrossSiteClosePageACK(int new_render_process_host_id,
+ int new_request_id) = 0;
+
+ // Called on the UI thread to wait for the next PaintRect message for the
+ // specified render widget. Returns true if successful, and the msg out-
+ // param will contain a copy of the received PaintRect message.
+ virtual bool WaitForPaintMsg(int render_widget_id,
+ const base::TimeDelta& max_delay,
+ IPC::Message* msg) = 0;
+
+ // Called when a received message cannot be decoded.
+ virtual void ReceivedBadMessage(uint16 msg_type) = 0;
+
+ // Track the count of visible widgets. Called by listeners to register and
+ // unregister visibility.
+ virtual void WidgetRestored() = 0;
+ virtual void WidgetHidden() = 0;
+
+ // Add a word in the spellchecker.
+ virtual void AddWord(const std::wstring& word) = 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;
+
+ // 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() {
+ return run_renderer_in_process_;
+ }
+ static void set_run_renderer_in_process(bool value) {
+ run_renderer_in_process_ = value;
+ }
+
+ // Allows iteration over all the RenderProcessHosts in the browser. Note
+ // that each host may not be active, and therefore may have NULL channels.
+ // This is just a standard STL iterator, so it is not valid if the list
+ // of RenderProcessHosts changes between iterations.
+ static iterator begin();
+ static iterator end();
+ static size_t size(); // TODO(brettw) rename this, it's very unclear.
+
+ // 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 profile, if
+ // possible. The renderer process is chosen randomly from the
+ // processes associated with the given profile.
+ // Returns NULL if no suitable renderer process is available.
+ static RenderProcessHost* GetExistingProcessHost(Profile* profile);
+
+ protected:
+ // Unregister this object from all globals that reference it.
+ // This would naturally be part of the destructor, but we destruct
+ // asynchronously.
+ //
+ // This can be overridden by derived classes to add their own unregister code,
+ // but you should be sure to always call this one AT THE END of your own.
+ virtual void Unregister();
+
+ base::Process process_;
+
+ // A proxy for our IPC::Channel that lives on the IO thread (see
+ // browser_process.h)
+ scoped_ptr<IPC::SyncChannel> channel_;
+
+ // the registered listeners. When this list is empty or all NULL, we should
+ // delete ourselves
+ IDMap<IPC::Channel::Listener> listeners_;
+
+ // The maximum page ID we've ever seen from the renderer process.
+ int32 max_page_id_;
+
+ // Indicates whether we have notified that the process has terminated. We
+ // only want to send this out once.
+ bool notified_termination_;
+
+ private:
+ int host_id_;
+
+ Profile* profile_;
+
+ // set of listeners that expect the renderer process to close
+ std::set<int> listeners_expecting_close_;
+
+ // See getter above.
+ static bool run_renderer_in_process_;
+
+ DISALLOW_COPY_AND_ASSIGN(RenderProcessHost);
+};
+
+#endif // CHROME_BROWSER_RENDERER_HOST_RENDER_PROCESS_HOST_H_
diff --git a/chrome/browser/resource_message_filter.cc b/chrome/browser/resource_message_filter.cc
index c15f4c1..5732ed9 100644
--- a/chrome/browser/resource_message_filter.cc
+++ b/chrome/browser/resource_message_filter.cc
@@ -14,7 +14,7 @@
#include "chrome/browser/printing/printer_query.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/plugin_service.h"
-#include "chrome/browser/render_process_host.h"
+#include "chrome/browser/renderer_host/browser_render_process_host.h"
#include "chrome/browser/render_widget_helper.h"
#include "chrome/browser/spellchecker.h"
#include "chrome/common/chrome_plugin_lib.h"
@@ -159,8 +159,8 @@ bool ResourceMessageFilter::OnMessageReceived(const IPC::Message& message) {
IPC_END_MESSAGE_MAP_EX()
if (!msg_is_ok) {
- RenderProcessHost::BadMessageTerminateProcess(message.type(),
- render_handle_);
+ BrowserRenderProcessHost::BadMessageTerminateProcess(message.type(),
+ render_handle_);
}
return handled;
diff --git a/chrome/browser/site_instance_unittest.cc b/chrome/browser/site_instance_unittest.cc
index 16e6883..647a221 100644
--- a/chrome/browser/site_instance_unittest.cc
+++ b/chrome/browser/site_instance_unittest.cc
@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "chrome/browser/render_view_host.h"
+#include "chrome/browser/renderer_host/browser_render_process_host.h"
#include "chrome/browser/tab_contents/navigation_entry.h"
#include "chrome/browser/tab_contents/web_contents.h"
#include "chrome/common/render_messages.h"
@@ -175,8 +176,10 @@ TEST_F(SiteInstanceTest, UpdateMaxPageID) {
TEST_F(SiteInstanceTest, GetProcess) {
// Ensure that GetProcess returns the process based on its host id.
scoped_ptr<TestingProfile> profile(new TestingProfile());
- scoped_ptr<RenderProcessHost> host1(new RenderProcessHost(profile.get()));
- scoped_refptr<SiteInstance> instance(SiteInstance::CreateSiteInstance(profile.get()));
+ scoped_ptr<BrowserRenderProcessHost> host1(
+ new BrowserRenderProcessHost(profile.get()));
+ scoped_refptr<SiteInstance> instance(
+ SiteInstance::CreateSiteInstance(profile.get()));
instance.get()->set_process_host_id(host1.get()->host_id());
EXPECT_EQ(host1.get(), instance.get()->GetProcess());
diff --git a/chrome/browser/tab_contents/navigation_entry.h b/chrome/browser/tab_contents/navigation_entry.h
index 3ffbfdb..7e6b1f3 100644
--- a/chrome/browser/tab_contents/navigation_entry.h
+++ b/chrome/browser/tab_contents/navigation_entry.h
@@ -7,6 +7,7 @@
#include "base/basictypes.h"
#include "base/scoped_ptr.h"
+#include "base/string_util.h"
#include "chrome/app/theme/theme_resources.h"
#include "chrome/browser/security_style.h"
#include "chrome/browser/tab_contents/site_instance.h"
diff --git a/chrome/browser/tab_contents/site_instance.cc b/chrome/browser/tab_contents/site_instance.cc
index a303f85..71a171e 100644
--- a/chrome/browser/tab_contents/site_instance.cc
+++ b/chrome/browser/tab_contents/site_instance.cc
@@ -4,6 +4,7 @@
#include "chrome/browser/tab_contents/site_instance.h"
+#include "chrome/browser/renderer_host/browser_render_process_host.h"
#include "net/base/registry_controlled_domain.h"
SiteInstance::~SiteInstance() {
@@ -28,7 +29,7 @@ RenderProcessHost* SiteInstance::GetProcess() {
// Otherwise (or if that fails), create a new one.
if (!process)
- process = new RenderProcessHost(browsing_instance_->profile());
+ process = new BrowserRenderProcessHost(browsing_instance_->profile());
// Update our host ID, so all pages in this SiteInstance will use
// the correct process.
diff --git a/chrome/browser/tab_contents/site_instance.h b/chrome/browser/tab_contents/site_instance.h
index 6759fe3..b0aa3ed 100644
--- a/chrome/browser/tab_contents/site_instance.h
+++ b/chrome/browser/tab_contents/site_instance.h
@@ -2,11 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef CHROME_BROWSER_SITE_INSTANCE_H__
-#define CHROME_BROWSER_SITE_INSTANCE_H__
+#ifndef CHROME_BROWSER_SITE_INSTANCE_H_
+#define CHROME_BROWSER_SITE_INSTANCE_H_
#include "chrome/browser/browsing_instance.h"
-#include "chrome/browser/render_process_host.h"
+#include "chrome/browser/renderer_host/render_process_host.h"
#include "googleurl/src/gurl.h"
///////////////////////////////////////////////////////////////////////////////
@@ -152,5 +152,4 @@ class SiteInstance : public base::RefCounted<SiteInstance> {
DISALLOW_EVIL_CONSTRUCTORS(SiteInstance);
};
-#endif // CHROME_BROWSER_SITE_INSTANCE_H__
-
+#endif // CHROME_BROWSER_SITE_INSTANCE_H_
diff --git a/chrome/browser/tab_contents/tab_contents_factory.cc b/chrome/browser/tab_contents/tab_contents_factory.cc
index 5151555..9a8aefe 100644
--- a/chrome/browser/tab_contents/tab_contents_factory.cc
+++ b/chrome/browser/tab_contents/tab_contents_factory.cc
@@ -9,7 +9,7 @@
#include "chrome/browser/dom_ui/html_dialog_contents.h"
#include "chrome/browser/dom_ui/new_tab_ui.h"
#include "chrome/browser/profile.h"
-#include "chrome/browser/render_process_host.h"
+#include "chrome/browser/renderer_host/render_process_host.h"
#include "chrome/browser/debugger/debugger_contents.h"
#include "chrome/browser/tab_contents/about_internets_status_view.h"
#include "chrome/browser/tab_contents/ipc_status_view.h"
diff --git a/chrome/browser/tab_contents/tab_util.cc b/chrome/browser/tab_contents/tab_util.cc
index a1a2f4e..8cea595 100644
--- a/chrome/browser/tab_contents/tab_util.cc
+++ b/chrome/browser/tab_contents/tab_util.cc
@@ -5,7 +5,7 @@
#include "chrome/browser/tab_contents/tab_util.h"
#include "chrome/browser/render_view_host.h"
-#include "chrome/browser/render_process_host.h"
+#include "chrome/browser/renderer_host/render_process_host.h"
#include "chrome/browser/renderer_host/resource_dispatcher_host.h"
#include "chrome/browser/tab_contents/web_contents.h"
#include "net/url_request/url_request.h"
diff --git a/chrome/browser/task_manager.cc b/chrome/browser/task_manager.cc
index 31c28ca..878c734 100644
--- a/chrome/browser/task_manager.cc
+++ b/chrome/browser/task_manager.cc
@@ -10,7 +10,7 @@
#include "chrome/app/theme/theme_resources.h"
#include "chrome/browser/browser_list.h"
#include "chrome/browser/browser_process.h"
-#include "chrome/browser/render_process_host.h"
+#include "chrome/browser/renderer_host/render_process_host.h"
#include "chrome/browser/task_manager_resource_providers.h"
#include "chrome/browser/tab_contents/tab_util.h"
#include "chrome/browser/views/standard_layout.h"
diff --git a/chrome/browser/task_manager_resource_providers.cc b/chrome/browser/task_manager_resource_providers.cc
index be0ed1f..50b55ac 100644
--- a/chrome/browser/task_manager_resource_providers.cc
+++ b/chrome/browser/task_manager_resource_providers.cc
@@ -14,7 +14,7 @@
#include "chrome/browser/browser_list.h"
#include "chrome/browser/plugin_process_host.h"
#include "chrome/browser/plugin_service.h"
-#include "chrome/browser/render_process_host.h"
+#include "chrome/browser/renderer_host/render_process_host.h"
#include "chrome/browser/resource_message_filter.h"
#include "chrome/browser/tab_contents/tab_util.h"
#include "chrome/browser/tab_contents/web_contents.h"
diff --git a/chrome/test/testing_profile.h b/chrome/test/testing_profile.h
index 2d622a7..76fa86f 100644
--- a/chrome/test/testing_profile.h
+++ b/chrome/test/testing_profile.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef CHROME_TEST_TESTING_PROFILE_H__
-#define CHROME_TEST_TESTING_PROFILE_H__
+#ifndef CHROME_TEST_TESTING_PROFILE_H_
+#define CHROME_TEST_TESTING_PROFILE_H_
#include "base/base_paths.h"
#include "base/path_service.h"
@@ -207,4 +207,4 @@ class TestingProfile : public Profile {
bool last_session_exited_cleanly_;
};
-#endif // CHROME_TEST_TESTING_PROFILE_H__
+#endif // CHROME_TEST_TESTING_PROFILE_H_