Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(529)

Unified Diff: content/browser/loader/resource_dispatcher_host_impl.cc

Issue 2390313002: Make SyncLoad result handling pluggable (Closed)
Patch Set: +#include "b/m/ref_counted.h" Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 8cc50c6f05820225092b7d051a9878edc962c5ee..88889ccfd3f18a8fe10f84f9c851c31e224f17f1 100644
--- a/content/browser/loader/resource_dispatcher_host_impl.cc
+++ b/content/browser/loader/resource_dispatcher_host_impl.cc
@@ -119,6 +119,8 @@ using base::Time;
using base::TimeDelta;
using base::TimeTicks;
using storage::ShareableFileReference;
+using SyncLoadResultCallback =
+ content::ResourceDispatcherHostImpl::SyncLoadResultCallback;
// ----------------------------------------------------------------------------
@@ -221,15 +223,15 @@ 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,
- mojom::URLLoaderClientPtr url_loader_client) {
- if (sync_result) {
+void AbortRequestBeforeItStarts(
+ ResourceMessageFilter* filter,
+ const SyncLoadResultCallback& sync_result_handler,
+ int request_id,
+ mojom::URLLoaderClientPtr url_loader_client) {
+ if (sync_result_handler) {
SyncLoadResult result;
result.error_code = net::ERR_ABORTED;
- ResourceHostMsg_SyncLoad::WriteReplyParams(sync_result, result);
- filter->Send(sync_result);
+ sync_result_handler.Run(&result);
} else {
// Tell the renderer that this request was disallowed.
ResourceRequestCompletionStatus request_complete_data;
@@ -414,6 +416,22 @@ void NotifyForEachFrameFromUI(
base::Passed(std::move(routing_ids))));
}
+// Sends back the result of a synchronous loading result to the renderer through
+// Chrome IPC.
+void HandleSyncLoadResult(base::WeakPtr<ResourceMessageFilter> filter,
+ std::unique_ptr<IPC::Message> sync_result,
+ const SyncLoadResult* result) {
+ if (!filter)
+ return;
+
+ if (result) {
+ ResourceHostMsg_SyncLoad::WriteReplyParams(sync_result.get(), *result);
+ } else {
+ sync_result->set_reply_error();
+ }
+ filter->Send(sync_result.release());
+}
+
} // namespace
ResourceDispatcherHostImpl::LoadInfo::LoadInfo() {}
@@ -1059,7 +1077,7 @@ void ResourceDispatcherHostImpl::OnRequestResourceInternal(
request_data.render_frame_id,
request_data.url));
}
- BeginRequest(request_id, request_data, NULL, routing_id,
+ BeginRequest(request_id, request_data, SyncLoadResultCallback(), routing_id,
std::move(mojo_request), std::move(url_loader_client));
}
@@ -1074,7 +1092,10 @@ void ResourceDispatcherHostImpl::OnRequestResourceInternal(
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(),
+ SyncLoadResultCallback callback = base::Bind(
+ &HandleSyncLoadResult, filter_->GetWeakPtr(),
+ base::Passed(WrapUnique(sync_result)));
+ BeginRequest(request_id, request_data, callback, sync_result->routing_id(),
nullptr, nullptr);
}
@@ -1181,7 +1202,7 @@ void ResourceDispatcherHostImpl::UpdateRequestForTransfer(
void ResourceDispatcherHostImpl::BeginRequest(
int request_id,
const ResourceRequest& request_data,
- IPC::Message* sync_result, // only valid for sync
+ const SyncLoadResultCallback& sync_result_handler, // only valid for sync
int route_id,
mojo::InterfaceRequest<mojom::URLLoader> mojo_request,
mojom::URLLoaderClientPtr url_loader_client) {
@@ -1256,7 +1277,7 @@ 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_handler, request_id,
std::move(url_loader_client));
return;
}
@@ -1281,22 +1302,22 @@ void ResourceDispatcherHostImpl::BeginRequest(
it.name(), it.value(), child_id, resource_context,
base::Bind(&ResourceDispatcherHostImpl::ContinuePendingBeginRequest,
base::Unretained(this), request_id, request_data,
- sync_result, route_id, headers,
+ sync_result_handler, route_id, headers,
base::Passed(std::move(mojo_request)),
base::Passed(std::move(url_loader_client))));
return;
}
}
}
- ContinuePendingBeginRequest(request_id, request_data, sync_result, route_id,
- headers, std::move(mojo_request),
+ ContinuePendingBeginRequest(request_id, request_data, sync_result_handler,
+ route_id, headers, std::move(mojo_request),
std::move(url_loader_client), true, 0);
}
void ResourceDispatcherHostImpl::ContinuePendingBeginRequest(
int request_id,
const ResourceRequest& request_data,
- IPC::Message* sync_result, // only valid for sync
+ const SyncLoadResultCallback& sync_result_handler, // only valid for sync
int route_id,
const net::HttpRequestHeaders& headers,
mojo::InterfaceRequest<mojom::URLLoader> mojo_request,
@@ -1307,7 +1328,7 @@ void ResourceDispatcherHostImpl::ContinuePendingBeginRequest(
// TODO(ananta): Find a way to specify the right error code here. Passing
// in a non-content error code is not safe.
bad_message::ReceivedBadMessage(filter_, bad_message::RDH_ILLEGAL_ORIGIN);
- AbortRequestBeforeItStarts(filter_, sync_result, request_id,
+ AbortRequestBeforeItStarts(filter_, sync_result_handler, request_id,
std::move(url_loader_client));
return;
}
@@ -1330,7 +1351,7 @@ void ResourceDispatcherHostImpl::ContinuePendingBeginRequest(
request_data.url,
request_data.resource_type,
resource_context)) {
- AbortRequestBeforeItStarts(filter_, sync_result, request_id,
+ AbortRequestBeforeItStarts(filter_, sync_result_handler, request_id,
std::move(url_loader_client));
return;
}
@@ -1403,7 +1424,7 @@ void ResourceDispatcherHostImpl::ContinuePendingBeginRequest(
bool allow_download = request_data.allow_download &&
IsResourceTypeFrame(request_data.resource_type);
bool do_not_prompt_for_login = request_data.do_not_prompt_for_login;
- bool is_sync_load = sync_result != NULL;
+ bool is_sync_load = !!sync_result_handler;
// Raw headers are sensitive, as they include Cookie/Set-Cookie, so only
// allow requesting them if requester has ReadRawCookies permission.
@@ -1515,8 +1536,8 @@ void ResourceDispatcherHostImpl::ContinuePendingBeginRequest(
request_data.should_reset_appcache);
std::unique_ptr<ResourceHandler> handler(CreateResourceHandler(
- new_request.get(), request_data, sync_result, route_id, process_type,
- child_id, resource_context, std::move(mojo_request),
+ new_request.get(), request_data, sync_result_handler, route_id,
+ process_type, child_id, resource_context, std::move(mojo_request),
std::move(url_loader_client)));
if (handler)
@@ -1527,7 +1548,7 @@ std::unique_ptr<ResourceHandler>
ResourceDispatcherHostImpl::CreateResourceHandler(
net::URLRequest* request,
const ResourceRequest& request_data,
- IPC::Message* sync_result,
+ const SyncLoadResultCallback& sync_result_handler,
int route_id,
int process_type,
int child_id,
@@ -1540,7 +1561,7 @@ ResourceDispatcherHostImpl::CreateResourceHandler(
"456331 ResourceDispatcherHostImpl::CreateResourceHandler"));
// Construct the IPC resource handler.
std::unique_ptr<ResourceHandler> handler;
- if (sync_result) {
+ if (sync_result_handler) {
// download_to_file is not supported for synchronous requests.
if (request_data.download_to_file) {
bad_message::ReceivedBadMessage(filter_, bad_message::RDH_BAD_DOWNLOAD);
@@ -1549,7 +1570,7 @@ ResourceDispatcherHostImpl::CreateResourceHandler(
DCHECK(!mojo_request.is_pending());
DCHECK(!url_loader_client);
- handler.reset(new SyncResourceHandler(request, sync_result, this));
+ handler.reset(new SyncResourceHandler(request, sync_result_handler, this));
} else {
if (mojo_request.is_pending()) {
handler.reset(new MojoAsyncResourceHandler(request, this,
@@ -1569,8 +1590,9 @@ ResourceDispatcherHostImpl::CreateResourceHandler(
bool start_detached = request_data.download_to_network_cache_only;
// Prefetches and <a ping> requests outlive their child process.
- if (!sync_result && (start_detached ||
- IsDetachableResourceType(request_data.resource_type))) {
+ if (!sync_result_handler &&
+ (start_detached ||
+ IsDetachableResourceType(request_data.resource_type))) {
std::unique_ptr<DetachableResourceHandler> detachable_handler =
base::MakeUnique<DetachableResourceHandler>(
request,
« no previous file with comments | « content/browser/loader/resource_dispatcher_host_impl.h ('k') | content/browser/loader/sync_resource_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698