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 981c71ba454f337c573f6c9b64805d7934a13ce5..693092eb00ae73b9dbd02870a516d76bbb471601 100644 |
--- a/content/browser/loader/resource_dispatcher_host_impl.cc |
+++ b/content/browser/loader/resource_dispatcher_host_impl.cc |
@@ -51,6 +51,7 @@ |
#include "content/browser/loader/detachable_resource_handler.h" |
#include "content/browser/loader/loader_delegate.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" |
@@ -225,7 +226,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; |
@@ -240,8 +242,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)); |
+ } |
} |
} |
@@ -545,6 +551,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; |
} |
@@ -1104,6 +1111,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) |
@@ -1145,6 +1153,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, |
+ mojo::InterfaceRequest<mojom::URLLoader> mojo_request, |
+ 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( |
@@ -1165,7 +1183,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(mojo_request), std::move(url_loader_client)); |
} |
// Begins a resource request with the given params on behalf of the specified |
@@ -1179,8 +1198,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( |
@@ -1295,7 +1314,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, |
+ mojo::InterfaceRequest<mojom::URLLoader> mojo_request, |
+ mojom::URLLoaderClientPtr url_loader_client) { |
int process_type = filter_->process_type(); |
int child_id = filter_->child_id(); |
@@ -1335,6 +1356,9 @@ void ResourceDispatcherHostImpl::BeginRequest( |
GlobalRequestID(request_data.transferred_request_child_id, |
request_data.transferred_request_request_id)); |
if (it != pending_loaders_.end()) { |
+ // TODO(yhirano): Make mojo work for this case. |
+ DCHECK(!url_loader_client); |
+ |
// If the request is transferring to a new process, we can update our |
// state and let it resume with its existing ResourceHandlers. |
if (it->second->is_transferring()) { |
@@ -1362,7 +1386,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; |
} |
@@ -1371,7 +1396,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; |
} |
@@ -1551,7 +1577,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(mojo_request), |
+ std::move(url_loader_client))); |
if (handler) |
BeginRequestInternal(std::move(new_request), std::move(handler)); |
@@ -1565,7 +1592,9 @@ ResourceDispatcherHostImpl::CreateResourceHandler( |
int route_id, |
int process_type, |
int child_id, |
- ResourceContext* resource_context) { |
+ ResourceContext* resource_context, |
+ mojo::InterfaceRequest<mojom::URLLoader> mojo_request, |
+ 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( |
@@ -1579,9 +1608,17 @@ ResourceDispatcherHostImpl::CreateResourceHandler( |
return std::unique_ptr<ResourceHandler>(); |
} |
+ DCHECK(!mojo_request.is_pending()); |
+ DCHECK(!url_loader_client); |
handler.reset(new SyncResourceHandler(request, sync_result, this)); |
} else { |
- handler.reset(new AsyncResourceHandler(request, this)); |
+ if (mojo_request.is_pending()) { |
+ handler.reset(new MojoAsyncResourceHandler(request, this, |
+ std::move(mojo_request), |
+ 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) { |
@@ -2281,6 +2318,20 @@ void ResourceDispatcherHostImpl::OnRenderFrameDeleted( |
CancelRequestsForRoute(global_routing_id); |
} |
+void ResourceDispatcherHostImpl::OnRequestResourceWithMojo( |
+ int routing_id, |
+ int request_id, |
+ const ResourceRequest& request, |
+ mojo::InterfaceRequest<mojom::URLLoader> mojo_request, |
+ mojom::URLLoaderClientPtr url_loader_client, |
+ ResourceMessageFilter* filter) { |
+ filter_ = filter; |
+ OnRequestResourceInternal(routing_id, request_id, request, |
+ std::move(mojo_request), |
+ std::move(url_loader_client)); |
+ filter_ = nullptr; |
+} |
+ |
// static |
int ResourceDispatcherHostImpl::CalculateApproximateMemoryCost( |
net::URLRequest* request) { |