diff options
Diffstat (limited to 'content/browser/loader/resource_dispatcher_host_impl.cc')
-rw-r--r-- | content/browser/loader/resource_dispatcher_host_impl.cc | 85 |
1 files changed, 60 insertions, 25 deletions
diff --git a/content/browser/loader/resource_dispatcher_host_impl.cc b/content/browser/loader/resource_dispatcher_host_impl.cc index 7eee77b..f3a441b 100644 --- a/content/browser/loader/resource_dispatcher_host_impl.cc +++ b/content/browser/loader/resource_dispatcher_host_impl.cc @@ -231,8 +231,10 @@ net::Error CallbackAndReturn( return net_error; } -int BuildLoadFlagsForRequest(const ResourceHostMsg_Request& request_data, - int child_id, bool is_sync_load) { +int BuildLoadFlagsForRequest( + const ResourceHostMsg_Request& request_data, + int child_id, + bool is_sync_load) { int load_flags = request_data.load_flags; // Although EV status is irrelevant to sub-frames and sub-resources, we have @@ -480,6 +482,13 @@ net::Error ResourceDispatcherHostImpl::BeginDownload( extra_load_flags |= net::LOAD_DISABLE_CACHE; } request->set_load_flags(request->load_flags() | extra_load_flags); + + // No need to get offline load flags for downloads, but make sure + // we have an OfflinePolicy to receive request completions. + GlobalRoutingID id(child_id, route_id); + if (!offline_policy_map_[id]) + offline_policy_map_[id] = new OfflinePolicy(); + // Check if the renderer is permitted to request the requested URL. if (!ChildProcessSecurityPolicyImpl::GetInstance()-> CanRequestURL(child_id, url)) { @@ -702,6 +711,12 @@ void ResourceDispatcherHostImpl::DidReceiveRedirect(ResourceLoader* loader, void ResourceDispatcherHostImpl::DidReceiveResponse(ResourceLoader* loader) { ResourceRequestInfoImpl* info = loader->GetRequestInfo(); + // There should be an entry in the map created when we dispatched the + // request. + GlobalRoutingID routing_id(info->GetGlobalRoutingID()); + DCHECK(offline_policy_map_.end() != offline_policy_map_.find(routing_id)); + offline_policy_map_[routing_id]-> + UpdateStateForCompletedRequest(loader->request()->response_info()); int render_process_id, render_view_id; if (!info->GetAssociatedRenderView(&render_process_id, &render_view_id)) @@ -789,17 +804,17 @@ void ResourceDispatcherHostImpl::OnShutdown() { // Note that we have to do this in 2 passes as we cannot call // CancelBlockedRequestsForRoute while iterating over // blocked_loaders_map_, as it modifies it. - std::set<ProcessRouteIDs> ids; + std::set<GlobalRoutingID> ids; for (BlockedLoadersMap::const_iterator iter = blocked_loaders_map_.begin(); iter != blocked_loaders_map_.end(); ++iter) { - std::pair<std::set<ProcessRouteIDs>::iterator, bool> result = + std::pair<std::set<GlobalRoutingID>::iterator, bool> result = ids.insert(iter->first); // We should not have duplicates. DCHECK(result.second); } - for (std::set<ProcessRouteIDs>::const_iterator iter = ids.begin(); + for (std::set<GlobalRoutingID>::const_iterator iter = ids.begin(); iter != ids.end(); ++iter) { - CancelBlockedRequestsForRoute(iter->first, iter->second); + CancelBlockedRequestsForRoute(iter->child_id, iter->route_id); } scheduler_.reset(); @@ -936,6 +951,12 @@ void ResourceDispatcherHostImpl::BeginRequest( int load_flags = BuildLoadFlagsForRequest(request_data, child_id, is_sync_load); + GlobalRoutingID id(child_id, route_id); + if (!offline_policy_map_[id]) + offline_policy_map_[id] = new OfflinePolicy(); + load_flags |= offline_policy_map_[id]->GetAdditionalLoadFlags( + load_flags, request_data.resource_type == ResourceType::MAIN_FRAME); + // Construct the request. scoped_ptr<net::URLRequest> new_request; net::URLRequest* request; @@ -1276,6 +1297,12 @@ void ResourceDispatcherHostImpl::BeginSaveFile( // future, maybe we can use a configuration to configure this behavior. request->set_load_flags(net::LOAD_PREFERRING_CACHE); + // No need to get offline load flags for save files, but make sure + // we have an OfflinePolicy to receive request completions. + GlobalRoutingID id(child_id, route_id); + if (!offline_policy_map_[id]) + offline_policy_map_[id] = new OfflinePolicy(); + // Since we're just saving some resources we need, disallow downloading. ResourceRequestInfoImpl* extra_info = CreateRequestInfo(child_id, route_id, false, context); @@ -1351,7 +1378,7 @@ void ResourceDispatcherHostImpl::CancelRequestsForRoute(int child_id, // Now deal with blocked requests if any. if (route_id != -1) { - if (blocked_loaders_map_.find(ProcessRouteIDs(child_id, route_id)) != + if (blocked_loaders_map_.find(GlobalRoutingID(child_id, route_id)) != blocked_loaders_map_.end()) { CancelBlockedRequestsForRoute(child_id, route_id); } @@ -1363,14 +1390,22 @@ void ResourceDispatcherHostImpl::CancelRequestsForRoute(int child_id, std::set<int> route_ids; for (BlockedLoadersMap::const_iterator iter = blocked_loaders_map_.begin(); iter != blocked_loaders_map_.end(); ++iter) { - if (iter->first.first == child_id) - route_ids.insert(iter->first.second); + if (iter->first.child_id == child_id) + route_ids.insert(iter->first.route_id); } for (std::set<int>::const_iterator iter = route_ids.begin(); iter != route_ids.end(); ++iter) { CancelBlockedRequestsForRoute(child_id, *iter); } } + + // Cleanup the offline state for the route. + OfflineMap::iterator it = offline_policy_map_.find( + GlobalRoutingID(child_id, route_id)); + if (offline_policy_map_.end() != it) { + delete it->second; + offline_policy_map_.erase(it); + } } // Cancels the request and removes it from the list. @@ -1502,8 +1537,8 @@ void ResourceDispatcherHostImpl::BeginRequestInternal( linked_ptr<ResourceLoader> loader( new ResourceLoader(request.Pass(), handler.Pass(), this)); - ProcessRouteIDs pair_id(info->GetChildID(), info->GetRouteID()); - BlockedLoadersMap::const_iterator iter = blocked_loaders_map_.find(pair_id); + GlobalRoutingID id(info->GetGlobalRoutingID()); + BlockedLoadersMap::const_iterator iter = blocked_loaders_map_.find(id); if (iter != blocked_loaders_map_.end()) { // The request should be blocked. iter->second->push_back(loader); @@ -1565,8 +1600,8 @@ struct LoadInfo { uint64 upload_size; }; -// Map from ProcessID+ViewID pair to LoadState -typedef std::map<std::pair<int, int>, LoadInfo> LoadInfoMap; +// Map from ProcessID+RouteID pair to LoadState +typedef std::map<GlobalRoutingID, LoadInfo> LoadInfoMap; // Used to marshal calls to LoadStateChanged from the IO to UI threads. We do // them all as a single callback to avoid spamming the UI thread. @@ -1574,7 +1609,7 @@ void LoadInfoUpdateCallback(const LoadInfoMap& info_map) { LoadInfoMap::const_iterator i; for (i = info_map.begin(); i != info_map.end(); ++i) { RenderViewHostImpl* view = - RenderViewHostImpl::FromID(i->first.first, i->first.second); + RenderViewHostImpl::FromID(i->first.child_id, i->first.route_id); if (view) // The view could be gone at this point. view->LoadStateChanged(i->second.url, i->second.load_state, i->second.upload_position, @@ -1593,16 +1628,16 @@ void ResourceDispatcherHostImpl::UpdateLoadStates() { // Determine the largest upload size of all requests // in each View (good chance it's zero). - std::map<std::pair<int, int>, uint64> largest_upload_size; + std::map<GlobalRoutingID, uint64> largest_upload_size; for (i = pending_loaders_.begin(); i != pending_loaders_.end(); ++i) { net::URLRequest* request = i->second->request(); ResourceRequestInfoImpl* info = i->second->GetRequestInfo(); uint64 upload_size = request->GetUploadProgress().size(); if (request->GetLoadState().state != net::LOAD_STATE_SENDING_REQUEST) upload_size = 0; - std::pair<int, int> key(info->GetChildID(), info->GetRouteID()); - if (upload_size && largest_upload_size[key] < upload_size) - largest_upload_size[key] = upload_size; + GlobalRoutingID id(info->GetGlobalRoutingID()); + if (upload_size && largest_upload_size[id] < upload_size) + largest_upload_size[id] = upload_size; } for (i = pending_loaders_.begin(); i != pending_loaders_.end(); ++i) { @@ -1615,23 +1650,23 @@ void ResourceDispatcherHostImpl::UpdateLoadStates() { // progress ipc messages to the plugin process. i->second->ReportUploadProgress(); - std::pair<int, int> key(info->GetChildID(), info->GetRouteID()); + GlobalRoutingID id(info->GetGlobalRoutingID()); // If a request is uploading data, ignore all other requests so that the // upload progress takes priority for being shown in the status bar. - if (largest_upload_size.find(key) != largest_upload_size.end() && - progress.size() < largest_upload_size[key]) + if (largest_upload_size.find(id) != largest_upload_size.end() && + progress.size() < largest_upload_size[id]) continue; net::LoadStateWithParam to_insert = load_state; - LoadInfoMap::iterator existing = info_map.find(key); + LoadInfoMap::iterator existing = info_map.find(id); if (existing != info_map.end()) { to_insert = MoreInterestingLoadState(existing->second.load_state, load_state); if (to_insert.state == existing->second.load_state.state) continue; } - LoadInfo& load_info = info_map[key]; + LoadInfo& load_info = info_map[id]; load_info.url = request->url(); load_info.load_state = to_insert; load_info.upload_size = progress.size(); @@ -1649,7 +1684,7 @@ void ResourceDispatcherHostImpl::UpdateLoadStates() { void ResourceDispatcherHostImpl::BlockRequestsForRoute(int child_id, int route_id) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - ProcessRouteIDs key(child_id, route_id); + GlobalRoutingID key(child_id, route_id); DCHECK(blocked_loaders_map_.find(key) == blocked_loaders_map_.end()) << "BlockRequestsForRoute called multiple time for the same RVH"; blocked_loaders_map_[key] = new BlockedLoadersList(); @@ -1670,7 +1705,7 @@ void ResourceDispatcherHostImpl::ProcessBlockedRequestsForRoute( int route_id, bool cancel_requests) { BlockedLoadersMap::iterator iter = blocked_loaders_map_.find( - std::pair<int, int>(child_id, route_id)); + GlobalRoutingID(child_id, route_id)); if (iter == blocked_loaders_map_.end()) { // It's possible to reach here if the renderer crashed while an interstitial // page was showing. |