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

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, 7 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 class ResourceDispatcherHostImpl::MojoHelper final {
542 public:
543 explicit MojoHelper(ResourceDispatcherHostImpl* owner) : owner_(owner) {}
544
545 void SetLoaderAndClientForNextLoadRequest(
546 std::unique_ptr<mojom::URLLoader> loader,
547 mojom::URLLoaderClientPtr client) {
548 loader_for_next_load_request_ = std::move(loader);
549 loader_client_for_next_load_request_ = std::move(client);
550 }
551
552 std::unique_ptr<mojom::URLLoader> TakeLoaderForNextLoadRequest() {
553 return std::move(loader_for_next_load_request_);
554 }
555
556 mojom::URLLoaderClientPtr TakeClientForNextLoadRequest() {
557 return std::move(loader_client_for_next_load_request_);
558 }
559
560 bool Send(const IPC::Message& message, ResourceMessageFilter* filter) {
561 if (IPC_MESSAGE_ID_CLASS(message.type()) != ResourceMsgStart)
562 return false;
563
564 base::PickleIterator iter(message);
565 int request_id = -1;
566 bool ok = iter.ReadInt(&request_id);
567 DCHECK(ok);
568 ResourceLoader* loader = owner_->GetLoader(filter->child_id(), request_id);
569 if (!loader || !loader->client())
570 return false;
571
572 DCHECK(!filter_);
573 filter_ = filter;
574 bool handled = true;
575 IPC_BEGIN_MESSAGE_MAP(MojoHelper, message)
576 IPC_MESSAGE_HANDLER(ResourceMsg_ReceivedResponse, OnReceivedResponse)
577 IPC_MESSAGE_HANDLER(ResourceMsg_RequestComplete, OnRequestComplete)
578 IPC_MESSAGE_UNHANDLED(handled = false)
579 IPC_END_MESSAGE_MAP()
580
581 filter_ = nullptr;
582 return handled;
583 }
584
585 void AddUninitiatedURLLoader(int child_id,
586 std::unique_ptr<mojom::URLLoader> loader) {
587 mojom::URLLoader* raw = loader.get();
588 uninitiated_url_loaders_.insert(
589 std::make_pair(raw, std::make_pair(child_id, std::move(loader))));
590 }
591
592 std::unique_ptr<mojom::URLLoader> TakeUninitiatedURLLoader(
593 mojom::URLLoader* loader) {
594 auto it = uninitiated_url_loaders_.find(loader);
595 if (it == uninitiated_url_loaders_.end())
596 return nullptr;
597 std::unique_ptr<mojom::URLLoader> result = std::move(it->second.second);
598 uninitiated_url_loaders_.erase(it);
599 return result;
600 }
601
602 void CancelUninitiatedLoaders(int child_id) {
603 auto it = uninitiated_url_loaders_.begin();
604 while (it != uninitiated_url_loaders_.end()) {
605 if (it->second.first == child_id) {
606 it = uninitiated_url_loaders_.erase(it);
607 } else {
608 ++it;
609 }
610 }
611 }
612
613 private:
614 void OnReceivedResponse(int request_id, const ResourceResponseHead& head) {
615 int child_id = filter_->child_id();
616 ResourceLoader* loader = owner_->GetLoader(child_id, request_id);
617 mojom::URLLoaderClient* client = loader->client();
618 client->OnReceiveResponse(head, loader->GetRequestInfo()->TakeBodyReader());
619 }
620
621 void OnRequestComplete(int request_id,
622 const ResourceRequestCompletionStatus& status) {
623 int child_id = filter_->child_id();
624 ResourceLoader* loader = owner_->GetLoader(child_id, request_id);
625 mojom::URLLoaderClient* client = loader->client();
626
627 client->OnComplete(status);
628 }
629
630 ResourceDispatcherHostImpl* owner_;
631 ResourceMessageFilter* filter_ = nullptr;
632 std::unique_ptr<mojom::URLLoader> loader_for_next_load_request_;
633 mojom::URLLoaderClientPtr loader_client_for_next_load_request_;
634 std::map<mojom::URLLoader*, std::pair<int, std::unique_ptr<mojom::URLLoader>>>
635 uninitiated_url_loaders_;
636
637 DISALLOW_COPY_AND_ASSIGN(MojoHelper);
638 };
639
541 ResourceDispatcherHostImpl::ResourceDispatcherHostImpl() 640 ResourceDispatcherHostImpl::ResourceDispatcherHostImpl()
542 : save_file_manager_(new SaveFileManager()), 641 : save_file_manager_(new SaveFileManager()),
543 request_id_(-1), 642 request_id_(-1),
544 is_shutdown_(false), 643 is_shutdown_(false),
545 num_in_flight_requests_(0), 644 num_in_flight_requests_(0),
546 max_num_in_flight_requests_(base::SharedMemory::GetHandleLimit()), 645 max_num_in_flight_requests_(base::SharedMemory::GetHandleLimit()),
547 max_num_in_flight_requests_per_process_(static_cast<int>( 646 max_num_in_flight_requests_per_process_(static_cast<int>(
548 max_num_in_flight_requests_ * kMaxRequestsPerProcessRatio)), 647 max_num_in_flight_requests_ * kMaxRequestsPerProcessRatio)),
549 max_outstanding_requests_cost_per_process_( 648 max_outstanding_requests_cost_per_process_(
550 kMaxOutstandingRequestsCostPerProcess), 649 kMaxOutstandingRequestsCostPerProcess),
551 filter_(NULL), 650 filter_(NULL),
552 delegate_(NULL), 651 delegate_(NULL),
553 allow_cross_origin_auth_prompt_(false), 652 allow_cross_origin_auth_prompt_(false),
554 cert_store_for_testing_(nullptr) { 653 cert_store_for_testing_(nullptr),
654 mojo_helper_(new MojoHelper(this)) {
555 DCHECK_CURRENTLY_ON(BrowserThread::UI); 655 DCHECK_CURRENTLY_ON(BrowserThread::UI);
556 DCHECK(!g_resource_dispatcher_host); 656 DCHECK(!g_resource_dispatcher_host);
557 g_resource_dispatcher_host = this; 657 g_resource_dispatcher_host = this;
558 658
559 GetContentClient()->browser()->ResourceDispatcherHostCreated(); 659 GetContentClient()->browser()->ResourceDispatcherHostCreated();
560 660
561 ANNOTATE_BENIGN_RACE( 661 ANNOTATE_BENIGN_RACE(
562 &last_user_gesture_time_, 662 &last_user_gesture_time_,
563 "We don't care about the precise value, see http://crbug.com/92889"); 663 "We don't care about the precise value, see http://crbug.com/92889");
564 664
(...skipping 12 matching lines...) Expand all
577 // navigation becomes the default. crbug.com/561610 677 // navigation becomes the default. crbug.com/561610
578 if (!IsBrowserSideNavigationEnabled() && 678 if (!IsBrowserSideNavigationEnabled() &&
579 base::FeatureList::IsEnabled(features::kStaleWhileRevalidate)) { 679 base::FeatureList::IsEnabled(features::kStaleWhileRevalidate)) {
580 async_revalidation_manager_.reset(new AsyncRevalidationManager); 680 async_revalidation_manager_.reset(new AsyncRevalidationManager);
581 } 681 }
582 } 682 }
583 683
584 ResourceDispatcherHostImpl::~ResourceDispatcherHostImpl() { 684 ResourceDispatcherHostImpl::~ResourceDispatcherHostImpl() {
585 DCHECK(outstanding_requests_stats_map_.empty()); 685 DCHECK(outstanding_requests_stats_map_.empty());
586 DCHECK(g_resource_dispatcher_host); 686 DCHECK(g_resource_dispatcher_host);
687 DCHECK_CURRENTLY_ON(BrowserThread::UI);
587 g_resource_dispatcher_host = NULL; 688 g_resource_dispatcher_host = NULL;
588 } 689 }
589 690
590 // static 691 // static
591 ResourceDispatcherHostImpl* ResourceDispatcherHostImpl::Get() { 692 ResourceDispatcherHostImpl* ResourceDispatcherHostImpl::Get() {
592 return g_resource_dispatcher_host; 693 return g_resource_dispatcher_host;
593 } 694 }
594 695
595 // static 696 // static
596 void ResourceDispatcherHostImpl::ResumeBlockedRequestsForRouteFromUI( 697 void ResourceDispatcherHostImpl::ResumeBlockedRequestsForRouteFromUI(
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after
1170 for (const auto& routing_id : ids) { 1271 for (const auto& routing_id : ids) {
1171 CancelBlockedRequestsForRoute(routing_id); 1272 CancelBlockedRequestsForRoute(routing_id);
1172 } 1273 }
1173 1274
1174 scheduler_.reset(); 1275 scheduler_.reset();
1175 } 1276 }
1176 1277
1177 bool ResourceDispatcherHostImpl::OnMessageReceived( 1278 bool ResourceDispatcherHostImpl::OnMessageReceived(
1178 const IPC::Message& message, 1279 const IPC::Message& message,
1179 ResourceMessageFilter* filter) { 1280 ResourceMessageFilter* filter) {
1281 DCHECK_CURRENTLY_ON(BrowserThread::IO);
1180 filter_ = filter; 1282 filter_ = filter;
1181 bool handled = true; 1283 bool handled = true;
1182 IPC_BEGIN_MESSAGE_MAP(ResourceDispatcherHostImpl, message) 1284 IPC_BEGIN_MESSAGE_MAP(ResourceDispatcherHostImpl, message)
1183 IPC_MESSAGE_HANDLER(ResourceHostMsg_RequestResource, OnRequestResource) 1285 IPC_MESSAGE_HANDLER(ResourceHostMsg_RequestResource, OnRequestResource)
1184 IPC_MESSAGE_HANDLER_DELAY_REPLY(ResourceHostMsg_SyncLoad, OnSyncLoad) 1286 IPC_MESSAGE_HANDLER_DELAY_REPLY(ResourceHostMsg_SyncLoad, OnSyncLoad)
1185 IPC_MESSAGE_HANDLER(ResourceHostMsg_ReleaseDownloadedFile, 1287 IPC_MESSAGE_HANDLER(ResourceHostMsg_ReleaseDownloadedFile,
1186 OnReleaseDownloadedFile) 1288 OnReleaseDownloadedFile)
1187 IPC_MESSAGE_HANDLER(ResourceHostMsg_DataDownloaded_ACK, OnDataDownloadedACK) 1289 IPC_MESSAGE_HANDLER(ResourceHostMsg_DataDownloaded_ACK, OnDataDownloadedACK)
1188 IPC_MESSAGE_HANDLER(ResourceHostMsg_CancelRequest, OnCancelRequest) 1290 IPC_MESSAGE_HANDLER(ResourceHostMsg_CancelRequest, OnCancelRequest)
1189 IPC_MESSAGE_HANDLER(ResourceHostMsg_DidChangePriority, OnDidChangePriority) 1291 IPC_MESSAGE_HANDLER(ResourceHostMsg_DidChangePriority, OnDidChangePriority)
(...skipping 21 matching lines...) Expand all
1211 } 1313 }
1212 1314
1213 filter_ = NULL; 1315 filter_ = NULL;
1214 return handled; 1316 return handled;
1215 } 1317 }
1216 1318
1217 void ResourceDispatcherHostImpl::OnRequestResource( 1319 void ResourceDispatcherHostImpl::OnRequestResource(
1218 int routing_id, 1320 int routing_id,
1219 int request_id, 1321 int request_id,
1220 const ResourceRequest& request_data) { 1322 const ResourceRequest& request_data) {
1323 std::unique_ptr<mojom::URLLoader> loader =
1324 mojo_helper_->TakeLoaderForNextLoadRequest();
1325 mojom::URLLoaderClientPtr client =
1326 mojo_helper_->TakeClientForNextLoadRequest();
kinuko 2016/05/20 15:56:46 nit: can these be taken by a single method call by
yhirano 2016/05/23 11:29:37 Removed
1327
1221 // TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed. 1328 // TODO(pkasting): Remove ScopedTracker below once crbug.com/477117 is fixed.
1222 tracked_objects::ScopedTracker tracking_profile( 1329 tracked_objects::ScopedTracker tracking_profile(
1223 FROM_HERE_WITH_EXPLICIT_FUNCTION( 1330 FROM_HERE_WITH_EXPLICIT_FUNCTION(
1224 "477117 ResourceDispatcherHostImpl::OnRequestResource")); 1331 "477117 ResourceDispatcherHostImpl::OnRequestResource"));
1225 // When logging time-to-network only care about main frame and non-transfer 1332 // When logging time-to-network only care about main frame and non-transfer
1226 // navigations. 1333 // navigations.
1227 // PlzNavigate: this log happens from NavigationRequest::OnRequestStarted 1334 // PlzNavigate: this log happens from NavigationRequest::OnRequestStarted
1228 // instead. 1335 // instead.
1229 if (request_data.resource_type == RESOURCE_TYPE_MAIN_FRAME && 1336 if (request_data.resource_type == RESOURCE_TYPE_MAIN_FRAME &&
1230 request_data.transferred_request_request_id == -1 && 1337 request_data.transferred_request_request_id == -1 &&
1231 !IsBrowserSideNavigationEnabled()) { 1338 !IsBrowserSideNavigationEnabled()) {
1232 BrowserThread::PostTask( 1339 BrowserThread::PostTask(
1233 BrowserThread::UI, 1340 BrowserThread::UI,
1234 FROM_HERE, 1341 FROM_HERE,
1235 base::Bind(&LogResourceRequestTimeOnUI, 1342 base::Bind(&LogResourceRequestTimeOnUI,
1236 TimeTicks::Now(), 1343 TimeTicks::Now(),
1237 filter_->child_id(), 1344 filter_->child_id(),
1238 request_data.render_frame_id, 1345 request_data.render_frame_id,
1239 request_data.url)); 1346 request_data.url));
1240 } 1347 }
1241 BeginRequest(request_id, request_data, NULL, routing_id); 1348 BeginRequest(request_id, request_data, NULL, routing_id, std::move(loader),
1349 std::move(client));
1242 } 1350 }
1243 1351
1244 // Begins a resource request with the given params on behalf of the specified 1352 // 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 1353 // 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 1354 // 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 1355 // a request from a renderer. request_context is the cookie/cache context to be
1248 // used for this request. 1356 // used for this request.
1249 // 1357 //
1250 // If sync_result is non-null, then a SyncLoad reply will be generated, else 1358 // 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. 1359 // a normal asynchronous set of response messages will be generated.
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
1361 } 1469 }
1362 1470
1363 // We should have a CrossSiteResourceHandler to finish the transfer. 1471 // We should have a CrossSiteResourceHandler to finish the transfer.
1364 DCHECK(info->cross_site_handler()); 1472 DCHECK(info->cross_site_handler());
1365 } 1473 }
1366 1474
1367 void ResourceDispatcherHostImpl::BeginRequest( 1475 void ResourceDispatcherHostImpl::BeginRequest(
1368 int request_id, 1476 int request_id,
1369 const ResourceRequest& request_data, 1477 const ResourceRequest& request_data,
1370 IPC::Message* sync_result, // only valid for sync 1478 IPC::Message* sync_result, // only valid for sync
1371 int route_id) { 1479 int route_id,
1480 std::unique_ptr<mojom::URLLoader> url_loader,
1481 mojom::URLLoaderClientPtr client) {
1372 int process_type = filter_->process_type(); 1482 int process_type = filter_->process_type();
1373 int child_id = filter_->child_id(); 1483 int child_id = filter_->child_id();
1374 1484
1375 // Reject request id that's currently in use. 1485 // Reject request id that's currently in use.
1376 if (IsRequestIDInUse(GlobalRequestID(child_id, request_id))) { 1486 if (IsRequestIDInUse(GlobalRequestID(child_id, request_id))) {
1377 bad_message::ReceivedBadMessage(filter_, 1487 bad_message::ReceivedBadMessage(filter_,
1378 bad_message::RDH_INVALID_REQUEST_ID); 1488 bad_message::RDH_INVALID_REQUEST_ID);
1379 return; 1489 return;
1380 } 1490 }
1381 1491
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
1620 } 1730 }
1621 1731
1622 // Have the appcache associate its extra info with the request. 1732 // Have the appcache associate its extra info with the request.
1623 AppCacheInterceptor::SetExtraRequestInfo( 1733 AppCacheInterceptor::SetExtraRequestInfo(
1624 new_request.get(), filter_->appcache_service(), child_id, 1734 new_request.get(), filter_->appcache_service(), child_id,
1625 request_data.appcache_host_id, request_data.resource_type, 1735 request_data.appcache_host_id, request_data.resource_type,
1626 request_data.should_reset_appcache); 1736 request_data.should_reset_appcache);
1627 1737
1628 std::unique_ptr<ResourceHandler> handler(CreateResourceHandler( 1738 std::unique_ptr<ResourceHandler> handler(CreateResourceHandler(
1629 new_request.get(), request_data, sync_result, route_id, process_type, 1739 new_request.get(), request_data, sync_result, route_id, process_type,
1630 child_id, resource_context)); 1740 child_id, resource_context, client != nullptr));
1631 1741
1632 if (handler) 1742 if (handler)
1633 BeginRequestInternal(std::move(new_request), std::move(handler)); 1743 BeginRequestInternal(std::move(new_request), std::move(handler),
1744 std::move(url_loader), std::move(client));
1634 } 1745 }
1635 1746
1636 std::unique_ptr<ResourceHandler> 1747 std::unique_ptr<ResourceHandler>
1637 ResourceDispatcherHostImpl::CreateResourceHandler( 1748 ResourceDispatcherHostImpl::CreateResourceHandler(
1638 net::URLRequest* request, 1749 net::URLRequest* request,
1639 const ResourceRequest& request_data, 1750 const ResourceRequest& request_data,
1640 IPC::Message* sync_result, 1751 IPC::Message* sync_result,
1641 int route_id, 1752 int route_id,
1642 int process_type, 1753 int process_type,
1643 int child_id, 1754 int child_id,
1644 ResourceContext* resource_context) { 1755 ResourceContext* resource_context,
1756 bool using_mojo) {
1645 // TODO(pkasting): Remove ScopedTracker below once crbug.com/456331 is fixed. 1757 // TODO(pkasting): Remove ScopedTracker below once crbug.com/456331 is fixed.
1646 tracked_objects::ScopedTracker tracking_profile( 1758 tracked_objects::ScopedTracker tracking_profile(
1647 FROM_HERE_WITH_EXPLICIT_FUNCTION( 1759 FROM_HERE_WITH_EXPLICIT_FUNCTION(
1648 "456331 ResourceDispatcherHostImpl::CreateResourceHandler")); 1760 "456331 ResourceDispatcherHostImpl::CreateResourceHandler"));
1649 // Construct the IPC resource handler. 1761 // Construct the IPC resource handler.
1650 std::unique_ptr<ResourceHandler> handler; 1762 std::unique_ptr<ResourceHandler> handler;
1651 if (sync_result) { 1763 if (sync_result) {
1764 DCHECK(!using_mojo);
1652 // download_to_file is not supported for synchronous requests. 1765 // download_to_file is not supported for synchronous requests.
1653 if (request_data.download_to_file) { 1766 if (request_data.download_to_file) {
1654 bad_message::ReceivedBadMessage(filter_, bad_message::RDH_BAD_DOWNLOAD); 1767 bad_message::ReceivedBadMessage(filter_, bad_message::RDH_BAD_DOWNLOAD);
1655 return std::unique_ptr<ResourceHandler>(); 1768 return std::unique_ptr<ResourceHandler>();
1656 } 1769 }
1657 1770
1658 handler.reset(new SyncResourceHandler(request, sync_result, this)); 1771 handler.reset(new SyncResourceHandler(request, sync_result, this));
1659 } else { 1772 } else {
1660 handler.reset(new AsyncResourceHandler(request, this)); 1773 handler.reset(new AsyncResourceHandler(request, this, using_mojo));
1661 1774
1662 // The RedirectToFileResourceHandler depends on being next in the chain. 1775 // The RedirectToFileResourceHandler depends on being next in the chain.
1663 if (request_data.download_to_file) { 1776 if (request_data.download_to_file) {
1664 handler.reset( 1777 handler.reset(
1665 new RedirectToFileResourceHandler(std::move(handler), request)); 1778 new RedirectToFileResourceHandler(std::move(handler), request));
1666 } 1779 }
1667 } 1780 }
1668 1781
1669 // Prefetches and <a ping> requests outlive their child process. 1782 // Prefetches and <a ping> requests outlive their child process.
1670 if (!sync_result && IsDetachableResourceType(request_data.resource_type)) { 1783 if (!sync_result && IsDetachableResourceType(request_data.resource_type)) {
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
2056 // blocked_loaders_map_, as blocking requests modifies the map. 2169 // blocked_loaders_map_, as blocking requests modifies the map.
2057 std::set<GlobalFrameRoutingId> routing_ids; 2170 std::set<GlobalFrameRoutingId> routing_ids;
2058 for (const auto& blocked_loaders : blocked_loaders_map_) { 2171 for (const auto& blocked_loaders : blocked_loaders_map_) {
2059 if (blocked_loaders.first.child_id == child_id) 2172 if (blocked_loaders.first.child_id == child_id)
2060 routing_ids.insert(blocked_loaders.first); 2173 routing_ids.insert(blocked_loaders.first);
2061 } 2174 }
2062 for (const GlobalFrameRoutingId& route_id : routing_ids) { 2175 for (const GlobalFrameRoutingId& route_id : routing_ids) {
2063 CancelBlockedRequestsForRoute(route_id); 2176 CancelBlockedRequestsForRoute(route_id);
2064 } 2177 }
2065 } 2178 }
2179
2180 // Uninitiated URLLoader has no routing ID, so it should be deleted only when
2181 // cancel_all_routes is specified.
2182 if (cancel_all_routes)
2183 mojo_helper_->CancelUninitiatedLoaders(child_id);
2066 } 2184 }
2067 2185
2068 // Cancels the request and removes it from the list. 2186 // Cancels the request and removes it from the list.
2069 void ResourceDispatcherHostImpl::RemovePendingRequest(int child_id, 2187 void ResourceDispatcherHostImpl::RemovePendingRequest(int child_id,
2070 int request_id) { 2188 int request_id) {
2071 LoaderMap::iterator i = pending_loaders_.find( 2189 LoaderMap::iterator i = pending_loaders_.find(
2072 GlobalRequestID(child_id, request_id)); 2190 GlobalRequestID(child_id, request_id));
2073 if (i == pending_loaders_.end()) { 2191 if (i == pending_loaders_.end()) {
2074 NOTREACHED() << "Trying to remove a request that's not here"; 2192 NOTREACHED() << "Trying to remove a request that's not here";
2075 return; 2193 return;
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
2343 std::move(handler)); 2461 std::move(handler));
2344 2462
2345 BeginRequestInternal(std::move(new_request), std::move(handler)); 2463 BeginRequestInternal(std::move(new_request), std::move(handler));
2346 } 2464 }
2347 2465
2348 void ResourceDispatcherHostImpl::EnableStaleWhileRevalidateForTesting() { 2466 void ResourceDispatcherHostImpl::EnableStaleWhileRevalidateForTesting() {
2349 if (!async_revalidation_manager_) 2467 if (!async_revalidation_manager_)
2350 async_revalidation_manager_.reset(new AsyncRevalidationManager); 2468 async_revalidation_manager_.reset(new AsyncRevalidationManager);
2351 } 2469 }
2352 2470
2471 bool ResourceDispatcherHostImpl::SendWithMojoIfPossible(
2472 const IPC::Message& message,
2473 ResourceMessageFilter* filter) {
2474 return mojo_helper_->Send(message, filter);
2475 }
2476
2477 void ResourceDispatcherHostImpl::AddUninitiatedURLLoader(
2478 int child_id,
2479 std::unique_ptr<mojom::URLLoader> loader) {
2480 mojo_helper_->AddUninitiatedURLLoader(child_id, std::move(loader));
2481 }
2482
2483 std::unique_ptr<mojom::URLLoader>
2484 ResourceDispatcherHostImpl::TakeUninitiatedURLLoader(mojom::URLLoader* loader) {
2485 return mojo_helper_->TakeUninitiatedURLLoader(loader);
2486 }
2487
2488 void ResourceDispatcherHostImpl::SetMojoLoaderAndClientForNextLoadRequest(
2489 std::unique_ptr<mojom::URLLoader> loader,
2490 mojom::URLLoaderClientPtr client) {
2491 mojo_helper_->SetLoaderAndClientForNextLoadRequest(std::move(loader),
2492 std::move(client));
2493 }
2494
2353 // static 2495 // static
2354 int ResourceDispatcherHostImpl::CalculateApproximateMemoryCost( 2496 int ResourceDispatcherHostImpl::CalculateApproximateMemoryCost(
2355 net::URLRequest* request) { 2497 net::URLRequest* request) {
2356 // The following fields should be a minor size contribution (experimentally 2498 // The following fields should be a minor size contribution (experimentally
2357 // on the order of 100). However since they are variable length, it could 2499 // on the order of 100). However since they are variable length, it could
2358 // in theory be a sizeable contribution. 2500 // in theory be a sizeable contribution.
2359 int strings_cost = request->extra_request_headers().ToString().size() + 2501 int strings_cost = request->extra_request_headers().ToString().size() +
2360 request->original_url().spec().size() + 2502 request->original_url().spec().size() +
2361 request->referrer().size() + 2503 request->referrer().size() +
2362 request->method().size(); 2504 request->method().size();
2363 2505
2364 // Note that this expression will typically be dominated by: 2506 // Note that this expression will typically be dominated by:
2365 // |kAvgBytesPerOutstandingRequest|. 2507 // |kAvgBytesPerOutstandingRequest|.
2366 return kAvgBytesPerOutstandingRequest + strings_cost; 2508 return kAvgBytesPerOutstandingRequest + strings_cost;
2367 } 2509 }
2368 2510
2369 void ResourceDispatcherHostImpl::BeginRequestInternal( 2511 void ResourceDispatcherHostImpl::BeginRequestInternal(
2370 std::unique_ptr<net::URLRequest> request, 2512 std::unique_ptr<net::URLRequest> request,
2371 std::unique_ptr<ResourceHandler> handler) { 2513 std::unique_ptr<ResourceHandler> handler,
2514 std::unique_ptr<mojom::URLLoader> url_loader,
2515 mojom::URLLoaderClientPtr client) {
2372 DCHECK(!request->is_pending()); 2516 DCHECK(!request->is_pending());
2373 ResourceRequestInfoImpl* info = 2517 ResourceRequestInfoImpl* info =
2374 ResourceRequestInfoImpl::ForRequest(request.get()); 2518 ResourceRequestInfoImpl::ForRequest(request.get());
2375 2519
2376 if ((TimeTicks::Now() - last_user_gesture_time_) < 2520 if ((TimeTicks::Now() - last_user_gesture_time_) <
2377 TimeDelta::FromMilliseconds(kUserGestureWindowMs)) { 2521 TimeDelta::FromMilliseconds(kUserGestureWindowMs)) {
2378 request->SetLoadFlags( 2522 request->SetLoadFlags(
2379 request->load_flags() | net::LOAD_MAYBE_USER_GESTURE); 2523 request->load_flags() | net::LOAD_MAYBE_USER_GESTURE);
2380 } 2524 }
2381 2525
(...skipping 15 matching lines...) Expand all
2397 NOTREACHED(); 2541 NOTREACHED();
2398 } 2542 }
2399 2543
2400 IncrementOutstandingRequestsMemory(-1, *info); 2544 IncrementOutstandingRequestsMemory(-1, *info);
2401 2545
2402 // A ResourceHandler must not outlive its associated URLRequest. 2546 // A ResourceHandler must not outlive its associated URLRequest.
2403 handler.reset(); 2547 handler.reset();
2404 return; 2548 return;
2405 } 2549 }
2406 2550
2407 std::unique_ptr<ResourceLoader> loader(new ResourceLoader( 2551 std::unique_ptr<ResourceLoader> loader(
2408 std::move(request), std::move(handler), GetCertStore(), this)); 2552 new ResourceLoader(std::move(request), std::move(handler), GetCertStore(),
2553 std::move(url_loader), std::move(client), this));
2409 2554
2410 GlobalFrameRoutingId id(info->GetChildID(), info->GetRenderFrameID()); 2555 GlobalFrameRoutingId id(info->GetChildID(), info->GetRenderFrameID());
2411 BlockedLoadersMap::const_iterator iter = blocked_loaders_map_.find(id); 2556 BlockedLoadersMap::const_iterator iter = blocked_loaders_map_.find(id);
2412 if (iter != blocked_loaders_map_.end()) { 2557 if (iter != blocked_loaders_map_.end()) {
2413 // The request should be blocked. 2558 // The request should be blocked.
2414 iter->second->push_back(std::move(loader)); 2559 iter->second->push_back(std::move(loader));
2415 return; 2560 return;
2416 } 2561 }
2417 2562
2418 StartLoading(info, std::move(loader)); 2563 StartLoading(info, std::move(loader));
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
2689 ssl.cert_id = GetCertStore()->StoreCert(ssl_info.cert.get(), child_id); 2834 ssl.cert_id = GetCertStore()->StoreCert(ssl_info.cert.get(), child_id);
2690 response->head.security_info = SerializeSecurityInfo(ssl); 2835 response->head.security_info = SerializeSecurityInfo(ssl);
2691 } 2836 }
2692 2837
2693 CertStore* ResourceDispatcherHostImpl::GetCertStore() { 2838 CertStore* ResourceDispatcherHostImpl::GetCertStore() {
2694 return cert_store_for_testing_ ? cert_store_for_testing_ 2839 return cert_store_for_testing_ ? cert_store_for_testing_
2695 : CertStore::GetInstance(); 2840 : CertStore::GetInstance();
2696 } 2841 }
2697 2842
2698 } // namespace content 2843 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698