Commit 02b87521 authored by Charlie Harrison's avatar Charlie Harrison Committed by Commit Bot

ResourceDispatcherHost: be more paranoid about null checking

Currently code on the UI thread checks to see if the RDH is available,
then posts a task to it on the IO thread. By the time the IO task is
posted, the RDH could be shut down or even destroyed.

This CL makes some of the UI -> IO hops from RenderViewHost do all
the shutdown checking on the IO thread.

Bug: 901468
Change-Id: I5077e70200b0da2824d1d0c1128d5d0ac614cd66
Reviewed-on: https://chromium-review.googlesource.com/c/1323409Reviewed-by: default avatarMatt Menke <mmenke@chromium.org>
Reviewed-by: default avatarDmitry Gozman <dgozman@chromium.org>
Commit-Queue: Charlie Harrison <csharrison@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606120}
parent a41133bb
...@@ -1185,24 +1185,38 @@ ResourceRequestInfoImpl* ResourceDispatcherHostImpl::CreateRequestInfo( ...@@ -1185,24 +1185,38 @@ ResourceRequestInfoImpl* ResourceDispatcherHostImpl::CreateRequestInfo(
false); // initiated_in_secure_context false); // initiated_in_secure_context
} }
// static
void ResourceDispatcherHostImpl::OnRenderViewHostCreated( void ResourceDispatcherHostImpl::OnRenderViewHostCreated(
int child_id, int child_id,
int route_id, int route_id,
net::URLRequestContextGetter* url_request_context_getter) { net::URLRequestContextGetter* url_request_context_getter) {
scheduler_->OnClientCreated(child_id, route_id, auto* host = ResourceDispatcherHostImpl::Get();
url_request_context_getter->GetURLRequestContext() if (host && host->scheduler_) {
->network_quality_estimator()); host->scheduler_->OnClientCreated(
child_id, route_id,
url_request_context_getter->GetURLRequestContext()
->network_quality_estimator());
}
} }
// static
void ResourceDispatcherHostImpl::OnRenderViewHostDeleted(int child_id, void ResourceDispatcherHostImpl::OnRenderViewHostDeleted(int child_id,
int route_id) { int route_id) {
scheduler_->OnClientDeleted(child_id, route_id); auto* host = ResourceDispatcherHostImpl::Get();
if (host && host->scheduler_) {
host->scheduler_->OnClientDeleted(child_id, route_id);
}
} }
// static
void ResourceDispatcherHostImpl::OnRenderViewHostSetIsLoading(int child_id, void ResourceDispatcherHostImpl::OnRenderViewHostSetIsLoading(int child_id,
int route_id, int route_id,
bool is_loading) { bool is_loading) {
scheduler_->DeprecatedOnLoadingStateChanged(child_id, route_id, !is_loading); auto* host = ResourceDispatcherHostImpl::Get();
if (host && host->scheduler_) {
host->scheduler_->DeprecatedOnLoadingStateChanged(child_id, route_id,
!is_loading);
}
} }
// The object died, so cancel and detach all requests associated with it except // The object died, so cancel and detach all requests associated with it except
......
...@@ -146,18 +146,18 @@ class CONTENT_EXPORT ResourceDispatcherHostImpl ...@@ -146,18 +146,18 @@ class CONTENT_EXPORT ResourceDispatcherHostImpl
static const int kAvgBytesPerOutstandingRequest = 4400; static const int kAvgBytesPerOutstandingRequest = 4400;
// Called when a RenderViewHost is created. // Called when a RenderViewHost is created.
void OnRenderViewHostCreated( static void OnRenderViewHostCreated(
int child_id, int child_id,
int route_id, int route_id,
net::URLRequestContextGetter* url_request_context_getter); net::URLRequestContextGetter* url_request_context_getter);
// Called when a RenderViewHost is deleted. // Called when a RenderViewHost is deleted.
void OnRenderViewHostDeleted(int child_id, int route_id); static void OnRenderViewHostDeleted(int child_id, int route_id);
// Called when a RenderViewHost starts or stops loading. // Called when a RenderViewHost starts or stops loading.
void OnRenderViewHostSetIsLoading(int child_id, static void OnRenderViewHostSetIsLoading(int child_id,
int route_id, int route_id,
bool is_loading); bool is_loading);
// Force cancels any pending requests for the given process. // Force cancels any pending requests for the given process.
void CancelRequestsForProcess(int child_id); void CancelRequestsForProcess(int child_id);
......
...@@ -248,16 +248,13 @@ RenderViewHostImpl::RenderViewHostImpl( ...@@ -248,16 +248,13 @@ RenderViewHostImpl::RenderViewHostImpl(
if (!is_active_) if (!is_active_)
GetWidget()->UpdatePriority(); GetWidget()->UpdatePriority();
if (ResourceDispatcherHostImpl::Get()) { base::PostTaskWithTraits(
base::PostTaskWithTraits( FROM_HERE, {BrowserThread::IO},
FROM_HERE, {BrowserThread::IO}, base::BindOnce(
base::BindOnce( &ResourceDispatcherHostImpl::OnRenderViewHostCreated,
&ResourceDispatcherHostImpl::OnRenderViewHostCreated, GetProcess()->GetID(), GetRoutingID(),
base::Unretained(ResourceDispatcherHostImpl::Get()), base::RetainedRef(
GetProcess()->GetID(), GetRoutingID(), GetProcess()->GetStoragePartition()->GetURLRequestContext())));
base::RetainedRef(
GetProcess()->GetStoragePartition()->GetURLRequestContext())));
}
close_timeout_.reset(new TimeoutMonitor(base::Bind( close_timeout_.reset(new TimeoutMonitor(base::Bind(
&RenderViewHostImpl::ClosePageTimeout, weak_factory_.GetWeakPtr()))); &RenderViewHostImpl::ClosePageTimeout, weak_factory_.GetWeakPtr())));
...@@ -266,13 +263,10 @@ RenderViewHostImpl::RenderViewHostImpl( ...@@ -266,13 +263,10 @@ RenderViewHostImpl::RenderViewHostImpl(
} }
RenderViewHostImpl::~RenderViewHostImpl() { RenderViewHostImpl::~RenderViewHostImpl() {
if (ResourceDispatcherHostImpl::Get()) { base::PostTaskWithTraits(
base::PostTaskWithTraits( FROM_HERE, {BrowserThread::IO},
FROM_HERE, {BrowserThread::IO}, base::BindOnce(&ResourceDispatcherHostImpl::OnRenderViewHostDeleted,
base::BindOnce(&ResourceDispatcherHostImpl::OnRenderViewHostDeleted, GetProcess()->GetID(), GetRoutingID()));
base::Unretained(ResourceDispatcherHostImpl::Get()),
GetProcess()->GetID(), GetRoutingID()));
}
ui::GpuSwitchingManager::GetInstance()->RemoveObserver(this); ui::GpuSwitchingManager::GetInstance()->RemoveObserver(this);
...@@ -724,14 +718,10 @@ void RenderViewHostImpl::SetInitialFocus(bool reverse) { ...@@ -724,14 +718,10 @@ void RenderViewHostImpl::SetInitialFocus(bool reverse) {
} }
void RenderViewHostImpl::RenderWidgetWillSetIsLoading(bool is_loading) { void RenderViewHostImpl::RenderWidgetWillSetIsLoading(bool is_loading) {
if (ResourceDispatcherHostImpl::Get()) { base::PostTaskWithTraits(
base::PostTaskWithTraits( FROM_HERE, {BrowserThread::IO},
FROM_HERE, {BrowserThread::IO}, base::BindOnce(&ResourceDispatcherHostImpl::OnRenderViewHostSetIsLoading,
base::BindOnce( GetProcess()->GetID(), GetRoutingID(), is_loading));
&ResourceDispatcherHostImpl::OnRenderViewHostSetIsLoading,
base::Unretained(ResourceDispatcherHostImpl::Get()),
GetProcess()->GetID(), GetRoutingID(), is_loading));
}
} }
void RenderViewHostImpl::RenderWidgetDidFirstVisuallyNonEmptyPaint() { void RenderViewHostImpl::RenderWidgetDidFirstVisuallyNonEmptyPaint() {
......
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