| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc
e-loading | 5 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc
e-loading |
| 6 | 6 |
| 7 #include "content/browser/loader/resource_dispatcher_host_impl.h" | 7 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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, int child_id, |
| 236 bool is_sync_load) { |
| 236 int load_flags = request_data.load_flags; | 237 int load_flags = request_data.load_flags; |
| 237 | 238 |
| 238 // Although EV status is irrelevant to sub-frames and sub-resources, we have | 239 // 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 | 240 // 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 | 241 // keep-alive connection created to load a sub-frame or a sub-resource could |
| 241 // be reused to load a main frame. | 242 // be reused to load a main frame. |
| 242 load_flags |= net::LOAD_VERIFY_EV_CERT; | 243 load_flags |= net::LOAD_VERIFY_EV_CERT; |
| 243 if (request_data.resource_type == ResourceType::MAIN_FRAME) { | 244 if (request_data.resource_type == ResourceType::MAIN_FRAME) { |
| 244 load_flags |= net::LOAD_MAIN_FRAME; | 245 load_flags |= net::LOAD_MAIN_FRAME; |
| 245 } else if (request_data.resource_type == ResourceType::SUB_FRAME) { | 246 } else if (request_data.resource_type == ResourceType::SUB_FRAME) { |
| (...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 694 BrowserThread::UI, FROM_HERE, | 695 BrowserThread::UI, FROM_HERE, |
| 695 base::Bind( | 696 base::Bind( |
| 696 &NotifyOnUI<ResourceRedirectDetails>, | 697 &NotifyOnUI<ResourceRedirectDetails>, |
| 697 static_cast<int>(NOTIFICATION_RESOURCE_RECEIVED_REDIRECT), | 698 static_cast<int>(NOTIFICATION_RESOURCE_RECEIVED_REDIRECT), |
| 698 render_process_id, render_view_id, base::Passed(&detail))); | 699 render_process_id, render_view_id, base::Passed(&detail))); |
| 699 } | 700 } |
| 700 | 701 |
| 701 void ResourceDispatcherHostImpl::DidReceiveResponse(ResourceLoader* loader) { | 702 void ResourceDispatcherHostImpl::DidReceiveResponse(ResourceLoader* loader) { |
| 702 ResourceRequestInfoImpl* info = loader->GetRequestInfo(); | 703 ResourceRequestInfoImpl* info = loader->GetRequestInfo(); |
| 703 | 704 |
| 705 offline_policy_.RequestCompleted(info->GetChildID(), info->GetRouteID(), |
| 706 loader->request()->response_info()); |
| 707 |
| 704 int render_process_id, render_view_id; | 708 int render_process_id, render_view_id; |
| 705 if (!info->GetAssociatedRenderView(&render_process_id, &render_view_id)) | 709 if (!info->GetAssociatedRenderView(&render_process_id, &render_view_id)) |
| 706 return; | 710 return; |
| 707 | 711 |
| 708 // Notify the observers on the UI thread. | 712 // Notify the observers on the UI thread. |
| 709 scoped_ptr<ResourceRequestDetails> detail(new ResourceRequestDetails( | 713 scoped_ptr<ResourceRequestDetails> detail(new ResourceRequestDetails( |
| 710 loader->request(), | 714 loader->request(), |
| 711 GetCertID(loader->request(), info->GetChildID()))); | 715 GetCertID(loader->request(), info->GetChildID()))); |
| 712 BrowserThread::PostTask( | 716 BrowserThread::PostTask( |
| 713 BrowserThread::UI, FROM_HERE, | 717 BrowserThread::UI, FROM_HERE, |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 926 request_data.resource_type, | 930 request_data.resource_type, |
| 927 resource_context, | 931 resource_context, |
| 928 referrer)) { | 932 referrer)) { |
| 929 AbortRequestBeforeItStarts(filter_, sync_result, route_id, request_id); | 933 AbortRequestBeforeItStarts(filter_, sync_result, route_id, request_id); |
| 930 return; | 934 return; |
| 931 } | 935 } |
| 932 | 936 |
| 933 bool is_sync_load = sync_result != NULL; | 937 bool is_sync_load = sync_result != NULL; |
| 934 int load_flags = | 938 int load_flags = |
| 935 BuildLoadFlagsForRequest(request_data, child_id, is_sync_load); | 939 BuildLoadFlagsForRequest(request_data, child_id, is_sync_load); |
| 940 load_flags |= offline_policy_.GetAdditionalLoadFlags( |
| 941 child_id, route_id, load_flags, request_data.resource_type); |
| 936 | 942 |
| 937 // Construct the request. | 943 // Construct the request. |
| 938 scoped_ptr<net::URLRequest> new_request; | 944 scoped_ptr<net::URLRequest> new_request; |
| 939 net::URLRequest* request; | 945 net::URLRequest* request; |
| 940 if (deferred_loader.get()) { | 946 if (deferred_loader.get()) { |
| 941 request = deferred_loader->request(); | 947 request = deferred_loader->request(); |
| 942 | 948 |
| 943 // Give the ResourceLoader (or any of the ResourceHandlers held by it) a | 949 // Give the ResourceLoader (or any of the ResourceHandlers held by it) a |
| 944 // chance to reset some state before we complete the transfer. | 950 // chance to reset some state before we complete the transfer. |
| 945 deferred_loader->WillCompleteTransfer(); | 951 deferred_loader->WillCompleteTransfer(); |
| (...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1361 for (BlockedLoadersMap::const_iterator iter = blocked_loaders_map_.begin(); | 1367 for (BlockedLoadersMap::const_iterator iter = blocked_loaders_map_.begin(); |
| 1362 iter != blocked_loaders_map_.end(); ++iter) { | 1368 iter != blocked_loaders_map_.end(); ++iter) { |
| 1363 if (iter->first.first == child_id) | 1369 if (iter->first.first == child_id) |
| 1364 route_ids.insert(iter->first.second); | 1370 route_ids.insert(iter->first.second); |
| 1365 } | 1371 } |
| 1366 for (std::set<int>::const_iterator iter = route_ids.begin(); | 1372 for (std::set<int>::const_iterator iter = route_ids.begin(); |
| 1367 iter != route_ids.end(); ++iter) { | 1373 iter != route_ids.end(); ++iter) { |
| 1368 CancelBlockedRequestsForRoute(child_id, *iter); | 1374 CancelBlockedRequestsForRoute(child_id, *iter); |
| 1369 } | 1375 } |
| 1370 } | 1376 } |
| 1377 |
| 1378 // Cleanup the offline state for the route. |
| 1379 offline_policy_.RouteRemoved(child_id, route_id); |
| 1371 } | 1380 } |
| 1372 | 1381 |
| 1373 // Cancels the request and removes it from the list. | 1382 // Cancels the request and removes it from the list. |
| 1374 void ResourceDispatcherHostImpl::RemovePendingRequest(int child_id, | 1383 void ResourceDispatcherHostImpl::RemovePendingRequest(int child_id, |
| 1375 int request_id) { | 1384 int request_id) { |
| 1376 LoaderMap::iterator i = pending_loaders_.find( | 1385 LoaderMap::iterator i = pending_loaders_.find( |
| 1377 GlobalRequestID(child_id, request_id)); | 1386 GlobalRequestID(child_id, request_id)); |
| 1378 if (i == pending_loaders_.end()) { | 1387 if (i == pending_loaders_.end()) { |
| 1379 NOTREACHED() << "Trying to remove a request that's not here"; | 1388 NOTREACHED() << "Trying to remove a request that's not here"; |
| 1380 return; | 1389 return; |
| (...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1753 DelegateMap::iterator it = delegate_map_.find(id); | 1762 DelegateMap::iterator it = delegate_map_.find(id); |
| 1754 DCHECK(it->second->HasObserver(delegate)); | 1763 DCHECK(it->second->HasObserver(delegate)); |
| 1755 it->second->RemoveObserver(delegate); | 1764 it->second->RemoveObserver(delegate); |
| 1756 if (it->second->size() == 0) { | 1765 if (it->second->size() == 0) { |
| 1757 delete it->second; | 1766 delete it->second; |
| 1758 delegate_map_.erase(it); | 1767 delegate_map_.erase(it); |
| 1759 } | 1768 } |
| 1760 } | 1769 } |
| 1761 | 1770 |
| 1762 } // namespace content | 1771 } // namespace content |
| OLD | NEW |