Chromium Code Reviews| 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 <algorithm> | 9 #include <algorithm> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 108 | 108 |
| 109 // ---------------------------------------------------------------------------- | 109 // ---------------------------------------------------------------------------- |
| 110 | 110 |
| 111 namespace content { | 111 namespace content { |
| 112 | 112 |
| 113 namespace { | 113 namespace { |
| 114 | 114 |
| 115 static ResourceDispatcherHostImpl* g_resource_dispatcher_host; | 115 static ResourceDispatcherHostImpl* g_resource_dispatcher_host; |
| 116 | 116 |
| 117 // The interval for calls to ResourceDispatcherHostImpl::UpdateLoadStates | 117 // The interval for calls to ResourceDispatcherHostImpl::UpdateLoadStates |
| 118 const int kUpdateLoadStatesIntervalMsec = 100; | 118 const int kUpdateLoadStatesIntervalMsec = 250; |
| 119 | 119 |
| 120 // Maximum byte "cost" of all the outstanding requests for a renderer. | 120 // Maximum byte "cost" of all the outstanding requests for a renderer. |
| 121 // See delcaration of |max_outstanding_requests_cost_per_process_| for details. | 121 // See delcaration of |max_outstanding_requests_cost_per_process_| for details. |
| 122 // This bound is 25MB, which allows for around 6000 outstanding requests. | 122 // This bound is 25MB, which allows for around 6000 outstanding requests. |
| 123 const int kMaxOutstandingRequestsCostPerProcess = 26214400; | 123 const int kMaxOutstandingRequestsCostPerProcess = 26214400; |
| 124 | 124 |
| 125 // The number of milliseconds after noting a user gesture that we will | 125 // The number of milliseconds after noting a user gesture that we will |
| 126 // tag newly-created URLRequest objects with the | 126 // tag newly-created URLRequest objects with the |
| 127 // net::LOAD_MAYBE_USER_GESTURE load flag. This is a fairly arbitrary | 127 // net::LOAD_MAYBE_USER_GESTURE load flag. This is a fairly arbitrary |
| 128 // guess at how long to expect direct impact from a user gesture, but | 128 // guess at how long to expect direct impact from a user gesture, but |
| (...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 781 info->GetContext()->GetRequestContext()->job_factory(); | 781 info->GetContext()->GetRequestContext()->job_factory(); |
| 782 if (job_factory->IsHandledURL(url)) | 782 if (job_factory->IsHandledURL(url)) |
| 783 return false; | 783 return false; |
| 784 | 784 |
| 785 return delegate_->HandleExternalProtocol( | 785 return delegate_->HandleExternalProtocol( |
| 786 url, info->GetChildID(), info->GetRouteID(), info->IsMainFrame(), | 786 url, info->GetChildID(), info->GetRouteID(), info->IsMainFrame(), |
| 787 info->GetPageTransition(), info->HasUserGesture()); | 787 info->GetPageTransition(), info->HasUserGesture()); |
| 788 } | 788 } |
| 789 | 789 |
| 790 void ResourceDispatcherHostImpl::DidStartRequest(ResourceLoader* loader) { | 790 void ResourceDispatcherHostImpl::DidStartRequest(ResourceLoader* loader) { |
| 791 // Make sure we have the load state monitor running | 791 // Make sure we have the load state monitor running. |
| 792 if (!update_load_states_timer_->IsRunning()) { | 792 if (!update_load_states_timer_->IsRunning() && |
| 793 scheduler_->HasLoadingClients()) { | |
| 793 update_load_states_timer_->Start( | 794 update_load_states_timer_->Start( |
| 794 FROM_HERE, TimeDelta::FromMilliseconds(kUpdateLoadStatesIntervalMsec), | 795 FROM_HERE, TimeDelta::FromMilliseconds(kUpdateLoadStatesIntervalMsec), |
| 795 this, &ResourceDispatcherHostImpl::UpdateLoadInfo); | 796 this, &ResourceDispatcherHostImpl::UpdateLoadInfo); |
| 796 } | 797 } |
| 797 } | 798 } |
| 798 | 799 |
| 799 void ResourceDispatcherHostImpl::DidReceiveRedirect(ResourceLoader* loader, | 800 void ResourceDispatcherHostImpl::DidReceiveRedirect(ResourceLoader* loader, |
| 800 const GURL& new_url) { | 801 const GURL& new_url) { |
| 801 ResourceRequestInfoImpl* info = loader->GetRequestInfo(); | 802 ResourceRequestInfoImpl* info = loader->GetRequestInfo(); |
| 802 | 803 |
| (...skipping 971 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1774 | 1775 |
| 1775 void ResourceDispatcherHostImpl::RemovePendingLoader( | 1776 void ResourceDispatcherHostImpl::RemovePendingLoader( |
| 1776 const LoaderMap::iterator& iter) { | 1777 const LoaderMap::iterator& iter) { |
| 1777 ResourceRequestInfoImpl* info = iter->second->GetRequestInfo(); | 1778 ResourceRequestInfoImpl* info = iter->second->GetRequestInfo(); |
| 1778 | 1779 |
| 1779 // Remove the memory credit that we added when pushing the request onto | 1780 // Remove the memory credit that we added when pushing the request onto |
| 1780 // the pending list. | 1781 // the pending list. |
| 1781 IncrementOutstandingRequestsMemory(-1, *info); | 1782 IncrementOutstandingRequestsMemory(-1, *info); |
| 1782 | 1783 |
| 1783 pending_loaders_.erase(iter); | 1784 pending_loaders_.erase(iter); |
| 1784 | |
| 1785 // If we have no more pending requests, then stop the load state monitor | |
| 1786 if (pending_loaders_.empty() && update_load_states_timer_) | |
| 1787 update_load_states_timer_->Stop(); | |
| 1788 } | 1785 } |
| 1789 | 1786 |
| 1790 void ResourceDispatcherHostImpl::CancelRequest(int child_id, | 1787 void ResourceDispatcherHostImpl::CancelRequest(int child_id, |
| 1791 int request_id) { | 1788 int request_id) { |
| 1792 ResourceLoader* loader = GetLoader(child_id, request_id); | 1789 ResourceLoader* loader = GetLoader(child_id, request_id); |
| 1793 if (!loader) { | 1790 if (!loader) { |
| 1794 // We probably want to remove this warning eventually, but I wanted to be | 1791 // We probably want to remove this warning eventually, but I wanted to be |
| 1795 // able to notice when this happens during initial development since it | 1792 // able to notice when this happens during initial development since it |
| 1796 // should be rare and may indicate a bug. | 1793 // should be rare and may indicate a bug. |
| 1797 DVLOG(1) << "Canceling a request that wasn't found"; | 1794 DVLOG(1) << "Canceling a request that wasn't found"; |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2199 LoadInfoIsMoreInteresting(load_info, existing->second)) { | 2196 LoadInfoIsMoreInteresting(load_info, existing->second)) { |
| 2200 (*info_map)[id] = load_info; | 2197 (*info_map)[id] = load_info; |
| 2201 } | 2198 } |
| 2202 } | 2199 } |
| 2203 return info_map.Pass(); | 2200 return info_map.Pass(); |
| 2204 } | 2201 } |
| 2205 | 2202 |
| 2206 void ResourceDispatcherHostImpl::UpdateLoadInfo() { | 2203 void ResourceDispatcherHostImpl::UpdateLoadInfo() { |
| 2207 scoped_ptr<LoadInfoMap> info_map(GetLoadInfoForAllRoutes()); | 2204 scoped_ptr<LoadInfoMap> info_map(GetLoadInfoForAllRoutes()); |
| 2208 | 2205 |
| 2209 if (info_map->empty()) | 2206 // Stop the timer if there are no more pending requests. Future new requests |
| 2207 // will restart it as necessary. | |
| 2208 // Also stop the timer if there are no loading clients, to avoid waking up | |
| 2209 // unnecessarily when there is a long running (hanging get) request like when | |
| 2210 // on a Google Docs document. | |
|
mmenke
2015/05/22 15:19:24
nit: Shouldn't mention Google Docs, think it's fi
Andre
2015/05/22 17:30:21
Done.
| |
| 2211 if (info_map->empty() || !scheduler_->HasLoadingClients()) { | |
| 2212 update_load_states_timer_->Stop(); | |
| 2210 return; | 2213 return; |
| 2214 } | |
| 2211 | 2215 |
| 2212 BrowserThread::PostTask( | 2216 BrowserThread::PostTask( |
| 2213 BrowserThread::UI, FROM_HERE, | 2217 BrowserThread::UI, FROM_HERE, |
| 2214 base::Bind(&ResourceDispatcherHostImpl::UpdateLoadInfoOnUIThread, | 2218 base::Bind(&ResourceDispatcherHostImpl::UpdateLoadInfoOnUIThread, |
| 2215 base::Passed(&info_map))); | 2219 base::Passed(&info_map))); |
| 2216 } | 2220 } |
| 2217 | 2221 |
| 2218 void ResourceDispatcherHostImpl::BlockRequestsForRoute(int child_id, | 2222 void ResourceDispatcherHostImpl::BlockRequestsForRoute(int child_id, |
| 2219 int route_id) { | 2223 int route_id) { |
| 2220 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 2224 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2369 | 2373 |
| 2370 // Add a flag to selectively bypass the data reduction proxy if the resource | 2374 // Add a flag to selectively bypass the data reduction proxy if the resource |
| 2371 // type is not an image. | 2375 // type is not an image. |
| 2372 if (request_data.resource_type != RESOURCE_TYPE_IMAGE) | 2376 if (request_data.resource_type != RESOURCE_TYPE_IMAGE) |
| 2373 load_flags |= net::LOAD_BYPASS_DATA_REDUCTION_PROXY; | 2377 load_flags |= net::LOAD_BYPASS_DATA_REDUCTION_PROXY; |
| 2374 | 2378 |
| 2375 return load_flags; | 2379 return load_flags; |
| 2376 } | 2380 } |
| 2377 | 2381 |
| 2378 } // namespace content | 2382 } // namespace content |
| OLD | NEW |