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

Side by Side 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: fix Created 4 years, 4 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc e-loading 5 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc e-loading
6 6
7 #include "content/browser/loader/resource_dispatcher_host_impl.h" 7 #include "content/browser/loader/resource_dispatcher_host_impl.h"
8 8
9 #include <stddef.h> 9 #include <stddef.h>
10 10
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 #include "content/browser/download/save_file_resource_handler.h" 44 #include "content/browser/download/save_file_resource_handler.h"
45 #include "content/browser/frame_host/frame_tree.h" 45 #include "content/browser/frame_host/frame_tree.h"
46 #include "content/browser/frame_host/navigation_request_info.h" 46 #include "content/browser/frame_host/navigation_request_info.h"
47 #include "content/browser/frame_host/navigator.h" 47 #include "content/browser/frame_host/navigator.h"
48 #include "content/browser/loader/async_resource_handler.h" 48 #include "content/browser/loader/async_resource_handler.h"
49 #include "content/browser/loader/async_revalidation_manager.h" 49 #include "content/browser/loader/async_revalidation_manager.h"
50 #include "content/browser/loader/cross_site_resource_handler.h" 50 #include "content/browser/loader/cross_site_resource_handler.h"
51 #include "content/browser/loader/detachable_resource_handler.h" 51 #include "content/browser/loader/detachable_resource_handler.h"
52 #include "content/browser/loader/loader_delegate.h" 52 #include "content/browser/loader/loader_delegate.h"
53 #include "content/browser/loader/mime_type_resource_handler.h" 53 #include "content/browser/loader/mime_type_resource_handler.h"
54 #include "content/browser/loader/mojo_async_resource_handler.h"
54 #include "content/browser/loader/navigation_resource_handler.h" 55 #include "content/browser/loader/navigation_resource_handler.h"
55 #include "content/browser/loader/navigation_resource_throttle.h" 56 #include "content/browser/loader/navigation_resource_throttle.h"
56 #include "content/browser/loader/navigation_url_loader_impl_core.h" 57 #include "content/browser/loader/navigation_url_loader_impl_core.h"
57 #include "content/browser/loader/power_save_block_resource_throttle.h" 58 #include "content/browser/loader/power_save_block_resource_throttle.h"
58 #include "content/browser/loader/redirect_to_file_resource_handler.h" 59 #include "content/browser/loader/redirect_to_file_resource_handler.h"
59 #include "content/browser/loader/resource_message_filter.h" 60 #include "content/browser/loader/resource_message_filter.h"
60 #include "content/browser/loader/resource_request_info_impl.h" 61 #include "content/browser/loader/resource_request_info_impl.h"
61 #include "content/browser/loader/stream_resource_handler.h" 62 #include "content/browser/loader/stream_resource_handler.h"
62 #include "content/browser/loader/sync_resource_handler.h" 63 #include "content/browser/loader/sync_resource_handler.h"
63 #include "content/browser/loader/throttling_resource_handler.h" 64 #include "content/browser/loader/throttling_resource_handler.h"
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 case RESOURCE_TYPE_CSP_REPORT: 219 case RESOURCE_TYPE_CSP_REPORT:
219 return true; 220 return true;
220 default: 221 default:
221 return false; 222 return false;
222 } 223 }
223 } 224 }
224 225
225 // Aborts a request before an URLRequest has actually been created. 226 // Aborts a request before an URLRequest has actually been created.
226 void AbortRequestBeforeItStarts(ResourceMessageFilter* filter, 227 void AbortRequestBeforeItStarts(ResourceMessageFilter* filter,
227 IPC::Message* sync_result, 228 IPC::Message* sync_result,
228 int request_id) { 229 int request_id,
230 mojom::URLLoaderClientPtr url_loader_client) {
229 if (sync_result) { 231 if (sync_result) {
230 SyncLoadResult result; 232 SyncLoadResult result;
231 result.error_code = net::ERR_ABORTED; 233 result.error_code = net::ERR_ABORTED;
232 ResourceHostMsg_SyncLoad::WriteReplyParams(sync_result, result); 234 ResourceHostMsg_SyncLoad::WriteReplyParams(sync_result, result);
233 filter->Send(sync_result); 235 filter->Send(sync_result);
234 } else { 236 } else {
235 // Tell the renderer that this request was disallowed. 237 // Tell the renderer that this request was disallowed.
236 ResourceRequestCompletionStatus request_complete_data; 238 ResourceRequestCompletionStatus request_complete_data;
237 request_complete_data.error_code = net::ERR_ABORTED; 239 request_complete_data.error_code = net::ERR_ABORTED;
238 request_complete_data.was_ignored_by_handler = false; 240 request_complete_data.was_ignored_by_handler = false;
239 request_complete_data.exists_in_cache = false; 241 request_complete_data.exists_in_cache = false;
240 // No security info needed, connection not established. 242 // No security info needed, connection not established.
241 request_complete_data.completion_time = base::TimeTicks(); 243 request_complete_data.completion_time = base::TimeTicks();
242 request_complete_data.encoded_data_length = 0; 244 request_complete_data.encoded_data_length = 0;
243 filter->Send(new ResourceMsg_RequestComplete( 245 if (url_loader_client) {
244 request_id, request_complete_data)); 246 url_loader_client->OnComplete(request_complete_data);
247 } else {
248 filter->Send(
249 new ResourceMsg_RequestComplete(request_id, request_complete_data));
250 }
245 } 251 }
246 } 252 }
247 253
248 void SetReferrerForRequest(net::URLRequest* request, const Referrer& referrer) { 254 void SetReferrerForRequest(net::URLRequest* request, const Referrer& referrer) {
249 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 255 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
250 if (!referrer.url.is_valid() || 256 if (!referrer.url.is_valid() ||
251 command_line->HasSwitch(switches::kNoReferrers)) { 257 command_line->HasSwitch(switches::kNoReferrers)) {
252 request->SetReferrer(std::string()); 258 request->SetReferrer(std::string());
253 } else { 259 } else {
254 request->SetReferrer(referrer.url.spec()); 260 request->SetReferrer(referrer.url.spec());
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 // navigation becomes the default. crbug.com/561610 542 // navigation becomes the default. crbug.com/561610
537 if (!IsBrowserSideNavigationEnabled() && 543 if (!IsBrowserSideNavigationEnabled() &&
538 base::FeatureList::IsEnabled(features::kStaleWhileRevalidate)) { 544 base::FeatureList::IsEnabled(features::kStaleWhileRevalidate)) {
539 async_revalidation_manager_.reset(new AsyncRevalidationManager); 545 async_revalidation_manager_.reset(new AsyncRevalidationManager);
540 } 546 }
541 } 547 }
542 548
543 ResourceDispatcherHostImpl::~ResourceDispatcherHostImpl() { 549 ResourceDispatcherHostImpl::~ResourceDispatcherHostImpl() {
544 DCHECK(outstanding_requests_stats_map_.empty()); 550 DCHECK(outstanding_requests_stats_map_.empty());
545 DCHECK(g_resource_dispatcher_host); 551 DCHECK(g_resource_dispatcher_host);
552 DCHECK_CURRENTLY_ON(BrowserThread::UI);
546 g_resource_dispatcher_host = NULL; 553 g_resource_dispatcher_host = NULL;
547 } 554 }
548 555
549 // static 556 // static
550 ResourceDispatcherHostImpl* ResourceDispatcherHostImpl::Get() { 557 ResourceDispatcherHostImpl* ResourceDispatcherHostImpl::Get() {
551 return g_resource_dispatcher_host; 558 return g_resource_dispatcher_host;
552 } 559 }
553 560
554 // static 561 // static
555 void ResourceDispatcherHostImpl::ResumeBlockedRequestsForRouteFromUI( 562 void ResourceDispatcherHostImpl::ResumeBlockedRequestsForRouteFromUI(
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after
1095 for (const auto& routing_id : ids) { 1102 for (const auto& routing_id : ids) {
1096 CancelBlockedRequestsForRoute(routing_id); 1103 CancelBlockedRequestsForRoute(routing_id);
1097 } 1104 }
1098 1105
1099 scheduler_.reset(); 1106 scheduler_.reset();
1100 } 1107 }
1101 1108
1102 bool ResourceDispatcherHostImpl::OnMessageReceived( 1109 bool ResourceDispatcherHostImpl::OnMessageReceived(
1103 const IPC::Message& message, 1110 const IPC::Message& message,
1104 ResourceMessageFilter* filter) { 1111 ResourceMessageFilter* filter) {
1112 DCHECK_CURRENTLY_ON(BrowserThread::IO);
1105 filter_ = filter; 1113 filter_ = filter;
1106 bool handled = true; 1114 bool handled = true;
1107 IPC_BEGIN_MESSAGE_MAP(ResourceDispatcherHostImpl, message) 1115 IPC_BEGIN_MESSAGE_MAP(ResourceDispatcherHostImpl, message)
1108 IPC_MESSAGE_HANDLER(ResourceHostMsg_RequestResource, OnRequestResource) 1116 IPC_MESSAGE_HANDLER(ResourceHostMsg_RequestResource, OnRequestResource)
1109 IPC_MESSAGE_HANDLER_DELAY_REPLY(ResourceHostMsg_SyncLoad, OnSyncLoad) 1117 IPC_MESSAGE_HANDLER_DELAY_REPLY(ResourceHostMsg_SyncLoad, OnSyncLoad)
1110 IPC_MESSAGE_HANDLER(ResourceHostMsg_ReleaseDownloadedFile, 1118 IPC_MESSAGE_HANDLER(ResourceHostMsg_ReleaseDownloadedFile,
1111 OnReleaseDownloadedFile) 1119 OnReleaseDownloadedFile)
1112 IPC_MESSAGE_HANDLER(ResourceHostMsg_DataDownloaded_ACK, OnDataDownloadedACK) 1120 IPC_MESSAGE_HANDLER(ResourceHostMsg_DataDownloaded_ACK, OnDataDownloadedACK)
1113 IPC_MESSAGE_HANDLER(ResourceHostMsg_CancelRequest, OnCancelRequest) 1121 IPC_MESSAGE_HANDLER(ResourceHostMsg_CancelRequest, OnCancelRequest)
1114 IPC_MESSAGE_HANDLER(ResourceHostMsg_DidChangePriority, OnDidChangePriority) 1122 IPC_MESSAGE_HANDLER(ResourceHostMsg_DidChangePriority, OnDidChangePriority)
(...skipping 21 matching lines...) Expand all
1136 } 1144 }
1137 1145
1138 filter_ = NULL; 1146 filter_ = NULL;
1139 return handled; 1147 return handled;
1140 } 1148 }
1141 1149
1142 void ResourceDispatcherHostImpl::OnRequestResource( 1150 void ResourceDispatcherHostImpl::OnRequestResource(
1143 int routing_id, 1151 int routing_id,
1144 int request_id, 1152 int request_id,
1145 const ResourceRequest& request_data) { 1153 const ResourceRequest& request_data) {
1154 OnRequestResourceInternal(routing_id, request_id, request_data, nullptr,
1155 nullptr);
1156 }
1157
1158 void ResourceDispatcherHostImpl::OnRequestResourceInternal(
1159 int routing_id,
1160 int request_id,
1161 const ResourceRequest& request_data,
1162 mojo::InterfaceRequest<mojom::URLLoader> mojo_request,
1163 mojom::URLLoaderClientPtr url_loader_client) {
1146 // TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed. 1164 // TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed.
1147 tracked_objects::ScopedTracker tracking_profile( 1165 tracked_objects::ScopedTracker tracking_profile(
1148 FROM_HERE_WITH_EXPLICIT_FUNCTION( 1166 FROM_HERE_WITH_EXPLICIT_FUNCTION(
1149 "477117 ResourceDispatcherHostImpl::OnRequestResource")); 1167 "477117 ResourceDispatcherHostImpl::OnRequestResource"));
1150 // When logging time-to-network only care about main frame and non-transfer 1168 // When logging time-to-network only care about main frame and non-transfer
1151 // navigations. 1169 // navigations.
1152 // PlzNavigate: this log happens from NavigationRequest::OnRequestStarted 1170 // PlzNavigate: this log happens from NavigationRequest::OnRequestStarted
1153 // instead. 1171 // instead.
1154 if (request_data.resource_type == RESOURCE_TYPE_MAIN_FRAME && 1172 if (request_data.resource_type == RESOURCE_TYPE_MAIN_FRAME &&
1155 request_data.transferred_request_request_id == -1 && 1173 request_data.transferred_request_request_id == -1 &&
1156 !IsBrowserSideNavigationEnabled()) { 1174 !IsBrowserSideNavigationEnabled()) {
1157 BrowserThread::PostTask( 1175 BrowserThread::PostTask(
1158 BrowserThread::UI, 1176 BrowserThread::UI,
1159 FROM_HERE, 1177 FROM_HERE,
1160 base::Bind(&LogResourceRequestTimeOnUI, 1178 base::Bind(&LogResourceRequestTimeOnUI,
1161 TimeTicks::Now(), 1179 TimeTicks::Now(),
1162 filter_->child_id(), 1180 filter_->child_id(),
1163 request_data.render_frame_id, 1181 request_data.render_frame_id,
1164 request_data.url)); 1182 request_data.url));
1165 } 1183 }
1166 BeginRequest(request_id, request_data, NULL, routing_id); 1184 BeginRequest(request_id, request_data, NULL, routing_id,
1185 std::move(mojo_request), std::move(url_loader_client));
1167 } 1186 }
1168 1187
1169 // Begins a resource request with the given params on behalf of the specified 1188 // Begins a resource request with the given params on behalf of the specified
1170 // child process. Responses will be dispatched through the given receiver. The 1189 // child process. Responses will be dispatched through the given receiver. The
1171 // process ID is used to lookup WebContentsImpl from routing_id's in the case of 1190 // process ID is used to lookup WebContentsImpl from routing_id's in the case of
1172 // a request from a renderer. request_context is the cookie/cache context to be 1191 // a request from a renderer. request_context is the cookie/cache context to be
1173 // used for this request. 1192 // used for this request.
1174 // 1193 //
1175 // If sync_result is non-null, then a SyncLoad reply will be generated, else 1194 // If sync_result is non-null, then a SyncLoad reply will be generated, else
1176 // a normal asynchronous set of response messages will be generated. 1195 // a normal asynchronous set of response messages will be generated.
1177 void ResourceDispatcherHostImpl::OnSyncLoad(int request_id, 1196 void ResourceDispatcherHostImpl::OnSyncLoad(int request_id,
1178 const ResourceRequest& request_data, 1197 const ResourceRequest& request_data,
1179 IPC::Message* sync_result) { 1198 IPC::Message* sync_result) {
1180 BeginRequest(request_id, request_data, sync_result, 1199 BeginRequest(request_id, request_data, sync_result, sync_result->routing_id(),
1181 sync_result->routing_id()); 1200 nullptr, nullptr);
1182 } 1201 }
1183 1202
1184 bool ResourceDispatcherHostImpl::IsRequestIDInUse( 1203 bool ResourceDispatcherHostImpl::IsRequestIDInUse(
1185 const GlobalRequestID& id) const { 1204 const GlobalRequestID& id) const {
1186 if (pending_loaders_.find(id) != pending_loaders_.end()) 1205 if (pending_loaders_.find(id) != pending_loaders_.end())
1187 return true; 1206 return true;
1188 for (const auto& blocked_loaders : blocked_loaders_map_) { 1207 for (const auto& blocked_loaders : blocked_loaders_map_) {
1189 for (const auto& loader : *blocked_loaders.second.get()) { 1208 for (const auto& loader : *blocked_loaders.second.get()) {
1190 ResourceRequestInfoImpl* info = loader->GetRequestInfo(); 1209 ResourceRequestInfoImpl* info = loader->GetRequestInfo();
1191 if (info->GetGlobalRequestID() == id) 1210 if (info->GetGlobalRequestID() == id)
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
1286 } 1305 }
1287 1306
1288 // We should have a CrossSiteResourceHandler to finish the transfer. 1307 // We should have a CrossSiteResourceHandler to finish the transfer.
1289 DCHECK(info->cross_site_handler()); 1308 DCHECK(info->cross_site_handler());
1290 } 1309 }
1291 1310
1292 void ResourceDispatcherHostImpl::BeginRequest( 1311 void ResourceDispatcherHostImpl::BeginRequest(
1293 int request_id, 1312 int request_id,
1294 const ResourceRequest& request_data, 1313 const ResourceRequest& request_data,
1295 IPC::Message* sync_result, // only valid for sync 1314 IPC::Message* sync_result, // only valid for sync
1296 int route_id) { 1315 int route_id,
1316 mojo::InterfaceRequest<mojom::URLLoader> mojo_request,
1317 mojom::URLLoaderClientPtr url_loader_client) {
1297 int process_type = filter_->process_type(); 1318 int process_type = filter_->process_type();
1298 int child_id = filter_->child_id(); 1319 int child_id = filter_->child_id();
1299 1320
1300 // Reject request id that's currently in use. 1321 // Reject request id that's currently in use.
1301 if (IsRequestIDInUse(GlobalRequestID(child_id, request_id))) { 1322 if (IsRequestIDInUse(GlobalRequestID(child_id, request_id))) {
1302 bad_message::ReceivedBadMessage(filter_, 1323 bad_message::ReceivedBadMessage(filter_,
1303 bad_message::RDH_INVALID_REQUEST_ID); 1324 bad_message::RDH_INVALID_REQUEST_ID);
1304 return; 1325 return;
1305 } 1326 }
1306 1327
(...skipping 19 matching lines...) Expand all
1326 char url_buf[128]; 1347 char url_buf[128];
1327 base::strlcpy(url_buf, request_data.url.spec().c_str(), arraysize(url_buf)); 1348 base::strlcpy(url_buf, request_data.url.spec().c_str(), arraysize(url_buf));
1328 base::debug::Alias(url_buf); 1349 base::debug::Alias(url_buf);
1329 1350
1330 // If the request that's coming in is being transferred from another process, 1351 // If the request that's coming in is being transferred from another process,
1331 // we want to reuse and resume the old loader rather than start a new one. 1352 // we want to reuse and resume the old loader rather than start a new one.
1332 LoaderMap::iterator it = pending_loaders_.find( 1353 LoaderMap::iterator it = pending_loaders_.find(
1333 GlobalRequestID(request_data.transferred_request_child_id, 1354 GlobalRequestID(request_data.transferred_request_child_id,
1334 request_data.transferred_request_request_id)); 1355 request_data.transferred_request_request_id));
1335 if (it != pending_loaders_.end()) { 1356 if (it != pending_loaders_.end()) {
1357 // TODO(yhirano): Make mojo work for this case.
1358 DCHECK(!url_loader_client);
1359
1336 // If the request is transferring to a new process, we can update our 1360 // If the request is transferring to a new process, we can update our
1337 // state and let it resume with its existing ResourceHandlers. 1361 // state and let it resume with its existing ResourceHandlers.
1338 if (it->second->is_transferring()) { 1362 if (it->second->is_transferring()) {
1339 ResourceLoader* deferred_loader = it->second.get(); 1363 ResourceLoader* deferred_loader = it->second.get();
1340 UpdateRequestForTransfer(child_id, route_id, request_id, 1364 UpdateRequestForTransfer(child_id, route_id, request_id,
1341 request_data, it); 1365 request_data, it);
1342 deferred_loader->CompleteTransfer(); 1366 deferred_loader->CompleteTransfer();
1343 } else { 1367 } else {
1344 bad_message::ReceivedBadMessage( 1368 bad_message::ReceivedBadMessage(
1345 filter_, bad_message::RDH_REQUEST_NOT_TRANSFERRING); 1369 filter_, bad_message::RDH_REQUEST_NOT_TRANSFERRING);
1346 } 1370 }
1347 return; 1371 return;
1348 } 1372 }
1349 1373
1350 ResourceContext* resource_context = NULL; 1374 ResourceContext* resource_context = NULL;
1351 net::URLRequestContext* request_context = NULL; 1375 net::URLRequestContext* request_context = NULL;
1352 filter_->GetContexts(request_data.resource_type, &resource_context, 1376 filter_->GetContexts(request_data.resource_type, &resource_context,
1353 &request_context); 1377 &request_context);
1354 1378
1355 // Parse the headers before calling ShouldServiceRequest, so that they are 1379 // Parse the headers before calling ShouldServiceRequest, so that they are
1356 // available to be validated. 1380 // available to be validated.
1357 net::HttpRequestHeaders headers; 1381 net::HttpRequestHeaders headers;
1358 headers.AddHeadersFromString(request_data.headers); 1382 headers.AddHeadersFromString(request_data.headers);
1359 1383
1360 if (is_shutdown_ || 1384 if (is_shutdown_ ||
1361 !ShouldServiceRequest(process_type, child_id, request_data, headers, 1385 !ShouldServiceRequest(process_type, child_id, request_data, headers,
1362 filter_, resource_context)) { 1386 filter_, resource_context)) {
1363 AbortRequestBeforeItStarts(filter_, sync_result, request_id); 1387 AbortRequestBeforeItStarts(filter_, sync_result, request_id,
1388 std::move(url_loader_client));
1364 return; 1389 return;
1365 } 1390 }
1366 1391
1367 // Allow the observer to block/handle the request. 1392 // Allow the observer to block/handle the request.
1368 if (delegate_ && !delegate_->ShouldBeginRequest(request_data.method, 1393 if (delegate_ && !delegate_->ShouldBeginRequest(request_data.method,
1369 request_data.url, 1394 request_data.url,
1370 request_data.resource_type, 1395 request_data.resource_type,
1371 resource_context)) { 1396 resource_context)) {
1372 AbortRequestBeforeItStarts(filter_, sync_result, request_id); 1397 AbortRequestBeforeItStarts(filter_, sync_result, request_id,
1398 std::move(url_loader_client));
1373 return; 1399 return;
1374 } 1400 }
1375 1401
1376 // Construct the request. 1402 // Construct the request.
1377 std::unique_ptr<net::URLRequest> new_request = request_context->CreateRequest( 1403 std::unique_ptr<net::URLRequest> new_request = request_context->CreateRequest(
1378 is_navigation_stream_request ? request_data.resource_body_stream_url 1404 is_navigation_stream_request ? request_data.resource_body_stream_url
1379 : request_data.url, 1405 : request_data.url,
1380 request_data.priority, nullptr); 1406 request_data.priority, nullptr);
1381 1407
1382 // PlzNavigate: Always set the method to GET when gaining access to the 1408 // PlzNavigate: Always set the method to GET when gaining access to the
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
1542 } 1568 }
1543 1569
1544 // Have the appcache associate its extra info with the request. 1570 // Have the appcache associate its extra info with the request.
1545 AppCacheInterceptor::SetExtraRequestInfo( 1571 AppCacheInterceptor::SetExtraRequestInfo(
1546 new_request.get(), filter_->appcache_service(), child_id, 1572 new_request.get(), filter_->appcache_service(), child_id,
1547 request_data.appcache_host_id, request_data.resource_type, 1573 request_data.appcache_host_id, request_data.resource_type,
1548 request_data.should_reset_appcache); 1574 request_data.should_reset_appcache);
1549 1575
1550 std::unique_ptr<ResourceHandler> handler(CreateResourceHandler( 1576 std::unique_ptr<ResourceHandler> handler(CreateResourceHandler(
1551 new_request.get(), request_data, sync_result, route_id, process_type, 1577 new_request.get(), request_data, sync_result, route_id, process_type,
1552 child_id, resource_context)); 1578 child_id, resource_context, std::move(mojo_request),
1579 std::move(url_loader_client)));
1553 1580
1554 if (handler) 1581 if (handler)
1555 BeginRequestInternal(std::move(new_request), std::move(handler)); 1582 BeginRequestInternal(std::move(new_request), std::move(handler));
1556 } 1583 }
1557 1584
1558 std::unique_ptr<ResourceHandler> 1585 std::unique_ptr<ResourceHandler>
1559 ResourceDispatcherHostImpl::CreateResourceHandler( 1586 ResourceDispatcherHostImpl::CreateResourceHandler(
1560 net::URLRequest* request, 1587 net::URLRequest* request,
1561 const ResourceRequest& request_data, 1588 const ResourceRequest& request_data,
1562 IPC::Message* sync_result, 1589 IPC::Message* sync_result,
1563 int route_id, 1590 int route_id,
1564 int process_type, 1591 int process_type,
1565 int child_id, 1592 int child_id,
1566 ResourceContext* resource_context) { 1593 ResourceContext* resource_context,
1594 mojo::InterfaceRequest<mojom::URLLoader> mojo_request,
1595 mojom::URLLoaderClientPtr url_loader_client) {
1567 // TODO(pkasting): Remove ScopedTracker below once crbug.com/456331 is fixed. 1596 // TODO(pkasting): Remove ScopedTracker below once crbug.com/456331 is fixed.
1568 tracked_objects::ScopedTracker tracking_profile( 1597 tracked_objects::ScopedTracker tracking_profile(
1569 FROM_HERE_WITH_EXPLICIT_FUNCTION( 1598 FROM_HERE_WITH_EXPLICIT_FUNCTION(
1570 "456331 ResourceDispatcherHostImpl::CreateResourceHandler")); 1599 "456331 ResourceDispatcherHostImpl::CreateResourceHandler"));
1571 // Construct the IPC resource handler. 1600 // Construct the IPC resource handler.
1572 std::unique_ptr<ResourceHandler> handler; 1601 std::unique_ptr<ResourceHandler> handler;
1573 if (sync_result) { 1602 if (sync_result) {
1574 // download_to_file is not supported for synchronous requests. 1603 // download_to_file is not supported for synchronous requests.
1575 if (request_data.download_to_file) { 1604 if (request_data.download_to_file) {
1576 bad_message::ReceivedBadMessage(filter_, bad_message::RDH_BAD_DOWNLOAD); 1605 bad_message::ReceivedBadMessage(filter_, bad_message::RDH_BAD_DOWNLOAD);
1577 return std::unique_ptr<ResourceHandler>(); 1606 return std::unique_ptr<ResourceHandler>();
1578 } 1607 }
1579 1608
1609 DCHECK(!mojo_request.is_pending());
1610 DCHECK(!url_loader_client);
1580 handler.reset(new SyncResourceHandler(request, sync_result, this)); 1611 handler.reset(new SyncResourceHandler(request, sync_result, this));
1581 } else { 1612 } else {
1582 handler.reset(new AsyncResourceHandler(request, this)); 1613 if (mojo_request.is_pending()) {
1614 handler.reset(new MojoAsyncResourceHandler(request, this,
1615 std::move(mojo_request),
1616 std::move(url_loader_client)));
1617 } else {
1618 handler.reset(new AsyncResourceHandler(request, this));
1619 }
1583 1620
1584 // The RedirectToFileResourceHandler depends on being next in the chain. 1621 // The RedirectToFileResourceHandler depends on being next in the chain.
1585 if (request_data.download_to_file) { 1622 if (request_data.download_to_file) {
1586 handler.reset( 1623 handler.reset(
1587 new RedirectToFileResourceHandler(std::move(handler), request)); 1624 new RedirectToFileResourceHandler(std::move(handler), request));
1588 } 1625 }
1589 } 1626 }
1590 1627
1591 // Prefetches and <a ping> requests outlive their child process. 1628 // Prefetches and <a ping> requests outlive their child process.
1592 if (!sync_result && IsDetachableResourceType(request_data.resource_type)) { 1629 if (!sync_result && IsDetachableResourceType(request_data.resource_type)) {
(...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after
2272 void ResourceDispatcherHostImpl::SetLoaderDelegate( 2309 void ResourceDispatcherHostImpl::SetLoaderDelegate(
2273 LoaderDelegate* loader_delegate) { 2310 LoaderDelegate* loader_delegate) {
2274 loader_delegate_ = loader_delegate; 2311 loader_delegate_ = loader_delegate;
2275 } 2312 }
2276 2313
2277 void ResourceDispatcherHostImpl::OnRenderFrameDeleted( 2314 void ResourceDispatcherHostImpl::OnRenderFrameDeleted(
2278 const GlobalFrameRoutingId& global_routing_id) { 2315 const GlobalFrameRoutingId& global_routing_id) {
2279 CancelRequestsForRoute(global_routing_id); 2316 CancelRequestsForRoute(global_routing_id);
2280 } 2317 }
2281 2318
2319 void ResourceDispatcherHostImpl::OnRequestResourceWithMojo(
2320 int routing_id,
2321 int request_id,
2322 const ResourceRequest& request,
2323 mojo::InterfaceRequest<mojom::URLLoader> mojo_request,
2324 mojom::URLLoaderClientPtr url_loader_client,
2325 ResourceMessageFilter* filter) {
2326 filter_ = filter;
2327 OnRequestResourceInternal(routing_id, request_id, request,
2328 std::move(mojo_request),
2329 std::move(url_loader_client));
2330 filter_ = nullptr;
2331 }
2332
2282 // static 2333 // static
2283 int ResourceDispatcherHostImpl::CalculateApproximateMemoryCost( 2334 int ResourceDispatcherHostImpl::CalculateApproximateMemoryCost(
2284 net::URLRequest* request) { 2335 net::URLRequest* request) {
2285 // The following fields should be a minor size contribution (experimentally 2336 // The following fields should be a minor size contribution (experimentally
2286 // on the order of 100). However since they are variable length, it could 2337 // on the order of 100). However since they are variable length, it could
2287 // in theory be a sizeable contribution. 2338 // in theory be a sizeable contribution.
2288 int strings_cost = request->extra_request_headers().ToString().size() + 2339 int strings_cost = request->extra_request_headers().ToString().size() +
2289 request->original_url().spec().size() + 2340 request->original_url().spec().size() +
2290 request->referrer().size() + 2341 request->referrer().size() +
2291 request->method().size(); 2342 request->method().size();
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
2599 ssl.cert_id = GetCertStore()->StoreCert(ssl_info.cert.get(), child_id); 2650 ssl.cert_id = GetCertStore()->StoreCert(ssl_info.cert.get(), child_id);
2600 response->head.security_info = SerializeSecurityInfo(ssl); 2651 response->head.security_info = SerializeSecurityInfo(ssl);
2601 } 2652 }
2602 2653
2603 CertStore* ResourceDispatcherHostImpl::GetCertStore() { 2654 CertStore* ResourceDispatcherHostImpl::GetCertStore() {
2604 return cert_store_for_testing_ ? cert_store_for_testing_ 2655 return cert_store_for_testing_ ? cert_store_for_testing_
2605 : CertStore::GetInstance(); 2656 : CertStore::GetInstance();
2606 } 2657 }
2607 2658
2608 } // namespace content 2659 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698