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

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

Issue 12886022: Implement offline mode behind a flag (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Setup OfflinePolicy for all started requests. Created 7 years, 8 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 | Annotate | Revision Log
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 <set> 9 #include <set>
10 #include <vector> 10 #include <vector>
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 net::Error net_error) { 224 net::Error net_error) {
225 if (started_cb.is_null()) 225 if (started_cb.is_null())
226 return net_error; 226 return net_error;
227 BrowserThread::PostTask( 227 BrowserThread::PostTask(
228 BrowserThread::UI, FROM_HERE, 228 BrowserThread::UI, FROM_HERE,
229 base::Bind(started_cb, static_cast<DownloadItem*>(NULL), net_error)); 229 base::Bind(started_cb, static_cast<DownloadItem*>(NULL), net_error));
230 230
231 return net_error; 231 return net_error;
232 } 232 }
233 233
234 int BuildLoadFlagsForRequest(const ResourceHostMsg_Request& request_data, 234 int BuildLoadFlagsForRequest(
235 int child_id, bool is_sync_load) { 235 const ResourceHostMsg_Request& request_data,
236 int child_id,
237 bool is_sync_load) {
236 int load_flags = request_data.load_flags; 238 int load_flags = request_data.load_flags;
237 239
238 // Although EV status is irrelevant to sub-frames and sub-resources, we have 240 // Although EV status is irrelevant to sub-frames and sub-resources, we have
239 // to perform EV certificate verification on all resources because an HTTP 241 // to perform EV certificate verification on all resources because an HTTP
240 // keep-alive connection created to load a sub-frame or a sub-resource could 242 // keep-alive connection created to load a sub-frame or a sub-resource could
241 // be reused to load a main frame. 243 // be reused to load a main frame.
242 load_flags |= net::LOAD_VERIFY_EV_CERT; 244 load_flags |= net::LOAD_VERIFY_EV_CERT;
243 if (request_data.resource_type == ResourceType::MAIN_FRAME) { 245 if (request_data.resource_type == ResourceType::MAIN_FRAME) {
244 load_flags |= net::LOAD_MAIN_FRAME; 246 load_flags |= net::LOAD_MAIN_FRAME;
245 } else if (request_data.resource_type == ResourceType::SUB_FRAME) { 247 } else if (request_data.resource_type == ResourceType::SUB_FRAME) {
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 // re-post. For GETs, try to retrieve data from the cache and skip 475 // re-post. For GETs, try to retrieve data from the cache and skip
474 // validating the entry if present. 476 // validating the entry if present.
475 if (request->get_upload() != NULL) 477 if (request->get_upload() != NULL)
476 extra_load_flags |= net::LOAD_ONLY_FROM_CACHE; 478 extra_load_flags |= net::LOAD_ONLY_FROM_CACHE;
477 else 479 else
478 extra_load_flags |= net::LOAD_PREFERRING_CACHE; 480 extra_load_flags |= net::LOAD_PREFERRING_CACHE;
479 } else { 481 } else {
480 extra_load_flags |= net::LOAD_DISABLE_CACHE; 482 extra_load_flags |= net::LOAD_DISABLE_CACHE;
481 } 483 }
482 request->set_load_flags(request->load_flags() | extra_load_flags); 484 request->set_load_flags(request->load_flags() | extra_load_flags);
485
486 // No need to get offline load flags for downloads, but make sure
487 // we have an OfflinePolicy to receive request completions.
488 GlobalRoutingID id(child_id, route_id);
489 if (!offline_policy_map_[id])
490 offline_policy_map_[id] = new OfflinePolicy();
491
483 // Check if the renderer is permitted to request the requested URL. 492 // Check if the renderer is permitted to request the requested URL.
484 if (!ChildProcessSecurityPolicyImpl::GetInstance()-> 493 if (!ChildProcessSecurityPolicyImpl::GetInstance()->
485 CanRequestURL(child_id, url)) { 494 CanRequestURL(child_id, url)) {
486 VLOG(1) << "Denied unauthorized download request for " 495 VLOG(1) << "Denied unauthorized download request for "
487 << url.possibly_invalid_spec(); 496 << url.possibly_invalid_spec();
488 return CallbackAndReturn(started_callback, net::ERR_ACCESS_DENIED); 497 return CallbackAndReturn(started_callback, net::ERR_ACCESS_DENIED);
489 } 498 }
490 499
491 request_id_--; 500 request_id_--;
492 501
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 BrowserThread::PostTask( 704 BrowserThread::PostTask(
696 BrowserThread::UI, FROM_HERE, 705 BrowserThread::UI, FROM_HERE,
697 base::Bind( 706 base::Bind(
698 &NotifyOnUI<ResourceRedirectDetails>, 707 &NotifyOnUI<ResourceRedirectDetails>,
699 static_cast<int>(NOTIFICATION_RESOURCE_RECEIVED_REDIRECT), 708 static_cast<int>(NOTIFICATION_RESOURCE_RECEIVED_REDIRECT),
700 render_process_id, render_view_id, base::Passed(&detail))); 709 render_process_id, render_view_id, base::Passed(&detail)));
701 } 710 }
702 711
703 void ResourceDispatcherHostImpl::DidReceiveResponse(ResourceLoader* loader) { 712 void ResourceDispatcherHostImpl::DidReceiveResponse(ResourceLoader* loader) {
704 ResourceRequestInfoImpl* info = loader->GetRequestInfo(); 713 ResourceRequestInfoImpl* info = loader->GetRequestInfo();
714 // There should be an entry in the map created when we dispatched the
715 // request.
716 GlobalRoutingID routing_id(info->GetGlobalRoutingID());
717 DCHECK(offline_policy_map_.end() != offline_policy_map_.find(routing_id));
718 offline_policy_map_[routing_id]->
719 UpdateStateForCompletedRequest(loader->request()->response_info());
705 720
706 int render_process_id, render_view_id; 721 int render_process_id, render_view_id;
707 if (!info->GetAssociatedRenderView(&render_process_id, &render_view_id)) 722 if (!info->GetAssociatedRenderView(&render_process_id, &render_view_id))
708 return; 723 return;
709 724
710 // Notify the observers on the UI thread. 725 // Notify the observers on the UI thread.
711 scoped_ptr<ResourceRequestDetails> detail(new ResourceRequestDetails( 726 scoped_ptr<ResourceRequestDetails> detail(new ResourceRequestDetails(
712 loader->request(), 727 loader->request(),
713 GetCertID(loader->request(), info->GetChildID()))); 728 GetCertID(loader->request(), info->GetChildID())));
714 BrowserThread::PostTask( 729 BrowserThread::PostTask(
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 797
783 // Make sure we shutdown the timer now, otherwise by the time our destructor 798 // Make sure we shutdown the timer now, otherwise by the time our destructor
784 // runs if the timer is still running the Task is deleted twice (once by 799 // runs if the timer is still running the Task is deleted twice (once by
785 // the MessageLoop and the second time by RepeatingTimer). 800 // the MessageLoop and the second time by RepeatingTimer).
786 update_load_states_timer_.reset(); 801 update_load_states_timer_.reset();
787 802
788 // Clear blocked requests if any left. 803 // Clear blocked requests if any left.
789 // Note that we have to do this in 2 passes as we cannot call 804 // Note that we have to do this in 2 passes as we cannot call
790 // CancelBlockedRequestsForRoute while iterating over 805 // CancelBlockedRequestsForRoute while iterating over
791 // blocked_loaders_map_, as it modifies it. 806 // blocked_loaders_map_, as it modifies it.
792 std::set<ProcessRouteIDs> ids; 807 std::set<GlobalRoutingID> ids;
793 for (BlockedLoadersMap::const_iterator iter = blocked_loaders_map_.begin(); 808 for (BlockedLoadersMap::const_iterator iter = blocked_loaders_map_.begin();
794 iter != blocked_loaders_map_.end(); ++iter) { 809 iter != blocked_loaders_map_.end(); ++iter) {
795 std::pair<std::set<ProcessRouteIDs>::iterator, bool> result = 810 std::pair<std::set<GlobalRoutingID>::iterator, bool> result =
796 ids.insert(iter->first); 811 ids.insert(iter->first);
797 // We should not have duplicates. 812 // We should not have duplicates.
798 DCHECK(result.second); 813 DCHECK(result.second);
799 } 814 }
800 for (std::set<ProcessRouteIDs>::const_iterator iter = ids.begin(); 815 for (std::set<GlobalRoutingID>::const_iterator iter = ids.begin();
801 iter != ids.end(); ++iter) { 816 iter != ids.end(); ++iter) {
802 CancelBlockedRequestsForRoute(iter->first, iter->second); 817 CancelBlockedRequestsForRoute(iter->child_id, iter->route_id);
803 } 818 }
804 819
805 scheduler_.reset(); 820 scheduler_.reset();
806 } 821 }
807 822
808 bool ResourceDispatcherHostImpl::OnMessageReceived( 823 bool ResourceDispatcherHostImpl::OnMessageReceived(
809 const IPC::Message& message, 824 const IPC::Message& message,
810 ResourceMessageFilter* filter, 825 ResourceMessageFilter* filter,
811 bool* message_was_ok) { 826 bool* message_was_ok) {
812 filter_ = filter; 827 filter_ = filter;
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
929 resource_context, 944 resource_context,
930 referrer)) { 945 referrer)) {
931 AbortRequestBeforeItStarts(filter_, sync_result, route_id, request_id); 946 AbortRequestBeforeItStarts(filter_, sync_result, route_id, request_id);
932 return; 947 return;
933 } 948 }
934 949
935 bool is_sync_load = sync_result != NULL; 950 bool is_sync_load = sync_result != NULL;
936 int load_flags = 951 int load_flags =
937 BuildLoadFlagsForRequest(request_data, child_id, is_sync_load); 952 BuildLoadFlagsForRequest(request_data, child_id, is_sync_load);
938 953
954 GlobalRoutingID id(child_id, route_id);
955 if (!offline_policy_map_[id])
956 offline_policy_map_[id] = new OfflinePolicy();
957 load_flags |= offline_policy_map_[id]->GetAdditionalLoadFlags(
958 load_flags, request_data.resource_type == ResourceType::MAIN_FRAME);
959
939 // Construct the request. 960 // Construct the request.
940 scoped_ptr<net::URLRequest> new_request; 961 scoped_ptr<net::URLRequest> new_request;
941 net::URLRequest* request; 962 net::URLRequest* request;
942 if (deferred_loader.get()) { 963 if (deferred_loader.get()) {
943 request = deferred_loader->request(); 964 request = deferred_loader->request();
944 965
945 // Give the ResourceLoader (or any of the ResourceHandlers held by it) a 966 // Give the ResourceLoader (or any of the ResourceHandlers held by it) a
946 // chance to reset some state before we complete the transfer. 967 // chance to reset some state before we complete the transfer.
947 deferred_loader->WillCompleteTransfer(); 968 deferred_loader->WillCompleteTransfer();
948 } else { 969 } else {
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
1269 scoped_ptr<net::URLRequest> request( 1290 scoped_ptr<net::URLRequest> request(
1270 request_context->CreateRequest(url, NULL)); 1291 request_context->CreateRequest(url, NULL));
1271 request->set_method("GET"); 1292 request->set_method("GET");
1272 request->SetReferrer(MaybeStripReferrer(referrer.url).spec()); 1293 request->SetReferrer(MaybeStripReferrer(referrer.url).spec());
1273 webkit_glue::ConfigureURLRequestForReferrerPolicy(request.get(), 1294 webkit_glue::ConfigureURLRequestForReferrerPolicy(request.get(),
1274 referrer.policy); 1295 referrer.policy);
1275 // So far, for saving page, we need fetch content from cache, in the 1296 // So far, for saving page, we need fetch content from cache, in the
1276 // future, maybe we can use a configuration to configure this behavior. 1297 // future, maybe we can use a configuration to configure this behavior.
1277 request->set_load_flags(net::LOAD_PREFERRING_CACHE); 1298 request->set_load_flags(net::LOAD_PREFERRING_CACHE);
1278 1299
1300 // No need to get offline load flags for save files, but make sure
1301 // we have an OfflinePolicy to receive request completions.
1302 GlobalRoutingID id(child_id, route_id);
1303 if (!offline_policy_map_[id])
1304 offline_policy_map_[id] = new OfflinePolicy();
1305
1279 // Since we're just saving some resources we need, disallow downloading. 1306 // Since we're just saving some resources we need, disallow downloading.
1280 ResourceRequestInfoImpl* extra_info = 1307 ResourceRequestInfoImpl* extra_info =
1281 CreateRequestInfo(child_id, route_id, false, context); 1308 CreateRequestInfo(child_id, route_id, false, context);
1282 extra_info->AssociateWithRequest(request.get()); // Request takes ownership. 1309 extra_info->AssociateWithRequest(request.get()); // Request takes ownership.
1283 1310
1284 BeginRequestInternal(request.Pass(), handler.Pass()); 1311 BeginRequestInternal(request.Pass(), handler.Pass());
1285 } 1312 }
1286 1313
1287 void ResourceDispatcherHostImpl::MarkAsTransferredNavigation( 1314 void ResourceDispatcherHostImpl::MarkAsTransferredNavigation(
1288 const GlobalRequestID& id) { 1315 const GlobalRequestID& id) {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1344 // net::URLRequest that needs exclusive access to the same cache entry, and 1371 // net::URLRequest that needs exclusive access to the same cache entry, and
1345 // that net::URLRequest may complete and remove itself from 1372 // that net::URLRequest may complete and remove itself from
1346 // pending_requests_. So we need to check that iter is not equal to 1373 // pending_requests_. So we need to check that iter is not equal to
1347 // pending_requests_.end(). 1374 // pending_requests_.end().
1348 if (iter != pending_loaders_.end()) 1375 if (iter != pending_loaders_.end())
1349 RemovePendingLoader(iter); 1376 RemovePendingLoader(iter);
1350 } 1377 }
1351 1378
1352 // Now deal with blocked requests if any. 1379 // Now deal with blocked requests if any.
1353 if (route_id != -1) { 1380 if (route_id != -1) {
1354 if (blocked_loaders_map_.find(ProcessRouteIDs(child_id, route_id)) != 1381 if (blocked_loaders_map_.find(GlobalRoutingID(child_id, route_id)) !=
1355 blocked_loaders_map_.end()) { 1382 blocked_loaders_map_.end()) {
1356 CancelBlockedRequestsForRoute(child_id, route_id); 1383 CancelBlockedRequestsForRoute(child_id, route_id);
1357 } 1384 }
1358 } else { 1385 } else {
1359 // We have to do all render views for the process |child_id|. 1386 // We have to do all render views for the process |child_id|.
1360 // Note that we have to do this in 2 passes as we cannot call 1387 // Note that we have to do this in 2 passes as we cannot call
1361 // CancelBlockedRequestsForRoute while iterating over 1388 // CancelBlockedRequestsForRoute while iterating over
1362 // blocked_loaders_map_, as it modifies it. 1389 // blocked_loaders_map_, as it modifies it.
1363 std::set<int> route_ids; 1390 std::set<int> route_ids;
1364 for (BlockedLoadersMap::const_iterator iter = blocked_loaders_map_.begin(); 1391 for (BlockedLoadersMap::const_iterator iter = blocked_loaders_map_.begin();
1365 iter != blocked_loaders_map_.end(); ++iter) { 1392 iter != blocked_loaders_map_.end(); ++iter) {
1366 if (iter->first.first == child_id) 1393 if (iter->first.child_id == child_id)
1367 route_ids.insert(iter->first.second); 1394 route_ids.insert(iter->first.route_id);
1368 } 1395 }
1369 for (std::set<int>::const_iterator iter = route_ids.begin(); 1396 for (std::set<int>::const_iterator iter = route_ids.begin();
1370 iter != route_ids.end(); ++iter) { 1397 iter != route_ids.end(); ++iter) {
1371 CancelBlockedRequestsForRoute(child_id, *iter); 1398 CancelBlockedRequestsForRoute(child_id, *iter);
1372 } 1399 }
1373 } 1400 }
1401
1402 // Cleanup the offline state for the route.
1403 OfflineMap::iterator it = offline_policy_map_.find(
1404 GlobalRoutingID(child_id, route_id));
1405 if (offline_policy_map_.end() != it) {
1406 delete it->second;
1407 offline_policy_map_.erase(it);
1408 }
1374 } 1409 }
1375 1410
1376 // Cancels the request and removes it from the list. 1411 // Cancels the request and removes it from the list.
1377 void ResourceDispatcherHostImpl::RemovePendingRequest(int child_id, 1412 void ResourceDispatcherHostImpl::RemovePendingRequest(int child_id,
1378 int request_id) { 1413 int request_id) {
1379 LoaderMap::iterator i = pending_loaders_.find( 1414 LoaderMap::iterator i = pending_loaders_.find(
1380 GlobalRequestID(child_id, request_id)); 1415 GlobalRequestID(child_id, request_id));
1381 if (i == pending_loaders_.end()) { 1416 if (i == pending_loaders_.end()) {
1382 NOTREACHED() << "Trying to remove a request that's not here"; 1417 NOTREACHED() << "Trying to remove a request that's not here";
1383 return; 1418 return;
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
1495 info->GetChildID()); 1530 info->GetChildID());
1496 1531
1497 // A ResourceHandler must not outlive its associated URLRequest. 1532 // A ResourceHandler must not outlive its associated URLRequest.
1498 handler.reset(); 1533 handler.reset();
1499 return; 1534 return;
1500 } 1535 }
1501 1536
1502 linked_ptr<ResourceLoader> loader( 1537 linked_ptr<ResourceLoader> loader(
1503 new ResourceLoader(request.Pass(), handler.Pass(), this)); 1538 new ResourceLoader(request.Pass(), handler.Pass(), this));
1504 1539
1505 ProcessRouteIDs pair_id(info->GetChildID(), info->GetRouteID()); 1540 GlobalRoutingID id(info->GetGlobalRoutingID());
1506 BlockedLoadersMap::const_iterator iter = blocked_loaders_map_.find(pair_id); 1541 BlockedLoadersMap::const_iterator iter = blocked_loaders_map_.find(id);
1507 if (iter != blocked_loaders_map_.end()) { 1542 if (iter != blocked_loaders_map_.end()) {
1508 // The request should be blocked. 1543 // The request should be blocked.
1509 iter->second->push_back(loader); 1544 iter->second->push_back(loader);
1510 return; 1545 return;
1511 } 1546 }
1512 1547
1513 StartLoading(info, loader); 1548 StartLoading(info, loader);
1514 } 1549 }
1515 1550
1516 void ResourceDispatcherHostImpl::StartLoading( 1551 void ResourceDispatcherHostImpl::StartLoading(
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1558 } 1593 }
1559 1594
1560 // Carries information about a load state change. 1595 // Carries information about a load state change.
1561 struct LoadInfo { 1596 struct LoadInfo {
1562 GURL url; 1597 GURL url;
1563 net::LoadStateWithParam load_state; 1598 net::LoadStateWithParam load_state;
1564 uint64 upload_position; 1599 uint64 upload_position;
1565 uint64 upload_size; 1600 uint64 upload_size;
1566 }; 1601 };
1567 1602
1568 // Map from ProcessID+ViewID pair to LoadState 1603 // Map from ProcessID+RouteID pair to LoadState
1569 typedef std::map<std::pair<int, int>, LoadInfo> LoadInfoMap; 1604 typedef std::map<GlobalRoutingID, LoadInfo> LoadInfoMap;
1570 1605
1571 // Used to marshal calls to LoadStateChanged from the IO to UI threads. We do 1606 // Used to marshal calls to LoadStateChanged from the IO to UI threads. We do
1572 // them all as a single callback to avoid spamming the UI thread. 1607 // them all as a single callback to avoid spamming the UI thread.
1573 void LoadInfoUpdateCallback(const LoadInfoMap& info_map) { 1608 void LoadInfoUpdateCallback(const LoadInfoMap& info_map) {
1574 LoadInfoMap::const_iterator i; 1609 LoadInfoMap::const_iterator i;
1575 for (i = info_map.begin(); i != info_map.end(); ++i) { 1610 for (i = info_map.begin(); i != info_map.end(); ++i) {
1576 RenderViewHostImpl* view = 1611 RenderViewHostImpl* view =
1577 RenderViewHostImpl::FromID(i->first.first, i->first.second); 1612 RenderViewHostImpl::FromID(i->first.child_id, i->first.route_id);
1578 if (view) // The view could be gone at this point. 1613 if (view) // The view could be gone at this point.
1579 view->LoadStateChanged(i->second.url, i->second.load_state, 1614 view->LoadStateChanged(i->second.url, i->second.load_state,
1580 i->second.upload_position, 1615 i->second.upload_position,
1581 i->second.upload_size); 1616 i->second.upload_size);
1582 } 1617 }
1583 } 1618 }
1584 1619
1585 } // namespace 1620 } // namespace
1586 1621
1587 void ResourceDispatcherHostImpl::UpdateLoadStates() { 1622 void ResourceDispatcherHostImpl::UpdateLoadStates() {
1588 // Populate this map with load state changes, and then send them on to the UI 1623 // Populate this map with load state changes, and then send them on to the UI
1589 // thread where they can be passed along to the respective RVHs. 1624 // thread where they can be passed along to the respective RVHs.
1590 LoadInfoMap info_map; 1625 LoadInfoMap info_map;
1591 1626
1592 LoaderMap::const_iterator i; 1627 LoaderMap::const_iterator i;
1593 1628
1594 // Determine the largest upload size of all requests 1629 // Determine the largest upload size of all requests
1595 // in each View (good chance it's zero). 1630 // in each View (good chance it's zero).
1596 std::map<std::pair<int, int>, uint64> largest_upload_size; 1631 std::map<GlobalRoutingID, uint64> largest_upload_size;
1597 for (i = pending_loaders_.begin(); i != pending_loaders_.end(); ++i) { 1632 for (i = pending_loaders_.begin(); i != pending_loaders_.end(); ++i) {
1598 net::URLRequest* request = i->second->request(); 1633 net::URLRequest* request = i->second->request();
1599 ResourceRequestInfoImpl* info = i->second->GetRequestInfo(); 1634 ResourceRequestInfoImpl* info = i->second->GetRequestInfo();
1600 uint64 upload_size = request->GetUploadProgress().size(); 1635 uint64 upload_size = request->GetUploadProgress().size();
1601 if (request->GetLoadState().state != net::LOAD_STATE_SENDING_REQUEST) 1636 if (request->GetLoadState().state != net::LOAD_STATE_SENDING_REQUEST)
1602 upload_size = 0; 1637 upload_size = 0;
1603 std::pair<int, int> key(info->GetChildID(), info->GetRouteID()); 1638 GlobalRoutingID id(info->GetGlobalRoutingID());
1604 if (upload_size && largest_upload_size[key] < upload_size) 1639 if (upload_size && largest_upload_size[id] < upload_size)
1605 largest_upload_size[key] = upload_size; 1640 largest_upload_size[id] = upload_size;
1606 } 1641 }
1607 1642
1608 for (i = pending_loaders_.begin(); i != pending_loaders_.end(); ++i) { 1643 for (i = pending_loaders_.begin(); i != pending_loaders_.end(); ++i) {
1609 net::URLRequest* request = i->second->request(); 1644 net::URLRequest* request = i->second->request();
1610 ResourceRequestInfoImpl* info = i->second->GetRequestInfo(); 1645 ResourceRequestInfoImpl* info = i->second->GetRequestInfo();
1611 net::LoadStateWithParam load_state = request->GetLoadState(); 1646 net::LoadStateWithParam load_state = request->GetLoadState();
1612 net::UploadProgress progress = request->GetUploadProgress(); 1647 net::UploadProgress progress = request->GetUploadProgress();
1613 1648
1614 // We also poll for upload progress on this timer and send upload 1649 // We also poll for upload progress on this timer and send upload
1615 // progress ipc messages to the plugin process. 1650 // progress ipc messages to the plugin process.
1616 i->second->ReportUploadProgress(); 1651 i->second->ReportUploadProgress();
1617 1652
1618 std::pair<int, int> key(info->GetChildID(), info->GetRouteID()); 1653 GlobalRoutingID id(info->GetGlobalRoutingID());
1619 1654
1620 // If a request is uploading data, ignore all other requests so that the 1655 // If a request is uploading data, ignore all other requests so that the
1621 // upload progress takes priority for being shown in the status bar. 1656 // upload progress takes priority for being shown in the status bar.
1622 if (largest_upload_size.find(key) != largest_upload_size.end() && 1657 if (largest_upload_size.find(id) != largest_upload_size.end() &&
1623 progress.size() < largest_upload_size[key]) 1658 progress.size() < largest_upload_size[id])
1624 continue; 1659 continue;
1625 1660
1626 net::LoadStateWithParam to_insert = load_state; 1661 net::LoadStateWithParam to_insert = load_state;
1627 LoadInfoMap::iterator existing = info_map.find(key); 1662 LoadInfoMap::iterator existing = info_map.find(id);
1628 if (existing != info_map.end()) { 1663 if (existing != info_map.end()) {
1629 to_insert = 1664 to_insert =
1630 MoreInterestingLoadState(existing->second.load_state, load_state); 1665 MoreInterestingLoadState(existing->second.load_state, load_state);
1631 if (to_insert.state == existing->second.load_state.state) 1666 if (to_insert.state == existing->second.load_state.state)
1632 continue; 1667 continue;
1633 } 1668 }
1634 LoadInfo& load_info = info_map[key]; 1669 LoadInfo& load_info = info_map[id];
1635 load_info.url = request->url(); 1670 load_info.url = request->url();
1636 load_info.load_state = to_insert; 1671 load_info.load_state = to_insert;
1637 load_info.upload_size = progress.size(); 1672 load_info.upload_size = progress.size();
1638 load_info.upload_position = progress.position(); 1673 load_info.upload_position = progress.position();
1639 } 1674 }
1640 1675
1641 if (info_map.empty()) 1676 if (info_map.empty())
1642 return; 1677 return;
1643 1678
1644 BrowserThread::PostTask( 1679 BrowserThread::PostTask(
1645 BrowserThread::UI, FROM_HERE, 1680 BrowserThread::UI, FROM_HERE,
1646 base::Bind(&LoadInfoUpdateCallback, info_map)); 1681 base::Bind(&LoadInfoUpdateCallback, info_map));
1647 } 1682 }
1648 1683
1649 void ResourceDispatcherHostImpl::BlockRequestsForRoute(int child_id, 1684 void ResourceDispatcherHostImpl::BlockRequestsForRoute(int child_id,
1650 int route_id) { 1685 int route_id) {
1651 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 1686 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
1652 ProcessRouteIDs key(child_id, route_id); 1687 GlobalRoutingID key(child_id, route_id);
1653 DCHECK(blocked_loaders_map_.find(key) == blocked_loaders_map_.end()) << 1688 DCHECK(blocked_loaders_map_.find(key) == blocked_loaders_map_.end()) <<
1654 "BlockRequestsForRoute called multiple time for the same RVH"; 1689 "BlockRequestsForRoute called multiple time for the same RVH";
1655 blocked_loaders_map_[key] = new BlockedLoadersList(); 1690 blocked_loaders_map_[key] = new BlockedLoadersList();
1656 } 1691 }
1657 1692
1658 void ResourceDispatcherHostImpl::ResumeBlockedRequestsForRoute(int child_id, 1693 void ResourceDispatcherHostImpl::ResumeBlockedRequestsForRoute(int child_id,
1659 int route_id) { 1694 int route_id) {
1660 ProcessBlockedRequestsForRoute(child_id, route_id, false); 1695 ProcessBlockedRequestsForRoute(child_id, route_id, false);
1661 } 1696 }
1662 1697
1663 void ResourceDispatcherHostImpl::CancelBlockedRequestsForRoute(int child_id, 1698 void ResourceDispatcherHostImpl::CancelBlockedRequestsForRoute(int child_id,
1664 int route_id) { 1699 int route_id) {
1665 ProcessBlockedRequestsForRoute(child_id, route_id, true); 1700 ProcessBlockedRequestsForRoute(child_id, route_id, true);
1666 } 1701 }
1667 1702
1668 void ResourceDispatcherHostImpl::ProcessBlockedRequestsForRoute( 1703 void ResourceDispatcherHostImpl::ProcessBlockedRequestsForRoute(
1669 int child_id, 1704 int child_id,
1670 int route_id, 1705 int route_id,
1671 bool cancel_requests) { 1706 bool cancel_requests) {
1672 BlockedLoadersMap::iterator iter = blocked_loaders_map_.find( 1707 BlockedLoadersMap::iterator iter = blocked_loaders_map_.find(
1673 std::pair<int, int>(child_id, route_id)); 1708 GlobalRoutingID(child_id, route_id));
1674 if (iter == blocked_loaders_map_.end()) { 1709 if (iter == blocked_loaders_map_.end()) {
1675 // It's possible to reach here if the renderer crashed while an interstitial 1710 // It's possible to reach here if the renderer crashed while an interstitial
1676 // page was showing. 1711 // page was showing.
1677 return; 1712 return;
1678 } 1713 }
1679 1714
1680 BlockedLoadersList* loaders = iter->second; 1715 BlockedLoadersList* loaders = iter->second;
1681 1716
1682 // Removing the vector from the map unblocks any subsequent requests. 1717 // Removing the vector from the map unblocks any subsequent requests.
1683 blocked_loaders_map_.erase(iter); 1718 blocked_loaders_map_.erase(iter);
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1756 DelegateMap::iterator it = delegate_map_.find(id); 1791 DelegateMap::iterator it = delegate_map_.find(id);
1757 DCHECK(it->second->HasObserver(delegate)); 1792 DCHECK(it->second->HasObserver(delegate));
1758 it->second->RemoveObserver(delegate); 1793 it->second->RemoveObserver(delegate);
1759 if (it->second->size() == 0) { 1794 if (it->second->size() == 0) {
1760 delete it->second; 1795 delete it->second;
1761 delegate_map_.erase(it); 1796 delegate_map_.erase(it);
1762 } 1797 }
1763 } 1798 }
1764 1799
1765 } // namespace content 1800 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/loader/resource_dispatcher_host_impl.h ('k') | content/browser/loader/resource_request_info_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698