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

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: Created 4 years, 6 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 520 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 // This is a helper class consisting of mojo-related functionalities used in
542 // ResourceDispatcherHostImpl.
mmenke 2016/05/24 20:01:35 This is confusing...Why is the filter calling into
yhirano 2016/05/25 12:47:06 Done.
543 class ResourceDispatcherHostImpl::MojoHelper final {
544 public:
545 explicit MojoHelper(ResourceDispatcherHostImpl* owner) : owner_(owner) {}
546
547 // Sends |message| via mojo. Returns true if it sends the message.
548 bool Send(const IPC::Message& message, ResourceMessageFilter* filter) {
549 if (IPC_MESSAGE_ID_CLASS(message.type()) != ResourceMsgStart)
550 return false;
551
552 base::PickleIterator iter(message);
553 int request_id = -1;
554 bool ok = iter.ReadInt(&request_id);
555 DCHECK(ok);
556 ResourceLoader* loader = owner_->GetLoader(filter->child_id(), request_id);
557 if (!loader || !loader->client())
558 return false;
559
560 DCHECK(!filter_);
561 filter_ = filter;
562 bool handled = true;
563 IPC_BEGIN_MESSAGE_MAP(MojoHelper, message)
564 IPC_MESSAGE_HANDLER(ResourceMsg_ReceivedResponse, OnReceivedResponse)
565 IPC_MESSAGE_HANDLER(ResourceMsg_RequestComplete, OnRequestComplete)
566 IPC_MESSAGE_UNHANDLED(handled = false)
567 IPC_END_MESSAGE_MAP()
568
569 filter_ = nullptr;
570 return handled;
571 }
572
573 // Adds |loader| as an uninitiated loader.
574 void AddUninitiatedURLLoader(int child_id,
575 std::unique_ptr<mojom::URLLoader> loader) {
576 mojom::URLLoader* raw = loader.get();
577 uninitiated_url_loaders_.insert(
578 std::make_pair(raw, std::make_pair(child_id, std::move(loader))));
579 }
580
581 // Takes and returns the uninitiated loader whose address equals to |loader|.
582 std::unique_ptr<mojom::URLLoader> TakeUninitiatedURLLoader(
583 mojom::URLLoader* loader) {
584 auto it = uninitiated_url_loaders_.find(loader);
585 if (it == uninitiated_url_loaders_.end())
586 return nullptr;
587 std::unique_ptr<mojom::URLLoader> result = std::move(it->second.second);
588 uninitiated_url_loaders_.erase(it);
589 return result;
590 }
591
592 // Cancels all uninitiated loaders for |child_id|.
593 void CancelUninitiatedLoaders(int child_id) {
594 auto it = uninitiated_url_loaders_.begin();
595 while (it != uninitiated_url_loaders_.end()) {
596 if (it->second.first == child_id) {
597 it = uninitiated_url_loaders_.erase(it);
598 } else {
599 ++it;
600 }
601 }
602 }
603
604 private:
605 void OnReceivedResponse(int request_id, const ResourceResponseHead& head) {
606 int child_id = filter_->child_id();
607 ResourceLoader* loader = owner_->GetLoader(child_id, request_id);
608 loader->client()->OnReceiveResponse(head);
609 }
610
611 void OnRequestComplete(int request_id,
612 const ResourceRequestCompletionStatus& status) {
613 int child_id = filter_->child_id();
614 ResourceLoader* loader = owner_->GetLoader(child_id, request_id);
615 mojom::URLLoaderClient* client = loader->client();
616
617 client->OnComplete(status);
618 }
619
620 ResourceDispatcherHostImpl* owner_;
621 ResourceMessageFilter* filter_ = nullptr;
622 std::map<mojom::URLLoader*, std::pair<int, std::unique_ptr<mojom::URLLoader>>>
623 uninitiated_url_loaders_;
624
625 DISALLOW_COPY_AND_ASSIGN(MojoHelper);
626 };
627
541 ResourceDispatcherHostImpl::ResourceDispatcherHostImpl() 628 ResourceDispatcherHostImpl::ResourceDispatcherHostImpl()
542 : save_file_manager_(new SaveFileManager()), 629 : save_file_manager_(new SaveFileManager()),
543 request_id_(-1), 630 request_id_(-1),
544 is_shutdown_(false), 631 is_shutdown_(false),
545 num_in_flight_requests_(0), 632 num_in_flight_requests_(0),
546 max_num_in_flight_requests_(base::SharedMemory::GetHandleLimit()), 633 max_num_in_flight_requests_(base::SharedMemory::GetHandleLimit()),
547 max_num_in_flight_requests_per_process_(static_cast<int>( 634 max_num_in_flight_requests_per_process_(static_cast<int>(
548 max_num_in_flight_requests_ * kMaxRequestsPerProcessRatio)), 635 max_num_in_flight_requests_ * kMaxRequestsPerProcessRatio)),
549 max_outstanding_requests_cost_per_process_( 636 max_outstanding_requests_cost_per_process_(
550 kMaxOutstandingRequestsCostPerProcess), 637 kMaxOutstandingRequestsCostPerProcess),
551 filter_(NULL), 638 filter_(NULL),
552 delegate_(NULL), 639 delegate_(NULL),
553 allow_cross_origin_auth_prompt_(false), 640 allow_cross_origin_auth_prompt_(false),
554 cert_store_for_testing_(nullptr) { 641 cert_store_for_testing_(nullptr),
642 mojo_helper_(new MojoHelper(this)) {
555 DCHECK_CURRENTLY_ON(BrowserThread::UI); 643 DCHECK_CURRENTLY_ON(BrowserThread::UI);
556 DCHECK(!g_resource_dispatcher_host); 644 DCHECK(!g_resource_dispatcher_host);
557 g_resource_dispatcher_host = this; 645 g_resource_dispatcher_host = this;
558 646
559 GetContentClient()->browser()->ResourceDispatcherHostCreated(); 647 GetContentClient()->browser()->ResourceDispatcherHostCreated();
560 648
561 ANNOTATE_BENIGN_RACE( 649 ANNOTATE_BENIGN_RACE(
562 &last_user_gesture_time_, 650 &last_user_gesture_time_,
563 "We don't care about the precise value, see http://crbug.com/92889"); 651 "We don't care about the precise value, see http://crbug.com/92889");
564 652
(...skipping 12 matching lines...) Expand all
577 // navigation becomes the default. crbug.com/561610 665 // navigation becomes the default. crbug.com/561610
578 if (!IsBrowserSideNavigationEnabled() && 666 if (!IsBrowserSideNavigationEnabled() &&
579 base::FeatureList::IsEnabled(features::kStaleWhileRevalidate)) { 667 base::FeatureList::IsEnabled(features::kStaleWhileRevalidate)) {
580 async_revalidation_manager_.reset(new AsyncRevalidationManager); 668 async_revalidation_manager_.reset(new AsyncRevalidationManager);
581 } 669 }
582 } 670 }
583 671
584 ResourceDispatcherHostImpl::~ResourceDispatcherHostImpl() { 672 ResourceDispatcherHostImpl::~ResourceDispatcherHostImpl() {
585 DCHECK(outstanding_requests_stats_map_.empty()); 673 DCHECK(outstanding_requests_stats_map_.empty());
586 DCHECK(g_resource_dispatcher_host); 674 DCHECK(g_resource_dispatcher_host);
675 DCHECK_CURRENTLY_ON(BrowserThread::UI);
587 g_resource_dispatcher_host = NULL; 676 g_resource_dispatcher_host = NULL;
588 } 677 }
589 678
590 // static 679 // static
591 ResourceDispatcherHostImpl* ResourceDispatcherHostImpl::Get() { 680 ResourceDispatcherHostImpl* ResourceDispatcherHostImpl::Get() {
592 return g_resource_dispatcher_host; 681 return g_resource_dispatcher_host;
593 } 682 }
594 683
595 // static 684 // static
596 void ResourceDispatcherHostImpl::ResumeBlockedRequestsForRouteFromUI( 685 void ResourceDispatcherHostImpl::ResumeBlockedRequestsForRouteFromUI(
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after
1171 for (const auto& routing_id : ids) { 1260 for (const auto& routing_id : ids) {
1172 CancelBlockedRequestsForRoute(routing_id); 1261 CancelBlockedRequestsForRoute(routing_id);
1173 } 1262 }
1174 1263
1175 scheduler_.reset(); 1264 scheduler_.reset();
1176 } 1265 }
1177 1266
1178 bool ResourceDispatcherHostImpl::OnMessageReceived( 1267 bool ResourceDispatcherHostImpl::OnMessageReceived(
1179 const IPC::Message& message, 1268 const IPC::Message& message,
1180 ResourceMessageFilter* filter) { 1269 ResourceMessageFilter* filter) {
1270 DCHECK_CURRENTLY_ON(BrowserThread::IO);
1181 filter_ = filter; 1271 filter_ = filter;
1182 bool handled = true; 1272 bool handled = true;
1183 IPC_BEGIN_MESSAGE_MAP(ResourceDispatcherHostImpl, message) 1273 IPC_BEGIN_MESSAGE_MAP(ResourceDispatcherHostImpl, message)
1184 IPC_MESSAGE_HANDLER(ResourceHostMsg_RequestResource, OnRequestResource) 1274 IPC_MESSAGE_HANDLER(ResourceHostMsg_RequestResource, OnRequestResource)
1185 IPC_MESSAGE_HANDLER_DELAY_REPLY(ResourceHostMsg_SyncLoad, OnSyncLoad) 1275 IPC_MESSAGE_HANDLER_DELAY_REPLY(ResourceHostMsg_SyncLoad, OnSyncLoad)
1186 IPC_MESSAGE_HANDLER(ResourceHostMsg_ReleaseDownloadedFile, 1276 IPC_MESSAGE_HANDLER(ResourceHostMsg_ReleaseDownloadedFile,
1187 OnReleaseDownloadedFile) 1277 OnReleaseDownloadedFile)
1188 IPC_MESSAGE_HANDLER(ResourceHostMsg_DataDownloaded_ACK, OnDataDownloadedACK) 1278 IPC_MESSAGE_HANDLER(ResourceHostMsg_DataDownloaded_ACK, OnDataDownloadedACK)
1189 IPC_MESSAGE_HANDLER(ResourceHostMsg_CancelRequest, OnCancelRequest) 1279 IPC_MESSAGE_HANDLER(ResourceHostMsg_CancelRequest, OnCancelRequest)
1190 IPC_MESSAGE_HANDLER(ResourceHostMsg_DidChangePriority, OnDidChangePriority) 1280 IPC_MESSAGE_HANDLER(ResourceHostMsg_DidChangePriority, OnDidChangePriority)
(...skipping 21 matching lines...) Expand all
1212 } 1302 }
1213 1303
1214 filter_ = NULL; 1304 filter_ = NULL;
1215 return handled; 1305 return handled;
1216 } 1306 }
1217 1307
1218 void ResourceDispatcherHostImpl::OnRequestResource( 1308 void ResourceDispatcherHostImpl::OnRequestResource(
1219 int routing_id, 1309 int routing_id,
1220 int request_id, 1310 int request_id,
1221 const ResourceRequest& request_data) { 1311 const ResourceRequest& request_data) {
1312 OnRequestResourceInternal(routing_id, request_id, request_data, nullptr,
1313 nullptr);
1314 }
1315
1316 void ResourceDispatcherHostImpl::OnRequestResourceInternal(
1317 int routing_id,
1318 int request_id,
1319 const ResourceRequest& request_data,
1320 std::unique_ptr<mojom::URLLoader> url_loader,
1321 mojom::URLLoaderClientPtr url_loader_client) {
1222 // TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed. 1322 // TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed.
1223 tracked_objects::ScopedTracker tracking_profile( 1323 tracked_objects::ScopedTracker tracking_profile(
1224 FROM_HERE_WITH_EXPLICIT_FUNCTION( 1324 FROM_HERE_WITH_EXPLICIT_FUNCTION(
1225 "477117 ResourceDispatcherHostImpl::OnRequestResource")); 1325 "477117 ResourceDispatcherHostImpl::OnRequestResource"));
1226 // When logging time-to-network only care about main frame and non-transfer 1326 // When logging time-to-network only care about main frame and non-transfer
1227 // navigations. 1327 // navigations.
1228 // PlzNavigate: this log happens from NavigationRequest::OnRequestStarted 1328 // PlzNavigate: this log happens from NavigationRequest::OnRequestStarted
1229 // instead. 1329 // instead.
1230 if (request_data.resource_type == RESOURCE_TYPE_MAIN_FRAME && 1330 if (request_data.resource_type == RESOURCE_TYPE_MAIN_FRAME &&
1231 request_data.transferred_request_request_id == -1 && 1331 request_data.transferred_request_request_id == -1 &&
1232 !IsBrowserSideNavigationEnabled()) { 1332 !IsBrowserSideNavigationEnabled()) {
1233 BrowserThread::PostTask( 1333 BrowserThread::PostTask(
1234 BrowserThread::UI, 1334 BrowserThread::UI,
1235 FROM_HERE, 1335 FROM_HERE,
1236 base::Bind(&LogResourceRequestTimeOnUI, 1336 base::Bind(&LogResourceRequestTimeOnUI,
1237 TimeTicks::Now(), 1337 TimeTicks::Now(),
1238 filter_->child_id(), 1338 filter_->child_id(),
1239 request_data.render_frame_id, 1339 request_data.render_frame_id,
1240 request_data.url)); 1340 request_data.url));
1241 } 1341 }
1242 BeginRequest(request_id, request_data, NULL, routing_id); 1342 BeginRequest(request_id, request_data, NULL, routing_id,
1343 std::move(url_loader), std::move(url_loader_client));
1243 } 1344 }
1244 1345
1245 // Begins a resource request with the given params on behalf of the specified 1346 // Begins a resource request with the given params on behalf of the specified
1246 // child process. Responses will be dispatched through the given receiver. The 1347 // child process. Responses will be dispatched through the given receiver. The
1247 // process ID is used to lookup WebContentsImpl from routing_id's in the case of 1348 // process ID is used to lookup WebContentsImpl from routing_id's in the case of
1248 // a request from a renderer. request_context is the cookie/cache context to be 1349 // a request from a renderer. request_context is the cookie/cache context to be
1249 // used for this request. 1350 // used for this request.
1250 // 1351 //
1251 // If sync_result is non-null, then a SyncLoad reply will be generated, else 1352 // If sync_result is non-null, then a SyncLoad reply will be generated, else
1252 // a normal asynchronous set of response messages will be generated. 1353 // a normal asynchronous set of response messages will be generated.
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
1362 } 1463 }
1363 1464
1364 // We should have a CrossSiteResourceHandler to finish the transfer. 1465 // We should have a CrossSiteResourceHandler to finish the transfer.
1365 DCHECK(info->cross_site_handler()); 1466 DCHECK(info->cross_site_handler());
1366 } 1467 }
1367 1468
1368 void ResourceDispatcherHostImpl::BeginRequest( 1469 void ResourceDispatcherHostImpl::BeginRequest(
1369 int request_id, 1470 int request_id,
1370 const ResourceRequest& request_data, 1471 const ResourceRequest& request_data,
1371 IPC::Message* sync_result, // only valid for sync 1472 IPC::Message* sync_result, // only valid for sync
1372 int route_id) { 1473 int route_id,
1474 std::unique_ptr<mojom::URLLoader> url_loader,
1475 mojom::URLLoaderClientPtr url_loader_client) {
1373 int process_type = filter_->process_type(); 1476 int process_type = filter_->process_type();
1374 int child_id = filter_->child_id(); 1477 int child_id = filter_->child_id();
1375 1478
1376 // Reject request id that's currently in use. 1479 // Reject request id that's currently in use.
1377 if (IsRequestIDInUse(GlobalRequestID(child_id, request_id))) { 1480 if (IsRequestIDInUse(GlobalRequestID(child_id, request_id))) {
1378 bad_message::ReceivedBadMessage(filter_, 1481 bad_message::ReceivedBadMessage(filter_,
1379 bad_message::RDH_INVALID_REQUEST_ID); 1482 bad_message::RDH_INVALID_REQUEST_ID);
1380 return; 1483 return;
1381 } 1484 }
1382 1485
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
1621 } 1724 }
1622 1725
1623 // Have the appcache associate its extra info with the request. 1726 // Have the appcache associate its extra info with the request.
1624 AppCacheInterceptor::SetExtraRequestInfo( 1727 AppCacheInterceptor::SetExtraRequestInfo(
1625 new_request.get(), filter_->appcache_service(), child_id, 1728 new_request.get(), filter_->appcache_service(), child_id,
1626 request_data.appcache_host_id, request_data.resource_type, 1729 request_data.appcache_host_id, request_data.resource_type,
1627 request_data.should_reset_appcache); 1730 request_data.should_reset_appcache);
1628 1731
1629 std::unique_ptr<ResourceHandler> handler(CreateResourceHandler( 1732 std::unique_ptr<ResourceHandler> handler(CreateResourceHandler(
1630 new_request.get(), request_data, sync_result, route_id, process_type, 1733 new_request.get(), request_data, sync_result, route_id, process_type,
1631 child_id, resource_context)); 1734 child_id, resource_context, url_loader_client != nullptr));
1632 1735
1633 if (handler) 1736 if (handler)
1634 BeginRequestInternal(std::move(new_request), std::move(handler)); 1737 BeginRequestInternal(std::move(new_request), std::move(handler),
1738 std::move(url_loader), std::move(url_loader_client));
1635 } 1739 }
1636 1740
1637 std::unique_ptr<ResourceHandler> 1741 std::unique_ptr<ResourceHandler>
1638 ResourceDispatcherHostImpl::CreateResourceHandler( 1742 ResourceDispatcherHostImpl::CreateResourceHandler(
1639 net::URLRequest* request, 1743 net::URLRequest* request,
1640 const ResourceRequest& request_data, 1744 const ResourceRequest& request_data,
1641 IPC::Message* sync_result, 1745 IPC::Message* sync_result,
1642 int route_id, 1746 int route_id,
1643 int process_type, 1747 int process_type,
1644 int child_id, 1748 int child_id,
1645 ResourceContext* resource_context) { 1749 ResourceContext* resource_context,
1750 bool using_mojo) {
1646 // TODO(pkasting): Remove ScopedTracker below once crbug.com/456331 is fixed. 1751 // TODO(pkasting): Remove ScopedTracker below once crbug.com/456331 is fixed.
1647 tracked_objects::ScopedTracker tracking_profile( 1752 tracked_objects::ScopedTracker tracking_profile(
1648 FROM_HERE_WITH_EXPLICIT_FUNCTION( 1753 FROM_HERE_WITH_EXPLICIT_FUNCTION(
1649 "456331 ResourceDispatcherHostImpl::CreateResourceHandler")); 1754 "456331 ResourceDispatcherHostImpl::CreateResourceHandler"));
1650 // Construct the IPC resource handler. 1755 // Construct the IPC resource handler.
1651 std::unique_ptr<ResourceHandler> handler; 1756 std::unique_ptr<ResourceHandler> handler;
1652 if (sync_result) { 1757 if (sync_result) {
1758 DCHECK(!using_mojo);
1653 // download_to_file is not supported for synchronous requests. 1759 // download_to_file is not supported for synchronous requests.
1654 if (request_data.download_to_file) { 1760 if (request_data.download_to_file) {
1655 bad_message::ReceivedBadMessage(filter_, bad_message::RDH_BAD_DOWNLOAD); 1761 bad_message::ReceivedBadMessage(filter_, bad_message::RDH_BAD_DOWNLOAD);
1656 return std::unique_ptr<ResourceHandler>(); 1762 return std::unique_ptr<ResourceHandler>();
1657 } 1763 }
1658 1764
1659 handler.reset(new SyncResourceHandler(request, sync_result, this)); 1765 handler.reset(new SyncResourceHandler(request, sync_result, this));
1660 } else { 1766 } else {
1661 handler.reset(new AsyncResourceHandler(request, this)); 1767 handler.reset(new AsyncResourceHandler(request, this, using_mojo));
mmenke 2016/05/24 20:06:07 Why doesn't the AsyncResourceHandler take ownershi
mmenke 2016/05/25 04:39:03 Actually, can we just make a MojoResourceHandler,
yhirano 2016/05/25 12:47:06 Done.
1662 1768
1663 // The RedirectToFileResourceHandler depends on being next in the chain. 1769 // The RedirectToFileResourceHandler depends on being next in the chain.
1664 if (request_data.download_to_file) { 1770 if (request_data.download_to_file) {
1665 handler.reset( 1771 handler.reset(
1666 new RedirectToFileResourceHandler(std::move(handler), request)); 1772 new RedirectToFileResourceHandler(std::move(handler), request));
1667 } 1773 }
1668 } 1774 }
1669 1775
1670 // Prefetches and <a ping> requests outlive their child process. 1776 // Prefetches and <a ping> requests outlive their child process.
1671 if (!sync_result && IsDetachableResourceType(request_data.resource_type)) { 1777 if (!sync_result && IsDetachableResourceType(request_data.resource_type)) {
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
2057 // blocked_loaders_map_, as blocking requests modifies the map. 2163 // blocked_loaders_map_, as blocking requests modifies the map.
2058 std::set<GlobalFrameRoutingId> routing_ids; 2164 std::set<GlobalFrameRoutingId> routing_ids;
2059 for (const auto& blocked_loaders : blocked_loaders_map_) { 2165 for (const auto& blocked_loaders : blocked_loaders_map_) {
2060 if (blocked_loaders.first.child_id == child_id) 2166 if (blocked_loaders.first.child_id == child_id)
2061 routing_ids.insert(blocked_loaders.first); 2167 routing_ids.insert(blocked_loaders.first);
2062 } 2168 }
2063 for (const GlobalFrameRoutingId& route_id : routing_ids) { 2169 for (const GlobalFrameRoutingId& route_id : routing_ids) {
2064 CancelBlockedRequestsForRoute(route_id); 2170 CancelBlockedRequestsForRoute(route_id);
2065 } 2171 }
2066 } 2172 }
2173
2174 // Uninitiated URLLoader has no routing ID, so it should be deleted only when
2175 // cancel_all_routes is specified.
2176 if (cancel_all_routes)
2177 mojo_helper_->CancelUninitiatedLoaders(child_id);
2067 } 2178 }
2068 2179
2069 // Cancels the request and removes it from the list. 2180 // Cancels the request and removes it from the list.
2070 void ResourceDispatcherHostImpl::RemovePendingRequest(int child_id, 2181 void ResourceDispatcherHostImpl::RemovePendingRequest(int child_id,
2071 int request_id) { 2182 int request_id) {
2072 LoaderMap::iterator i = pending_loaders_.find( 2183 LoaderMap::iterator i = pending_loaders_.find(
2073 GlobalRequestID(child_id, request_id)); 2184 GlobalRequestID(child_id, request_id));
2074 if (i == pending_loaders_.end()) { 2185 if (i == pending_loaders_.end()) {
2075 NOTREACHED() << "Trying to remove a request that's not here"; 2186 NOTREACHED() << "Trying to remove a request that's not here";
2076 return; 2187 return;
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
2344 std::move(handler)); 2455 std::move(handler));
2345 2456
2346 BeginRequestInternal(std::move(new_request), std::move(handler)); 2457 BeginRequestInternal(std::move(new_request), std::move(handler));
2347 } 2458 }
2348 2459
2349 void ResourceDispatcherHostImpl::EnableStaleWhileRevalidateForTesting() { 2460 void ResourceDispatcherHostImpl::EnableStaleWhileRevalidateForTesting() {
2350 if (!async_revalidation_manager_) 2461 if (!async_revalidation_manager_)
2351 async_revalidation_manager_.reset(new AsyncRevalidationManager); 2462 async_revalidation_manager_.reset(new AsyncRevalidationManager);
2352 } 2463 }
2353 2464
2465 void ResourceDispatcherHostImpl::OnRequestResourceWithMojo(
2466 int routing_id,
2467 int request_id,
2468 const ResourceRequest& request,
2469 std::unique_ptr<mojom::URLLoader> url_loader,
2470 mojom::URLLoaderClientPtr url_loader_client,
2471 ResourceMessageFilter* filter) {
2472 filter_ = filter;
2473 OnRequestResourceInternal(routing_id, request_id, request,
2474 std::move(url_loader),
2475 std::move(url_loader_client));
2476 filter_ = nullptr;
2477 }
2478
2479 bool ResourceDispatcherHostImpl::SendWithMojoIfPossible(
2480 const IPC::Message& message,
2481 ResourceMessageFilter* filter) {
2482 return mojo_helper_->Send(message, filter);
2483 }
2484
2485 void ResourceDispatcherHostImpl::OnStartLoadingResponseBodyWithMojo(
2486 const GlobalRequestID& id,
2487 mojo::ScopedDataPipeConsumerHandle response_body) {
2488 ResourceLoader* loader = GetLoader(id);
2489 if (!loader)
2490 return;
2491
2492 loader->client()->OnStartLoadingResponseBody(std::move(response_body));
2493 }
2494
2495 void ResourceDispatcherHostImpl::AddUninitiatedURLLoader(
2496 int child_id,
2497 std::unique_ptr<mojom::URLLoader> loader) {
2498 mojo_helper_->AddUninitiatedURLLoader(child_id, std::move(loader));
2499 }
2500
2501 std::unique_ptr<mojom::URLLoader>
2502 ResourceDispatcherHostImpl::TakeUninitiatedURLLoader(mojom::URLLoader* loader) {
2503 return mojo_helper_->TakeUninitiatedURLLoader(loader);
2504 }
2505
2354 // static 2506 // static
2355 int ResourceDispatcherHostImpl::CalculateApproximateMemoryCost( 2507 int ResourceDispatcherHostImpl::CalculateApproximateMemoryCost(
2356 net::URLRequest* request) { 2508 net::URLRequest* request) {
2357 // The following fields should be a minor size contribution (experimentally 2509 // The following fields should be a minor size contribution (experimentally
2358 // on the order of 100). However since they are variable length, it could 2510 // on the order of 100). However since they are variable length, it could
2359 // in theory be a sizeable contribution. 2511 // in theory be a sizeable contribution.
2360 int strings_cost = request->extra_request_headers().ToString().size() + 2512 int strings_cost = request->extra_request_headers().ToString().size() +
2361 request->original_url().spec().size() + 2513 request->original_url().spec().size() +
2362 request->referrer().size() + 2514 request->referrer().size() +
2363 request->method().size(); 2515 request->method().size();
2364 2516
2365 // Note that this expression will typically be dominated by: 2517 // Note that this expression will typically be dominated by:
2366 // |kAvgBytesPerOutstandingRequest|. 2518 // |kAvgBytesPerOutstandingRequest|.
2367 return kAvgBytesPerOutstandingRequest + strings_cost; 2519 return kAvgBytesPerOutstandingRequest + strings_cost;
2368 } 2520 }
2369 2521
2370 void ResourceDispatcherHostImpl::BeginRequestInternal( 2522 void ResourceDispatcherHostImpl::BeginRequestInternal(
2371 std::unique_ptr<net::URLRequest> request, 2523 std::unique_ptr<net::URLRequest> request,
2372 std::unique_ptr<ResourceHandler> handler) { 2524 std::unique_ptr<ResourceHandler> handler,
2525 std::unique_ptr<mojom::URLLoader> url_loader,
2526 mojom::URLLoaderClientPtr url_loader_client) {
2373 DCHECK(!request->is_pending()); 2527 DCHECK(!request->is_pending());
2374 ResourceRequestInfoImpl* info = 2528 ResourceRequestInfoImpl* info =
2375 ResourceRequestInfoImpl::ForRequest(request.get()); 2529 ResourceRequestInfoImpl::ForRequest(request.get());
2376 2530
2377 if ((TimeTicks::Now() - last_user_gesture_time_) < 2531 if ((TimeTicks::Now() - last_user_gesture_time_) <
2378 TimeDelta::FromMilliseconds(kUserGestureWindowMs)) { 2532 TimeDelta::FromMilliseconds(kUserGestureWindowMs)) {
2379 request->SetLoadFlags( 2533 request->SetLoadFlags(
2380 request->load_flags() | net::LOAD_MAYBE_USER_GESTURE); 2534 request->load_flags() | net::LOAD_MAYBE_USER_GESTURE);
2381 } 2535 }
2382 2536
(...skipping 16 matching lines...) Expand all
2399 } 2553 }
2400 2554
2401 IncrementOutstandingRequestsMemory(-1, *info); 2555 IncrementOutstandingRequestsMemory(-1, *info);
2402 2556
2403 // A ResourceHandler must not outlive its associated URLRequest. 2557 // A ResourceHandler must not outlive its associated URLRequest.
2404 handler.reset(); 2558 handler.reset();
2405 return; 2559 return;
2406 } 2560 }
2407 2561
2408 std::unique_ptr<ResourceLoader> loader(new ResourceLoader( 2562 std::unique_ptr<ResourceLoader> loader(new ResourceLoader(
2409 std::move(request), std::move(handler), GetCertStore(), this)); 2563 std::move(request), std::move(handler), GetCertStore(),
2564 std::move(url_loader), std::move(url_loader_client), this));
2410 2565
2411 GlobalFrameRoutingId id(info->GetChildID(), info->GetRenderFrameID()); 2566 GlobalFrameRoutingId id(info->GetChildID(), info->GetRenderFrameID());
2412 BlockedLoadersMap::const_iterator iter = blocked_loaders_map_.find(id); 2567 BlockedLoadersMap::const_iterator iter = blocked_loaders_map_.find(id);
2413 if (iter != blocked_loaders_map_.end()) { 2568 if (iter != blocked_loaders_map_.end()) {
2414 // The request should be blocked. 2569 // The request should be blocked.
2415 iter->second->push_back(std::move(loader)); 2570 iter->second->push_back(std::move(loader));
2416 return; 2571 return;
2417 } 2572 }
2418 2573
2419 StartLoading(info, std::move(loader)); 2574 StartLoading(info, std::move(loader));
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
2690 ssl.cert_id = GetCertStore()->StoreCert(ssl_info.cert.get(), child_id); 2845 ssl.cert_id = GetCertStore()->StoreCert(ssl_info.cert.get(), child_id);
2691 response->head.security_info = SerializeSecurityInfo(ssl); 2846 response->head.security_info = SerializeSecurityInfo(ssl);
2692 } 2847 }
2693 2848
2694 CertStore* ResourceDispatcherHostImpl::GetCertStore() { 2849 CertStore* ResourceDispatcherHostImpl::GetCertStore() {
2695 return cert_store_for_testing_ ? cert_store_for_testing_ 2850 return cert_store_for_testing_ ? cert_store_for_testing_
2696 : CertStore::GetInstance(); 2851 : CertStore::GetInstance();
2697 } 2852 }
2698 2853
2699 } // namespace content 2854 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698