| 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 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 693 BrowserThread::PostTask( | 694 BrowserThread::PostTask( |
| 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(); |
| 704 // There should be an entry in the map created when we dispatched the |
| 705 // request. |
| 706 offline_map_[ProcessRouteIDs(info->GetChildID(), info->GetRouteID())]-> |
| 707 RequestCompleted(loader->request()->response_info()); |
| 703 | 708 |
| 704 int render_process_id, render_view_id; | 709 int render_process_id, render_view_id; |
| 705 if (!info->GetAssociatedRenderView(&render_process_id, &render_view_id)) | 710 if (!info->GetAssociatedRenderView(&render_process_id, &render_view_id)) |
| 706 return; | 711 return; |
| 707 | 712 |
| 708 // Notify the observers on the UI thread. | 713 // Notify the observers on the UI thread. |
| 709 scoped_ptr<ResourceRequestDetails> detail(new ResourceRequestDetails( | 714 scoped_ptr<ResourceRequestDetails> detail(new ResourceRequestDetails( |
| 710 loader->request(), | 715 loader->request(), |
| 711 GetCertID(loader->request(), info->GetChildID()))); | 716 GetCertID(loader->request(), info->GetChildID()))); |
| 712 BrowserThread::PostTask( | 717 BrowserThread::PostTask( |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 927 resource_context, | 932 resource_context, |
| 928 referrer)) { | 933 referrer)) { |
| 929 AbortRequestBeforeItStarts(filter_, sync_result, route_id, request_id); | 934 AbortRequestBeforeItStarts(filter_, sync_result, route_id, request_id); |
| 930 return; | 935 return; |
| 931 } | 936 } |
| 932 | 937 |
| 933 bool is_sync_load = sync_result != NULL; | 938 bool is_sync_load = sync_result != NULL; |
| 934 int load_flags = | 939 int load_flags = |
| 935 BuildLoadFlagsForRequest(request_data, child_id, is_sync_load); | 940 BuildLoadFlagsForRequest(request_data, child_id, is_sync_load); |
| 936 | 941 |
| 942 ProcessRouteIDs id(child_id, route_id); |
| 943 if (!offline_map_[id]) |
| 944 offline_map_[id] = new OfflinePolicy(); |
| 945 load_flags |= offline_map_[id]->GetAdditionalLoadFlags( |
| 946 load_flags, request_data.resource_type); |
| 947 |
| 937 // Construct the request. | 948 // Construct the request. |
| 938 scoped_ptr<net::URLRequest> new_request; | 949 scoped_ptr<net::URLRequest> new_request; |
| 939 net::URLRequest* request; | 950 net::URLRequest* request; |
| 940 if (deferred_loader.get()) { | 951 if (deferred_loader.get()) { |
| 941 request = deferred_loader->request(); | 952 request = deferred_loader->request(); |
| 942 | 953 |
| 943 // Give the ResourceLoader (or any of the ResourceHandlers held by it) a | 954 // Give the ResourceLoader (or any of the ResourceHandlers held by it) a |
| 944 // chance to reset some state before we complete the transfer. | 955 // chance to reset some state before we complete the transfer. |
| 945 deferred_loader->WillCompleteTransfer(); | 956 deferred_loader->WillCompleteTransfer(); |
| 946 } else { | 957 } else { |
| (...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1361 for (BlockedLoadersMap::const_iterator iter = blocked_loaders_map_.begin(); | 1372 for (BlockedLoadersMap::const_iterator iter = blocked_loaders_map_.begin(); |
| 1362 iter != blocked_loaders_map_.end(); ++iter) { | 1373 iter != blocked_loaders_map_.end(); ++iter) { |
| 1363 if (iter->first.first == child_id) | 1374 if (iter->first.first == child_id) |
| 1364 route_ids.insert(iter->first.second); | 1375 route_ids.insert(iter->first.second); |
| 1365 } | 1376 } |
| 1366 for (std::set<int>::const_iterator iter = route_ids.begin(); | 1377 for (std::set<int>::const_iterator iter = route_ids.begin(); |
| 1367 iter != route_ids.end(); ++iter) { | 1378 iter != route_ids.end(); ++iter) { |
| 1368 CancelBlockedRequestsForRoute(child_id, *iter); | 1379 CancelBlockedRequestsForRoute(child_id, *iter); |
| 1369 } | 1380 } |
| 1370 } | 1381 } |
| 1382 |
| 1383 // Cleanup the offline state for the route. |
| 1384 delete offline_map_[ProcessRouteIDs(child_id, route_id)]; |
| 1385 offline_map_.erase(ProcessRouteIDs(child_id, route_id)); |
| 1371 } | 1386 } |
| 1372 | 1387 |
| 1373 // Cancels the request and removes it from the list. | 1388 // Cancels the request and removes it from the list. |
| 1374 void ResourceDispatcherHostImpl::RemovePendingRequest(int child_id, | 1389 void ResourceDispatcherHostImpl::RemovePendingRequest(int child_id, |
| 1375 int request_id) { | 1390 int request_id) { |
| 1376 LoaderMap::iterator i = pending_loaders_.find( | 1391 LoaderMap::iterator i = pending_loaders_.find( |
| 1377 GlobalRequestID(child_id, request_id)); | 1392 GlobalRequestID(child_id, request_id)); |
| 1378 if (i == pending_loaders_.end()) { | 1393 if (i == pending_loaders_.end()) { |
| 1379 NOTREACHED() << "Trying to remove a request that's not here"; | 1394 NOTREACHED() << "Trying to remove a request that's not here"; |
| 1380 return; | 1395 return; |
| (...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1753 DelegateMap::iterator it = delegate_map_.find(id); | 1768 DelegateMap::iterator it = delegate_map_.find(id); |
| 1754 DCHECK(it->second->HasObserver(delegate)); | 1769 DCHECK(it->second->HasObserver(delegate)); |
| 1755 it->second->RemoveObserver(delegate); | 1770 it->second->RemoveObserver(delegate); |
| 1756 if (it->second->size() == 0) { | 1771 if (it->second->size() == 0) { |
| 1757 delete it->second; | 1772 delete it->second; |
| 1758 delegate_map_.erase(it); | 1773 delegate_map_.erase(it); |
| 1759 } | 1774 } |
| 1760 } | 1775 } |
| 1761 | 1776 |
| 1762 } // namespace content | 1777 } // namespace content |
| OLD | NEW |