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

Side by Side Diff: content/browser/loader/resource_dispatcher_host_impl.cc

Issue 1603503002: Use scoped_ptr for loaders map in ResourceDispatcherHostImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove linked_ptr.h Created 4 years, 11 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
« no previous file with comments | « content/browser/loader/resource_dispatcher_host_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include <algorithm> 10 #include <algorithm>
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 ResourceContext* context) { 556 ResourceContext* context) {
557 DCHECK_CURRENTLY_ON(BrowserThread::IO); 557 DCHECK_CURRENTLY_ON(BrowserThread::IO);
558 DCHECK(context); 558 DCHECK(context);
559 559
560 CHECK(ContainsKey(active_resource_contexts_, context)); 560 CHECK(ContainsKey(active_resource_contexts_, context));
561 561
562 // Note that request cancellation has side effects. Therefore, we gather all 562 // Note that request cancellation has side effects. Therefore, we gather all
563 // the requests to cancel first, and then we start cancelling. We assert at 563 // the requests to cancel first, and then we start cancelling. We assert at
564 // the end that there are no more to cancel since the context is about to go 564 // the end that there are no more to cancel since the context is about to go
565 // away. 565 // away.
566 typedef std::vector<linked_ptr<ResourceLoader>> LoaderList; 566 typedef std::vector<scoped_ptr<ResourceLoader>> LoaderList;
567 LoaderList loaders_to_cancel; 567 LoaderList loaders_to_cancel;
568 568
569 for (LoaderMap::iterator i = pending_loaders_.begin(); 569 for (LoaderMap::iterator i = pending_loaders_.begin();
570 i != pending_loaders_.end();) { 570 i != pending_loaders_.end();) {
571 if (i->second->GetRequestInfo()->GetContext() == context) { 571 ResourceLoader* loader = i->second.get();
572 loaders_to_cancel.push_back(i->second); 572 if (loader->GetRequestInfo()->GetContext() == context) {
573 IncrementOutstandingRequestsMemory(-1, *i->second->GetRequestInfo()); 573 loaders_to_cancel.push_back(std::move(i->second));
574 IncrementOutstandingRequestsMemory(-1, *loader->GetRequestInfo());
574 pending_loaders_.erase(i++); 575 pending_loaders_.erase(i++);
575 } else { 576 } else {
576 ++i; 577 ++i;
577 } 578 }
578 } 579 }
579 580
580 for (BlockedLoadersMap::iterator i = blocked_loaders_map_.begin(); 581 for (BlockedLoadersMap::iterator i = blocked_loaders_map_.begin();
581 i != blocked_loaders_map_.end();) { 582 i != blocked_loaders_map_.end();) {
582 BlockedLoadersList* loaders = i->second; 583 BlockedLoadersList* loaders = i->second.get();
583 if (loaders->empty()) { 584 if (loaders->empty()) {
584 // This can happen if BlockRequestsForRoute() has been called for a route, 585 // This can happen if BlockRequestsForRoute() has been called for a route,
585 // but we haven't blocked any matching requests yet. 586 // but we haven't blocked any matching requests yet.
586 ++i; 587 ++i;
587 continue; 588 continue;
588 } 589 }
589 ResourceRequestInfoImpl* info = loaders->front()->GetRequestInfo(); 590 ResourceRequestInfoImpl* info = loaders->front()->GetRequestInfo();
590 if (info->GetContext() == context) { 591 if (info->GetContext() == context) {
592 scoped_ptr<BlockedLoadersList> deleter(std::move(i->second));
591 blocked_loaders_map_.erase(i++); 593 blocked_loaders_map_.erase(i++);
592 for (BlockedLoadersList::const_iterator it = loaders->begin(); 594 for (auto& loader : *loaders) {
593 it != loaders->end(); ++it) {
594 linked_ptr<ResourceLoader> loader = *it;
595 info = loader->GetRequestInfo(); 595 info = loader->GetRequestInfo();
596 // We make the assumption that all requests on the list have the same 596 // We make the assumption that all requests on the list have the same
597 // ResourceContext. 597 // ResourceContext.
598 DCHECK_EQ(context, info->GetContext()); 598 DCHECK_EQ(context, info->GetContext());
599 IncrementOutstandingRequestsMemory(-1, *info); 599 IncrementOutstandingRequestsMemory(-1, *info);
600 loaders_to_cancel.push_back(loader); 600 loaders_to_cancel.push_back(std::move(loader));
601 } 601 }
602 delete loaders;
603 } else { 602 } else {
604 ++i; 603 ++i;
605 } 604 }
606 } 605 }
607 606
608 #ifndef NDEBUG 607 #ifndef NDEBUG
609 for (LoaderList::iterator i = loaders_to_cancel.begin(); 608 for (const auto& loader : loaders_to_cancel) {
610 i != loaders_to_cancel.end(); ++i) {
611 // There is no strict requirement that this be the case, but currently 609 // There is no strict requirement that this be the case, but currently
612 // downloads, streams, detachable requests, transferred requests, and 610 // downloads, streams, detachable requests, transferred requests, and
613 // browser-owned requests are the only requests that aren't cancelled when 611 // browser-owned requests are the only requests that aren't cancelled when
614 // the associated processes go away. It may be OK for this invariant to 612 // the associated processes go away. It may be OK for this invariant to
615 // change in the future, but if this assertion fires without the invariant 613 // change in the future, but if this assertion fires without the invariant
616 // changing, then it's indicative of a leak. 614 // changing, then it's indicative of a leak.
617 DCHECK((*i)->GetRequestInfo()->IsDownload() || 615 DCHECK(loader->GetRequestInfo()->IsDownload() ||
618 (*i)->GetRequestInfo()->is_stream() || 616 loader->GetRequestInfo()->is_stream() ||
619 ((*i)->GetRequestInfo()->detachable_handler() && 617 (loader->GetRequestInfo()->detachable_handler() &&
620 (*i)->GetRequestInfo()->detachable_handler()->is_detached()) || 618 loader->GetRequestInfo()->detachable_handler()->is_detached()) ||
621 (*i)->GetRequestInfo()->GetProcessType() == PROCESS_TYPE_BROWSER || 619 loader->GetRequestInfo()->GetProcessType() == PROCESS_TYPE_BROWSER ||
622 (*i)->is_transferring()); 620 loader->is_transferring());
623 } 621 }
624 #endif 622 #endif
625 623
626 loaders_to_cancel.clear(); 624 loaders_to_cancel.clear();
627 625
628 if (async_revalidation_manager_) { 626 if (async_revalidation_manager_) {
629 // Cancelling async revalidations should not result in the creation of new 627 // Cancelling async revalidations should not result in the creation of new
630 // requests. Do it before the CHECKs to ensure this does not happen. 628 // requests. Do it before the CHECKs to ensure this does not happen.
631 async_revalidation_manager_->CancelAsyncRevalidationsForResourceContext( 629 async_revalidation_manager_->CancelAsyncRevalidationsForResourceContext(
632 context); 630 context);
633 } 631 }
634 632
635 // Validate that no more requests for this context were added. 633 // Validate that no more requests for this context were added.
636 for (LoaderMap::const_iterator i = pending_loaders_.begin(); 634 for (const auto& loader : pending_loaders_) {
637 i != pending_loaders_.end(); ++i) {
638 // http://crbug.com/90971 635 // http://crbug.com/90971
639 CHECK_NE(i->second->GetRequestInfo()->GetContext(), context); 636 CHECK_NE(loader.second->GetRequestInfo()->GetContext(), context);
640 } 637 }
641 638
642 for (BlockedLoadersMap::const_iterator i = blocked_loaders_map_.begin(); 639 for (const auto& blocked_loaders : blocked_loaders_map_) {
643 i != blocked_loaders_map_.end(); ++i) { 640 BlockedLoadersList* loaders = blocked_loaders.second.get();
644 BlockedLoadersList* loaders = i->second;
645 if (!loaders->empty()) { 641 if (!loaders->empty()) {
646 ResourceRequestInfoImpl* info = loaders->front()->GetRequestInfo(); 642 ResourceRequestInfoImpl* info = loaders->front()->GetRequestInfo();
647 // http://crbug.com/90971 643 // http://crbug.com/90971
648 CHECK_NE(info->GetContext(), context); 644 CHECK_NE(info->GetContext(), context);
649 } 645 }
650 } 646 }
651 } 647 }
652 648
653 DownloadInterruptReason ResourceDispatcherHostImpl::BeginDownload( 649 DownloadInterruptReason ResourceDispatcherHostImpl::BeginDownload(
654 scoped_ptr<net::URLRequest> request, 650 scoped_ptr<net::URLRequest> request,
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
1065 // Make sure we shutdown the timer now, otherwise by the time our destructor 1061 // Make sure we shutdown the timer now, otherwise by the time our destructor
1066 // runs if the timer is still running the Task is deleted twice (once by 1062 // runs if the timer is still running the Task is deleted twice (once by
1067 // the MessageLoop and the second time by RepeatingTimer). 1063 // the MessageLoop and the second time by RepeatingTimer).
1068 update_load_states_timer_.reset(); 1064 update_load_states_timer_.reset();
1069 1065
1070 // Clear blocked requests if any left. 1066 // Clear blocked requests if any left.
1071 // Note that we have to do this in 2 passes as we cannot call 1067 // Note that we have to do this in 2 passes as we cannot call
1072 // CancelBlockedRequestsForRoute while iterating over 1068 // CancelBlockedRequestsForRoute while iterating over
1073 // blocked_loaders_map_, as it modifies it. 1069 // blocked_loaders_map_, as it modifies it.
1074 std::set<GlobalRoutingID> ids; 1070 std::set<GlobalRoutingID> ids;
1075 for (BlockedLoadersMap::const_iterator iter = blocked_loaders_map_.begin(); 1071 for (const auto& blocked_loaders : blocked_loaders_map_) {
1076 iter != blocked_loaders_map_.end(); ++iter) {
1077 std::pair<std::set<GlobalRoutingID>::iterator, bool> result = 1072 std::pair<std::set<GlobalRoutingID>::iterator, bool> result =
1078 ids.insert(iter->first); 1073 ids.insert(blocked_loaders.first);
1079 // We should not have duplicates. 1074 // We should not have duplicates.
1080 DCHECK(result.second); 1075 DCHECK(result.second);
1081 } 1076 }
1082 for (std::set<GlobalRoutingID>::const_iterator iter = ids.begin(); 1077 for (const auto& routing_id : ids) {
1083 iter != ids.end(); ++iter) { 1078 CancelBlockedRequestsForRoute(routing_id.child_id, routing_id.route_id);
1084 CancelBlockedRequestsForRoute(iter->child_id, iter->route_id);
1085 } 1079 }
1086 1080
1087 scheduler_.reset(); 1081 scheduler_.reset();
1088 } 1082 }
1089 1083
1090 bool ResourceDispatcherHostImpl::OnMessageReceived( 1084 bool ResourceDispatcherHostImpl::OnMessageReceived(
1091 const IPC::Message& message, 1085 const IPC::Message& message,
1092 ResourceMessageFilter* filter) { 1086 ResourceMessageFilter* filter) {
1093 filter_ = filter; 1087 filter_ = filter;
1094 bool handled = true; 1088 bool handled = true;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1168 IPC::Message* sync_result) { 1162 IPC::Message* sync_result) {
1169 BeginRequest(request_id, request_data, sync_result, 1163 BeginRequest(request_id, request_data, sync_result,
1170 sync_result->routing_id()); 1164 sync_result->routing_id());
1171 } 1165 }
1172 1166
1173 void ResourceDispatcherHostImpl::UpdateRequestForTransfer( 1167 void ResourceDispatcherHostImpl::UpdateRequestForTransfer(
1174 int child_id, 1168 int child_id,
1175 int route_id, 1169 int route_id,
1176 int request_id, 1170 int request_id,
1177 const ResourceHostMsg_Request& request_data, 1171 const ResourceHostMsg_Request& request_data,
1178 const linked_ptr<ResourceLoader>& loader) { 1172 LoaderMap::iterator iter) {
1179 ResourceRequestInfoImpl* info = loader->GetRequestInfo(); 1173 ResourceRequestInfoImpl* info = iter->second->GetRequestInfo();
1180 GlobalRoutingID old_routing_id( 1174 GlobalRoutingID old_routing_id(
1181 request_data.transferred_request_child_id, info->GetRouteID()); 1175 request_data.transferred_request_child_id, info->GetRouteID());
1182 GlobalRequestID old_request_id(request_data.transferred_request_child_id, 1176 GlobalRequestID old_request_id(request_data.transferred_request_child_id,
1183 request_data.transferred_request_request_id); 1177 request_data.transferred_request_request_id);
1184 GlobalRoutingID new_routing_id(child_id, route_id); 1178 GlobalRoutingID new_routing_id(child_id, route_id);
1185 GlobalRequestID new_request_id(child_id, request_id); 1179 GlobalRequestID new_request_id(child_id, request_id);
1186 1180
1187 // Clear out data that depends on |info| before updating it. 1181 // Clear out data that depends on |info| before updating it.
1188 // We always need to move the memory stats to the new process. In contrast, 1182 // We always need to move the memory stats to the new process. In contrast,
1189 // stats.num_requests is only tracked for some requests (those that require 1183 // stats.num_requests is only tracked for some requests (those that require
1190 // file descriptors for their shared memory buffer). 1184 // file descriptors for their shared memory buffer).
1191 IncrementOutstandingRequestsMemory(-1, *info); 1185 IncrementOutstandingRequestsMemory(-1, *info);
1192 bool should_update_count = info->counted_as_in_flight_request(); 1186 bool should_update_count = info->counted_as_in_flight_request();
1193 if (should_update_count) 1187 if (should_update_count)
1194 IncrementOutstandingRequestsCount(-1, info); 1188 IncrementOutstandingRequestsCount(-1, info);
1195 pending_loaders_.erase(old_request_id); 1189
1190 DCHECK(pending_loaders_.find(old_request_id) == iter);
1191 scoped_ptr<ResourceLoader> loader = std::move(iter->second);
1192 ResourceLoader* loader_ptr = loader.get();
1193 pending_loaders_.erase(iter);
1196 1194
1197 // ResourceHandlers should always get state related to the request from the 1195 // ResourceHandlers should always get state related to the request from the
1198 // ResourceRequestInfo rather than caching it locally. This lets us update 1196 // ResourceRequestInfo rather than caching it locally. This lets us update
1199 // the info object when a transfer occurs. 1197 // the info object when a transfer occurs.
1200 info->UpdateForTransfer(child_id, route_id, request_data.render_frame_id, 1198 info->UpdateForTransfer(child_id, route_id, request_data.render_frame_id,
1201 request_data.origin_pid, request_id, 1199 request_data.origin_pid, request_id,
1202 filter_->GetWeakPtr()); 1200 filter_->GetWeakPtr());
1203 1201
1204 // Update maps that used the old IDs, if necessary. Some transfers in tests 1202 // Update maps that used the old IDs, if necessary. Some transfers in tests
1205 // do not actually use a different ID, so not all maps need to be updated. 1203 // do not actually use a different ID, so not all maps need to be updated.
1206 pending_loaders_[new_request_id] = loader; 1204 pending_loaders_[new_request_id] = std::move(loader);
1207 IncrementOutstandingRequestsMemory(1, *info); 1205 IncrementOutstandingRequestsMemory(1, *info);
1208 if (should_update_count) 1206 if (should_update_count)
1209 IncrementOutstandingRequestsCount(1, info); 1207 IncrementOutstandingRequestsCount(1, info);
1210 if (old_routing_id != new_routing_id) { 1208 if (old_routing_id != new_routing_id) {
1211 if (blocked_loaders_map_.find(old_routing_id) != 1209 if (blocked_loaders_map_.find(old_routing_id) !=
1212 blocked_loaders_map_.end()) { 1210 blocked_loaders_map_.end()) {
1213 blocked_loaders_map_[new_routing_id] = 1211 blocked_loaders_map_[new_routing_id] =
1214 blocked_loaders_map_[old_routing_id]; 1212 std::move(blocked_loaders_map_[old_routing_id]);
1215 blocked_loaders_map_.erase(old_routing_id); 1213 blocked_loaders_map_.erase(old_routing_id);
1216 } 1214 }
1217 } 1215 }
1218 if (old_request_id != new_request_id) { 1216 if (old_request_id != new_request_id) {
1219 DelegateMap::iterator it = delegate_map_.find(old_request_id); 1217 DelegateMap::iterator it = delegate_map_.find(old_request_id);
1220 if (it != delegate_map_.end()) { 1218 if (it != delegate_map_.end()) {
1221 // Tell each delegate that the request ID has changed. 1219 // Tell each delegate that the request ID has changed.
1222 base::ObserverList<ResourceMessageDelegate>::Iterator del_it(it->second); 1220 base::ObserverList<ResourceMessageDelegate>::Iterator del_it(it->second);
1223 ResourceMessageDelegate* delegate; 1221 ResourceMessageDelegate* delegate;
1224 while ((delegate = del_it.GetNext()) != NULL) { 1222 while ((delegate = del_it.GetNext()) != NULL) {
1225 delegate->set_request_id(new_request_id); 1223 delegate->set_request_id(new_request_id);
1226 } 1224 }
1227 // Now store the observer list under the new request ID. 1225 // Now store the observer list under the new request ID.
1228 delegate_map_[new_request_id] = delegate_map_[old_request_id]; 1226 delegate_map_[new_request_id] = delegate_map_[old_request_id];
1229 delegate_map_.erase(old_request_id); 1227 delegate_map_.erase(old_request_id);
1230 } 1228 }
1231 } 1229 }
1232 1230
1233 AppCacheInterceptor::CompleteCrossSiteTransfer( 1231 AppCacheInterceptor::CompleteCrossSiteTransfer(
1234 loader->request(), 1232 loader_ptr->request(),
1235 child_id, 1233 child_id,
1236 request_data.appcache_host_id, 1234 request_data.appcache_host_id,
1237 filter_); 1235 filter_);
1238 1236
1239 ServiceWorkerRequestHandler* handler = 1237 ServiceWorkerRequestHandler* handler =
1240 ServiceWorkerRequestHandler::GetHandler(loader->request()); 1238 ServiceWorkerRequestHandler::GetHandler(loader_ptr->request());
1241 if (handler) { 1239 if (handler) {
1242 handler->CompleteCrossSiteTransfer( 1240 handler->CompleteCrossSiteTransfer(
1243 child_id, request_data.service_worker_provider_id); 1241 child_id, request_data.service_worker_provider_id);
1244 } 1242 }
1245 1243
1246 // We should have a CrossSiteResourceHandler to finish the transfer. 1244 // We should have a CrossSiteResourceHandler to finish the transfer.
1247 DCHECK(info->cross_site_handler()); 1245 DCHECK(info->cross_site_handler());
1248 } 1246 }
1249 1247
1250 void ResourceDispatcherHostImpl::BeginRequest( 1248 void ResourceDispatcherHostImpl::BeginRequest(
(...skipping 27 matching lines...) Expand all
1278 1276
1279 // If the request that's coming in is being transferred from another process, 1277 // If the request that's coming in is being transferred from another process,
1280 // we want to reuse and resume the old loader rather than start a new one. 1278 // we want to reuse and resume the old loader rather than start a new one.
1281 LoaderMap::iterator it = pending_loaders_.find( 1279 LoaderMap::iterator it = pending_loaders_.find(
1282 GlobalRequestID(request_data.transferred_request_child_id, 1280 GlobalRequestID(request_data.transferred_request_child_id,
1283 request_data.transferred_request_request_id)); 1281 request_data.transferred_request_request_id));
1284 if (it != pending_loaders_.end()) { 1282 if (it != pending_loaders_.end()) {
1285 // If the request is transferring to a new process, we can update our 1283 // If the request is transferring to a new process, we can update our
1286 // state and let it resume with its existing ResourceHandlers. 1284 // state and let it resume with its existing ResourceHandlers.
1287 if (it->second->is_transferring()) { 1285 if (it->second->is_transferring()) {
1288 linked_ptr<ResourceLoader> deferred_loader = it->second; 1286 ResourceLoader* deferred_loader = it->second.get();
1289 UpdateRequestForTransfer(child_id, route_id, request_id, 1287 UpdateRequestForTransfer(child_id, route_id, request_id,
1290 request_data, deferred_loader); 1288 request_data, it);
1291
1292 deferred_loader->CompleteTransfer(); 1289 deferred_loader->CompleteTransfer();
1293 } else { 1290 } else {
1294 bad_message::ReceivedBadMessage( 1291 bad_message::ReceivedBadMessage(
1295 filter_, bad_message::RDH_REQUEST_NOT_TRANSFERRING); 1292 filter_, bad_message::RDH_REQUEST_NOT_TRANSFERRING);
1296 } 1293 }
1297 return; 1294 return;
1298 } 1295 }
1299 1296
1300 ResourceContext* resource_context = NULL; 1297 ResourceContext* resource_context = NULL;
1301 net::URLRequestContext* request_context = NULL; 1298 net::URLRequestContext* request_context = NULL;
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after
1876 void ResourceDispatcherHostImpl::CancelRequestsForRoute(int child_id, 1873 void ResourceDispatcherHostImpl::CancelRequestsForRoute(int child_id,
1877 int route_id) { 1874 int route_id) {
1878 // Since pending_requests_ is a map, we first build up a list of all of the 1875 // Since pending_requests_ is a map, we first build up a list of all of the
1879 // matching requests to be cancelled, and then we cancel them. Since there 1876 // matching requests to be cancelled, and then we cancel them. Since there
1880 // may be more than one request to cancel, we cannot simply hold onto the map 1877 // may be more than one request to cancel, we cannot simply hold onto the map
1881 // iterators found in the first loop. 1878 // iterators found in the first loop.
1882 1879
1883 // Find the global ID of all matching elements. 1880 // Find the global ID of all matching elements.
1884 bool any_requests_transferring = false; 1881 bool any_requests_transferring = false;
1885 std::vector<GlobalRequestID> matching_requests; 1882 std::vector<GlobalRequestID> matching_requests;
1886 for (LoaderMap::const_iterator i = pending_loaders_.begin(); 1883 for (const auto& loader : pending_loaders_) {
1887 i != pending_loaders_.end(); ++i) { 1884 if (loader.first.child_id != child_id)
1888 if (i->first.child_id != child_id)
1889 continue; 1885 continue;
1890 1886
1891 ResourceRequestInfoImpl* info = i->second->GetRequestInfo(); 1887 ResourceRequestInfoImpl* info = loader.second->GetRequestInfo();
1892 1888
1893 GlobalRequestID id(child_id, i->first.request_id); 1889 GlobalRequestID id(child_id, loader.first.request_id);
1894 DCHECK(id == i->first); 1890 DCHECK(id == loader.first);
1895 // Don't cancel navigations that are expected to live beyond this process. 1891 // Don't cancel navigations that are expected to live beyond this process.
1896 if (IsTransferredNavigation(id)) 1892 if (IsTransferredNavigation(id))
1897 any_requests_transferring = true; 1893 any_requests_transferring = true;
1898 if (info->detachable_handler()) { 1894 if (info->detachable_handler()) {
1899 info->detachable_handler()->Detach(); 1895 info->detachable_handler()->Detach();
1900 } else if (!info->IsDownload() && !info->is_stream() && 1896 } else if (!info->IsDownload() && !info->is_stream() &&
1901 !IsTransferredNavigation(id) && 1897 !IsTransferredNavigation(id) &&
1902 (route_id == -1 || route_id == info->GetRouteID())) { 1898 (route_id == -1 || route_id == info->GetRouteID())) {
1903 matching_requests.push_back(id); 1899 matching_requests.push_back(id);
1904 } 1900 }
(...skipping 28 matching lines...) Expand all
1933 if (blocked_loaders_map_.find(GlobalRoutingID(child_id, route_id)) != 1929 if (blocked_loaders_map_.find(GlobalRoutingID(child_id, route_id)) !=
1934 blocked_loaders_map_.end()) { 1930 blocked_loaders_map_.end()) {
1935 CancelBlockedRequestsForRoute(child_id, route_id); 1931 CancelBlockedRequestsForRoute(child_id, route_id);
1936 } 1932 }
1937 } else { 1933 } else {
1938 // We have to do all render views for the process |child_id|. 1934 // We have to do all render views for the process |child_id|.
1939 // Note that we have to do this in 2 passes as we cannot call 1935 // Note that we have to do this in 2 passes as we cannot call
1940 // CancelBlockedRequestsForRoute while iterating over 1936 // CancelBlockedRequestsForRoute while iterating over
1941 // blocked_loaders_map_, as it modifies it. 1937 // blocked_loaders_map_, as it modifies it.
1942 std::set<int> route_ids; 1938 std::set<int> route_ids;
1943 for (BlockedLoadersMap::const_iterator iter = blocked_loaders_map_.begin(); 1939 for (const auto& blocked_loaders : blocked_loaders_map_) {
1944 iter != blocked_loaders_map_.end(); ++iter) { 1940 if (blocked_loaders.first.child_id == child_id)
1945 if (iter->first.child_id == child_id) 1941 route_ids.insert(blocked_loaders.first.route_id);
1946 route_ids.insert(iter->first.route_id);
1947 } 1942 }
1948 for (std::set<int>::const_iterator iter = route_ids.begin(); 1943 for (int route_id : route_ids) {
1949 iter != route_ids.end(); ++iter) { 1944 CancelBlockedRequestsForRoute(child_id, route_id);
1950 CancelBlockedRequestsForRoute(child_id, *iter);
1951 } 1945 }
1952 } 1946 }
1953 } 1947 }
1954 1948
1955 // Cancels the request and removes it from the list. 1949 // Cancels the request and removes it from the list.
1956 void ResourceDispatcherHostImpl::RemovePendingRequest(int child_id, 1950 void ResourceDispatcherHostImpl::RemovePendingRequest(int child_id,
1957 int request_id) { 1951 int request_id) {
1958 LoaderMap::iterator i = pending_loaders_.find( 1952 LoaderMap::iterator i = pending_loaders_.find(
1959 GlobalRequestID(child_id, request_id)); 1953 GlobalRequestID(child_id, request_id));
1960 if (i == pending_loaders_.end()) { 1954 if (i == pending_loaders_.end()) {
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
2284 NOTREACHED(); 2278 NOTREACHED();
2285 } 2279 }
2286 2280
2287 IncrementOutstandingRequestsMemory(-1, *info); 2281 IncrementOutstandingRequestsMemory(-1, *info);
2288 2282
2289 // A ResourceHandler must not outlive its associated URLRequest. 2283 // A ResourceHandler must not outlive its associated URLRequest.
2290 handler.reset(); 2284 handler.reset();
2291 return; 2285 return;
2292 } 2286 }
2293 2287
2294 linked_ptr<ResourceLoader> loader( 2288 scoped_ptr<ResourceLoader> loader(
2295 new ResourceLoader(std::move(request), std::move(handler), this)); 2289 new ResourceLoader(std::move(request), std::move(handler), this));
2296 2290
2297 GlobalRoutingID id(info->GetGlobalRoutingID()); 2291 GlobalRoutingID id(info->GetGlobalRoutingID());
2298 BlockedLoadersMap::const_iterator iter = blocked_loaders_map_.find(id); 2292 BlockedLoadersMap::const_iterator iter = blocked_loaders_map_.find(id);
2299 if (iter != blocked_loaders_map_.end()) { 2293 if (iter != blocked_loaders_map_.end()) {
2300 // The request should be blocked. 2294 // The request should be blocked.
2301 iter->second->push_back(loader); 2295 iter->second->push_back(std::move(loader));
2302 return; 2296 return;
2303 } 2297 }
2304 2298
2305 StartLoading(info, loader); 2299 StartLoading(info, std::move(loader));
2306 } 2300 }
2307 2301
2308 void ResourceDispatcherHostImpl::StartLoading( 2302 void ResourceDispatcherHostImpl::StartLoading(
2309 ResourceRequestInfoImpl* info, 2303 ResourceRequestInfoImpl* info,
2310 const linked_ptr<ResourceLoader>& loader) { 2304 scoped_ptr<ResourceLoader> loader) {
2311 // TODO(pkasting): Remove ScopedTracker below once crbug.com/456331 is fixed. 2305 // TODO(pkasting): Remove ScopedTracker below once crbug.com/456331 is fixed.
2312 tracked_objects::ScopedTracker tracking_profile( 2306 tracked_objects::ScopedTracker tracking_profile(
2313 FROM_HERE_WITH_EXPLICIT_FUNCTION( 2307 FROM_HERE_WITH_EXPLICIT_FUNCTION(
2314 "456331 ResourceDispatcherHostImpl::StartLoading")); 2308 "456331 ResourceDispatcherHostImpl::StartLoading"));
2315 pending_loaders_[info->GetGlobalRequestID()] = loader;
2316 2309
2317 loader->StartRequest(); 2310 ResourceLoader* loader_ptr = loader.get();
2311 pending_loaders_[info->GetGlobalRequestID()] = std::move(loader);
2312
2313 loader_ptr->StartRequest();
2318 } 2314 }
2319 2315
2320 void ResourceDispatcherHostImpl::OnUserGesture(WebContentsImpl* contents) { 2316 void ResourceDispatcherHostImpl::OnUserGesture(WebContentsImpl* contents) {
2321 last_user_gesture_time_ = TimeTicks::Now(); 2317 last_user_gesture_time_ = TimeTicks::Now();
2322 } 2318 }
2323 2319
2324 net::URLRequest* ResourceDispatcherHostImpl::GetURLRequest( 2320 net::URLRequest* ResourceDispatcherHostImpl::GetURLRequest(
2325 const GlobalRequestID& id) { 2321 const GlobalRequestID& id) {
2326 ResourceLoader* loader = GetLoader(id); 2322 ResourceLoader* loader = GetLoader(id);
2327 if (!loader) 2323 if (!loader)
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
2415 base::Bind(&ResourceDispatcherHostImpl::UpdateLoadInfoOnUIThread, 2411 base::Bind(&ResourceDispatcherHostImpl::UpdateLoadInfoOnUIThread,
2416 base::Passed(&info_map))); 2412 base::Passed(&info_map)));
2417 } 2413 }
2418 2414
2419 void ResourceDispatcherHostImpl::BlockRequestsForRoute(int child_id, 2415 void ResourceDispatcherHostImpl::BlockRequestsForRoute(int child_id,
2420 int route_id) { 2416 int route_id) {
2421 DCHECK_CURRENTLY_ON(BrowserThread::IO); 2417 DCHECK_CURRENTLY_ON(BrowserThread::IO);
2422 GlobalRoutingID key(child_id, route_id); 2418 GlobalRoutingID key(child_id, route_id);
2423 DCHECK(blocked_loaders_map_.find(key) == blocked_loaders_map_.end()) << 2419 DCHECK(blocked_loaders_map_.find(key) == blocked_loaders_map_.end()) <<
2424 "BlockRequestsForRoute called multiple time for the same RVH"; 2420 "BlockRequestsForRoute called multiple time for the same RVH";
2425 blocked_loaders_map_[key] = new BlockedLoadersList(); 2421 blocked_loaders_map_[key] = make_scoped_ptr(new BlockedLoadersList());
2426 } 2422 }
2427 2423
2428 void ResourceDispatcherHostImpl::ResumeBlockedRequestsForRoute(int child_id, 2424 void ResourceDispatcherHostImpl::ResumeBlockedRequestsForRoute(int child_id,
2429 int route_id) { 2425 int route_id) {
2430 ProcessBlockedRequestsForRoute(child_id, route_id, false); 2426 ProcessBlockedRequestsForRoute(child_id, route_id, false);
2431 } 2427 }
2432 2428
2433 void ResourceDispatcherHostImpl::CancelBlockedRequestsForRoute(int child_id, 2429 void ResourceDispatcherHostImpl::CancelBlockedRequestsForRoute(int child_id,
2434 int route_id) { 2430 int route_id) {
2435 ProcessBlockedRequestsForRoute(child_id, route_id, true); 2431 ProcessBlockedRequestsForRoute(child_id, route_id, true);
2436 } 2432 }
2437 2433
2438 void ResourceDispatcherHostImpl::ProcessBlockedRequestsForRoute( 2434 void ResourceDispatcherHostImpl::ProcessBlockedRequestsForRoute(
2439 int child_id, 2435 int child_id,
2440 int route_id, 2436 int route_id,
2441 bool cancel_requests) { 2437 bool cancel_requests) {
2442 BlockedLoadersMap::iterator iter = blocked_loaders_map_.find( 2438 BlockedLoadersMap::iterator iter = blocked_loaders_map_.find(
2443 GlobalRoutingID(child_id, route_id)); 2439 GlobalRoutingID(child_id, route_id));
2444 if (iter == blocked_loaders_map_.end()) { 2440 if (iter == blocked_loaders_map_.end()) {
2445 // It's possible to reach here if the renderer crashed while an interstitial 2441 // It's possible to reach here if the renderer crashed while an interstitial
2446 // page was showing. 2442 // page was showing.
2447 return; 2443 return;
2448 } 2444 }
2449 2445
2450 BlockedLoadersList* loaders = iter->second; 2446 BlockedLoadersList* loaders = iter->second.get();
2447 scoped_ptr<BlockedLoadersList> deleter(std::move(iter->second));
2451 2448
2452 // Removing the vector from the map unblocks any subsequent requests. 2449 // Removing the vector from the map unblocks any subsequent requests.
2453 blocked_loaders_map_.erase(iter); 2450 blocked_loaders_map_.erase(iter);
2454 2451
2455 for (BlockedLoadersList::iterator loaders_iter = loaders->begin(); 2452 for (scoped_ptr<ResourceLoader>& loader : *loaders) {
2456 loaders_iter != loaders->end(); ++loaders_iter) {
2457 linked_ptr<ResourceLoader> loader = *loaders_iter;
2458 ResourceRequestInfoImpl* info = loader->GetRequestInfo(); 2453 ResourceRequestInfoImpl* info = loader->GetRequestInfo();
2459 if (cancel_requests) { 2454 if (cancel_requests) {
2460 IncrementOutstandingRequestsMemory(-1, *info); 2455 IncrementOutstandingRequestsMemory(-1, *info);
2461 } else { 2456 } else {
2462 StartLoading(info, loader); 2457 StartLoading(info, std::move(loader));
2463 } 2458 }
2464 } 2459 }
2465
2466 delete loaders;
2467 } 2460 }
2468 2461
2469 ResourceDispatcherHostImpl::HttpAuthRelationType 2462 ResourceDispatcherHostImpl::HttpAuthRelationType
2470 ResourceDispatcherHostImpl::HttpAuthRelationTypeOf( 2463 ResourceDispatcherHostImpl::HttpAuthRelationTypeOf(
2471 const GURL& request_url, 2464 const GURL& request_url,
2472 const GURL& first_party) { 2465 const GURL& first_party) {
2473 if (!first_party.is_valid()) 2466 if (!first_party.is_valid())
2474 return HTTP_AUTH_RELATION_TOP; 2467 return HTTP_AUTH_RELATION_TOP;
2475 2468
2476 if (net::registry_controlled_domains::SameDomainOrHost( 2469 if (net::registry_controlled_domains::SameDomainOrHost(
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
2552 load_flags |= net::LOAD_PREFETCH; 2545 load_flags |= net::LOAD_PREFETCH;
2553 } 2546 }
2554 2547
2555 if (is_sync_load) 2548 if (is_sync_load)
2556 load_flags |= net::LOAD_IGNORE_LIMITS; 2549 load_flags |= net::LOAD_IGNORE_LIMITS;
2557 2550
2558 return load_flags; 2551 return load_flags;
2559 } 2552 }
2560 2553
2561 } // namespace content 2554 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/loader/resource_dispatcher_host_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698