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

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

Powered by Google App Engine
This is Rietveld 408576698