Index: content/browser/renderer_host/resource_dispatcher_host_impl.cc |
diff --git a/content/browser/renderer_host/resource_dispatcher_host_impl.cc b/content/browser/renderer_host/resource_dispatcher_host_impl.cc |
index a8973534cab184a71ead2c220edcece6ce0dd050..35e154a622e59d2dcf708e8819d94156461f3665 100644 |
--- a/content/browser/renderer_host/resource_dispatcher_host_impl.cc |
+++ b/content/browser/renderer_host/resource_dispatcher_host_impl.cc |
@@ -21,7 +21,6 @@ |
#include "base/shared_memory.h" |
#include "base/stl_util.h" |
#include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
-#include "base/threading/thread_restrictions.h" |
#include "content/browser/appcache/chrome_appcache_service.h" |
#include "content/browser/cert_store_impl.h" |
#include "content/browser/child_process_security_policy_impl.h" |
@@ -357,7 +356,8 @@ ResourceDispatcherHostImpl::ResourceDispatcherHostImpl() |
kMaxOutstandingRequestsCostPerProcess), |
filter_(NULL), |
delegate_(NULL), |
- allow_cross_origin_auth_prompt_(false) { |
+ allow_cross_origin_auth_prompt_(false), |
+ weak_ptr_factory_(this) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
DCHECK(!g_resource_dispatcher_host); |
g_resource_dispatcher_host = this; |
@@ -803,6 +803,8 @@ void ResourceDispatcherHostImpl::OnShutdown() { |
iter != ids.end(); ++iter) { |
CancelBlockedRequestsForRoute(iter->first, iter->second); |
} |
+ |
+ weak_ptr_factory_.InvalidateWeakPtrs(); |
} |
bool ResourceDispatcherHostImpl::OnMessageReceived( |
@@ -841,7 +843,7 @@ void ResourceDispatcherHostImpl::OnRequestResource( |
const IPC::Message& message, |
int request_id, |
const ResourceHostMsg_Request& request_data) { |
- BeginRequest(request_id, request_data, NULL, message.routing_id()); |
+ PrepareToBeginRequest(request_id, request_data, NULL, message.routing_id()); |
} |
// Begins a resource request with the given params on behalf of the specified |
@@ -856,17 +858,49 @@ void ResourceDispatcherHostImpl::OnSyncLoad( |
int request_id, |
const ResourceHostMsg_Request& request_data, |
IPC::Message* sync_result) { |
- BeginRequest(request_id, request_data, sync_result, |
- sync_result->routing_id()); |
+ PrepareToBeginRequest(request_id, request_data, sync_result, |
+ sync_result->routing_id()); |
+} |
+ |
+void ResourceDispatcherHostImpl::PrepareToBeginRequest( |
+ int request_id, |
+ const ResourceHostMsg_Request& request_data, |
+ IPC::Message* sync_result, |
+ int route_id) { |
+ if (!is_shutdown_ && request_data.upload_data) { |
+ ResourceContext* resource_context = filter_->resource_context(); |
+ // http://crbug.com/90971 |
+ CHECK(ContainsKey(active_resource_contexts_, resource_context)); |
+ |
+ // Might need to resolve the blob references in the upload data. |
+ GetBlobStorageControllerForResourceContext(resource_context)-> |
+ ResolveBlobReferencesInUploadData(request_data.upload_data.get()); |
+ |
+ // BeginRequest() will be called later with upload_size. |
+ request_data.upload_data->GetContentLength( |
+ base::Bind(&ResourceDispatcherHostImpl::BeginRequest, |
darin (slow to review)
2012/07/31 19:29:46
note: The ResourceDispatcherHostImpl out-lives the
|
+ weak_ptr_factory_.GetWeakPtr(), |
+ scoped_refptr<ResourceMessageFilter>(filter_), |
+ request_id, |
+ request_data, |
+ sync_result, |
+ route_id)); |
+ } else { // There is no upload data. |
+ const uint64 upload_size = 0; |
+ BeginRequest( |
+ filter_, request_id, request_data, sync_result, route_id, upload_size); |
+ } |
} |
void ResourceDispatcherHostImpl::BeginRequest( |
+ scoped_refptr<ResourceMessageFilter> filter, |
int request_id, |
const ResourceHostMsg_Request& request_data, |
IPC::Message* sync_result, // only valid for sync |
- int route_id) { |
- ProcessType process_type = filter_->process_type(); |
- int child_id = filter_->child_id(); |
+ int route_id, |
+ uint64 upload_size) { |
+ ProcessType process_type = filter->process_type(); |
+ int child_id = filter->child_id(); |
// If we crash here, figure out what URL the renderer was requesting. |
// http://crbug.com/91398 |
@@ -887,25 +921,19 @@ void ResourceDispatcherHostImpl::BeginRequest( |
pending_loaders_.erase(it); |
} else { |
RecordAction(UserMetricsAction("BadMessageTerminate_RDH")); |
- filter_->BadMessageReceived(); |
+ filter->BadMessageReceived(); |
return; |
} |
} |
} |
- ResourceContext* resource_context = filter_->resource_context(); |
+ ResourceContext* resource_context = filter->resource_context(); |
// http://crbug.com/90971 |
CHECK(ContainsKey(active_resource_contexts_, resource_context)); |
- // Might need to resolve the blob references in the upload data. |
- if (request_data.upload_data) { |
- GetBlobStorageControllerForResourceContext(resource_context)-> |
- ResolveBlobReferencesInUploadData(request_data.upload_data.get()); |
- } |
- |
if (is_shutdown_ || |
!ShouldServiceRequest(process_type, child_id, request_data)) { |
- AbortRequestBeforeItStarts(filter_, sync_result, route_id, request_id); |
+ AbortRequestBeforeItStarts(filter, sync_result, route_id, request_id); |
return; |
} |
@@ -920,7 +948,7 @@ void ResourceDispatcherHostImpl::BeginRequest( |
request_data.resource_type, |
resource_context, |
referrer)) { |
- AbortRequestBeforeItStarts(filter_, sync_result, route_id, request_id); |
+ AbortRequestBeforeItStarts(filter, sync_result, route_id, request_id); |
return; |
} |
@@ -940,7 +968,7 @@ void ResourceDispatcherHostImpl::BeginRequest( |
new_request.reset(new net::URLRequest( |
request_data.url, |
NULL, |
- filter_->GetURLRequestContext(request_data.resource_type))); |
+ filter->GetURLRequestContext(request_data.resource_type))); |
request = new_request.get(); |
request->set_method(request_data.method); |
@@ -961,13 +989,8 @@ void ResourceDispatcherHostImpl::BeginRequest( |
request->set_priority(DetermineRequestPriority(request_data.resource_type)); |
// Set upload data. |
- uint64 upload_size = 0; |
- if (request_data.upload_data) { |
+ if (request_data.upload_data) |
request->set_upload(request_data.upload_data); |
- // This results in performing file IO. crbug.com/112607. |
- base::ThreadRestrictions::ScopedAllowIO allow_io; |
- upload_size = request_data.upload_data->GetContentLengthSync(); |
- } |
bool allow_download = request_data.allow_download && |
ResourceType::IsFrame(request_data.resource_type); |
@@ -1012,10 +1035,10 @@ void ResourceDispatcherHostImpl::BeginRequest( |
scoped_ptr<ResourceHandler> handler; |
if (sync_result) { |
handler.reset(new SyncResourceHandler( |
- filter_, request, sync_result, this)); |
+ filter, request, sync_result, this)); |
} else { |
handler.reset(new AsyncResourceHandler( |
- filter_, route_id, request, this)); |
+ filter, route_id, request, this)); |
} |
// The RedirectToFileResourceHandler depends on being next in the chain. |