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

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

Issue 465363003: ResourceScheduler get visual signal from RenderViewHostImpl (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Do not throttle when should not Created 6 years, 4 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 | Annotate | Revision Log
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 #include <set> 5 #include <set>
6 6
7 #include "content/browser/loader/resource_scheduler.h" 7 #include "content/browser/loader/resource_scheduler.h"
8 8
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "content/common/resource_messages.h" 10 #include "content/common/resource_messages.h"
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 void ResourceScheduler::RequestQueue::Insert( 223 void ResourceScheduler::RequestQueue::Insert(
224 ScheduledResourceRequest* request) { 224 ScheduledResourceRequest* request) {
225 DCHECK(!ContainsKey(pointers_, request)); 225 DCHECK(!ContainsKey(pointers_, request));
226 request->set_fifo_ordering(MakeFifoOrderingId()); 226 request->set_fifo_ordering(MakeFifoOrderingId());
227 pointers_[request] = queue_.insert(request); 227 pointers_[request] = queue_.insert(request);
228 } 228 }
229 229
230 // Each client represents a tab. 230 // Each client represents a tab.
231 class ResourceScheduler::Client { 231 class ResourceScheduler::Client {
232 public: 232 public:
233 explicit Client(ResourceScheduler* scheduler) 233 explicit Client(ResourceScheduler* scheduler, bool is_visible)
234 : is_audible_(false), 234 : is_audible_(false),
235 is_visible_(false), 235 is_visible_(is_visible),
236 is_loaded_(false), 236 is_loaded_(false),
237 is_paused_(false), 237 is_paused_(false),
238 has_body_(false), 238 has_body_(false),
239 using_spdy_proxy_(false), 239 using_spdy_proxy_(false),
240 total_delayable_count_(0), 240 total_delayable_count_(0),
241 throttle_state_(ResourceScheduler::THROTTLED) { 241 throttle_state_(ResourceScheduler::THROTTLED) {
242 scheduler_ = scheduler; 242 scheduler_ = scheduler;
243 } 243 }
244 244
245 ~Client() { 245 ~Client() {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 (*it)->set_accounted_as_delayable_request(false); 281 (*it)->set_accounted_as_delayable_request(false);
282 } 282 }
283 ClearInFlightRequests(); 283 ClearInFlightRequests();
284 return unowned_requests; 284 return unowned_requests;
285 } 285 }
286 286
287 bool is_active() const { return is_visible_ || is_audible_; } 287 bool is_active() const { return is_visible_ || is_audible_; }
288 288
289 bool is_loaded() const { return is_loaded_; } 289 bool is_loaded() const { return is_loaded_; }
290 290
291 bool IsVisible() const { return is_visible_; }
292
291 void OnAudibilityChanged(bool is_audible) { 293 void OnAudibilityChanged(bool is_audible) {
292 if (is_audible == is_audible_) { 294 if (is_audible == is_audible_) {
293 return; 295 return;
294 } 296 }
295 is_audible_ = is_audible; 297 is_audible_ = is_audible;
296 UpdateThrottleState(); 298 UpdateThrottleState();
297 } 299 }
298 300
299 void OnVisibilityChanged(bool is_visible) { 301 void OnVisibilityChanged(bool is_visible) {
300 if (is_visible == is_visible_) { 302 if (is_visible == is_visible_) {
(...skipping 11 matching lines...) Expand all
312 UpdateThrottleState(); 314 UpdateThrottleState();
313 } 315 }
314 316
315 void SetPaused() { 317 void SetPaused() {
316 is_paused_ = true; 318 is_paused_ = true;
317 UpdateThrottleState(); 319 UpdateThrottleState();
318 } 320 }
319 321
320 void UpdateThrottleState() { 322 void UpdateThrottleState() {
321 ClientThrottleState old_throttle_state = throttle_state_; 323 ClientThrottleState old_throttle_state = throttle_state_;
322 if (is_active() && !is_loaded_) { 324 if (!scheduler_->should_throttle()) {
325 SetThrottleState(UNTHROTTLED);
326 } else if (is_active() && !is_loaded_) {
323 SetThrottleState(ACTIVE_AND_LOADING); 327 SetThrottleState(ACTIVE_AND_LOADING);
324 } else if (is_active()) { 328 } else if (is_active()) {
325 SetThrottleState(UNTHROTTLED); 329 SetThrottleState(UNTHROTTLED);
326 } else if (is_paused_) { 330 } else if (is_paused_) {
327 SetThrottleState(PAUSED); 331 SetThrottleState(PAUSED);
328 } else if (!scheduler_->active_clients_loaded()) { 332 } else if (!scheduler_->active_clients_loaded()) {
329 SetThrottleState(THROTTLED); 333 SetThrottleState(THROTTLED);
330 } else if (is_loaded_ && scheduler_->should_coalesce()) { 334 } else if (is_loaded_ && scheduler_->should_coalesce()) {
331 SetThrottleState(COALESCED); 335 SetThrottleState(COALESCED);
332 } else if (!is_active()) { 336 } else if (!is_active()) {
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
724 728
725 ClientMap::iterator client_it = client_map_.find(request->client_id()); 729 ClientMap::iterator client_it = client_map_.find(request->client_id());
726 if (client_it == client_map_.end()) { 730 if (client_it == client_map_.end()) {
727 return; 731 return;
728 } 732 }
729 733
730 Client* client = client_it->second; 734 Client* client = client_it->second;
731 client->RemoveRequest(request); 735 client->RemoveRequest(request);
732 } 736 }
733 737
734 void ResourceScheduler::OnClientCreated(int child_id, int route_id) { 738 void ResourceScheduler::OnClientCreated(int child_id,
739 int route_id,
740 bool is_visible) {
735 DCHECK(CalledOnValidThread()); 741 DCHECK(CalledOnValidThread());
736 ClientId client_id = MakeClientId(child_id, route_id); 742 ClientId client_id = MakeClientId(child_id, route_id);
737 DCHECK(!ContainsKey(client_map_, client_id)); 743 DCHECK(!ContainsKey(client_map_, client_id));
738 744
739 Client* client = new Client(this); 745 Client* client = new Client(this, is_visible);
740 client_map_[client_id] = client; 746 client_map_[client_id] = client;
741 747
742 // TODO(aiolos): set Client visibility/audibility when signals are added 748 // TODO(aiolos): set Client visibility/audibility when signals are added
743 // this will UNTHROTTLE Clients as needed 749 // this will UNTHROTTLE Clients as needed
744 client->UpdateThrottleState(); 750 client->UpdateThrottleState();
745 } 751 }
746 752
747 void ResourceScheduler::OnClientDeleted(int child_id, int route_id) { 753 void ResourceScheduler::OnClientDeleted(int child_id, int route_id) {
748 DCHECK(CalledOnValidThread()); 754 DCHECK(CalledOnValidThread());
749 ClientId client_id = MakeClientId(child_id, route_id); 755 ClientId client_id = MakeClientId(child_id, route_id);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
826 } 832 }
827 833
828 void ResourceScheduler::OnLoadingStateChanged(int child_id, 834 void ResourceScheduler::OnLoadingStateChanged(int child_id,
829 int route_id, 835 int route_id,
830 bool is_loaded) { 836 bool is_loaded) {
831 Client* client = GetClient(child_id, route_id); 837 Client* client = GetClient(child_id, route_id);
832 DCHECK(client); 838 DCHECK(client);
833 client->OnLoadingStateChanged(is_loaded); 839 client->OnLoadingStateChanged(is_loaded);
834 } 840 }
835 841
842 bool ResourceScheduler::IsClientVisibleForTesting(int child_id, int route_id) {
843 Client* client = GetClient(child_id, route_id);
844 DCHECK(client);
845 return client->IsVisible();
846 }
847
836 ResourceScheduler::Client* ResourceScheduler::GetClient(int child_id, 848 ResourceScheduler::Client* ResourceScheduler::GetClient(int child_id,
837 int route_id) { 849 int route_id) {
838 ClientId client_id = MakeClientId(child_id, route_id); 850 ClientId client_id = MakeClientId(child_id, route_id);
839 ClientMap::iterator client_it = client_map_.find(client_id); 851 ClientMap::iterator client_it = client_map_.find(client_id);
840 if (client_it == client_map_.end()) { 852 if (client_it == client_map_.end()) {
841 return NULL; 853 return NULL;
842 } 854 }
843 return client_it->second; 855 return client_it->second;
844 } 856 }
845 857
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
960 client->ReprioritizeRequest( 972 client->ReprioritizeRequest(
961 request, old_priority_params, new_priority_params); 973 request, old_priority_params, new_priority_params);
962 } 974 }
963 975
964 ResourceScheduler::ClientId ResourceScheduler::MakeClientId( 976 ResourceScheduler::ClientId ResourceScheduler::MakeClientId(
965 int child_id, int route_id) { 977 int child_id, int route_id) {
966 return (static_cast<ResourceScheduler::ClientId>(child_id) << 32) | route_id; 978 return (static_cast<ResourceScheduler::ClientId>(child_id) << 32) | route_id;
967 } 979 }
968 980
969 } // namespace content 981 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/loader/resource_scheduler.h ('k') | content/browser/loader/resource_scheduler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698