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

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, 5 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 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 // navigation becomes the default. crbug.com/561610 557 // navigation becomes the default. crbug.com/561610
552 if (!IsBrowserSideNavigationEnabled() && 558 if (!IsBrowserSideNavigationEnabled() &&
553 base::FeatureList::IsEnabled(features::kStaleWhileRevalidate)) { 559 base::FeatureList::IsEnabled(features::kStaleWhileRevalidate)) {
554 async_revalidation_manager_.reset(new AsyncRevalidationManager); 560 async_revalidation_manager_.reset(new AsyncRevalidationManager);
555 } 561 }
556 } 562 }
557 563
558 ResourceDispatcherHostImpl::~ResourceDispatcherHostImpl() { 564 ResourceDispatcherHostImpl::~ResourceDispatcherHostImpl() {
559 DCHECK(outstanding_requests_stats_map_.empty()); 565 DCHECK(outstanding_requests_stats_map_.empty());
560 DCHECK(g_resource_dispatcher_host); 566 DCHECK(g_resource_dispatcher_host);
567 DCHECK_CURRENTLY_ON(BrowserThread::UI);
561 g_resource_dispatcher_host = NULL; 568 g_resource_dispatcher_host = NULL;
562 } 569 }
563 570
564 // static 571 // static
565 ResourceDispatcherHostImpl* ResourceDispatcherHostImpl::Get() { 572 ResourceDispatcherHostImpl* ResourceDispatcherHostImpl::Get() {
566 return g_resource_dispatcher_host; 573 return g_resource_dispatcher_host;
567 } 574 }
568 575
569 // static 576 // static
570 void ResourceDispatcherHostImpl::ResumeBlockedRequestsForRouteFromUI( 577 void ResourceDispatcherHostImpl::ResumeBlockedRequestsForRouteFromUI(
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after
1110 for (const auto& routing_id : ids) { 1117 for (const auto& routing_id : ids) {
1111 CancelBlockedRequestsForRoute(routing_id); 1118 CancelBlockedRequestsForRoute(routing_id);
1112 } 1119 }
1113 1120
1114 scheduler_.reset(); 1121 scheduler_.reset();
1115 } 1122 }
1116 1123
1117 bool ResourceDispatcherHostImpl::OnMessageReceived( 1124 bool ResourceDispatcherHostImpl::OnMessageReceived(
1118 const IPC::Message& message, 1125 const IPC::Message& message,
1119 ResourceMessageFilter* filter) { 1126 ResourceMessageFilter* filter) {
1127 DCHECK_CURRENTLY_ON(BrowserThread::IO);
1120 filter_ = filter; 1128 filter_ = filter;
1121 bool handled = true; 1129 bool handled = true;
1122 IPC_BEGIN_MESSAGE_MAP(ResourceDispatcherHostImpl, message) 1130 IPC_BEGIN_MESSAGE_MAP(ResourceDispatcherHostImpl, message)
1123 IPC_MESSAGE_HANDLER(ResourceHostMsg_RequestResource, OnRequestResource) 1131 IPC_MESSAGE_HANDLER(ResourceHostMsg_RequestResource, OnRequestResource)
1124 IPC_MESSAGE_HANDLER_DELAY_REPLY(ResourceHostMsg_SyncLoad, OnSyncLoad) 1132 IPC_MESSAGE_HANDLER_DELAY_REPLY(ResourceHostMsg_SyncLoad, OnSyncLoad)
1125 IPC_MESSAGE_HANDLER(ResourceHostMsg_ReleaseDownloadedFile, 1133 IPC_MESSAGE_HANDLER(ResourceHostMsg_ReleaseDownloadedFile,
1126 OnReleaseDownloadedFile) 1134 OnReleaseDownloadedFile)
1127 IPC_MESSAGE_HANDLER(ResourceHostMsg_DataDownloaded_ACK, OnDataDownloadedACK) 1135 IPC_MESSAGE_HANDLER(ResourceHostMsg_DataDownloaded_ACK, OnDataDownloadedACK)
1128 IPC_MESSAGE_HANDLER(ResourceHostMsg_CancelRequest, OnCancelRequest) 1136 IPC_MESSAGE_HANDLER(ResourceHostMsg_CancelRequest, OnCancelRequest)
1129 IPC_MESSAGE_HANDLER(ResourceHostMsg_DidChangePriority, OnDidChangePriority) 1137 IPC_MESSAGE_HANDLER(ResourceHostMsg_DidChangePriority, OnDidChangePriority)
(...skipping 21 matching lines...) Expand all
1151 } 1159 }
1152 1160
1153 filter_ = NULL; 1161 filter_ = NULL;
1154 return handled; 1162 return handled;
1155 } 1163 }
1156 1164
1157 void ResourceDispatcherHostImpl::OnRequestResource( 1165 void ResourceDispatcherHostImpl::OnRequestResource(
1158 int routing_id, 1166 int routing_id,
1159 int request_id, 1167 int request_id,
1160 const ResourceRequest& request_data) { 1168 const ResourceRequest& request_data) {
1169 OnRequestResourceInternal(routing_id, request_id, request_data, nullptr,
1170 nullptr);
1171 }
1172
1173 void ResourceDispatcherHostImpl::OnRequestResourceInternal(
1174 int routing_id,
1175 int request_id,
1176 const ResourceRequest& request_data,
1177 mojo::InterfaceRequest<mojom::URLLoader> mojo_request,
1178 mojom::URLLoaderClientPtr url_loader_client) {
1161 // TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed. 1179 // TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed.
1162 tracked_objects::ScopedTracker tracking_profile( 1180 tracked_objects::ScopedTracker tracking_profile(
1163 FROM_HERE_WITH_EXPLICIT_FUNCTION( 1181 FROM_HERE_WITH_EXPLICIT_FUNCTION(
1164 "477117 ResourceDispatcherHostImpl::OnRequestResource")); 1182 "477117 ResourceDispatcherHostImpl::OnRequestResource"));
1165 // When logging time-to-network only care about main frame and non-transfer 1183 // When logging time-to-network only care about main frame and non-transfer
1166 // navigations. 1184 // navigations.
1167 // PlzNavigate: this log happens from NavigationRequest::OnRequestStarted 1185 // PlzNavigate: this log happens from NavigationRequest::OnRequestStarted
1168 // instead. 1186 // instead.
1169 if (request_data.resource_type == RESOURCE_TYPE_MAIN_FRAME && 1187 if (request_data.resource_type == RESOURCE_TYPE_MAIN_FRAME &&
1170 request_data.transferred_request_request_id == -1 && 1188 request_data.transferred_request_request_id == -1 &&
1171 !IsBrowserSideNavigationEnabled()) { 1189 !IsBrowserSideNavigationEnabled()) {
1172 BrowserThread::PostTask( 1190 BrowserThread::PostTask(
1173 BrowserThread::UI, 1191 BrowserThread::UI,
1174 FROM_HERE, 1192 FROM_HERE,
1175 base::Bind(&LogResourceRequestTimeOnUI, 1193 base::Bind(&LogResourceRequestTimeOnUI,
1176 TimeTicks::Now(), 1194 TimeTicks::Now(),
1177 filter_->child_id(), 1195 filter_->child_id(),
1178 request_data.render_frame_id, 1196 request_data.render_frame_id,
1179 request_data.url)); 1197 request_data.url));
1180 } 1198 }
1181 BeginRequest(request_id, request_data, NULL, routing_id); 1199 BeginRequest(request_id, request_data, NULL, routing_id,
1200 std::move(mojo_request), std::move(url_loader_client));
1182 } 1201 }
1183 1202
1184 // Begins a resource request with the given params on behalf of the specified 1203 // Begins a resource request with the given params on behalf of the specified
1185 // child process. Responses will be dispatched through the given receiver. The 1204 // child process. Responses will be dispatched through the given receiver. The
1186 // process ID is used to lookup WebContentsImpl from routing_id's in the case of 1205 // process ID is used to lookup WebContentsImpl from routing_id's in the case of
1187 // a request from a renderer. request_context is the cookie/cache context to be 1206 // a request from a renderer. request_context is the cookie/cache context to be
1188 // used for this request. 1207 // used for this request.
1189 // 1208 //
1190 // If sync_result is non-null, then a SyncLoad reply will be generated, else 1209 // If sync_result is non-null, then a SyncLoad reply will be generated, else
1191 // a normal asynchronous set of response messages will be generated. 1210 // a normal asynchronous set of response messages will be generated.
1192 void ResourceDispatcherHostImpl::OnSyncLoad(int request_id, 1211 void ResourceDispatcherHostImpl::OnSyncLoad(int request_id,
1193 const ResourceRequest& request_data, 1212 const ResourceRequest& request_data,
1194 IPC::Message* sync_result) { 1213 IPC::Message* sync_result) {
1195 BeginRequest(request_id, request_data, sync_result, 1214 BeginRequest(request_id, request_data, sync_result, sync_result->routing_id(),
1196 sync_result->routing_id()); 1215 nullptr, nullptr);
1197 } 1216 }
1198 1217
1199 bool ResourceDispatcherHostImpl::IsRequestIDInUse( 1218 bool ResourceDispatcherHostImpl::IsRequestIDInUse(
1200 const GlobalRequestID& id) const { 1219 const GlobalRequestID& id) const {
1201 if (pending_loaders_.find(id) != pending_loaders_.end()) 1220 if (pending_loaders_.find(id) != pending_loaders_.end())
1202 return true; 1221 return true;
1203 for (const auto& blocked_loaders : blocked_loaders_map_) { 1222 for (const auto& blocked_loaders : blocked_loaders_map_) {
1204 for (const auto& loader : *blocked_loaders.second.get()) { 1223 for (const auto& loader : *blocked_loaders.second.get()) {
1205 ResourceRequestInfoImpl* info = loader->GetRequestInfo(); 1224 ResourceRequestInfoImpl* info = loader->GetRequestInfo();
1206 if (info->GetGlobalRequestID() == id) 1225 if (info->GetGlobalRequestID() == id)
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
1301 } 1320 }
1302 1321
1303 // We should have a CrossSiteResourceHandler to finish the transfer. 1322 // We should have a CrossSiteResourceHandler to finish the transfer.
1304 DCHECK(info->cross_site_handler()); 1323 DCHECK(info->cross_site_handler());
1305 } 1324 }
1306 1325
1307 void ResourceDispatcherHostImpl::BeginRequest( 1326 void ResourceDispatcherHostImpl::BeginRequest(
1308 int request_id, 1327 int request_id,
1309 const ResourceRequest& request_data, 1328 const ResourceRequest& request_data,
1310 IPC::Message* sync_result, // only valid for sync 1329 IPC::Message* sync_result, // only valid for sync
1311 int route_id) { 1330 int route_id,
1331 mojo::InterfaceRequest<mojom::URLLoader> mojo_request,
1332 mojom::URLLoaderClientPtr url_loader_client) {
1312 int process_type = filter_->process_type(); 1333 int process_type = filter_->process_type();
1313 int child_id = filter_->child_id(); 1334 int child_id = filter_->child_id();
1314 1335
1315 // Reject request id that's currently in use. 1336 // Reject request id that's currently in use.
1316 if (IsRequestIDInUse(GlobalRequestID(child_id, request_id))) { 1337 if (IsRequestIDInUse(GlobalRequestID(child_id, request_id))) {
1317 bad_message::ReceivedBadMessage(filter_, 1338 bad_message::ReceivedBadMessage(filter_,
1318 bad_message::RDH_INVALID_REQUEST_ID); 1339 bad_message::RDH_INVALID_REQUEST_ID);
1319 return; 1340 return;
1320 } 1341 }
1321 1342
(...skipping 19 matching lines...) Expand all
1341 char url_buf[128]; 1362 char url_buf[128];
1342 base::strlcpy(url_buf, request_data.url.spec().c_str(), arraysize(url_buf)); 1363 base::strlcpy(url_buf, request_data.url.spec().c_str(), arraysize(url_buf));
1343 base::debug::Alias(url_buf); 1364 base::debug::Alias(url_buf);
1344 1365
1345 // If the request that's coming in is being transferred from another process, 1366 // If the request that's coming in is being transferred from another process,
1346 // we want to reuse and resume the old loader rather than start a new one. 1367 // we want to reuse and resume the old loader rather than start a new one.
1347 LoaderMap::iterator it = pending_loaders_.find( 1368 LoaderMap::iterator it = pending_loaders_.find(
1348 GlobalRequestID(request_data.transferred_request_child_id, 1369 GlobalRequestID(request_data.transferred_request_child_id,
1349 request_data.transferred_request_request_id)); 1370 request_data.transferred_request_request_id));
1350 if (it != pending_loaders_.end()) { 1371 if (it != pending_loaders_.end()) {
1372 // TODO(yhirano): Make mojo work for this case.
1373 DCHECK(!url_loader_client);
1374
1351 // If the request is transferring to a new process, we can update our 1375 // If the request is transferring to a new process, we can update our
1352 // state and let it resume with its existing ResourceHandlers. 1376 // state and let it resume with its existing ResourceHandlers.
1353 if (it->second->is_transferring()) { 1377 if (it->second->is_transferring()) {
1354 ResourceLoader* deferred_loader = it->second.get(); 1378 ResourceLoader* deferred_loader = it->second.get();
1355 UpdateRequestForTransfer(child_id, route_id, request_id, 1379 UpdateRequestForTransfer(child_id, route_id, request_id,
1356 request_data, it); 1380 request_data, it);
1357 deferred_loader->CompleteTransfer(); 1381 deferred_loader->CompleteTransfer();
1358 } else { 1382 } else {
1359 bad_message::ReceivedBadMessage( 1383 bad_message::ReceivedBadMessage(
1360 filter_, bad_message::RDH_REQUEST_NOT_TRANSFERRING); 1384 filter_, bad_message::RDH_REQUEST_NOT_TRANSFERRING);
1361 } 1385 }
1362 return; 1386 return;
1363 } 1387 }
1364 1388
1365 ResourceContext* resource_context = NULL; 1389 ResourceContext* resource_context = NULL;
1366 net::URLRequestContext* request_context = NULL; 1390 net::URLRequestContext* request_context = NULL;
1367 filter_->GetContexts(request_data.resource_type, request_data.origin_pid, 1391 filter_->GetContexts(request_data.resource_type, request_data.origin_pid,
1368 &resource_context, &request_context); 1392 &resource_context, &request_context);
1369 1393
1370 // Parse the headers before calling ShouldServiceRequest, so that they are 1394 // Parse the headers before calling ShouldServiceRequest, so that they are
1371 // available to be validated. 1395 // available to be validated.
1372 net::HttpRequestHeaders headers; 1396 net::HttpRequestHeaders headers;
1373 headers.AddHeadersFromString(request_data.headers); 1397 headers.AddHeadersFromString(request_data.headers);
1374 1398
1375 if (is_shutdown_ || 1399 if (is_shutdown_ ||
1376 !ShouldServiceRequest(process_type, child_id, request_data, headers, 1400 !ShouldServiceRequest(process_type, child_id, request_data, headers,
1377 filter_, resource_context)) { 1401 filter_, resource_context)) {
1378 AbortRequestBeforeItStarts(filter_, sync_result, request_id); 1402 AbortRequestBeforeItStarts(filter_, sync_result, request_id,
1403 std::move(url_loader_client));
1379 return; 1404 return;
1380 } 1405 }
1381 1406
1382 // Allow the observer to block/handle the request. 1407 // Allow the observer to block/handle the request.
1383 if (delegate_ && !delegate_->ShouldBeginRequest(request_data.method, 1408 if (delegate_ && !delegate_->ShouldBeginRequest(request_data.method,
1384 request_data.url, 1409 request_data.url,
1385 request_data.resource_type, 1410 request_data.resource_type,
1386 resource_context)) { 1411 resource_context)) {
1387 AbortRequestBeforeItStarts(filter_, sync_result, request_id); 1412 AbortRequestBeforeItStarts(filter_, sync_result, request_id,
1413 std::move(url_loader_client));
1388 return; 1414 return;
1389 } 1415 }
1390 1416
1391 // Construct the request. 1417 // Construct the request.
1392 std::unique_ptr<net::URLRequest> new_request = request_context->CreateRequest( 1418 std::unique_ptr<net::URLRequest> new_request = request_context->CreateRequest(
1393 is_navigation_stream_request ? request_data.resource_body_stream_url 1419 is_navigation_stream_request ? request_data.resource_body_stream_url
1394 : request_data.url, 1420 : request_data.url,
1395 request_data.priority, nullptr); 1421 request_data.priority, nullptr);
1396 1422
1397 // PlzNavigate: Always set the method to GET when gaining access to the 1423 // PlzNavigate: Always set the method to GET when gaining access to the
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
1559 } 1585 }
1560 1586
1561 // Have the appcache associate its extra info with the request. 1587 // Have the appcache associate its extra info with the request.
1562 AppCacheInterceptor::SetExtraRequestInfo( 1588 AppCacheInterceptor::SetExtraRequestInfo(
1563 new_request.get(), filter_->appcache_service(), child_id, 1589 new_request.get(), filter_->appcache_service(), child_id,
1564 request_data.appcache_host_id, request_data.resource_type, 1590 request_data.appcache_host_id, request_data.resource_type,
1565 request_data.should_reset_appcache); 1591 request_data.should_reset_appcache);
1566 1592
1567 std::unique_ptr<ResourceHandler> handler(CreateResourceHandler( 1593 std::unique_ptr<ResourceHandler> handler(CreateResourceHandler(
1568 new_request.get(), request_data, sync_result, route_id, process_type, 1594 new_request.get(), request_data, sync_result, route_id, process_type,
1569 child_id, resource_context)); 1595 child_id, resource_context, std::move(mojo_request),
1596 std::move(url_loader_client)));
1570 1597
1571 if (handler) 1598 if (handler)
1572 BeginRequestInternal(std::move(new_request), std::move(handler)); 1599 BeginRequestInternal(std::move(new_request), std::move(handler));
1573 } 1600 }
1574 1601
1575 std::unique_ptr<ResourceHandler> 1602 std::unique_ptr<ResourceHandler>
1576 ResourceDispatcherHostImpl::CreateResourceHandler( 1603 ResourceDispatcherHostImpl::CreateResourceHandler(
1577 net::URLRequest* request, 1604 net::URLRequest* request,
1578 const ResourceRequest& request_data, 1605 const ResourceRequest& request_data,
1579 IPC::Message* sync_result, 1606 IPC::Message* sync_result,
1580 int route_id, 1607 int route_id,
1581 int process_type, 1608 int process_type,
1582 int child_id, 1609 int child_id,
1583 ResourceContext* resource_context) { 1610 ResourceContext* resource_context,
1611 mojo::InterfaceRequest<mojom::URLLoader> mojo_request,
1612 mojom::URLLoaderClientPtr url_loader_client) {
1584 // TODO(pkasting): Remove ScopedTracker below once crbug.com/456331 is fixed. 1613 // TODO(pkasting): Remove ScopedTracker below once crbug.com/456331 is fixed.
1585 tracked_objects::ScopedTracker tracking_profile( 1614 tracked_objects::ScopedTracker tracking_profile(
1586 FROM_HERE_WITH_EXPLICIT_FUNCTION( 1615 FROM_HERE_WITH_EXPLICIT_FUNCTION(
1587 "456331 ResourceDispatcherHostImpl::CreateResourceHandler")); 1616 "456331 ResourceDispatcherHostImpl::CreateResourceHandler"));
1588 // Construct the IPC resource handler. 1617 // Construct the IPC resource handler.
1589 std::unique_ptr<ResourceHandler> handler; 1618 std::unique_ptr<ResourceHandler> handler;
1590 if (sync_result) { 1619 if (sync_result) {
1591 // download_to_file is not supported for synchronous requests. 1620 // download_to_file is not supported for synchronous requests.
1592 if (request_data.download_to_file) { 1621 if (request_data.download_to_file) {
1593 bad_message::ReceivedBadMessage(filter_, bad_message::RDH_BAD_DOWNLOAD); 1622 bad_message::ReceivedBadMessage(filter_, bad_message::RDH_BAD_DOWNLOAD);
1594 return std::unique_ptr<ResourceHandler>(); 1623 return std::unique_ptr<ResourceHandler>();
1595 } 1624 }
1596 1625
1626 DCHECK(!mojo_request.is_pending());
1627 DCHECK(!url_loader_client);
1597 handler.reset(new SyncResourceHandler(request, sync_result, this)); 1628 handler.reset(new SyncResourceHandler(request, sync_result, this));
1598 } else { 1629 } else {
1599 handler.reset(new AsyncResourceHandler(request, this)); 1630 if (mojo_request.is_pending()) {
1631 handler.reset(new MojoAsyncResourceHandler(request, this,
1632 std::move(mojo_request),
1633 std::move(url_loader_client)));
1634 } else {
1635 handler.reset(new AsyncResourceHandler(request, this));
1636 }
1600 1637
1601 // The RedirectToFileResourceHandler depends on being next in the chain. 1638 // The RedirectToFileResourceHandler depends on being next in the chain.
1602 if (request_data.download_to_file) { 1639 if (request_data.download_to_file) {
1603 handler.reset( 1640 handler.reset(
1604 new RedirectToFileResourceHandler(std::move(handler), request)); 1641 new RedirectToFileResourceHandler(std::move(handler), request));
1605 } 1642 }
1606 } 1643 }
1607 1644
1608 // Prefetches and <a ping> requests outlive their child process. 1645 // Prefetches and <a ping> requests outlive their child process.
1609 if (!sync_result && IsDetachableResourceType(request_data.resource_type)) { 1646 if (!sync_result && IsDetachableResourceType(request_data.resource_type)) {
(...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after
2273 void ResourceDispatcherHostImpl::EnableStaleWhileRevalidateForTesting() { 2310 void ResourceDispatcherHostImpl::EnableStaleWhileRevalidateForTesting() {
2274 if (!async_revalidation_manager_) 2311 if (!async_revalidation_manager_)
2275 async_revalidation_manager_.reset(new AsyncRevalidationManager); 2312 async_revalidation_manager_.reset(new AsyncRevalidationManager);
2276 } 2313 }
2277 2314
2278 void ResourceDispatcherHostImpl::SetLoaderDelegate( 2315 void ResourceDispatcherHostImpl::SetLoaderDelegate(
2279 LoaderDelegate* loader_delegate) { 2316 LoaderDelegate* loader_delegate) {
2280 loader_delegate_ = loader_delegate; 2317 loader_delegate_ = loader_delegate;
2281 } 2318 }
2282 2319
2320 void ResourceDispatcherHostImpl::OnRequestResourceWithMojo(
2321 int routing_id,
2322 int request_id,
2323 const ResourceRequest& request,
2324 mojo::InterfaceRequest<mojom::URLLoader> mojo_request,
2325 mojom::URLLoaderClientPtr url_loader_client,
2326 ResourceMessageFilter* filter) {
2327 filter_ = filter;
2328 OnRequestResourceInternal(routing_id, request_id, request,
2329 std::move(mojo_request),
2330 std::move(url_loader_client));
2331 filter_ = nullptr;
2332 }
2333
2283 // static 2334 // static
2284 int ResourceDispatcherHostImpl::CalculateApproximateMemoryCost( 2335 int ResourceDispatcherHostImpl::CalculateApproximateMemoryCost(
2285 net::URLRequest* request) { 2336 net::URLRequest* request) {
2286 // The following fields should be a minor size contribution (experimentally 2337 // The following fields should be a minor size contribution (experimentally
2287 // on the order of 100). However since they are variable length, it could 2338 // on the order of 100). However since they are variable length, it could
2288 // in theory be a sizeable contribution. 2339 // in theory be a sizeable contribution.
2289 int strings_cost = request->extra_request_headers().ToString().size() + 2340 int strings_cost = request->extra_request_headers().ToString().size() +
2290 request->original_url().spec().size() + 2341 request->original_url().spec().size() +
2291 request->referrer().size() + 2342 request->referrer().size() +
2292 request->method().size(); 2343 request->method().size();
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
2600 ssl.cert_id = GetCertStore()->StoreCert(ssl_info.cert.get(), child_id); 2651 ssl.cert_id = GetCertStore()->StoreCert(ssl_info.cert.get(), child_id);
2601 response->head.security_info = SerializeSecurityInfo(ssl); 2652 response->head.security_info = SerializeSecurityInfo(ssl);
2602 } 2653 }
2603 2654
2604 CertStore* ResourceDispatcherHostImpl::GetCertStore() { 2655 CertStore* ResourceDispatcherHostImpl::GetCertStore() {
2605 return cert_store_for_testing_ ? cert_store_for_testing_ 2656 return cert_store_for_testing_ ? cert_store_for_testing_
2606 : CertStore::GetInstance(); 2657 : CertStore::GetInstance();
2607 } 2658 }
2608 2659
2609 } // namespace content 2660 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698