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

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

Issue 1117923004: Run load state update timer only when needed (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cpu
Patch Set: Rebase Created 5 years, 7 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
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 <algorithm> 9 #include <algorithm>
10 #include <set> 10 #include <set>
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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 969 matching lines...) Expand 10 before | Expand all | Expand 10 after
1772 1773
1773 void ResourceDispatcherHostImpl::RemovePendingLoader( 1774 void ResourceDispatcherHostImpl::RemovePendingLoader(
1774 const LoaderMap::iterator& iter) { 1775 const LoaderMap::iterator& iter) {
1775 ResourceRequestInfoImpl* info = iter->second->GetRequestInfo(); 1776 ResourceRequestInfoImpl* info = iter->second->GetRequestInfo();
1776 1777
1777 // Remove the memory credit that we added when pushing the request onto 1778 // Remove the memory credit that we added when pushing the request onto
1778 // the pending list. 1779 // the pending list.
1779 IncrementOutstandingRequestsMemory(-1, *info); 1780 IncrementOutstandingRequestsMemory(-1, *info);
1780 1781
1781 pending_loaders_.erase(iter); 1782 pending_loaders_.erase(iter);
1782
1783 // If we have no more pending requests, then stop the load state monitor
1784 if (pending_loaders_.empty() && update_load_states_timer_)
1785 update_load_states_timer_->Stop();
1786 } 1783 }
1787 1784
1788 void ResourceDispatcherHostImpl::CancelRequest(int child_id, 1785 void ResourceDispatcherHostImpl::CancelRequest(int child_id,
1789 int request_id) { 1786 int request_id) {
1790 ResourceLoader* loader = GetLoader(child_id, request_id); 1787 ResourceLoader* loader = GetLoader(child_id, request_id);
1791 if (!loader) { 1788 if (!loader) {
1792 // We probably want to remove this warning eventually, but I wanted to be 1789 // We probably want to remove this warning eventually, but I wanted to be
1793 // able to notice when this happens during initial development since it 1790 // able to notice when this happens during initial development since it
1794 // should be rare and may indicate a bug. 1791 // should be rare and may indicate a bug.
1795 DVLOG(1) << "Canceling a request that wasn't found"; 1792 DVLOG(1) << "Canceling a request that wasn't found";
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
2193 LoadInfoIsMoreInteresting(load_info, existing->second)) { 2190 LoadInfoIsMoreInteresting(load_info, existing->second)) {
2194 (*info_map)[id] = load_info; 2191 (*info_map)[id] = load_info;
2195 } 2192 }
2196 } 2193 }
2197 return info_map.Pass(); 2194 return info_map.Pass();
2198 } 2195 }
2199 2196
2200 void ResourceDispatcherHostImpl::UpdateLoadInfo() { 2197 void ResourceDispatcherHostImpl::UpdateLoadInfo() {
2201 scoped_ptr<LoadInfoMap> info_map(GetLoadInfoForAllRoutes()); 2198 scoped_ptr<LoadInfoMap> info_map(GetLoadInfoForAllRoutes());
2202 2199
2203 if (info_map->empty()) 2200 // Stop the timer if there are no more pending requests. Future new requests
2201 // will restart it as necessary.
2202 // Also stop the timer if there are no loading clients, to avoid waking up
2203 // unnecessarily when there is a long running (hanging get) request.
2204 if (info_map->empty() || !scheduler_->HasLoadingClients()) {
2205 update_load_states_timer_->Stop();
2204 return; 2206 return;
2207 }
2205 2208
2206 BrowserThread::PostTask( 2209 BrowserThread::PostTask(
2207 BrowserThread::UI, FROM_HERE, 2210 BrowserThread::UI, FROM_HERE,
2208 base::Bind(&ResourceDispatcherHostImpl::UpdateLoadInfoOnUIThread, 2211 base::Bind(&ResourceDispatcherHostImpl::UpdateLoadInfoOnUIThread,
2209 base::Passed(&info_map))); 2212 base::Passed(&info_map)));
2210 } 2213 }
2211 2214
2212 void ResourceDispatcherHostImpl::BlockRequestsForRoute(int child_id, 2215 void ResourceDispatcherHostImpl::BlockRequestsForRoute(int child_id,
2213 int route_id) { 2216 int route_id) {
2214 DCHECK_CURRENTLY_ON(BrowserThread::IO); 2217 DCHECK_CURRENTLY_ON(BrowserThread::IO);
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
2363 2366
2364 // Add a flag to selectively bypass the data reduction proxy if the resource 2367 // Add a flag to selectively bypass the data reduction proxy if the resource
2365 // type is not an image. 2368 // type is not an image.
2366 if (request_data.resource_type != RESOURCE_TYPE_IMAGE) 2369 if (request_data.resource_type != RESOURCE_TYPE_IMAGE)
2367 load_flags |= net::LOAD_BYPASS_DATA_REDUCTION_PROXY; 2370 load_flags |= net::LOAD_BYPASS_DATA_REDUCTION_PROXY;
2368 2371
2369 return load_flags; 2372 return load_flags;
2370 } 2373 }
2371 2374
2372 } // namespace content 2375 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/loader/resource_dispatcher_host_impl.h ('k') | content/browser/loader/resource_scheduler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698