Commit c76225b0 authored by ananta@chromium.org's avatar ananta@chromium.org

Provide a way for RenderProcessHosts to register themselves in the global host map.

This is in the form of static RegisterHost/UnregisterHost functions in the RenderProcessHostImpl class.

BUG=98716
TEST=No change in functionality. Hopefully it all compiles and works.
Review URL: http://codereview.chromium.org/8597005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@110635 0039d316-1c4b-4281-b951-d872f2087c98
parent e27489b6
...@@ -8,19 +8,11 @@ ...@@ -8,19 +8,11 @@
#include "base/message_loop.h" #include "base/message_loop.h"
#include "base/time.h" #include "base/time.h"
#include "content/browser/child_process_security_policy.h" #include "content/browser/child_process_security_policy.h"
#include "content/browser/renderer_host/render_process_host_impl.h"
#include "content/common/child_process_info.h" #include "content/common/child_process_info.h"
#include "content/public/browser/notification_service.h" #include "content/public/browser/notification_service.h"
#include "content/public/browser/notification_types.h" #include "content/public/browser/notification_types.h"
// This map is the global list of all renderer processes and is defined in
// render_process_host_impl.cc
// TODO(ananta)
// Clean up this dependency in a subsequent CL.
extern base::LazyInstance<
IDMap<content::RenderProcessHost>,
base::LeakyLazyInstanceTraits<IDMap<content::RenderProcessHost> > >
g_all_hosts;
MockRenderProcessHost::MockRenderProcessHost( MockRenderProcessHost::MockRenderProcessHost(
content::BrowserContext* browser_context) content::BrowserContext* browser_context)
: transport_dib_(NULL), : transport_dib_(NULL),
...@@ -33,7 +25,8 @@ MockRenderProcessHost::MockRenderProcessHost( ...@@ -33,7 +25,8 @@ MockRenderProcessHost::MockRenderProcessHost(
// Child process security operations can't be unit tested unless we add // Child process security operations can't be unit tested unless we add
// ourselves as an existing child process. // ourselves as an existing child process.
ChildProcessSecurityPolicy::GetInstance()->Add(GetID()); ChildProcessSecurityPolicy::GetInstance()->Add(GetID());
g_all_hosts.Get().AddWithID(this, GetID());
RenderProcessHostImpl::RegisterHost(GetID(), this);
} }
MockRenderProcessHost::~MockRenderProcessHost() { MockRenderProcessHost::~MockRenderProcessHost() {
...@@ -42,8 +35,7 @@ MockRenderProcessHost::~MockRenderProcessHost() { ...@@ -42,8 +35,7 @@ MockRenderProcessHost::~MockRenderProcessHost() {
if (factory_) if (factory_)
factory_->Remove(this); factory_->Remove(this);
// In unit tests, Release() might not have been called. // In unit tests, Release() might not have been called.
if (g_all_hosts.Get().Lookup(GetID())) RenderProcessHostImpl::UnregisterHost(GetID());
g_all_hosts.Get().Remove(GetID());
} }
void MockRenderProcessHost::EnableSendQueue() { void MockRenderProcessHost::EnableSendQueue() {
...@@ -173,7 +165,7 @@ void MockRenderProcessHost::Cleanup() { ...@@ -173,7 +165,7 @@ void MockRenderProcessHost::Cleanup() {
content::Source<RenderProcessHost>(this), content::Source<RenderProcessHost>(this),
content::NotificationService::NoDetails()); content::NotificationService::NoDetails());
MessageLoop::current()->DeleteSoon(FROM_HERE, this); MessageLoop::current()->DeleteSoon(FROM_HERE, this);
g_all_hosts.Get().Remove(GetID()); RenderProcessHostImpl::UnregisterHost(GetID());
} }
} }
......
...@@ -249,14 +249,14 @@ static bool IsSuitableHost(content::RenderProcessHost* host, ...@@ -249,14 +249,14 @@ static bool IsSuitableHost(content::RenderProcessHost* host,
return content::GetContentClient()->browser()->IsSuitableHost(host, site_url); return content::GetContentClient()->browser()->IsSuitableHost(host, site_url);
} }
} // namespace
// the global list of all renderer processes // the global list of all renderer processes
base::LazyInstance< base::LazyInstance<
IDMap<content::RenderProcessHost>, IDMap<content::RenderProcessHost>,
base::LeakyLazyInstanceTraits<IDMap<content::RenderProcessHost> > > base::LeakyLazyInstanceTraits<IDMap<content::RenderProcessHost> > >
g_all_hosts = LAZY_INSTANCE_INITIALIZER; g_all_hosts = LAZY_INSTANCE_INITIALIZER;
} // namespace
// static // static
bool g_run_renderer_in_process_ = false; bool g_run_renderer_in_process_ = false;
...@@ -323,7 +323,7 @@ RenderProcessHostImpl::RenderProcessHostImpl( ...@@ -323,7 +323,7 @@ RenderProcessHostImpl::RenderProcessHostImpl(
base::PLATFORM_FILE_WRITE); base::PLATFORM_FILE_WRITE);
CHECK(!content::ExitedMainMessageLoop()); CHECK(!content::ExitedMainMessageLoop());
g_all_hosts.Get().AddWithID(this, GetID()); RegisterHost(GetID(), this);
g_all_hosts.Get().set_check_on_null_data(true); g_all_hosts.Get().set_check_on_null_data(true);
// Initialize |child_process_activity_time_| to a reasonable value. // Initialize |child_process_activity_time_| to a reasonable value.
mark_child_process_activity_time(); mark_child_process_activity_time();
...@@ -344,8 +344,7 @@ RenderProcessHostImpl::~RenderProcessHostImpl() { ...@@ -344,8 +344,7 @@ RenderProcessHostImpl::~RenderProcessHostImpl() {
} }
ClearTransportDIBCache(); ClearTransportDIBCache();
if (g_all_hosts.Get().Lookup(GetID())) UnregisterHost(GetID());
g_all_hosts.Get().Remove(GetID());
} }
void RenderProcessHostImpl::EnableSendQueue() { void RenderProcessHostImpl::EnableSendQueue() {
...@@ -1104,6 +1103,18 @@ bool RenderProcessHostImpl::FastShutdownStarted() const { ...@@ -1104,6 +1103,18 @@ bool RenderProcessHostImpl::FastShutdownStarted() const {
return fast_shutdown_started_; return fast_shutdown_started_;
} }
// static
void RenderProcessHostImpl::RegisterHost(int host_id,
content::RenderProcessHost* host) {
g_all_hosts.Get().AddWithID(host, host_id);
}
// static
void RenderProcessHostImpl::UnregisterHost(int host_id) {
if (g_all_hosts.Get().Lookup(host_id))
g_all_hosts.Get().Remove(host_id);
}
// static // static
bool content::RenderProcessHost::run_renderer_in_process() { bool content::RenderProcessHost::run_renderer_in_process() {
return g_run_renderer_in_process_; return g_run_renderer_in_process_;
......
...@@ -115,6 +115,11 @@ class CONTENT_EXPORT RenderProcessHostImpl ...@@ -115,6 +115,11 @@ class CONTENT_EXPORT RenderProcessHostImpl
child_process_activity_time_ = base::TimeTicks::Now(); child_process_activity_time_ = base::TimeTicks::Now();
} }
// Register/unregister the host identified by the host id in the global host
// list.
static void RegisterHost(int host_id, content::RenderProcessHost* host);
static void UnregisterHost(int host_id);
protected: protected:
// A proxy for our IPC::Channel that lives on the IO thread (see // A proxy for our IPC::Channel that lives on the IO thread (see
// browser_process.h) // browser_process.h)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment