| 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 da256df980413b76fe334efae34d9216b3394399..fbf4f7dcbd08a5eb1ab56888d02e5de28d7c3549 100644
|
| --- a/content/browser/loader/resource_dispatcher_host_impl.cc
|
| +++ b/content/browser/loader/resource_dispatcher_host_impl.cc
|
| @@ -50,6 +50,7 @@
|
| #include "content/browser/loader/cross_site_resource_handler.h"
|
| #include "content/browser/loader/detachable_resource_handler.h"
|
| #include "content/browser/loader/mime_type_resource_handler.h"
|
| +#include "content/browser/loader/mojo_async_resource_handler.h"
|
| #include "content/browser/loader/navigation_resource_handler.h"
|
| #include "content/browser/loader/navigation_resource_throttle.h"
|
| #include "content/browser/loader/navigation_url_loader_impl_core.h"
|
| @@ -229,7 +230,8 @@ bool IsDetachableResourceType(ResourceType type) {
|
| // Aborts a request before an URLRequest has actually been created.
|
| void AbortRequestBeforeItStarts(ResourceMessageFilter* filter,
|
| IPC::Message* sync_result,
|
| - int request_id) {
|
| + int request_id,
|
| + mojom::URLLoaderClientPtr url_loader_client) {
|
| if (sync_result) {
|
| SyncLoadResult result;
|
| result.error_code = net::ERR_ABORTED;
|
| @@ -244,8 +246,12 @@ void AbortRequestBeforeItStarts(ResourceMessageFilter* filter,
|
| // No security info needed, connection not established.
|
| request_complete_data.completion_time = base::TimeTicks();
|
| request_complete_data.encoded_data_length = 0;
|
| - filter->Send(new ResourceMsg_RequestComplete(
|
| - request_id, request_complete_data));
|
| + if (url_loader_client) {
|
| + url_loader_client->OnComplete(request_complete_data);
|
| + } else {
|
| + filter->Send(
|
| + new ResourceMsg_RequestComplete(request_id, request_complete_data));
|
| + }
|
| }
|
| }
|
|
|
| @@ -584,6 +590,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;
|
| }
|
|
|
| @@ -1178,6 +1185,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)
|
| @@ -1219,6 +1227,16 @@ void ResourceDispatcherHostImpl::OnRequestResource(
|
| int routing_id,
|
| int request_id,
|
| const ResourceRequest& request_data) {
|
| + OnRequestResourceInternal(routing_id, request_id, request_data, nullptr,
|
| + nullptr);
|
| +}
|
| +
|
| +void ResourceDispatcherHostImpl::OnRequestResourceInternal(
|
| + int routing_id,
|
| + int request_id,
|
| + const ResourceRequest& request_data,
|
| + std::unique_ptr<mojom::URLLoader> url_loader,
|
| + mojom::URLLoaderClientPtr url_loader_client) {
|
| // TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed.
|
| tracked_objects::ScopedTracker tracking_profile(
|
| FROM_HERE_WITH_EXPLICIT_FUNCTION(
|
| @@ -1239,7 +1257,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(url_loader), std::move(url_loader_client));
|
| }
|
|
|
| // Begins a resource request with the given params on behalf of the specified
|
| @@ -1253,8 +1272,8 @@ void ResourceDispatcherHostImpl::OnRequestResource(
|
| void ResourceDispatcherHostImpl::OnSyncLoad(int request_id,
|
| const ResourceRequest& request_data,
|
| IPC::Message* sync_result) {
|
| - BeginRequest(request_id, request_data, sync_result,
|
| - sync_result->routing_id());
|
| + BeginRequest(request_id, request_data, sync_result, sync_result->routing_id(),
|
| + nullptr, nullptr);
|
| }
|
|
|
| bool ResourceDispatcherHostImpl::IsRequestIDInUse(
|
| @@ -1369,7 +1388,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 url_loader_client) {
|
| int process_type = filter_->process_type();
|
| int child_id = filter_->child_id();
|
|
|
| @@ -1438,7 +1459,8 @@ void ResourceDispatcherHostImpl::BeginRequest(
|
| if (is_shutdown_ ||
|
| !ShouldServiceRequest(process_type, child_id, request_data, headers,
|
| filter_, resource_context)) {
|
| - AbortRequestBeforeItStarts(filter_, sync_result, request_id);
|
| + AbortRequestBeforeItStarts(filter_, sync_result, request_id,
|
| + std::move(url_loader_client));
|
| return;
|
| }
|
|
|
| @@ -1447,7 +1469,8 @@ void ResourceDispatcherHostImpl::BeginRequest(
|
| request_data.url,
|
| request_data.resource_type,
|
| resource_context)) {
|
| - AbortRequestBeforeItStarts(filter_, sync_result, request_id);
|
| + AbortRequestBeforeItStarts(filter_, sync_result, request_id,
|
| + std::move(url_loader_client));
|
| return;
|
| }
|
|
|
| @@ -1628,7 +1651,8 @@ 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, std::move(url_loader),
|
| + std::move(url_loader_client)));
|
|
|
| if (handler)
|
| BeginRequestInternal(std::move(new_request), std::move(handler));
|
| @@ -1642,7 +1666,9 @@ ResourceDispatcherHostImpl::CreateResourceHandler(
|
| int route_id,
|
| int process_type,
|
| int child_id,
|
| - ResourceContext* resource_context) {
|
| + ResourceContext* resource_context,
|
| + std::unique_ptr<mojom::URLLoader> url_loader,
|
| + mojom::URLLoaderClientPtr url_loader_client) {
|
| // TODO(pkasting): Remove ScopedTracker below once crbug.com/456331 is fixed.
|
| tracked_objects::ScopedTracker tracking_profile(
|
| FROM_HERE_WITH_EXPLICIT_FUNCTION(
|
| @@ -1656,9 +1682,16 @@ ResourceDispatcherHostImpl::CreateResourceHandler(
|
| return std::unique_ptr<ResourceHandler>();
|
| }
|
|
|
| + DCHECK(!url_loader);
|
| + DCHECK(!url_loader_client);
|
| handler.reset(new SyncResourceHandler(request, sync_result, this));
|
| } else {
|
| - handler.reset(new AsyncResourceHandler(request, this));
|
| + if (url_loader) {
|
| + handler.reset(new MojoAsyncResourceHandler(
|
| + request, this, std::move(url_loader), std::move(url_loader_client)));
|
| + } else {
|
| + handler.reset(new AsyncResourceHandler(request, this));
|
| + }
|
|
|
| // The RedirectToFileResourceHandler depends on being next in the chain.
|
| if (request_data.download_to_file) {
|
| @@ -2064,6 +2097,19 @@ void ResourceDispatcherHostImpl::CancelRequestsForRoute(
|
| CancelBlockedRequestsForRoute(route_id);
|
| }
|
| }
|
| +
|
| + // Unstarted URLLoader has no routing ID, so it should be deleted only when
|
| + // cancel_all_routes is specified.
|
| + if (cancel_all_routes) {
|
| + auto it = unstarted_url_loaders_.begin();
|
| + while (it != unstarted_url_loaders_.end()) {
|
| + if (it->second.first == child_id) {
|
| + it = unstarted_url_loaders_.erase(it);
|
| + } else {
|
| + ++it;
|
| + }
|
| + }
|
| + }
|
| }
|
|
|
| // Cancels the request and removes it from the list.
|
| @@ -2351,6 +2397,38 @@ void ResourceDispatcherHostImpl::EnableStaleWhileRevalidateForTesting() {
|
| async_revalidation_manager_.reset(new AsyncRevalidationManager);
|
| }
|
|
|
| +void ResourceDispatcherHostImpl::OnRequestResourceWithMojo(
|
| + int routing_id,
|
| + int request_id,
|
| + const ResourceRequest& request,
|
| + std::unique_ptr<mojom::URLLoader> url_loader,
|
| + mojom::URLLoaderClientPtr url_loader_client,
|
| + ResourceMessageFilter* filter) {
|
| + filter_ = filter;
|
| + OnRequestResourceInternal(routing_id, request_id, request,
|
| + std::move(url_loader),
|
| + std::move(url_loader_client));
|
| + filter_ = nullptr;
|
| +}
|
| +
|
| +void ResourceDispatcherHostImpl::AddUnstartedURLLoader(
|
| + int child_id,
|
| + std::unique_ptr<mojom::URLLoader> loader) {
|
| + mojom::URLLoader* raw = loader.get();
|
| + unstarted_url_loaders_.insert(
|
| + std::make_pair(raw, std::make_pair(child_id, std::move(loader))));
|
| +}
|
| +
|
| +std::unique_ptr<mojom::URLLoader>
|
| +ResourceDispatcherHostImpl::TakeUnstartedURLLoader(mojom::URLLoader* loader) {
|
| + auto it = unstarted_url_loaders_.find(loader);
|
| + if (it == unstarted_url_loaders_.end())
|
| + return nullptr;
|
| + std::unique_ptr<mojom::URLLoader> result = std::move(it->second.second);
|
| + unstarted_url_loaders_.erase(it);
|
| + return result;
|
| +}
|
| +
|
| // static
|
| int ResourceDispatcherHostImpl::CalculateApproximateMemoryCost(
|
| net::URLRequest* request) {
|
|
|