Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 531 static_cast<RenderFrameHostImpl*>(render_frame_host) | 531 static_cast<RenderFrameHostImpl*>(render_frame_host) |
| 532 ->GetGlobalFrameRoutingId(), | 532 ->GetGlobalFrameRoutingId(), |
| 533 base::Bind(&ResourceDispatcherHostImpl::OnRenderFrameDeleted)); | 533 base::Bind(&ResourceDispatcherHostImpl::OnRenderFrameDeleted)); |
| 534 } | 534 } |
| 535 | 535 |
| 536 // static | 536 // static |
| 537 ResourceDispatcherHost* ResourceDispatcherHost::Get() { | 537 ResourceDispatcherHost* ResourceDispatcherHost::Get() { |
| 538 return g_resource_dispatcher_host; | 538 return g_resource_dispatcher_host; |
| 539 } | 539 } |
| 540 | 540 |
| 541 class ResourceDispatcherHostImpl::MojoHelper final { | |
|
mmenke
2016/05/23 17:34:53
Add comments.
yhirano
2016/05/24 06:40:03
Done.
| |
| 542 public: | |
| 543 explicit MojoHelper(ResourceDispatcherHostImpl* owner) : owner_(owner) {} | |
| 544 | |
| 545 bool Send(const IPC::Message& message, ResourceMessageFilter* filter) { | |
| 546 if (IPC_MESSAGE_ID_CLASS(message.type()) != ResourceMsgStart) | |
| 547 return false; | |
| 548 | |
| 549 base::PickleIterator iter(message); | |
| 550 int request_id = -1; | |
| 551 bool ok = iter.ReadInt(&request_id); | |
| 552 DCHECK(ok); | |
| 553 ResourceLoader* loader = owner_->GetLoader(filter->child_id(), request_id); | |
| 554 if (!loader || !loader->client()) | |
| 555 return false; | |
| 556 | |
| 557 DCHECK(!filter_); | |
| 558 filter_ = filter; | |
| 559 bool handled = true; | |
| 560 IPC_BEGIN_MESSAGE_MAP(MojoHelper, message) | |
| 561 IPC_MESSAGE_HANDLER(ResourceMsg_ReceivedResponse, OnReceivedResponse) | |
| 562 IPC_MESSAGE_HANDLER(ResourceMsg_RequestComplete, OnRequestComplete) | |
| 563 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 564 IPC_END_MESSAGE_MAP() | |
| 565 | |
| 566 filter_ = nullptr; | |
| 567 return handled; | |
| 568 } | |
| 569 | |
| 570 void AddUninitiatedURLLoader(int child_id, | |
| 571 std::unique_ptr<mojom::URLLoader> loader) { | |
| 572 mojom::URLLoader* raw = loader.get(); | |
| 573 uninitiated_url_loaders_.insert( | |
| 574 std::make_pair(raw, std::make_pair(child_id, std::move(loader)))); | |
| 575 } | |
| 576 | |
| 577 std::unique_ptr<mojom::URLLoader> TakeUninitiatedURLLoader( | |
| 578 mojom::URLLoader* loader) { | |
| 579 auto it = uninitiated_url_loaders_.find(loader); | |
| 580 if (it == uninitiated_url_loaders_.end()) | |
| 581 return nullptr; | |
| 582 std::unique_ptr<mojom::URLLoader> result = std::move(it->second.second); | |
| 583 uninitiated_url_loaders_.erase(it); | |
| 584 return result; | |
| 585 } | |
| 586 | |
| 587 void CancelUninitiatedLoaders(int child_id) { | |
| 588 auto it = uninitiated_url_loaders_.begin(); | |
| 589 while (it != uninitiated_url_loaders_.end()) { | |
| 590 if (it->second.first == child_id) { | |
| 591 it = uninitiated_url_loaders_.erase(it); | |
| 592 } else { | |
| 593 ++it; | |
| 594 } | |
| 595 } | |
| 596 } | |
| 597 | |
| 598 private: | |
| 599 void OnReceivedResponse(int request_id, const ResourceResponseHead& head) { | |
| 600 int child_id = filter_->child_id(); | |
| 601 ResourceLoader* loader = owner_->GetLoader(child_id, request_id); | |
| 602 mojom::URLLoaderClient* client = loader->client(); | |
| 603 client->OnReceiveResponse(head, loader->GetRequestInfo()->TakeBodyReader()); | |
|
mmenke
2016/05/23 17:34:53
Why do we need to pass the body reader all over th
yhirano
2016/05/24 06:40:04
What dependency are you concerned about? Even with
yhirano
2016/05/24 08:03:21
PS24 removes the response body from ResourceReques
| |
| 604 } | |
| 605 | |
| 606 void OnRequestComplete(int request_id, | |
| 607 const ResourceRequestCompletionStatus& status) { | |
| 608 int child_id = filter_->child_id(); | |
| 609 ResourceLoader* loader = owner_->GetLoader(child_id, request_id); | |
| 610 mojom::URLLoaderClient* client = loader->client(); | |
| 611 | |
| 612 client->OnComplete(status); | |
| 613 } | |
| 614 | |
| 615 ResourceDispatcherHostImpl* owner_; | |
| 616 ResourceMessageFilter* filter_ = nullptr; | |
| 617 std::map<mojom::URLLoader*, std::pair<int, std::unique_ptr<mojom::URLLoader>>> | |
| 618 uninitiated_url_loaders_; | |
| 619 | |
| 620 DISALLOW_COPY_AND_ASSIGN(MojoHelper); | |
| 621 }; | |
| 622 | |
| 541 ResourceDispatcherHostImpl::ResourceDispatcherHostImpl() | 623 ResourceDispatcherHostImpl::ResourceDispatcherHostImpl() |
| 542 : save_file_manager_(new SaveFileManager()), | 624 : save_file_manager_(new SaveFileManager()), |
| 543 request_id_(-1), | 625 request_id_(-1), |
| 544 is_shutdown_(false), | 626 is_shutdown_(false), |
| 545 num_in_flight_requests_(0), | 627 num_in_flight_requests_(0), |
| 546 max_num_in_flight_requests_(base::SharedMemory::GetHandleLimit()), | 628 max_num_in_flight_requests_(base::SharedMemory::GetHandleLimit()), |
| 547 max_num_in_flight_requests_per_process_(static_cast<int>( | 629 max_num_in_flight_requests_per_process_(static_cast<int>( |
| 548 max_num_in_flight_requests_ * kMaxRequestsPerProcessRatio)), | 630 max_num_in_flight_requests_ * kMaxRequestsPerProcessRatio)), |
| 549 max_outstanding_requests_cost_per_process_( | 631 max_outstanding_requests_cost_per_process_( |
| 550 kMaxOutstandingRequestsCostPerProcess), | 632 kMaxOutstandingRequestsCostPerProcess), |
| 551 filter_(NULL), | 633 filter_(NULL), |
| 552 delegate_(NULL), | 634 delegate_(NULL), |
| 553 allow_cross_origin_auth_prompt_(false), | 635 allow_cross_origin_auth_prompt_(false), |
| 554 cert_store_for_testing_(nullptr) { | 636 cert_store_for_testing_(nullptr), |
| 637 mojo_helper_(new MojoHelper(this)) { | |
| 555 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 638 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 556 DCHECK(!g_resource_dispatcher_host); | 639 DCHECK(!g_resource_dispatcher_host); |
| 557 g_resource_dispatcher_host = this; | 640 g_resource_dispatcher_host = this; |
| 558 | 641 |
| 559 GetContentClient()->browser()->ResourceDispatcherHostCreated(); | 642 GetContentClient()->browser()->ResourceDispatcherHostCreated(); |
| 560 | 643 |
| 561 ANNOTATE_BENIGN_RACE( | 644 ANNOTATE_BENIGN_RACE( |
| 562 &last_user_gesture_time_, | 645 &last_user_gesture_time_, |
| 563 "We don't care about the precise value, see http://crbug.com/92889"); | 646 "We don't care about the precise value, see http://crbug.com/92889"); |
| 564 | 647 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 577 // navigation becomes the default. crbug.com/561610 | 660 // navigation becomes the default. crbug.com/561610 |
| 578 if (!IsBrowserSideNavigationEnabled() && | 661 if (!IsBrowserSideNavigationEnabled() && |
| 579 base::FeatureList::IsEnabled(features::kStaleWhileRevalidate)) { | 662 base::FeatureList::IsEnabled(features::kStaleWhileRevalidate)) { |
| 580 async_revalidation_manager_.reset(new AsyncRevalidationManager); | 663 async_revalidation_manager_.reset(new AsyncRevalidationManager); |
| 581 } | 664 } |
| 582 } | 665 } |
| 583 | 666 |
| 584 ResourceDispatcherHostImpl::~ResourceDispatcherHostImpl() { | 667 ResourceDispatcherHostImpl::~ResourceDispatcherHostImpl() { |
| 585 DCHECK(outstanding_requests_stats_map_.empty()); | 668 DCHECK(outstanding_requests_stats_map_.empty()); |
| 586 DCHECK(g_resource_dispatcher_host); | 669 DCHECK(g_resource_dispatcher_host); |
| 670 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 587 g_resource_dispatcher_host = NULL; | 671 g_resource_dispatcher_host = NULL; |
| 588 } | 672 } |
| 589 | 673 |
| 590 // static | 674 // static |
| 591 ResourceDispatcherHostImpl* ResourceDispatcherHostImpl::Get() { | 675 ResourceDispatcherHostImpl* ResourceDispatcherHostImpl::Get() { |
| 592 return g_resource_dispatcher_host; | 676 return g_resource_dispatcher_host; |
| 593 } | 677 } |
| 594 | 678 |
| 595 // static | 679 // static |
| 596 void ResourceDispatcherHostImpl::ResumeBlockedRequestsForRouteFromUI( | 680 void ResourceDispatcherHostImpl::ResumeBlockedRequestsForRouteFromUI( |
| (...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1170 for (const auto& routing_id : ids) { | 1254 for (const auto& routing_id : ids) { |
| 1171 CancelBlockedRequestsForRoute(routing_id); | 1255 CancelBlockedRequestsForRoute(routing_id); |
| 1172 } | 1256 } |
| 1173 | 1257 |
| 1174 scheduler_.reset(); | 1258 scheduler_.reset(); |
| 1175 } | 1259 } |
| 1176 | 1260 |
| 1177 bool ResourceDispatcherHostImpl::OnMessageReceived( | 1261 bool ResourceDispatcherHostImpl::OnMessageReceived( |
| 1178 const IPC::Message& message, | 1262 const IPC::Message& message, |
| 1179 ResourceMessageFilter* filter) { | 1263 ResourceMessageFilter* filter) { |
| 1264 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 1180 filter_ = filter; | 1265 filter_ = filter; |
| 1181 bool handled = true; | 1266 bool handled = true; |
| 1182 IPC_BEGIN_MESSAGE_MAP(ResourceDispatcherHostImpl, message) | 1267 IPC_BEGIN_MESSAGE_MAP(ResourceDispatcherHostImpl, message) |
| 1183 IPC_MESSAGE_HANDLER(ResourceHostMsg_RequestResource, OnRequestResource) | 1268 IPC_MESSAGE_HANDLER(ResourceHostMsg_RequestResource, OnRequestResource) |
| 1184 IPC_MESSAGE_HANDLER_DELAY_REPLY(ResourceHostMsg_SyncLoad, OnSyncLoad) | 1269 IPC_MESSAGE_HANDLER_DELAY_REPLY(ResourceHostMsg_SyncLoad, OnSyncLoad) |
| 1185 IPC_MESSAGE_HANDLER(ResourceHostMsg_ReleaseDownloadedFile, | 1270 IPC_MESSAGE_HANDLER(ResourceHostMsg_ReleaseDownloadedFile, |
| 1186 OnReleaseDownloadedFile) | 1271 OnReleaseDownloadedFile) |
| 1187 IPC_MESSAGE_HANDLER(ResourceHostMsg_DataDownloaded_ACK, OnDataDownloadedACK) | 1272 IPC_MESSAGE_HANDLER(ResourceHostMsg_DataDownloaded_ACK, OnDataDownloadedACK) |
| 1188 IPC_MESSAGE_HANDLER(ResourceHostMsg_CancelRequest, OnCancelRequest) | 1273 IPC_MESSAGE_HANDLER(ResourceHostMsg_CancelRequest, OnCancelRequest) |
| 1189 IPC_MESSAGE_HANDLER(ResourceHostMsg_DidChangePriority, OnDidChangePriority) | 1274 IPC_MESSAGE_HANDLER(ResourceHostMsg_DidChangePriority, OnDidChangePriority) |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 1211 } | 1296 } |
| 1212 | 1297 |
| 1213 filter_ = NULL; | 1298 filter_ = NULL; |
| 1214 return handled; | 1299 return handled; |
| 1215 } | 1300 } |
| 1216 | 1301 |
| 1217 void ResourceDispatcherHostImpl::OnRequestResource( | 1302 void ResourceDispatcherHostImpl::OnRequestResource( |
| 1218 int routing_id, | 1303 int routing_id, |
| 1219 int request_id, | 1304 int request_id, |
| 1220 const ResourceRequest& request_data) { | 1305 const ResourceRequest& request_data) { |
| 1306 OnRequestResourceInternal(routing_id, request_id, request_data, nullptr, | |
| 1307 nullptr); | |
| 1308 } | |
| 1309 | |
| 1310 void ResourceDispatcherHostImpl::OnRequestResourceInternal( | |
| 1311 int routing_id, | |
| 1312 int request_id, | |
| 1313 const ResourceRequest& request_data, | |
| 1314 std::unique_ptr<mojom::URLLoader> loader, | |
|
mmenke
2016/05/23 17:34:53
loader is not a good variable name, given that we
yhirano
2016/05/24 06:40:03
Done.
| |
| 1315 mojom::URLLoaderClientPtr client) { | |
| 1221 // TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed. | 1316 // TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed. |
| 1222 tracked_objects::ScopedTracker tracking_profile( | 1317 tracked_objects::ScopedTracker tracking_profile( |
| 1223 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 1318 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1224 "477117 ResourceDispatcherHostImpl::OnRequestResource")); | 1319 "477117 ResourceDispatcherHostImpl::OnRequestResource")); |
| 1225 // When logging time-to-network only care about main frame and non-transfer | 1320 // When logging time-to-network only care about main frame and non-transfer |
| 1226 // navigations. | 1321 // navigations. |
| 1227 // PlzNavigate: this log happens from NavigationRequest::OnRequestStarted | 1322 // PlzNavigate: this log happens from NavigationRequest::OnRequestStarted |
| 1228 // instead. | 1323 // instead. |
| 1229 if (request_data.resource_type == RESOURCE_TYPE_MAIN_FRAME && | 1324 if (request_data.resource_type == RESOURCE_TYPE_MAIN_FRAME && |
| 1230 request_data.transferred_request_request_id == -1 && | 1325 request_data.transferred_request_request_id == -1 && |
| 1231 !IsBrowserSideNavigationEnabled()) { | 1326 !IsBrowserSideNavigationEnabled()) { |
| 1232 BrowserThread::PostTask( | 1327 BrowserThread::PostTask( |
| 1233 BrowserThread::UI, | 1328 BrowserThread::UI, |
| 1234 FROM_HERE, | 1329 FROM_HERE, |
| 1235 base::Bind(&LogResourceRequestTimeOnUI, | 1330 base::Bind(&LogResourceRequestTimeOnUI, |
| 1236 TimeTicks::Now(), | 1331 TimeTicks::Now(), |
| 1237 filter_->child_id(), | 1332 filter_->child_id(), |
| 1238 request_data.render_frame_id, | 1333 request_data.render_frame_id, |
| 1239 request_data.url)); | 1334 request_data.url)); |
| 1240 } | 1335 } |
| 1241 BeginRequest(request_id, request_data, NULL, routing_id); | 1336 BeginRequest(request_id, request_data, NULL, routing_id, std::move(loader), |
| 1337 std::move(client)); | |
| 1242 } | 1338 } |
| 1243 | 1339 |
| 1244 // Begins a resource request with the given params on behalf of the specified | 1340 // Begins a resource request with the given params on behalf of the specified |
| 1245 // child process. Responses will be dispatched through the given receiver. The | 1341 // child process. Responses will be dispatched through the given receiver. The |
| 1246 // process ID is used to lookup WebContentsImpl from routing_id's in the case of | 1342 // process ID is used to lookup WebContentsImpl from routing_id's in the case of |
| 1247 // a request from a renderer. request_context is the cookie/cache context to be | 1343 // a request from a renderer. request_context is the cookie/cache context to be |
| 1248 // used for this request. | 1344 // used for this request. |
| 1249 // | 1345 // |
| 1250 // If sync_result is non-null, then a SyncLoad reply will be generated, else | 1346 // If sync_result is non-null, then a SyncLoad reply will be generated, else |
| 1251 // a normal asynchronous set of response messages will be generated. | 1347 // a normal asynchronous set of response messages will be generated. |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1361 } | 1457 } |
| 1362 | 1458 |
| 1363 // We should have a CrossSiteResourceHandler to finish the transfer. | 1459 // We should have a CrossSiteResourceHandler to finish the transfer. |
| 1364 DCHECK(info->cross_site_handler()); | 1460 DCHECK(info->cross_site_handler()); |
| 1365 } | 1461 } |
| 1366 | 1462 |
| 1367 void ResourceDispatcherHostImpl::BeginRequest( | 1463 void ResourceDispatcherHostImpl::BeginRequest( |
| 1368 int request_id, | 1464 int request_id, |
| 1369 const ResourceRequest& request_data, | 1465 const ResourceRequest& request_data, |
| 1370 IPC::Message* sync_result, // only valid for sync | 1466 IPC::Message* sync_result, // only valid for sync |
| 1371 int route_id) { | 1467 int route_id, |
| 1468 std::unique_ptr<mojom::URLLoader> url_loader, | |
| 1469 mojom::URLLoaderClientPtr client) { | |
| 1372 int process_type = filter_->process_type(); | 1470 int process_type = filter_->process_type(); |
| 1373 int child_id = filter_->child_id(); | 1471 int child_id = filter_->child_id(); |
| 1374 | 1472 |
| 1375 // Reject request id that's currently in use. | 1473 // Reject request id that's currently in use. |
| 1376 if (IsRequestIDInUse(GlobalRequestID(child_id, request_id))) { | 1474 if (IsRequestIDInUse(GlobalRequestID(child_id, request_id))) { |
| 1377 bad_message::ReceivedBadMessage(filter_, | 1475 bad_message::ReceivedBadMessage(filter_, |
| 1378 bad_message::RDH_INVALID_REQUEST_ID); | 1476 bad_message::RDH_INVALID_REQUEST_ID); |
| 1379 return; | 1477 return; |
| 1380 } | 1478 } |
| 1381 | 1479 |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1620 } | 1718 } |
| 1621 | 1719 |
| 1622 // Have the appcache associate its extra info with the request. | 1720 // Have the appcache associate its extra info with the request. |
| 1623 AppCacheInterceptor::SetExtraRequestInfo( | 1721 AppCacheInterceptor::SetExtraRequestInfo( |
| 1624 new_request.get(), filter_->appcache_service(), child_id, | 1722 new_request.get(), filter_->appcache_service(), child_id, |
| 1625 request_data.appcache_host_id, request_data.resource_type, | 1723 request_data.appcache_host_id, request_data.resource_type, |
| 1626 request_data.should_reset_appcache); | 1724 request_data.should_reset_appcache); |
| 1627 | 1725 |
| 1628 std::unique_ptr<ResourceHandler> handler(CreateResourceHandler( | 1726 std::unique_ptr<ResourceHandler> handler(CreateResourceHandler( |
| 1629 new_request.get(), request_data, sync_result, route_id, process_type, | 1727 new_request.get(), request_data, sync_result, route_id, process_type, |
| 1630 child_id, resource_context)); | 1728 child_id, resource_context, client != nullptr)); |
| 1631 | 1729 |
| 1632 if (handler) | 1730 if (handler) |
| 1633 BeginRequestInternal(std::move(new_request), std::move(handler)); | 1731 BeginRequestInternal(std::move(new_request), std::move(handler), |
| 1732 std::move(url_loader), std::move(client)); | |
| 1634 } | 1733 } |
| 1635 | 1734 |
| 1636 std::unique_ptr<ResourceHandler> | 1735 std::unique_ptr<ResourceHandler> |
| 1637 ResourceDispatcherHostImpl::CreateResourceHandler( | 1736 ResourceDispatcherHostImpl::CreateResourceHandler( |
| 1638 net::URLRequest* request, | 1737 net::URLRequest* request, |
| 1639 const ResourceRequest& request_data, | 1738 const ResourceRequest& request_data, |
| 1640 IPC::Message* sync_result, | 1739 IPC::Message* sync_result, |
| 1641 int route_id, | 1740 int route_id, |
| 1642 int process_type, | 1741 int process_type, |
| 1643 int child_id, | 1742 int child_id, |
| 1644 ResourceContext* resource_context) { | 1743 ResourceContext* resource_context, |
| 1744 bool using_mojo) { | |
| 1645 // TODO(pkasting): Remove ScopedTracker below once crbug.com/456331 is fixed. | 1745 // TODO(pkasting): Remove ScopedTracker below once crbug.com/456331 is fixed. |
| 1646 tracked_objects::ScopedTracker tracking_profile( | 1746 tracked_objects::ScopedTracker tracking_profile( |
| 1647 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 1747 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1648 "456331 ResourceDispatcherHostImpl::CreateResourceHandler")); | 1748 "456331 ResourceDispatcherHostImpl::CreateResourceHandler")); |
| 1649 // Construct the IPC resource handler. | 1749 // Construct the IPC resource handler. |
| 1650 std::unique_ptr<ResourceHandler> handler; | 1750 std::unique_ptr<ResourceHandler> handler; |
| 1651 if (sync_result) { | 1751 if (sync_result) { |
| 1752 DCHECK(!using_mojo); | |
| 1652 // download_to_file is not supported for synchronous requests. | 1753 // download_to_file is not supported for synchronous requests. |
| 1653 if (request_data.download_to_file) { | 1754 if (request_data.download_to_file) { |
| 1654 bad_message::ReceivedBadMessage(filter_, bad_message::RDH_BAD_DOWNLOAD); | 1755 bad_message::ReceivedBadMessage(filter_, bad_message::RDH_BAD_DOWNLOAD); |
| 1655 return std::unique_ptr<ResourceHandler>(); | 1756 return std::unique_ptr<ResourceHandler>(); |
| 1656 } | 1757 } |
| 1657 | 1758 |
| 1658 handler.reset(new SyncResourceHandler(request, sync_result, this)); | 1759 handler.reset(new SyncResourceHandler(request, sync_result, this)); |
| 1659 } else { | 1760 } else { |
| 1660 handler.reset(new AsyncResourceHandler(request, this)); | 1761 handler.reset(new AsyncResourceHandler(request, this, using_mojo)); |
| 1661 | 1762 |
| 1662 // The RedirectToFileResourceHandler depends on being next in the chain. | 1763 // The RedirectToFileResourceHandler depends on being next in the chain. |
| 1663 if (request_data.download_to_file) { | 1764 if (request_data.download_to_file) { |
| 1664 handler.reset( | 1765 handler.reset( |
| 1665 new RedirectToFileResourceHandler(std::move(handler), request)); | 1766 new RedirectToFileResourceHandler(std::move(handler), request)); |
| 1666 } | 1767 } |
| 1667 } | 1768 } |
| 1668 | 1769 |
| 1669 // Prefetches and <a ping> requests outlive their child process. | 1770 // Prefetches and <a ping> requests outlive their child process. |
| 1670 if (!sync_result && IsDetachableResourceType(request_data.resource_type)) { | 1771 if (!sync_result && IsDetachableResourceType(request_data.resource_type)) { |
| (...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2056 // blocked_loaders_map_, as blocking requests modifies the map. | 2157 // blocked_loaders_map_, as blocking requests modifies the map. |
| 2057 std::set<GlobalFrameRoutingId> routing_ids; | 2158 std::set<GlobalFrameRoutingId> routing_ids; |
| 2058 for (const auto& blocked_loaders : blocked_loaders_map_) { | 2159 for (const auto& blocked_loaders : blocked_loaders_map_) { |
| 2059 if (blocked_loaders.first.child_id == child_id) | 2160 if (blocked_loaders.first.child_id == child_id) |
| 2060 routing_ids.insert(blocked_loaders.first); | 2161 routing_ids.insert(blocked_loaders.first); |
| 2061 } | 2162 } |
| 2062 for (const GlobalFrameRoutingId& route_id : routing_ids) { | 2163 for (const GlobalFrameRoutingId& route_id : routing_ids) { |
| 2063 CancelBlockedRequestsForRoute(route_id); | 2164 CancelBlockedRequestsForRoute(route_id); |
| 2064 } | 2165 } |
| 2065 } | 2166 } |
| 2167 | |
| 2168 // Uninitiated URLLoader has no routing ID, so it should be deleted only when | |
| 2169 // cancel_all_routes is specified. | |
| 2170 if (cancel_all_routes) | |
| 2171 mojo_helper_->CancelUninitiatedLoaders(child_id); | |
| 2066 } | 2172 } |
| 2067 | 2173 |
| 2068 // Cancels the request and removes it from the list. | 2174 // Cancels the request and removes it from the list. |
| 2069 void ResourceDispatcherHostImpl::RemovePendingRequest(int child_id, | 2175 void ResourceDispatcherHostImpl::RemovePendingRequest(int child_id, |
| 2070 int request_id) { | 2176 int request_id) { |
| 2071 LoaderMap::iterator i = pending_loaders_.find( | 2177 LoaderMap::iterator i = pending_loaders_.find( |
| 2072 GlobalRequestID(child_id, request_id)); | 2178 GlobalRequestID(child_id, request_id)); |
| 2073 if (i == pending_loaders_.end()) { | 2179 if (i == pending_loaders_.end()) { |
| 2074 NOTREACHED() << "Trying to remove a request that's not here"; | 2180 NOTREACHED() << "Trying to remove a request that's not here"; |
| 2075 return; | 2181 return; |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2343 std::move(handler)); | 2449 std::move(handler)); |
| 2344 | 2450 |
| 2345 BeginRequestInternal(std::move(new_request), std::move(handler)); | 2451 BeginRequestInternal(std::move(new_request), std::move(handler)); |
| 2346 } | 2452 } |
| 2347 | 2453 |
| 2348 void ResourceDispatcherHostImpl::EnableStaleWhileRevalidateForTesting() { | 2454 void ResourceDispatcherHostImpl::EnableStaleWhileRevalidateForTesting() { |
| 2349 if (!async_revalidation_manager_) | 2455 if (!async_revalidation_manager_) |
| 2350 async_revalidation_manager_.reset(new AsyncRevalidationManager); | 2456 async_revalidation_manager_.reset(new AsyncRevalidationManager); |
| 2351 } | 2457 } |
| 2352 | 2458 |
| 2459 void ResourceDispatcherHostImpl::OnRequestResourceWithMojo( | |
| 2460 int routing_id, | |
| 2461 int request_id, | |
| 2462 const ResourceRequest& request, | |
| 2463 std::unique_ptr<mojom::URLLoader> loader, | |
| 2464 mojom::URLLoaderClientPtr client, | |
| 2465 ResourceMessageFilter* filter) { | |
| 2466 filter_ = filter; | |
| 2467 OnRequestResourceInternal(routing_id, request_id, request, std::move(loader), | |
| 2468 std::move(client)); | |
| 2469 filter_ = nullptr; | |
| 2470 } | |
| 2471 | |
| 2472 bool ResourceDispatcherHostImpl::SendWithMojoIfPossible( | |
| 2473 const IPC::Message& message, | |
| 2474 ResourceMessageFilter* filter) { | |
| 2475 return mojo_helper_->Send(message, filter); | |
| 2476 } | |
| 2477 | |
| 2478 void ResourceDispatcherHostImpl::AddUninitiatedURLLoader( | |
| 2479 int child_id, | |
| 2480 std::unique_ptr<mojom::URLLoader> loader) { | |
| 2481 mojo_helper_->AddUninitiatedURLLoader(child_id, std::move(loader)); | |
| 2482 } | |
| 2483 | |
| 2484 std::unique_ptr<mojom::URLLoader> | |
| 2485 ResourceDispatcherHostImpl::TakeUninitiatedURLLoader(mojom::URLLoader* loader) { | |
| 2486 return mojo_helper_->TakeUninitiatedURLLoader(loader); | |
| 2487 } | |
| 2488 | |
| 2353 // static | 2489 // static |
| 2354 int ResourceDispatcherHostImpl::CalculateApproximateMemoryCost( | 2490 int ResourceDispatcherHostImpl::CalculateApproximateMemoryCost( |
| 2355 net::URLRequest* request) { | 2491 net::URLRequest* request) { |
| 2356 // The following fields should be a minor size contribution (experimentally | 2492 // The following fields should be a minor size contribution (experimentally |
| 2357 // on the order of 100). However since they are variable length, it could | 2493 // on the order of 100). However since they are variable length, it could |
| 2358 // in theory be a sizeable contribution. | 2494 // in theory be a sizeable contribution. |
| 2359 int strings_cost = request->extra_request_headers().ToString().size() + | 2495 int strings_cost = request->extra_request_headers().ToString().size() + |
| 2360 request->original_url().spec().size() + | 2496 request->original_url().spec().size() + |
| 2361 request->referrer().size() + | 2497 request->referrer().size() + |
| 2362 request->method().size(); | 2498 request->method().size(); |
| 2363 | 2499 |
| 2364 // Note that this expression will typically be dominated by: | 2500 // Note that this expression will typically be dominated by: |
| 2365 // |kAvgBytesPerOutstandingRequest|. | 2501 // |kAvgBytesPerOutstandingRequest|. |
| 2366 return kAvgBytesPerOutstandingRequest + strings_cost; | 2502 return kAvgBytesPerOutstandingRequest + strings_cost; |
| 2367 } | 2503 } |
| 2368 | 2504 |
| 2369 void ResourceDispatcherHostImpl::BeginRequestInternal( | 2505 void ResourceDispatcherHostImpl::BeginRequestInternal( |
| 2370 std::unique_ptr<net::URLRequest> request, | 2506 std::unique_ptr<net::URLRequest> request, |
| 2371 std::unique_ptr<ResourceHandler> handler) { | 2507 std::unique_ptr<ResourceHandler> handler, |
| 2508 std::unique_ptr<mojom::URLLoader> url_loader, | |
| 2509 mojom::URLLoaderClientPtr client) { | |
| 2372 DCHECK(!request->is_pending()); | 2510 DCHECK(!request->is_pending()); |
| 2373 ResourceRequestInfoImpl* info = | 2511 ResourceRequestInfoImpl* info = |
| 2374 ResourceRequestInfoImpl::ForRequest(request.get()); | 2512 ResourceRequestInfoImpl::ForRequest(request.get()); |
| 2375 | 2513 |
| 2376 if ((TimeTicks::Now() - last_user_gesture_time_) < | 2514 if ((TimeTicks::Now() - last_user_gesture_time_) < |
| 2377 TimeDelta::FromMilliseconds(kUserGestureWindowMs)) { | 2515 TimeDelta::FromMilliseconds(kUserGestureWindowMs)) { |
| 2378 request->SetLoadFlags( | 2516 request->SetLoadFlags( |
| 2379 request->load_flags() | net::LOAD_MAYBE_USER_GESTURE); | 2517 request->load_flags() | net::LOAD_MAYBE_USER_GESTURE); |
| 2380 } | 2518 } |
| 2381 | 2519 |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 2397 NOTREACHED(); | 2535 NOTREACHED(); |
| 2398 } | 2536 } |
| 2399 | 2537 |
| 2400 IncrementOutstandingRequestsMemory(-1, *info); | 2538 IncrementOutstandingRequestsMemory(-1, *info); |
| 2401 | 2539 |
| 2402 // A ResourceHandler must not outlive its associated URLRequest. | 2540 // A ResourceHandler must not outlive its associated URLRequest. |
| 2403 handler.reset(); | 2541 handler.reset(); |
| 2404 return; | 2542 return; |
| 2405 } | 2543 } |
| 2406 | 2544 |
| 2407 std::unique_ptr<ResourceLoader> loader(new ResourceLoader( | 2545 std::unique_ptr<ResourceLoader> loader( |
| 2408 std::move(request), std::move(handler), GetCertStore(), this)); | 2546 new ResourceLoader(std::move(request), std::move(handler), GetCertStore(), |
| 2547 std::move(url_loader), std::move(client), this)); | |
| 2409 | 2548 |
| 2410 GlobalFrameRoutingId id(info->GetChildID(), info->GetRenderFrameID()); | 2549 GlobalFrameRoutingId id(info->GetChildID(), info->GetRenderFrameID()); |
| 2411 BlockedLoadersMap::const_iterator iter = blocked_loaders_map_.find(id); | 2550 BlockedLoadersMap::const_iterator iter = blocked_loaders_map_.find(id); |
| 2412 if (iter != blocked_loaders_map_.end()) { | 2551 if (iter != blocked_loaders_map_.end()) { |
| 2413 // The request should be blocked. | 2552 // The request should be blocked. |
| 2414 iter->second->push_back(std::move(loader)); | 2553 iter->second->push_back(std::move(loader)); |
| 2415 return; | 2554 return; |
| 2416 } | 2555 } |
| 2417 | 2556 |
| 2418 StartLoading(info, std::move(loader)); | 2557 StartLoading(info, std::move(loader)); |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2689 ssl.cert_id = GetCertStore()->StoreCert(ssl_info.cert.get(), child_id); | 2828 ssl.cert_id = GetCertStore()->StoreCert(ssl_info.cert.get(), child_id); |
| 2690 response->head.security_info = SerializeSecurityInfo(ssl); | 2829 response->head.security_info = SerializeSecurityInfo(ssl); |
| 2691 } | 2830 } |
| 2692 | 2831 |
| 2693 CertStore* ResourceDispatcherHostImpl::GetCertStore() { | 2832 CertStore* ResourceDispatcherHostImpl::GetCertStore() { |
| 2694 return cert_store_for_testing_ ? cert_store_for_testing_ | 2833 return cert_store_for_testing_ ? cert_store_for_testing_ |
| 2695 : CertStore::GetInstance(); | 2834 : CertStore::GetInstance(); |
| 2696 } | 2835 } |
| 2697 | 2836 |
| 2698 } // namespace content | 2837 } // namespace content |
| OLD | NEW |