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

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

Issue 1970693002: Use mojo for Chrome Loading, Part 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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 4de8a0874c8d0f7434c35b0f0506527284926508..ccf07cad4fc45744a472a41a7070a450b3d027ee 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));
+ }
}
}
@@ -538,6 +544,50 @@ ResourceDispatcherHost* ResourceDispatcherHost::Get() {
return g_resource_dispatcher_host;
}
+// This is a helper class consisting of mojo-related functionalities used in
+// ResourceDispatcherHostImpl.
+class ResourceDispatcherHostImpl::MojoHelper final {
kinuko 2016/05/26 08:43:12 (At this point it may not make much sense to have
yhirano 2016/05/26 15:42:44 Done.
+ public:
+ MojoHelper() {}
+
+ // Adds |loader| as an uninitiated loader.
+ void 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))));
+ }
+
+ // Takes and returns the uninitiated loader whose address equals to |loader|.
+ std::unique_ptr<mojom::URLLoader> 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;
+ }
+
+ // Cancels all uninitiated loaders for |child_id|.
+ void CancelUninitiatedLoaders(int child_id) {
+ 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;
+ }
+ }
+ }
+
+ private:
+ std::map<mojom::URLLoader*, std::pair<int, std::unique_ptr<mojom::URLLoader>>>
+ uninitiated_url_loaders_;
+
+ DISALLOW_COPY_AND_ASSIGN(MojoHelper);
+};
+
ResourceDispatcherHostImpl::ResourceDispatcherHostImpl()
: save_file_manager_(new SaveFileManager()),
request_id_(-1),
@@ -551,7 +601,8 @@ ResourceDispatcherHostImpl::ResourceDispatcherHostImpl()
filter_(NULL),
delegate_(NULL),
allow_cross_origin_auth_prompt_(false),
- cert_store_for_testing_(nullptr) {
+ cert_store_for_testing_(nullptr),
+ mojo_helper_(new MojoHelper()) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
DCHECK(!g_resource_dispatcher_host);
g_resource_dispatcher_host = this;
@@ -584,6 +635,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 +1230,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 +1272,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 +1302,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
@@ -1254,7 +1318,7 @@ 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());
+ sync_result->routing_id(), nullptr, nullptr);
}
bool ResourceDispatcherHostImpl::IsRequestIDInUse(
@@ -1369,7 +1433,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 +1504,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 +1514,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 +1696,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 +1711,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 +1727,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 +2142,11 @@ 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)
+ mojo_helper_->CancelUninitiatedLoaders(child_id);
}
// Cancels the request and removes it from the list.
@@ -2351,6 +2434,31 @@ 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::AddUninitiatedURLLoader(
+ int child_id,
+ std::unique_ptr<mojom::URLLoader> loader) {
+ mojo_helper_->AddUninitiatedURLLoader(child_id, std::move(loader));
+}
+
+std::unique_ptr<mojom::URLLoader>
+ResourceDispatcherHostImpl::TakeUninitiatedURLLoader(mojom::URLLoader* loader) {
+ return mojo_helper_->TakeUninitiatedURLLoader(loader);
+}
+
// static
int ResourceDispatcherHostImpl::CalculateApproximateMemoryCost(
net::URLRequest* request) {

Powered by Google App Engine
This is Rietveld 408576698