Index: content/browser/loader/resource_dispatcher_host_impl.cc |
diff --git a/content/browser/loader/resource_dispatcher_host_impl.cc b/content/browser/loader/resource_dispatcher_host_impl.cc |
index cb64dc8880b575a8b9d68095f688b4de3ade8ef9..c443315331f67596b313da1a1d0b626559667ba7 100644 |
--- a/content/browser/loader/resource_dispatcher_host_impl.cc |
+++ b/content/browser/loader/resource_dispatcher_host_impl.cc |
@@ -584,6 +584,7 @@ ResourceDispatcherHostImpl::ResourceDispatcherHostImpl() |
ResourceDispatcherHostImpl::~ResourceDispatcherHostImpl() { |
DCHECK(outstanding_requests_stats_map_.empty()); |
DCHECK(g_resource_dispatcher_host); |
+ DCHECK_CURRENTLY_ON(BrowserThread::UI); |
g_resource_dispatcher_host = NULL; |
} |
@@ -1177,6 +1178,7 @@ void ResourceDispatcherHostImpl::OnShutdown() { |
bool ResourceDispatcherHostImpl::OnMessageReceived( |
const IPC::Message& message, |
ResourceMessageFilter* filter) { |
+ DCHECK_CURRENTLY_ON(BrowserThread::IO); |
filter_ = filter; |
bool handled = true; |
IPC_BEGIN_MESSAGE_MAP(ResourceDispatcherHostImpl, message) |
@@ -1218,6 +1220,11 @@ void ResourceDispatcherHostImpl::OnRequestResource( |
int routing_id, |
int request_id, |
const ResourceRequest& request_data) { |
+ std::unique_ptr<mojom::URLLoader> loader = |
+ std::move(mojo_loader_for_next_load_request_); |
+ mojom::URLLoaderClientPtr client = |
+ std::move(mojo_loader_client_for_next_load_request_); |
+ |
// TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed. |
tracked_objects::ScopedTracker tracking_profile( |
FROM_HERE_WITH_EXPLICIT_FUNCTION( |
@@ -1238,7 +1245,8 @@ void ResourceDispatcherHostImpl::OnRequestResource( |
request_data.render_frame_id, |
request_data.url)); |
} |
- BeginRequest(request_id, request_data, NULL, routing_id); |
+ BeginRequest(request_id, request_data, NULL, routing_id, std::move(loader), |
+ std::move(client)); |
} |
// Begins a resource request with the given params on behalf of the specified |
@@ -1368,7 +1376,9 @@ void ResourceDispatcherHostImpl::BeginRequest( |
int request_id, |
const ResourceRequest& request_data, |
IPC::Message* sync_result, // only valid for sync |
- int route_id) { |
+ int route_id, |
+ std::unique_ptr<mojom::URLLoader> url_loader, |
+ mojom::URLLoaderClientPtr client) { |
int process_type = filter_->process_type(); |
int child_id = filter_->child_id(); |
@@ -1627,10 +1637,11 @@ void ResourceDispatcherHostImpl::BeginRequest( |
std::unique_ptr<ResourceHandler> handler(CreateResourceHandler( |
new_request.get(), request_data, sync_result, route_id, process_type, |
- child_id, resource_context)); |
+ child_id, resource_context, client != nullptr)); |
if (handler) |
- BeginRequestInternal(std::move(new_request), std::move(handler)); |
+ BeginRequestInternal(std::move(new_request), std::move(handler), |
+ std::move(url_loader), std::move(client)); |
} |
std::unique_ptr<ResourceHandler> |
@@ -1641,7 +1652,8 @@ ResourceDispatcherHostImpl::CreateResourceHandler( |
int route_id, |
int process_type, |
int child_id, |
- ResourceContext* resource_context) { |
+ ResourceContext* resource_context, |
+ bool using_mojo) { |
// TODO(pkasting): Remove ScopedTracker below once crbug.com/456331 is fixed. |
tracked_objects::ScopedTracker tracking_profile( |
FROM_HERE_WITH_EXPLICIT_FUNCTION( |
@@ -1649,6 +1661,7 @@ ResourceDispatcherHostImpl::CreateResourceHandler( |
// Construct the IPC resource handler. |
std::unique_ptr<ResourceHandler> handler; |
if (sync_result) { |
+ DCHECK(!using_mojo); |
// download_to_file is not supported for synchronous requests. |
if (request_data.download_to_file) { |
bad_message::ReceivedBadMessage(filter_, bad_message::RDH_BAD_DOWNLOAD); |
@@ -1657,7 +1670,7 @@ ResourceDispatcherHostImpl::CreateResourceHandler( |
handler.reset(new SyncResourceHandler(request, sync_result, this)); |
} else { |
- handler.reset(new AsyncResourceHandler(request, this)); |
+ handler.reset(new AsyncResourceHandler(request, this, using_mojo)); |
// The RedirectToFileResourceHandler depends on being next in the chain. |
if (request_data.download_to_file) { |
@@ -1778,6 +1791,27 @@ void ResourceDispatcherHostImpl::OnDidChangePriority( |
intra_priority_value); |
} |
+void ResourceDispatcherHostImpl::OnReceivedResponseForMojo( |
+ int request_id, |
+ const ResourceResponseHead& head) { |
+ int child_id = filter_->child_id(); |
+ ResourceLoader* loader = GetLoader(child_id, request_id); |
+ mojom::URLLoaderClient* client = loader->client(); |
+ client->OnReceiveResponse(head, loader->GetRequestInfo()->TakeBodyReader()); |
+} |
+ |
+void ResourceDispatcherHostImpl::OnRequestCompleteForMojo( |
+ int request_id, |
+ const ResourceRequestCompletionStatus& status) { |
+ int child_id = filter_->child_id(); |
+ ResourceLoader* loader = GetLoader(child_id, request_id); |
+ DCHECK(loader); |
+ mojom::URLLoaderClient* client = loader->client(); |
+ DCHECK(client); |
+ |
+ client->OnComplete(status); |
+} |
+ |
void ResourceDispatcherHostImpl::OnDataDownloadedACK(int request_id) { |
// TODO(michaeln): maybe throttle DataDownloaded messages |
} |
@@ -2063,6 +2097,19 @@ void ResourceDispatcherHostImpl::CancelRequestsForRoute( |
CancelBlockedRequestsForRoute(route_id); |
} |
} |
+ |
+ // Uninitiated URLLoader has no routing ID, so it should be deleted only when |
+ // cancel_all_routes is specified. |
+ if (cancel_all_routes) { |
+ auto it = uninitiated_url_loaders_.begin(); |
+ while (it != uninitiated_url_loaders_.end()) { |
+ if (it->second.first == child_id) { |
+ it = uninitiated_url_loaders_.erase(it); |
+ } else { |
+ ++it; |
+ } |
+ } |
+ } |
} |
// Cancels the request and removes it from the list. |
@@ -2350,6 +2397,58 @@ void ResourceDispatcherHostImpl::EnableStaleWhileRevalidateForTesting() { |
async_revalidation_manager_.reset(new AsyncRevalidationManager); |
} |
+bool ResourceDispatcherHostImpl::SendWithMojoIfPossible( |
+ const IPC::Message& message, |
+ ResourceMessageFilter* filter) { |
+ if (IPC_MESSAGE_ID_CLASS(message.type()) != ResourceMsgStart) |
+ return false; |
+ |
+ base::PickleIterator iter(message); |
+ int request_id = -1; |
+ bool ok = iter.ReadInt(&request_id); |
+ DCHECK(ok); |
+ ResourceLoader* loader = GetLoader(filter->child_id(), request_id); |
+ if (!loader || !loader->client()) |
+ return false; |
+ |
+ DCHECK(!filter_); |
+ filter_ = filter; |
+ bool handled = true; |
+ IPC_BEGIN_MESSAGE_MAP(ResourceDispatcherHostImpl, message) |
+ IPC_MESSAGE_HANDLER(ResourceMsg_ReceivedResponse, OnReceivedResponseForMojo) |
+ IPC_MESSAGE_HANDLER(ResourceMsg_RequestComplete, OnRequestCompleteForMojo) |
+ IPC_MESSAGE_UNHANDLED(handled = false) |
+ IPC_END_MESSAGE_MAP() |
+ |
+ filter_ = nullptr; |
+ return handled; |
+} |
+ |
+void ResourceDispatcherHostImpl::AddUninitiatedURLLoader( |
+ int child_id, |
+ std::unique_ptr<mojom::URLLoader> loader) { |
+ mojom::URLLoader* raw = loader.get(); |
+ uninitiated_url_loaders_.insert( |
+ std::make_pair(raw, std::make_pair(child_id, std::move(loader)))); |
+} |
+ |
+std::unique_ptr<mojom::URLLoader> |
+ResourceDispatcherHostImpl::TakeUninitiatedURLLoader(mojom::URLLoader* loader) { |
+ auto it = uninitiated_url_loaders_.find(loader); |
+ if (it == uninitiated_url_loaders_.end()) |
+ return nullptr; |
+ std::unique_ptr<mojom::URLLoader> result = std::move(it->second.second); |
+ uninitiated_url_loaders_.erase(it); |
+ return result; |
+} |
+ |
+void ResourceDispatcherHostImpl::SetMojoLoaderAndClientrForNextLoadRequest( |
+ std::unique_ptr<mojom::URLLoader> loader, |
+ mojom::URLLoaderClientPtr client) { |
+ mojo_loader_for_next_load_request_ = std::move(loader); |
+ mojo_loader_client_for_next_load_request_ = std::move(client); |
+} |
+ |
// static |
int ResourceDispatcherHostImpl::CalculateApproximateMemoryCost( |
net::URLRequest* request) { |
@@ -2368,7 +2467,9 @@ int ResourceDispatcherHostImpl::CalculateApproximateMemoryCost( |
void ResourceDispatcherHostImpl::BeginRequestInternal( |
std::unique_ptr<net::URLRequest> request, |
- std::unique_ptr<ResourceHandler> handler) { |
+ std::unique_ptr<ResourceHandler> handler, |
+ std::unique_ptr<mojom::URLLoader> url_loader, |
+ mojom::URLLoaderClientPtr client) { |
DCHECK(!request->is_pending()); |
ResourceRequestInfoImpl* info = |
ResourceRequestInfoImpl::ForRequest(request.get()); |
@@ -2404,8 +2505,9 @@ void ResourceDispatcherHostImpl::BeginRequestInternal( |
return; |
} |
- std::unique_ptr<ResourceLoader> loader(new ResourceLoader( |
- std::move(request), std::move(handler), GetCertStore(), this)); |
+ std::unique_ptr<ResourceLoader> loader( |
+ new ResourceLoader(std::move(request), std::move(handler), GetCertStore(), |
+ std::move(url_loader), std::move(client), this)); |
GlobalFrameRoutingId id(info->GetChildID(), info->GetRenderFrameID()); |
BlockedLoadersMap::const_iterator iter = blocked_loaders_map_.find(id); |