Commit 039b84a4 authored by nasko@chromium.org's avatar nasko@chromium.org

Refactor RenderProcessHost to use IPC::Listener instead of RenderWidgetHost

BUG=248160

Review URL: https://chromiumcodereview.appspot.com/16431010

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@207913 0039d316-1c4b-4281-b951-d872f2087c98
parent 477e5843
...@@ -352,21 +352,12 @@ const icu::TimeZone* TimezoneSettingsBaseImpl::GetKnownTimezoneOrNull( ...@@ -352,21 +352,12 @@ const icu::TimeZone* TimezoneSettingsBaseImpl::GetKnownTimezoneOrNull(
} }
void TimezoneSettingsBaseImpl::NotifyRenderers() { void TimezoneSettingsBaseImpl::NotifyRenderers() {
content::RenderProcessHost::iterator process_iterator( content::RenderWidgetHost::List widgets =
content::RenderProcessHost::AllHostsIterator()); content::RenderWidgetHost::GetRenderWidgetHosts();
for (; !process_iterator.IsAtEnd(); process_iterator.Advance()) { for (size_t i = 0; i < widgets.size(); ++i) {
content::RenderProcessHost* render_process_host = if (widgets[i]->IsRenderView()) {
process_iterator.GetCurrentValue(); content::RenderViewHost* view = content::RenderViewHost::From(widgets[i]);
content::RenderProcessHost::RenderWidgetHostsIterator widget_iterator( view->NotifyTimezoneChange();
render_process_host->GetRenderWidgetHostsIterator());
for (; !widget_iterator.IsAtEnd(); widget_iterator.Advance()) {
const content::RenderWidgetHost* widget =
widget_iterator.GetCurrentValue();
if (widget->IsRenderView()) {
content::RenderViewHost* view = content::RenderViewHost::From(
const_cast<content::RenderWidgetHost*>(widget));
view->NotifyTimezoneChange();
}
} }
} }
} }
......
...@@ -112,16 +112,15 @@ ListValue* GetTabsForProcess(int process_id) { ...@@ -112,16 +112,15 @@ ListValue* GetTabsForProcess(int process_id) {
int tab_id = -1; int tab_id = -1;
// We need to loop through all the RVHs to ensure we collect the set of all // We need to loop through all the RVHs to ensure we collect the set of all
// tabs using this renderer process. // tabs using this renderer process.
content::RenderProcessHost::RenderWidgetHostsIterator iter( content::RenderWidgetHost::List widgets =
rph->GetRenderWidgetHostsIterator()); content::RenderWidgetHost::GetRenderWidgetHosts();
for (; !iter.IsAtEnd(); iter.Advance()) { for (size_t i = 0; i < widgets.size(); ++i) {
const content::RenderWidgetHost* widget = iter.GetCurrentValue(); if (widgets[i]->GetProcess()->GetID() != process_id)
DCHECK(widget); continue;
if (!widget || !widget->IsRenderView()) if (!widgets[i]->IsRenderView())
continue; continue;
content::RenderViewHost* host = content::RenderViewHost::From( content::RenderViewHost* host = content::RenderViewHost::From(widgets[i]);
const_cast<content::RenderWidgetHost*>(widget));
content::WebContents* contents = content::WebContents* contents =
content::WebContents::FromRenderViewHost(host); content::WebContents::FromRenderViewHost(host);
if (contents) { if (contents) {
......
...@@ -214,11 +214,10 @@ void MemoryDetails::CollectChildInfoOnUIThread() { ...@@ -214,11 +214,10 @@ void MemoryDetails::CollectChildInfoOnUIThread() {
ProcessMemoryInformation& process = ProcessMemoryInformation& process =
chrome_browser->processes[index]; chrome_browser->processes[index];
for (content::RenderProcessHost::iterator renderer_iter( RenderWidgetHost::List widgets = RenderWidgetHost::GetRenderWidgetHosts();
content::RenderProcessHost::AllHostsIterator()); for (size_t i = 0; i < widgets.size(); ++i) {
!renderer_iter.IsAtEnd(); renderer_iter.Advance()) {
content::RenderProcessHost* render_process_host = content::RenderProcessHost* render_process_host =
renderer_iter.GetCurrentValue(); widgets[i]->GetProcess();
DCHECK(render_process_host); DCHECK(render_process_host);
// Ignore processes that don't have a connection, such as crashed tabs. // Ignore processes that don't have a connection, such as crashed tabs.
if (!render_process_host->HasConnection() || if (!render_process_host->HasConnection() ||
...@@ -238,110 +237,104 @@ void MemoryDetails::CollectChildInfoOnUIThread() { ...@@ -238,110 +237,104 @@ void MemoryDetails::CollectChildInfoOnUIThread() {
// The RenderProcessHost may host multiple WebContentses. Any // The RenderProcessHost may host multiple WebContentses. Any
// of them which contain diagnostics information make the whole // of them which contain diagnostics information make the whole
// process be considered a diagnostics process. // process be considered a diagnostics process.
content::RenderProcessHost::RenderWidgetHostsIterator iter( if (!widgets[i]->IsRenderView())
render_process_host->GetRenderWidgetHostsIterator()); continue;
for (; !iter.IsAtEnd(); iter.Advance()) {
const RenderWidgetHost* widget = iter.GetCurrentValue();
DCHECK(widget);
if (!widget || !widget->IsRenderView())
continue;
RenderViewHost* host = RenderViewHost* host = RenderViewHost::From(widgets[i]);
RenderViewHost::From(const_cast<RenderWidgetHost*>(widget)); WebContents* contents = WebContents::FromRenderViewHost(host);
WebContents* contents = WebContents::FromRenderViewHost(host); GURL url;
GURL url; if (contents) {
if (contents) { url = contents->GetURL();
url = contents->GetURL(); SiteData* site_data =
SiteData* site_data = &chrome_browser->site_data[contents->GetBrowserContext()];
&chrome_browser->site_data[contents->GetBrowserContext()]; SiteDetails::CollectSiteInfo(contents, site_data);
SiteDetails::CollectSiteInfo(contents, site_data); }
} extensions::ViewType type = extensions::GetViewType(contents);
extensions::ViewType type = extensions::GetViewType(contents); if (host->GetEnabledBindings() & content::BINDINGS_POLICY_WEB_UI) {
if (host->GetEnabledBindings() & content::BINDINGS_POLICY_WEB_UI) { process.renderer_type = ProcessMemoryInformation::RENDERER_CHROME;
process.renderer_type = ProcessMemoryInformation::RENDERER_CHROME; } else if (extension_process_map &&
} else if (extension_process_map && extension_process_map->Contains(host->GetProcess()->GetID())) {
extension_process_map->Contains(host->GetProcess()->GetID())) { // For our purposes, don't count processes containing only hosted apps
// For our purposes, don't count processes containing only hosted apps // as extension processes. See also: crbug.com/102533.
// as extension processes. See also: crbug.com/102533. std::set<std::string> extension_ids =
std::set<std::string> extension_ids = extension_process_map->GetExtensionsInProcess(
extension_process_map->GetExtensionsInProcess( host->GetProcess()->GetID());
host->GetProcess()->GetID()); for (std::set<std::string>::iterator iter = extension_ids.begin();
for (std::set<std::string>::iterator iter = extension_ids.begin(); iter != extension_ids.end(); ++iter) {
iter != extension_ids.end(); ++iter) {
const Extension* extension =
extension_service->GetExtensionById(*iter, false);
if (extension && !extension->is_hosted_app()) {
process.renderer_type =
ProcessMemoryInformation::RENDERER_EXTENSION;
break;
}
}
}
if (extension_process_map &&
extension_process_map->Contains(host->GetProcess()->GetID())) {
const Extension* extension = const Extension* extension =
extension_service->extensions()->GetByID(url.host()); extension_service->GetExtensionById(*iter, false);
if (extension) { if (extension && !extension->is_hosted_app()) {
string16 title = UTF8ToUTF16(extension->name());
process.titles.push_back(title);
process.renderer_type = process.renderer_type =
ProcessMemoryInformation::RENDERER_EXTENSION; ProcessMemoryInformation::RENDERER_EXTENSION;
continue; break;
} }
} }
}
if (!contents) { if (extension_process_map &&
extension_process_map->Contains(host->GetProcess()->GetID())) {
const Extension* extension =
extension_service->extensions()->GetByID(url.host());
if (extension) {
string16 title = UTF8ToUTF16(extension->name());
process.titles.push_back(title);
process.renderer_type = process.renderer_type =
ProcessMemoryInformation::RENDERER_INTERSTITIAL; ProcessMemoryInformation::RENDERER_EXTENSION;
continue; continue;
} }
}
if (type == extensions::VIEW_TYPE_BACKGROUND_CONTENTS) { if (!contents) {
process.titles.push_back(UTF8ToUTF16(url.spec())); process.renderer_type =
process.renderer_type = ProcessMemoryInformation::RENDERER_INTERSTITIAL;
ProcessMemoryInformation::RENDERER_BACKGROUND_APP; continue;
continue; }
}
if (type == extensions::VIEW_TYPE_NOTIFICATION) { if (type == extensions::VIEW_TYPE_BACKGROUND_CONTENTS) {
process.titles.push_back(UTF8ToUTF16(url.spec())); process.titles.push_back(UTF8ToUTF16(url.spec()));
process.renderer_type = process.renderer_type =
ProcessMemoryInformation::RENDERER_NOTIFICATION; ProcessMemoryInformation::RENDERER_BACKGROUND_APP;
continue; continue;
} }
if (type == extensions::VIEW_TYPE_NOTIFICATION) {
process.titles.push_back(UTF8ToUTF16(url.spec()));
process.renderer_type =
ProcessMemoryInformation::RENDERER_NOTIFICATION;
continue;
}
// Since we have a WebContents and and the renderer type hasn't been // Since we have a WebContents and and the renderer type hasn't been
// set yet, it must be a normal tabbed renderer. // set yet, it must be a normal tabbed renderer.
if (process.renderer_type == ProcessMemoryInformation::RENDERER_UNKNOWN) if (process.renderer_type == ProcessMemoryInformation::RENDERER_UNKNOWN)
process.renderer_type = ProcessMemoryInformation::RENDERER_NORMAL; process.renderer_type = ProcessMemoryInformation::RENDERER_NORMAL;
string16 title = contents->GetTitle(); string16 title = contents->GetTitle();
if (!title.length()) if (!title.length())
title = l10n_util::GetStringUTF16(IDS_DEFAULT_TAB_TITLE); title = l10n_util::GetStringUTF16(IDS_DEFAULT_TAB_TITLE);
process.titles.push_back(title); process.titles.push_back(title);
// We need to check the pending entry as well as the virtual_url to // We need to check the pending entry as well as the virtual_url to
// see if it's a chrome://memory URL (we don't want to count these in // see if it's a chrome://memory URL (we don't want to count these in
// the total memory usage of the browser). // the total memory usage of the browser).
// //
// When we reach here, chrome://memory will be the pending entry since // When we reach here, chrome://memory will be the pending entry since
// we haven't responded with any data such that it would be committed. // we haven't responded with any data such that it would be committed.
// If you have another chrome://memory tab open (which would be // If you have another chrome://memory tab open (which would be
// committed), we don't want to count it either, so we also check the // committed), we don't want to count it either, so we also check the
// last committed entry. // last committed entry.
// //
// Either the pending or last committed entries can be NULL. // Either the pending or last committed entries can be NULL.
const NavigationEntry* pending_entry = const NavigationEntry* pending_entry =
contents->GetController().GetPendingEntry(); contents->GetController().GetPendingEntry();
const NavigationEntry* last_committed_entry = const NavigationEntry* last_committed_entry =
contents->GetController().GetLastCommittedEntry(); contents->GetController().GetLastCommittedEntry();
if ((last_committed_entry && if ((last_committed_entry &&
LowerCaseEqualsASCII(last_committed_entry->GetVirtualURL().spec(), LowerCaseEqualsASCII(last_committed_entry->GetVirtualURL().spec(),
chrome::kChromeUIMemoryURL)) || chrome::kChromeUIMemoryURL)) ||
(pending_entry && (pending_entry &&
LowerCaseEqualsASCII(pending_entry->GetVirtualURL().spec(), LowerCaseEqualsASCII(pending_entry->GetVirtualURL().spec(),
chrome::kChromeUIMemoryURL))) chrome::kChromeUIMemoryURL))) {
process.is_diagnostics = true; process.is_diagnostics = true;
} }
} }
......
...@@ -618,23 +618,19 @@ void PerformanceMonitor::AddRendererClosedEvent( ...@@ -618,23 +618,19 @@ void PerformanceMonitor::AddRendererClosedEvent(
details.status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED ? details.status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED ?
EVENT_RENDERER_KILLED : EVENT_RENDERER_CRASH; EVENT_RENDERER_KILLED : EVENT_RENDERER_CRASH;
content::RenderProcessHost::RenderWidgetHostsIterator iter =
host->GetRenderWidgetHostsIterator();
// A RenderProcessHost may contain multiple render views - for each valid // A RenderProcessHost may contain multiple render views - for each valid
// render view, extract the url, and append it to the string, comma-separating // render view, extract the url, and append it to the string, comma-separating
// the entries. // the entries.
std::string url_list; std::string url_list;
for (; !iter.IsAtEnd(); iter.Advance()) { content::RenderWidgetHost::List widgets =
const content::RenderWidgetHost* widget = iter.GetCurrentValue(); content::RenderWidgetHost::GetRenderWidgetHosts();
DCHECK(widget); for (size_t i = 0; i < widgets.size(); ++i) {
if (!widget || !widget->IsRenderView()) if (widgets[i]->GetProcess()->GetID() != host->GetID())
continue;
if (!widgets[i]->IsRenderView())
continue; continue;
content::RenderViewHost* view = content::RenderViewHost* view = content::RenderViewHost::From(widgets[i]);
content::RenderViewHost::From(
const_cast<content::RenderWidgetHost*>(widget));
std::string url; std::string url;
if (!MaybeGetURLFromRenderView(view, &url)) if (!MaybeGetURLFromRenderView(view, &url))
continue; continue;
......
...@@ -36,27 +36,17 @@ int RenderProcessHostCount() { ...@@ -36,27 +36,17 @@ int RenderProcessHostCount() {
} }
RenderViewHost* FindFirstDevToolsHost() { RenderViewHost* FindFirstDevToolsHost() {
content::RenderProcessHost::iterator hosts = RenderWidgetHost::List widgets = RenderWidgetHost::GetRenderWidgetHosts();
content::RenderProcessHost::AllHostsIterator(); for (size_t i = 0; i < widgets.size(); ++i) {
for (; !hosts.IsAtEnd(); hosts.Advance()) { if (!widgets[i]->GetProcess()->HasConnection())
content::RenderProcessHost* render_process_host = hosts.GetCurrentValue(); continue;
DCHECK(render_process_host); if (!widgets[i]->IsRenderView())
if (!render_process_host->HasConnection())
continue; continue;
content::RenderProcessHost::RenderWidgetHostsIterator iter( RenderViewHost* host = RenderViewHost::From(widgets[i]);
render_process_host->GetRenderWidgetHostsIterator()); WebContents* contents = WebContents::FromRenderViewHost(host);
for (; !iter.IsAtEnd(); iter.Advance()) { GURL url = contents->GetURL();
const RenderWidgetHost* widget = iter.GetCurrentValue(); if (url.SchemeIs(chrome::kChromeDevToolsScheme))
DCHECK(widget); return host;
if (!widget || !widget->IsRenderView())
continue;
RenderViewHost* host =
RenderViewHost::From(const_cast<RenderWidgetHost*>(widget));
WebContents* contents = WebContents::FromRenderViewHost(host);
GURL url = contents->GetURL();
if (url.SchemeIs(chrome::kChromeDevToolsScheme))
return host;
}
} }
return NULL; return NULL;
} }
......
...@@ -132,19 +132,12 @@ void GuestResourceProvider::StartUpdating() { ...@@ -132,19 +132,12 @@ void GuestResourceProvider::StartUpdating() {
updating_ = true; updating_ = true;
// Add all the existing guest WebContents. // Add all the existing guest WebContents.
for (RenderProcessHost::iterator i( RenderWidgetHost::List widgets = RenderWidgetHost::GetRenderWidgetHosts();
RenderProcessHost::AllHostsIterator()); for (size_t i = 0; i < widgets.size(); ++i) {
!i.IsAtEnd(); i.Advance()) { if (widgets[i]->IsRenderView()) {
RenderProcessHost::RenderWidgetHostsIterator iter = RenderViewHost* rvh = RenderViewHost::From(widgets[i]);
i.GetCurrentValue()->GetRenderWidgetHostsIterator(); if (rvh->IsSubframe())
for (; !iter.IsAtEnd(); iter.Advance()) { Add(rvh);
const RenderWidgetHost* widget = iter.GetCurrentValue();
if (widget->IsRenderView()) {
RenderViewHost* rvh =
RenderViewHost::From(const_cast<RenderWidgetHost*>(widget));
if (rvh->IsSubframe())
Add(rvh);
}
} }
} }
......
...@@ -136,9 +136,9 @@ void ChromeWebContentsViewDelegateGtk::ShowContextMenu( ...@@ -136,9 +136,9 @@ void ChromeWebContentsViewDelegateGtk::ShowContextMenu(
content::RenderWidgetHostView* view = NULL; content::RenderWidgetHostView* view = NULL;
if (params.custom_context.render_widget_id != if (params.custom_context.render_widget_id !=
content::CustomContextMenuContext::kCurrentRenderWidget) { content::CustomContextMenuContext::kCurrentRenderWidget) {
content::RenderWidgetHost* host = content::RenderWidgetHost* host = content::RenderWidgetHost::FromID(
web_contents_->GetRenderProcessHost()->GetRenderWidgetHostByID( web_contents_->GetRenderProcessHost()->GetID(),
params.custom_context.render_widget_id); params.custom_context.render_widget_id);
if (!host) { if (!host) {
NOTREACHED(); NOTREACHED();
return; return;
......
...@@ -62,8 +62,8 @@ void ValidationMessageMessageFilter::OverrideThreadForMessage( ...@@ -62,8 +62,8 @@ void ValidationMessageMessageFilter::OverrideThreadForMessage(
void ValidationMessageMessageFilter::OnShowValidationMessage( void ValidationMessageMessageFilter::OnShowValidationMessage(
int route_id, const gfx::Rect& anchor_in_root_view, int route_id, const gfx::Rect& anchor_in_root_view,
const string16& main_text, const string16& sub_text) { const string16& main_text, const string16& sub_text) {
RenderProcessHost* process = RenderProcessHost::FromID(renderer_id_); RenderWidgetHost* widget_host =
RenderWidgetHost* widget_host = process->GetRenderWidgetHostByID(route_id); RenderWidgetHost::FromID(renderer_id_, route_id);
validation_message_bubble_ = chrome::ValidationMessageBubble::CreateAndShow( validation_message_bubble_ = chrome::ValidationMessageBubble::CreateAndShow(
widget_host, anchor_in_root_view, main_text, sub_text); widget_host, anchor_in_root_view, main_text, sub_text);
} }
...@@ -76,8 +76,8 @@ void ValidationMessageMessageFilter::OnMoveValidationMessage( ...@@ -76,8 +76,8 @@ void ValidationMessageMessageFilter::OnMoveValidationMessage(
int route_id, const gfx::Rect& anchor_in_root_view) { int route_id, const gfx::Rect& anchor_in_root_view) {
if (!validation_message_bubble_) if (!validation_message_bubble_)
return; return;
RenderProcessHost* process = RenderProcessHost::FromID(renderer_id_); RenderWidgetHost* widget_host =
RenderWidgetHost* widget_host = process->GetRenderWidgetHostByID(route_id); RenderWidgetHost::FromID(renderer_id_, route_id);
validation_message_bubble_->SetPositionRelativeToAnchor( validation_message_bubble_->SetPositionRelativeToAnchor(
widget_host, anchor_in_root_view); widget_host, anchor_in_root_view);
} }
......
...@@ -91,28 +91,16 @@ void SendTargetsData( ...@@ -91,28 +91,16 @@ void SendTargetsData(
const WebUIDataSource::GotDataCallback& callback) { const WebUIDataSource::GotDataCallback& callback) {
scoped_ptr<base::ListValue> rvh_list(new base::ListValue()); scoped_ptr<base::ListValue> rvh_list(new base::ListValue());
for (RenderProcessHost::iterator it(RenderProcessHost::AllHostsIterator()); RenderWidgetHost::List widgets = RenderWidgetHost::GetRenderWidgetHosts();
!it.IsAtEnd(); it.Advance()) { for (size_t i = 0; i < widgets.size(); ++i) {
RenderProcessHost* render_process_host = it.GetCurrentValue();
DCHECK(render_process_host);
// Ignore processes that don't have a connection, such as crashed tabs. // Ignore processes that don't have a connection, such as crashed tabs.
if (!render_process_host->HasConnection()) if (!widgets[i]->GetProcess()->HasConnection())
continue; continue;
if (!widgets[i]->IsRenderView())
RenderProcessHost::RenderWidgetHostsIterator rwh_it(
render_process_host->GetRenderWidgetHostsIterator());
for (; !rwh_it.IsAtEnd(); rwh_it.Advance()) {
const RenderWidgetHost* rwh = rwh_it.GetCurrentValue();
DCHECK(rwh);
if (!rwh || !rwh->IsRenderView())
continue; continue;
RenderViewHost* rvh = RenderViewHost* rvh = RenderViewHost::From(widgets[i]);
RenderViewHost::From(const_cast<RenderWidgetHost*>(rwh)); rvh_list->Append(BuildTargetDescriptor(rvh));
rvh_list->Append(BuildTargetDescriptor(rvh));
}
} }
scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue()); scoped_ptr<base::DictionaryValue> data(new base::DictionaryValue());
......
...@@ -128,27 +128,16 @@ void BrowserAccessibilityStateImpl::SetAccessibilityMode( ...@@ -128,27 +128,16 @@ void BrowserAccessibilityStateImpl::SetAccessibilityMode(
if (accessibility_mode_ == mode) if (accessibility_mode_ == mode)
return; return;
accessibility_mode_ = mode; accessibility_mode_ = mode;
for (RenderProcessHost::iterator it(RenderProcessHost::AllHostsIterator());
!it.IsAtEnd(); it.Advance()) {
RenderProcessHost* render_process_host = it.GetCurrentValue();
DCHECK(render_process_host);
RenderWidgetHost::List widgets = RenderWidgetHost::GetRenderWidgetHosts();
for (size_t i = 0; i < widgets.size(); ++i) {
// Ignore processes that don't have a connection, such as crashed tabs. // Ignore processes that don't have a connection, such as crashed tabs.
if (!render_process_host->HasConnection()) if (!widgets[i]->GetProcess()->HasConnection())
continue;
if (!widgets[i]->IsRenderView())
continue; continue;
for (RenderProcessHost::RenderWidgetHostsIterator rwit( RenderWidgetHostImpl::From(widgets[i])->SetAccessibilityMode(mode);
render_process_host->GetRenderWidgetHostsIterator());
!rwit.IsAtEnd();
rwit.Advance()) {
RenderWidgetHost* rwh = const_cast<RenderWidgetHost*>(
rwit.GetCurrentValue());
DCHECK(rwh);
if (!rwh || !rwh->IsRenderView())
continue;
RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(rwh);
rwhi->SetAccessibilityMode(mode);
}
} }
} }
......
...@@ -120,37 +120,26 @@ void DevToolsAgentHost::ConnectRenderViewHost(const std::string& cookie, ...@@ -120,37 +120,26 @@ void DevToolsAgentHost::ConnectRenderViewHost(const std::string& cookie,
//static //static
std::vector<RenderViewHost*> DevToolsAgentHost::GetValidRenderViewHosts() { std::vector<RenderViewHost*> DevToolsAgentHost::GetValidRenderViewHosts() {
std::vector<RenderViewHost*> result; std::vector<RenderViewHost*> result;
for (RenderProcessHost::iterator it(RenderProcessHost::AllHostsIterator()); RenderWidgetHost::List widgets = RenderWidgetHost::GetRenderWidgetHosts();
!it.IsAtEnd(); it.Advance()) { for (size_t i = 0; i < widgets.size(); ++i) {
RenderProcessHost* render_process_host = it.GetCurrentValue();
DCHECK(render_process_host);
// Ignore processes that don't have a connection, such as crashed contents. // Ignore processes that don't have a connection, such as crashed contents.
if (!render_process_host->HasConnection()) if (!widgets[i]->GetProcess()->HasConnection())
continue;
if (!widgets[i]->IsRenderView())
continue; continue;
RenderProcessHost::RenderWidgetHostsIterator rwit( RenderViewHost* rvh = RenderViewHost::From(widgets[i]);
render_process_host->GetRenderWidgetHostsIterator()); // Don't report swapped out views.
for (; !rwit.IsAtEnd(); rwit.Advance()) { if (static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out())
const RenderWidgetHost* widget = rwit.GetCurrentValue(); continue;
DCHECK(widget);
if (!widget || !widget->IsRenderView()) WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
continue; // Don't report a RenderViewHost if it is not the current RenderViewHost
// for some WebContents.
RenderViewHost* rvh = if (!web_contents || rvh != web_contents->GetRenderViewHost())
RenderViewHost::From(const_cast<RenderWidgetHost*>(widget)); continue;
// Don't report swapped out views.
if (static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out()) result.push_back(rvh);
continue;
WebContents* web_contents = WebContents::FromRenderViewHost(rvh);
// Don't report a RenderViewHost if it is not the current RenderViewHost
// for some WebContents.
if (!web_contents || rvh != web_contents->GetRenderViewHost())
continue;
result.push_back(rvh);
}
} }
return result; return result;
} }
......
...@@ -133,10 +133,8 @@ void AcceleratedSurfaceBuffersSwappedCompletedForRenderer( ...@@ -133,10 +133,8 @@ void AcceleratedSurfaceBuffersSwappedCompletedForRenderer(
RenderWidgetHostImpl::CompositorFrameDrawn(latency_info); RenderWidgetHostImpl::CompositorFrameDrawn(latency_info);
return; return;
} }
RenderProcessHost* host = RenderProcessHost::FromID(render_process_id); RenderWidgetHost* rwh =
if (!host) RenderWidgetHost::FromID(render_process_id, render_widget_id);
return;
RenderWidgetHost* rwh = host->GetRenderWidgetHostByID(render_widget_id);
if (!rwh) if (!rwh)
return; return;
RenderWidgetHostImpl::From(rwh)->AcknowledgeSwapBuffersToRenderer(); RenderWidgetHostImpl::From(rwh)->AcknowledgeSwapBuffersToRenderer();
......
...@@ -90,11 +90,8 @@ RenderWidgetHostViewPort* GetRenderWidgetHostViewFromSurfaceID( ...@@ -90,11 +90,8 @@ RenderWidgetHostViewPort* GetRenderWidgetHostViewFromSurfaceID(
surface_id, &render_process_id, &render_widget_id)) surface_id, &render_process_id, &render_widget_id))
return NULL; return NULL;
RenderProcessHost* process = RenderProcessHost::FromID(render_process_id); RenderWidgetHost* host =
if (!process) RenderWidgetHost::FromID(render_process_id, render_widget_id);
return NULL;
RenderWidgetHost* host = process->GetRenderWidgetHostByID(render_widget_id);
return host ? RenderWidgetHostViewPort::FromRWHV(host->GetView()) : NULL; return host ? RenderWidgetHostViewPort::FromRWHV(host->GetView()) : NULL;
} }
...@@ -231,10 +228,8 @@ void GpuProcessHostUIShim::OnUpdateVSyncParameters(int surface_id, ...@@ -231,10 +228,8 @@ void GpuProcessHostUIShim::OnUpdateVSyncParameters(int surface_id,
surface_id, &render_process_id, &render_widget_id)) { surface_id, &render_process_id, &render_widget_id)) {
return; return;
} }
RenderProcessHost* host = RenderProcessHost::FromID(render_process_id); RenderWidgetHost* rwh =
if (!host) RenderWidgetHost::FromID(render_process_id, render_widget_id);
return;
RenderWidgetHost* rwh = host->GetRenderWidgetHostByID(render_widget_id);
if (!rwh) if (!rwh)
return; return;
RenderWidgetHostImpl::From(rwh)->UpdateVSyncParameters(timebase, interval); RenderWidgetHostImpl::From(rwh)->UpdateVSyncParameters(timebase, interval);
......
...@@ -873,8 +873,8 @@ RenderWidgetHost* CaptureMachine::GetTarget() { ...@@ -873,8 +873,8 @@ RenderWidgetHost* CaptureMachine::GetTarget() {
RenderWidgetHost* rwh = NULL; RenderWidgetHost* rwh = NULL;
if (fullscreen_widget_id_ != MSG_ROUTING_NONE) { if (fullscreen_widget_id_ != MSG_ROUTING_NONE) {
RenderProcessHost* process = web_contents()->GetRenderProcessHost(); RenderProcessHost* process = web_contents()->GetRenderProcessHost();
rwh = process ? process->GetRenderWidgetHostByID(fullscreen_widget_id_) if (process)
: NULL; rwh = RenderWidgetHost::FromID(process->GetID(), fullscreen_widget_id_);
} else { } else {
rwh = web_contents()->GetRenderViewHost(); rwh = web_contents()->GetRenderViewHost();
} }
......
...@@ -105,6 +105,7 @@ ...@@ -105,6 +105,7 @@
#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"
#include "content/public/browser/render_process_host_factory.h" #include "content/public/browser/render_process_host_factory.h"
#include "content/public/browser/render_widget_host.h"
#include "content/public/browser/resource_context.h" #include "content/public/browser/resource_context.h"
#include "content/public/browser/user_metrics.h" #include "content/public/browser/user_metrics.h"
#include "content/public/common/content_constants.h" #include "content/public/common/content_constants.h"
...@@ -708,11 +709,40 @@ int RenderProcessHostImpl::GetNextRoutingID() { ...@@ -708,11 +709,40 @@ int RenderProcessHostImpl::GetNextRoutingID() {
return widget_helper_->GetNextRoutingID(); return widget_helper_->GetNextRoutingID();
} }
void RenderProcessHostImpl::ResumeDeferredNavigation( void RenderProcessHostImpl::ResumeDeferredNavigation(
const GlobalRequestID& request_id) { const GlobalRequestID& request_id) {
widget_helper_->ResumeDeferredNavigation(request_id); widget_helper_->ResumeDeferredNavigation(request_id);
} }
void RenderProcessHostImpl::AddRoute(
int32 routing_id,
IPC::Listener* listener) {
listeners_.AddWithID(listener, routing_id);
}
void RenderProcessHostImpl::RemoveRoute(int32 routing_id) {
DCHECK(listeners_.Lookup(routing_id) != NULL);
listeners_.Remove(routing_id);
#if defined(OS_WIN)
// Dump the handle table if handle auditing is enabled.
const CommandLine& browser_command_line =
*CommandLine::ForCurrentProcess();
if (browser_command_line.HasSwitch(switches::kAuditHandles) ||
browser_command_line.HasSwitch(switches::kAuditAllHandles)) {
DumpHandles();
// We wait to close the channels until the child process has finished
// dumping handles and sends us ChildProcessHostMsg_DumpHandlesDone.
return;
}
#endif
// Keep the one renderer thread around forever in single process mode.
if (!run_renderer_in_process())
Cleanup();
}
bool RenderProcessHostImpl::WaitForBackingStoreMsg( bool RenderProcessHostImpl::WaitForBackingStoreMsg(
int render_widget_id, int render_widget_id,
const base::TimeDelta& max_delay, const base::TimeDelta& max_delay,
...@@ -1186,9 +1216,9 @@ bool RenderProcessHostImpl::OnMessageReceived(const IPC::Message& msg) { ...@@ -1186,9 +1216,9 @@ bool RenderProcessHostImpl::OnMessageReceived(const IPC::Message& msg) {
return true; return true;
} }
// Dispatch incoming messages to the appropriate RenderView/WidgetHost. // Dispatch incoming messages to the appropriate IPC::Listener.
RenderWidgetHost* rwh = render_widget_hosts_.Lookup(msg.routing_id()); IPC::Listener* listener = listeners_.Lookup(msg.routing_id());
if (!rwh) { if (!listener) {
if (msg.is_sync()) { if (msg.is_sync()) {
// The listener has gone away, so we must respond or else the caller will // The listener has gone away, so we must respond or else the caller will
// hang waiting for a reply. // hang waiting for a reply.
...@@ -1206,7 +1236,7 @@ bool RenderProcessHostImpl::OnMessageReceived(const IPC::Message& msg) { ...@@ -1206,7 +1236,7 @@ bool RenderProcessHostImpl::OnMessageReceived(const IPC::Message& msg) {
IPC_END_MESSAGE_MAP_EX() IPC_END_MESSAGE_MAP_EX()
return true; return true;
} }
return RenderWidgetHostImpl::From(rwh)->OnMessageReceived(msg); return listener->OnMessageReceived(msg);
} }
void RenderProcessHostImpl::OnChannelConnected(int32 peer_pid) { void RenderProcessHostImpl::OnChannelConnected(int32 peer_pid) {
...@@ -1241,11 +1271,6 @@ bool RenderProcessHostImpl::HasConnection() const { ...@@ -1241,11 +1271,6 @@ bool RenderProcessHostImpl::HasConnection() const {
return channel_.get() != NULL; return channel_.get() != NULL;
} }
RenderWidgetHost* RenderProcessHostImpl::GetRenderWidgetHostByID(
int routing_id) {
return render_widget_hosts_.Lookup(routing_id);
}
void RenderProcessHostImpl::SetIgnoreInputEvents(bool ignore_input_events) { void RenderProcessHostImpl::SetIgnoreInputEvents(bool ignore_input_events) {
ignore_input_events_ = ignore_input_events; ignore_input_events_ = ignore_input_events;
} }
...@@ -1254,36 +1279,9 @@ bool RenderProcessHostImpl::IgnoreInputEvents() const { ...@@ -1254,36 +1279,9 @@ bool RenderProcessHostImpl::IgnoreInputEvents() const {
return ignore_input_events_; return ignore_input_events_;
} }
void RenderProcessHostImpl::Attach(RenderWidgetHost* host,
int routing_id) {
render_widget_hosts_.AddWithID(host, routing_id);
}
void RenderProcessHostImpl::Release(int routing_id) {
DCHECK(render_widget_hosts_.Lookup(routing_id) != NULL);
render_widget_hosts_.Remove(routing_id);
#if defined(OS_WIN)
// Dump the handle table if handle auditing is enabled.
const CommandLine& browser_command_line =
*CommandLine::ForCurrentProcess();
if (browser_command_line.HasSwitch(switches::kAuditHandles) ||
browser_command_line.HasSwitch(switches::kAuditAllHandles)) {
DumpHandles();
// We wait to close the channels until the child process has finished
// dumping handles and sends us ChildProcessHostMsg_DumpHandlesDone.
return;
}
#endif
// Keep the one renderer thread around forever in single process mode.
if (!run_renderer_in_process())
Cleanup();
}
void RenderProcessHostImpl::Cleanup() { void RenderProcessHostImpl::Cleanup() {
// When no other owners of this object, we can delete ourselves // When no other owners of this object, we can delete ourselves
if (render_widget_hosts_.IsEmpty()) { if (listeners_.IsEmpty()) {
DCHECK_EQ(0, pending_views_); DCHECK_EQ(0, pending_views_);
NotificationService::current()->Notify( NotificationService::current()->Notify(
NOTIFICATION_RENDERER_PROCESS_TERMINATED, NOTIFICATION_RENDERER_PROCESS_TERMINATED,
...@@ -1344,13 +1342,8 @@ IPC::ChannelProxy* RenderProcessHostImpl::GetChannel() { ...@@ -1344,13 +1342,8 @@ IPC::ChannelProxy* RenderProcessHostImpl::GetChannel() {
return channel_.get(); return channel_.get();
} }
RenderProcessHost::RenderWidgetHostsIterator
RenderProcessHostImpl::GetRenderWidgetHostsIterator() {
return RenderWidgetHostsIterator(&render_widget_hosts_);
}
bool RenderProcessHostImpl::FastShutdownForPageCount(size_t count) { bool RenderProcessHostImpl::FastShutdownForPageCount(size_t count) {
if (render_widget_hosts_.size() == count) if (static_cast<size_t>(GetActiveViewCount()) == count)
return FastShutdownIfPossible(); return FastShutdownIfPossible();
return false; return false;
} }
...@@ -1605,13 +1598,14 @@ void RenderProcessHostImpl::ProcessDied(bool already_dead) { ...@@ -1605,13 +1598,14 @@ void RenderProcessHostImpl::ProcessDied(bool already_dead) {
channel_.reset(); channel_.reset();
gpu_message_filter_ = NULL; gpu_message_filter_ = NULL;
IDMap<RenderWidgetHost>::iterator iter(&render_widget_hosts_); RenderWidgetHost::List widgets = RenderWidgetHost::GetRenderWidgetHosts();
while (!iter.IsAtEnd()) { for (size_t i = 0; i < widgets.size(); ++i) {
RenderWidgetHostImpl::From(iter.GetCurrentValue())->OnMessageReceived( if (widgets[i]->GetProcess()->GetID() != GetID())
ViewHostMsg_RenderViewGone(iter.GetCurrentKey(), continue;
RenderWidgetHostImpl::From(widgets[i])->OnMessageReceived(
ViewHostMsg_RenderViewGone(widgets[i]->GetRoutingID(),
static_cast<int>(status), static_cast<int>(status),
exit_code)); exit_code));
iter.Advance();
} }
ClearTransportDIBCache(); ClearTransportDIBCache();
...@@ -1622,23 +1616,20 @@ void RenderProcessHostImpl::ProcessDied(bool already_dead) { ...@@ -1622,23 +1616,20 @@ void RenderProcessHostImpl::ProcessDied(bool already_dead) {
int RenderProcessHostImpl::GetActiveViewCount() { int RenderProcessHostImpl::GetActiveViewCount() {
int num_active_views = 0; int num_active_views = 0;
for (RenderWidgetHostsIterator iter = GetRenderWidgetHostsIterator(); RenderWidgetHost::List widgets = RenderWidgetHost::GetRenderWidgetHosts();
!iter.IsAtEnd(); for (size_t i = 0; i < widgets.size(); ++i) {
iter.Advance()) { // Count only RenderWidgetHosts in this process.
const RenderWidgetHost* widget = iter.GetCurrentValue(); if (widgets[i]->GetProcess()->GetID() != GetID())
DCHECK(widget);
if (!widget)
continue; continue;
// All RenderWidgetHosts are swapped in. // All RenderWidgetHosts are swapped in.
if (!widget->IsRenderView()) { if (!widgets[i]->IsRenderView()) {
num_active_views++; num_active_views++;
continue; continue;
} }
// Don't count swapped out views. // Don't count swapped out views.
RenderViewHost* rvh = RenderViewHost* rvh = RenderViewHost::From(widgets[i]);
RenderViewHost::From(const_cast<RenderWidgetHost*>(widget));
if (!static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out()) if (!static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out())
num_active_views++; num_active_views++;
} }
...@@ -1771,17 +1762,16 @@ void RenderProcessHostImpl::OnCompositorSurfaceBuffersSwappedNoHost( ...@@ -1771,17 +1762,16 @@ void RenderProcessHostImpl::OnCompositorSurfaceBuffersSwappedNoHost(
} }
void RenderProcessHostImpl::OnGpuSwitching() { void RenderProcessHostImpl::OnGpuSwitching() {
for (RenderWidgetHostsIterator iter = GetRenderWidgetHostsIterator(); RenderWidgetHost::List widgets = RenderWidgetHost::GetRenderWidgetHosts();
!iter.IsAtEnd(); for (size_t i = 0; i < widgets.size(); ++i) {
iter.Advance()) { if (!widgets[i]->IsRenderView())
const RenderWidgetHost* widget = iter.GetCurrentValue();
DCHECK(widget);
if (!widget || !widget->IsRenderView())
continue; continue;
RenderViewHost* rvh = // Skip widgets in other processes.
RenderViewHost::From(const_cast<RenderWidgetHost*>(widget)); if (widgets[i]->GetProcess()->GetID() != GetID())
continue;
RenderViewHost* rvh = RenderViewHost::From(widgets[i]);
rvh->UpdateWebkitPreferences(rvh->GetWebkitPreferences()); rvh->UpdateWebkitPreferences(rvh->GetWebkitPreferences());
} }
} }
......
...@@ -76,6 +76,8 @@ class CONTENT_EXPORT RenderProcessHostImpl ...@@ -76,6 +76,8 @@ class CONTENT_EXPORT RenderProcessHostImpl
virtual void EnableSendQueue() OVERRIDE; virtual void EnableSendQueue() OVERRIDE;
virtual bool Init() OVERRIDE; virtual bool Init() OVERRIDE;
virtual int GetNextRoutingID() OVERRIDE; virtual int GetNextRoutingID() OVERRIDE;
virtual void AddRoute(int32 routing_id, IPC::Listener* listener) OVERRIDE;
virtual void RemoveRoute(int32 routing_id) OVERRIDE;
virtual bool WaitForBackingStoreMsg(int render_widget_id, virtual bool WaitForBackingStoreMsg(int render_widget_id,
const base::TimeDelta& max_delay, const base::TimeDelta& max_delay,
IPC::Message* msg) OVERRIDE; IPC::Message* msg) OVERRIDE;
...@@ -95,20 +97,14 @@ class CONTENT_EXPORT RenderProcessHostImpl ...@@ -95,20 +97,14 @@ class CONTENT_EXPORT RenderProcessHostImpl
StoragePartition* partition) const OVERRIDE; StoragePartition* partition) const OVERRIDE;
virtual int GetID() const OVERRIDE; virtual int GetID() const OVERRIDE;
virtual bool HasConnection() const OVERRIDE; virtual bool HasConnection() const OVERRIDE;
virtual RenderWidgetHost* GetRenderWidgetHostByID(int routing_id)
OVERRIDE;
virtual void SetIgnoreInputEvents(bool ignore_input_events) OVERRIDE; virtual void SetIgnoreInputEvents(bool ignore_input_events) OVERRIDE;
virtual bool IgnoreInputEvents() const OVERRIDE; virtual bool IgnoreInputEvents() const OVERRIDE;
virtual void Attach(RenderWidgetHost* host, int routing_id)
OVERRIDE;
virtual void Release(int routing_id) OVERRIDE;
virtual void Cleanup() OVERRIDE; virtual void Cleanup() OVERRIDE;
virtual void AddPendingView() OVERRIDE; virtual void AddPendingView() OVERRIDE;
virtual void RemovePendingView() OVERRIDE; virtual void RemovePendingView() OVERRIDE;
virtual void SetSuddenTerminationAllowed(bool enabled) OVERRIDE; virtual void SetSuddenTerminationAllowed(bool enabled) OVERRIDE;
virtual bool SuddenTerminationAllowed() const OVERRIDE; virtual bool SuddenTerminationAllowed() const OVERRIDE;
virtual IPC::ChannelProxy* GetChannel() OVERRIDE; virtual IPC::ChannelProxy* GetChannel() OVERRIDE;
virtual RenderWidgetHostsIterator GetRenderWidgetHostsIterator() OVERRIDE;
virtual bool FastShutdownForPageCount(size_t count) OVERRIDE; virtual bool FastShutdownForPageCount(size_t count) OVERRIDE;
virtual bool FastShutdownStarted() const OVERRIDE; virtual bool FastShutdownStarted() const OVERRIDE;
virtual base::TimeDelta GetChildProcessIdleTime() const OVERRIDE; virtual base::TimeDelta GetChildProcessIdleTime() const OVERRIDE;
...@@ -185,10 +181,6 @@ class CONTENT_EXPORT RenderProcessHostImpl ...@@ -185,10 +181,6 @@ class CONTENT_EXPORT RenderProcessHostImpl
// browser_process.h) // browser_process.h)
scoped_ptr<IPC::ChannelProxy> channel_; scoped_ptr<IPC::ChannelProxy> channel_;
// The registered render widget hosts. When this list is empty or all NULL,
// we should delete ourselves
IDMap<RenderWidgetHost> render_widget_hosts_;
// True if fast shutdown has been performed on this RPH. // True if fast shutdown has been performed on this RPH.
bool fast_shutdown_started_; bool fast_shutdown_started_;
...@@ -235,6 +227,10 @@ class CONTENT_EXPORT RenderProcessHostImpl ...@@ -235,6 +227,10 @@ class CONTENT_EXPORT RenderProcessHostImpl
virtual void OnGpuSwitching() OVERRIDE; virtual void OnGpuSwitching() OVERRIDE;
// The registered IPC listener objects. When this list is empty, we should
// delete ourselves.
IDMap<IPC::Listener> listeners_;
// The count of currently visible widgets. Since the host can be a container // 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 // for multiple widgets, it uses this count to determine when it should be
// backgrounded. // backgrounded.
......
...@@ -118,10 +118,8 @@ g_created_callbacks = LAZY_INSTANCE_INITIALIZER; ...@@ -118,10 +118,8 @@ g_created_callbacks = LAZY_INSTANCE_INITIALIZER;
// static // static
RenderViewHost* RenderViewHost::FromID(int render_process_id, RenderViewHost* RenderViewHost::FromID(int render_process_id,
int render_view_id) { int render_view_id) {
RenderProcessHost* process = RenderProcessHost::FromID(render_process_id); RenderWidgetHost* widget =
if (!process) RenderWidgetHost::FromID(render_process_id, render_view_id);
return NULL;
RenderWidgetHost* widget = process->GetRenderWidgetHostByID(render_view_id);
if (!widget || !widget->IsRenderView()) if (!widget || !widget->IsRenderView())
return NULL; return NULL;
return static_cast<RenderViewHostImpl*>(RenderWidgetHostImpl::From(widget)); return static_cast<RenderViewHostImpl*>(RenderWidgetHostImpl::From(widget));
...@@ -480,10 +478,11 @@ void RenderViewHostImpl::WasSwappedOut() { ...@@ -480,10 +478,11 @@ void RenderViewHostImpl::WasSwappedOut() {
// Count the number of widget hosts for the process, which is equivalent to // Count the number of widget hosts for the process, which is equivalent to
// views using the process as of this writing. // views using the process as of this writing.
RenderProcessHost::RenderWidgetHostsIterator iter( RenderWidgetHost::List widgets = RenderWidgetHost::GetRenderWidgetHosts();
GetProcess()->GetRenderWidgetHostsIterator()); for (size_t i = 0; i < widgets.size(); ++i) {
for (; !iter.IsAtEnd(); iter.Advance()) if (widgets[i]->GetProcess()->GetID() == GetProcess()->GetID())
++views; ++views;
}
if (!RenderProcessHost::run_renderer_in_process() && if (!RenderProcessHost::run_renderer_in_process() &&
process_handle && views <= 1) { process_handle && views <= 1) {
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/auto_reset.h" #include "base/auto_reset.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/containers/hash_tables.h"
#include "base/debug/trace_event.h" #include "base/debug/trace_event.h"
#include "base/i18n/rtl.h" #include "base/i18n/rtl.h"
#include "base/lazy_instance.h" #include "base/lazy_instance.h"
...@@ -117,6 +118,12 @@ g_created_callbacks = LAZY_INSTANCE_INITIALIZER; ...@@ -117,6 +118,12 @@ g_created_callbacks = LAZY_INSTANCE_INITIALIZER;
} // namespace } // namespace
typedef std::pair<int32, int32> RenderWidgetHostID;
typedef base::hash_map<RenderWidgetHostID, RenderWidgetHostImpl*>
RoutingIDWidgetMap;
static base::LazyInstance<RoutingIDWidgetMap> g_routing_id_widget_map =
LAZY_INSTANCE_INITIALIZER;
// static // static
void RenderWidgetHost::RemoveAllBackingStores() { void RenderWidgetHost::RemoveAllBackingStores() {
BackingStoreManager::RemoveAllBackingStores(); BackingStoreManager::RemoveAllBackingStores();
...@@ -196,7 +203,9 @@ RenderWidgetHostImpl::RenderWidgetHostImpl(RenderWidgetHostDelegate* delegate, ...@@ -196,7 +203,9 @@ RenderWidgetHostImpl::RenderWidgetHostImpl(RenderWidgetHostDelegate* delegate,
is_threaded_compositing_enabled_ = IsThreadedCompositingEnabled(); is_threaded_compositing_enabled_ = IsThreadedCompositingEnabled();
process_->Attach(this, routing_id_); g_routing_id_widget_map.Get().insert(std::make_pair(
RenderWidgetHostID(process->GetID(), routing_id_), this));
process_->AddRoute(routing_id_, this);
// Because the widget initializes as is_hidden_ == false, // Because the widget initializes as is_hidden_ == false,
// tell the process host that we're alive. // tell the process host that we're alive.
process_->WidgetRestored(); process_->WidgetRestored();
...@@ -223,12 +232,43 @@ RenderWidgetHostImpl::~RenderWidgetHostImpl() { ...@@ -223,12 +232,43 @@ RenderWidgetHostImpl::~RenderWidgetHostImpl() {
GpuSurfaceTracker::Get()->RemoveSurface(surface_id_); GpuSurfaceTracker::Get()->RemoveSurface(surface_id_);
surface_id_ = 0; surface_id_ = 0;
process_->Release(routing_id_); process_->RemoveRoute(routing_id_);
g_routing_id_widget_map.Get().erase(
RenderWidgetHostID(process_->GetID(), routing_id_));
if (delegate_) if (delegate_)
delegate_->RenderWidgetDeleted(this); delegate_->RenderWidgetDeleted(this);
} }
// static
RenderWidgetHost* RenderWidgetHost::FromID(
int32 process_id,
int32 routing_id) {
return RenderWidgetHostImpl::FromID(process_id, routing_id);
}
// static
RenderWidgetHostImpl* RenderWidgetHostImpl::FromID(
int32 process_id,
int32 routing_id) {
RoutingIDWidgetMap* widgets = g_routing_id_widget_map.Pointer();
RoutingIDWidgetMap::iterator it = widgets->find(
RenderWidgetHostID(process_id, routing_id));
return it == widgets->end() ? NULL : it->second;
}
// static
std::vector<RenderWidgetHost*> RenderWidgetHost::GetRenderWidgetHosts() {
std::vector<RenderWidgetHost*> hosts;
RoutingIDWidgetMap* widgets = g_routing_id_widget_map.Pointer();
for (RoutingIDWidgetMap::const_iterator it = widgets->begin();
it != widgets->end();
++it) {
hosts.push_back(it->second);
}
return hosts;
}
// static // static
RenderWidgetHostImpl* RenderWidgetHostImpl::From(RenderWidgetHost* rwh) { RenderWidgetHostImpl* RenderWidgetHostImpl::From(RenderWidgetHost* rwh) {
return rwh->AsRenderWidgetHostImpl(); return rwh->AsRenderWidgetHostImpl();
...@@ -2554,10 +2594,8 @@ void RenderWidgetHostImpl::CompositorFrameDrawn( ...@@ -2554,10 +2594,8 @@ void RenderWidgetHostImpl::CompositorFrameDrawn(
// Matches with GetLatencyComponentId // Matches with GetLatencyComponentId
int routing_id = b->first.second & 0xffffffff; int routing_id = b->first.second & 0xffffffff;
int process_id = (b->first.second >> 32) & 0xffffffff; int process_id = (b->first.second >> 32) & 0xffffffff;
RenderProcessHost* host = RenderProcessHost::FromID(process_id); RenderWidgetHost* rwh =
if (!host) RenderWidgetHost::FromID(process_id, routing_id);
continue;
RenderWidgetHost* rwh = host->GetRenderWidgetHostByID(routing_id);
if (!rwh) if (!rwh)
continue; continue;
RenderWidgetHostImpl::From(rwh)->FrameSwapped(latency_info); RenderWidgetHostImpl::From(rwh)->FrameSwapped(latency_info);
......
...@@ -94,6 +94,9 @@ class CONTENT_EXPORT RenderWidgetHostImpl : virtual public RenderWidgetHost, ...@@ -94,6 +94,9 @@ class CONTENT_EXPORT RenderWidgetHostImpl : virtual public RenderWidgetHost,
int routing_id); int routing_id);
virtual ~RenderWidgetHostImpl(); virtual ~RenderWidgetHostImpl();
// Similar to RenderWidgetHost::FromID, but returning the Impl object.
static RenderWidgetHostImpl* FromID(int32 process_id, int32 routing_id);
// Use RenderWidgetHostImpl::From(rwh) to downcast a // Use RenderWidgetHostImpl::From(rwh) to downcast a
// RenderWidgetHost to a RenderWidgetHostImpl. Internally, this // RenderWidgetHost to a RenderWidgetHostImpl. Internally, this
// uses RenderWidgetHost::AsRenderWidgetHostImpl(). // uses RenderWidgetHost::AsRenderWidgetHostImpl().
......
...@@ -110,25 +110,16 @@ void WorkerPrioritySetter::GatherVisibleIDsAndUpdateWorkerPriorities() { ...@@ -110,25 +110,16 @@ void WorkerPrioritySetter::GatherVisibleIDsAndUpdateWorkerPriorities() {
new std::set<std::pair<int, int> >(); new std::set<std::pair<int, int> >();
// Gather up all the visible renderer process/view pairs // Gather up all the visible renderer process/view pairs
for (RenderProcessHost::iterator it = RenderWidgetHost::List widgets = RenderWidgetHost::GetRenderWidgetHosts();
RenderProcessHost::AllHostsIterator(); for (size_t i = 0; i < widgets.size(); ++i) {
!it.IsAtEnd(); it.Advance()) { if (widgets[i]->GetProcess()->VisibleWidgetCount() == 0)
RenderProcessHost* render_process_host = it.GetCurrentValue(); continue;
if (render_process_host->VisibleWidgetCount()) {
for (RenderProcessHost::RenderWidgetHostsIterator rit = RenderWidgetHostView* render_view = widgets[i]->GetView();
render_process_host->GetRenderWidgetHostsIterator(); !rit.IsAtEnd(); if (render_view && render_view->IsShowing()) {
rit.Advance()) { visible_renderer_ids->insert(
RenderWidgetHost* render_widget = std::pair<int, int>(widgets[i]->GetProcess()->GetID(),
render_process_host->GetRenderWidgetHostByID(rit.GetCurrentKey()); widgets[i]->GetRoutingID()));
if (render_widget) {
RenderWidgetHostView* render_view = render_widget->GetView();
if (render_view && render_view->IsShowing()) {
visible_renderer_ids->insert(
std::pair<int, int>(render_process_host->GetID(),
render_widget->GetRoutingID()));
}
}
}
} }
} }
......
...@@ -37,7 +37,6 @@ class CONTENT_EXPORT RenderProcessHost : public IPC::Sender, ...@@ -37,7 +37,6 @@ class CONTENT_EXPORT RenderProcessHost : public IPC::Sender,
public IPC::Listener { public IPC::Listener {
public: public:
typedef IDMap<RenderProcessHost>::iterator iterator; typedef IDMap<RenderProcessHost>::iterator iterator;
typedef IDMap<RenderWidgetHost>::const_iterator RenderWidgetHostsIterator;
// Details for RENDERER_PROCESS_CLOSED notifications. // Details for RENDERER_PROCESS_CLOSED notifications.
struct RendererClosedDetails { struct RendererClosedDetails {
...@@ -64,6 +63,13 @@ class CONTENT_EXPORT RenderProcessHost : public IPC::Sender, ...@@ -64,6 +63,13 @@ class CONTENT_EXPORT RenderProcessHost : public IPC::Sender,
// Gets the next available routing id. // Gets the next available routing id.
virtual int GetNextRoutingID() = 0; virtual int GetNextRoutingID() = 0;
// These methods add or remove listener for a specific message routing ID.
// Used for refcounting, each holder of this object must AddRoute and
// RemoveRoute. This object should be allocated on the heap; when no
// listeners own it any more, it will delete itself.
virtual void AddRoute(int32 routing_id, IPC::Listener* listener) = 0;
virtual void RemoveRoute(int32 routing_id) = 0;
// Called to wait for the next UpdateRect message for the specified render // 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 // widget. Returns true if successful, and the msg out-param will contain a
// copy of the received UpdateRect message. // copy of the received UpdateRect message.
...@@ -140,9 +146,6 @@ class CONTENT_EXPORT RenderProcessHost : public IPC::Sender, ...@@ -140,9 +146,6 @@ class CONTENT_EXPORT RenderProcessHost : public IPC::Sender,
// etc. // etc.
virtual int GetID() const = 0; virtual int GetID() const = 0;
// Returns the render widget host for the routing id passed in.
virtual RenderWidgetHost* GetRenderWidgetHostByID(int routing_id) = 0;
// Returns true iff channel_ has been set to non-NULL. Use this for checking // 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. // if there is connection or not. Virtual for mocking out for tests.
virtual bool HasConnection() const = 0; virtual bool HasConnection() const = 0;
...@@ -154,9 +157,6 @@ class CONTENT_EXPORT RenderProcessHost : public IPC::Sender, ...@@ -154,9 +157,6 @@ class CONTENT_EXPORT RenderProcessHost : public IPC::Sender,
// Returns the renderer channel. // Returns the renderer channel.
virtual IPC::ChannelProxy* GetChannel() = 0; virtual IPC::ChannelProxy* GetChannel() = 0;
// Returns the list of attached render widget hosts.
virtual RenderWidgetHostsIterator GetRenderWidgetHostsIterator() = 0;
// Try to shutdown the associated render process as fast as possible // Try to shutdown the associated render process as fast as possible
virtual bool FastShutdownForPageCount(size_t count) = 0; virtual bool FastShutdownForPageCount(size_t count) = 0;
...@@ -166,14 +166,6 @@ class CONTENT_EXPORT RenderProcessHost : public IPC::Sender, ...@@ -166,14 +166,6 @@ class CONTENT_EXPORT RenderProcessHost : public IPC::Sender,
virtual void SetIgnoreInputEvents(bool ignore_input_events) = 0; virtual void SetIgnoreInputEvents(bool ignore_input_events) = 0;
virtual bool IgnoreInputEvents() const = 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(content::RenderWidgetHost* host, int routing_id) = 0;
// See Attach()
virtual void Release(int routing_id) = 0;
// Schedules the host for deletion and removes it from the all_hosts list. // Schedules the host for deletion and removes it from the all_hosts list.
virtual void Cleanup() = 0; virtual void Cleanup() = 0;
......
...@@ -117,6 +117,14 @@ class CONTENT_EXPORT RenderWidgetHost : public IPC::Sender { ...@@ -117,6 +117,14 @@ class CONTENT_EXPORT RenderWidgetHost : public IPC::Sender {
static void AddCreatedCallback(const CreatedCallback& callback); static void AddCreatedCallback(const CreatedCallback& callback);
static void RemoveCreatedCallback(const CreatedCallback& callback); static void RemoveCreatedCallback(const CreatedCallback& callback);
// Returns the RenderWidgetHost given its ID and the ID of its render process.
// Returns NULL if the IDs do not correspond to a live RenderWidgetHost.
static RenderWidgetHost* FromID(int32 process_id, int32 routing_id);
typedef std::vector<RenderWidgetHost*> List;
// Returns the global list of render widget hosts.
static RenderWidgetHost::List GetRenderWidgetHosts();
virtual ~RenderWidgetHost() {} virtual ~RenderWidgetHost() {}
// Edit operations. // Edit operations.
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/time.h" #include "base/time.h"
#include "content/browser/child_process_security_policy_impl.h" #include "content/browser/child_process_security_policy_impl.h"
#include "content/browser/renderer_host/render_process_host_impl.h" #include "content/browser/renderer_host/render_process_host_impl.h"
#include "content/browser/renderer_host/render_view_host_impl.h"
#include "content/browser/renderer_host/render_widget_host_impl.h" #include "content/browser/renderer_host/render_widget_host_impl.h"
#include "content/common/child_process_host_impl.h" #include "content/common/child_process_host_impl.h"
#include "content/public/browser/notification_service.h" #include "content/public/browser/notification_service.h"
...@@ -53,6 +54,18 @@ int MockRenderProcessHost::GetNextRoutingID() { ...@@ -53,6 +54,18 @@ int MockRenderProcessHost::GetNextRoutingID() {
return ++prev_routing_id; return ++prev_routing_id;
} }
void MockRenderProcessHost::AddRoute(
int32 routing_id,
IPC::Listener* listener) {
listeners_.AddWithID(listener, routing_id);
}
void MockRenderProcessHost::RemoveRoute(int32 routing_id) {
DCHECK(listeners_.Lookup(routing_id) != NULL);
listeners_.Remove(routing_id);
Cleanup();
}
bool MockRenderProcessHost::WaitForBackingStoreMsg( bool MockRenderProcessHost::WaitForBackingStoreMsg(
int render_widget_id, int render_widget_id,
const base::TimeDelta& max_delay, const base::TimeDelta& max_delay,
...@@ -153,18 +166,8 @@ bool MockRenderProcessHost::IgnoreInputEvents() const { ...@@ -153,18 +166,8 @@ bool MockRenderProcessHost::IgnoreInputEvents() const {
return false; return false;
} }
void MockRenderProcessHost::Attach(RenderWidgetHost* host,
int routing_id) {
render_widget_hosts_.AddWithID(host, routing_id);
}
void MockRenderProcessHost::Release(int routing_id) {
render_widget_hosts_.Remove(routing_id);
Cleanup();
}
void MockRenderProcessHost::Cleanup() { void MockRenderProcessHost::Cleanup() {
if (render_widget_hosts_.IsEmpty()) { if (listeners_.IsEmpty()) {
NotificationService::current()->Notify( NotificationService::current()->Notify(
NOTIFICATION_RENDERER_PROCESS_TERMINATED, NOTIFICATION_RENDERER_PROCESS_TERMINATED,
Source<RenderProcessHost>(this), Source<RenderProcessHost>(this),
...@@ -187,11 +190,6 @@ bool MockRenderProcessHost::SuddenTerminationAllowed() const { ...@@ -187,11 +190,6 @@ bool MockRenderProcessHost::SuddenTerminationAllowed() const {
return true; return true;
} }
RenderWidgetHost* MockRenderProcessHost::GetRenderWidgetHostByID(
int routing_id) {
return render_widget_hosts_.Lookup(routing_id);
}
BrowserContext* MockRenderProcessHost::GetBrowserContext() const { BrowserContext* MockRenderProcessHost::GetBrowserContext() const {
return browser_context_; return browser_context_;
} }
...@@ -206,8 +204,30 @@ IPC::ChannelProxy* MockRenderProcessHost::GetChannel() { ...@@ -206,8 +204,30 @@ IPC::ChannelProxy* MockRenderProcessHost::GetChannel() {
return NULL; return NULL;
} }
int MockRenderProcessHost::GetActiveViewCount() {
int num_active_views = 0;
RenderWidgetHost::List widgets = RenderWidgetHost::GetRenderWidgetHosts();
for (size_t i = 0; i < widgets.size(); ++i) {
// Count only RenderWidgetHosts in this process.
if (widgets[i]->GetProcess()->GetID() != GetID())
continue;
// All RenderWidgetHosts are swapped in.
if (!widgets[i]->IsRenderView()) {
num_active_views++;
continue;
}
// Don't count swapped out views.
RenderViewHost* rvh = RenderViewHost::From(widgets[i]);
if (!static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out())
num_active_views++;
}
return num_active_views;
}
bool MockRenderProcessHost::FastShutdownForPageCount(size_t count) { bool MockRenderProcessHost::FastShutdownForPageCount(size_t count) {
if (render_widget_hosts_.size() == count) if (static_cast<size_t>(GetActiveViewCount()) == count)
return FastShutdownIfPossible(); return FastShutdownIfPossible();
return false; return false;
} }
...@@ -222,15 +242,11 @@ void MockRenderProcessHost::SurfaceUpdated(int32 surface_id) { ...@@ -222,15 +242,11 @@ void MockRenderProcessHost::SurfaceUpdated(int32 surface_id) {
void MockRenderProcessHost::ResumeRequestsForView(int route_id) { void MockRenderProcessHost::ResumeRequestsForView(int route_id) {
} }
RenderProcessHost::RenderWidgetHostsIterator
MockRenderProcessHost::GetRenderWidgetHostsIterator() {
return RenderWidgetHostsIterator(&render_widget_hosts_);
}
bool MockRenderProcessHost::OnMessageReceived(const IPC::Message& msg) { bool MockRenderProcessHost::OnMessageReceived(const IPC::Message& msg) {
RenderWidgetHost* rwh = render_widget_hosts_.Lookup(msg.routing_id()); IPC::Listener* listener = listeners_.Lookup(msg.routing_id());
if (rwh) if (listener)
return RenderWidgetHostImpl::From(rwh)->OnMessageReceived(msg); return listener->OnMessageReceived(msg);
return false; return false;
} }
......
...@@ -36,6 +36,8 @@ class MockRenderProcessHost : public RenderProcessHost { ...@@ -36,6 +36,8 @@ class MockRenderProcessHost : public RenderProcessHost {
virtual void EnableSendQueue() OVERRIDE; virtual void EnableSendQueue() OVERRIDE;
virtual bool Init() OVERRIDE; virtual bool Init() OVERRIDE;
virtual int GetNextRoutingID() OVERRIDE; virtual int GetNextRoutingID() OVERRIDE;
virtual void AddRoute(int32 routing_id, IPC::Listener* listener) OVERRIDE;
virtual void RemoveRoute(int32 routing_id) OVERRIDE;
virtual bool WaitForBackingStoreMsg(int render_widget_id, virtual bool WaitForBackingStoreMsg(int render_widget_id,
const base::TimeDelta& max_delay, const base::TimeDelta& max_delay,
IPC::Message* msg) OVERRIDE; IPC::Message* msg) OVERRIDE;
...@@ -56,20 +58,15 @@ class MockRenderProcessHost : public RenderProcessHost { ...@@ -56,20 +58,15 @@ class MockRenderProcessHost : public RenderProcessHost {
virtual bool HasConnection() const OVERRIDE; virtual bool HasConnection() const OVERRIDE;
virtual void SetIgnoreInputEvents(bool ignore_input_events) OVERRIDE; virtual void SetIgnoreInputEvents(bool ignore_input_events) OVERRIDE;
virtual bool IgnoreInputEvents() const OVERRIDE; virtual bool IgnoreInputEvents() const OVERRIDE;
virtual void Attach(RenderWidgetHost* host, int routing_id) OVERRIDE;
virtual void Release(int routing_id) OVERRIDE;
virtual void Cleanup() OVERRIDE; virtual void Cleanup() OVERRIDE;
virtual void AddPendingView() OVERRIDE; virtual void AddPendingView() OVERRIDE;
virtual void RemovePendingView() OVERRIDE; virtual void RemovePendingView() OVERRIDE;
virtual void SetSuddenTerminationAllowed(bool allowed) OVERRIDE; virtual void SetSuddenTerminationAllowed(bool allowed) OVERRIDE;
virtual bool SuddenTerminationAllowed() const OVERRIDE; virtual bool SuddenTerminationAllowed() const OVERRIDE;
virtual RenderWidgetHost* GetRenderWidgetHostByID(int routing_id)
OVERRIDE;
virtual BrowserContext* GetBrowserContext() const OVERRIDE; virtual BrowserContext* GetBrowserContext() const OVERRIDE;
virtual bool InSameStoragePartition( virtual bool InSameStoragePartition(
StoragePartition* partition) const OVERRIDE; StoragePartition* partition) const OVERRIDE;
virtual IPC::ChannelProxy* GetChannel() OVERRIDE; virtual IPC::ChannelProxy* GetChannel() OVERRIDE;
virtual RenderWidgetHostsIterator GetRenderWidgetHostsIterator() OVERRIDE;
virtual bool FastShutdownForPageCount(size_t count) OVERRIDE; virtual bool FastShutdownForPageCount(size_t count) OVERRIDE;
virtual base::TimeDelta GetChildProcessIdleTime() const OVERRIDE; virtual base::TimeDelta GetChildProcessIdleTime() const OVERRIDE;
virtual void SurfaceUpdated(int32 surface_id) OVERRIDE; virtual void SurfaceUpdated(int32 surface_id) OVERRIDE;
...@@ -88,6 +85,8 @@ class MockRenderProcessHost : public RenderProcessHost { ...@@ -88,6 +85,8 @@ class MockRenderProcessHost : public RenderProcessHost {
factory_ = factory; factory_ = factory;
} }
int GetActiveViewCount();
private: private:
// Stores IPC messages that would have been sent to the renderer. // Stores IPC messages that would have been sent to the renderer.
IPC::TestSink sink_; IPC::TestSink sink_;
...@@ -98,6 +97,7 @@ class MockRenderProcessHost : public RenderProcessHost { ...@@ -98,6 +97,7 @@ class MockRenderProcessHost : public RenderProcessHost {
BrowserContext* browser_context_; BrowserContext* browser_context_;
IDMap<RenderWidgetHost> render_widget_hosts_; IDMap<RenderWidgetHost> render_widget_hosts_;
IDMap<IPC::Listener> listeners_;
bool fast_shutdown_started_; bool fast_shutdown_started_;
DISALLOW_COPY_AND_ASSIGN(MockRenderProcessHost); DISALLOW_COPY_AND_ASSIGN(MockRenderProcessHost);
......
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