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

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: unit test fix 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 (is_active() && !is_loaded_) {
aiolos (Not reviewing) 2014/08/21 17:27:02 Add if (!scheduler_->should_throttle()) { SetTh
Zhen Wang 2014/08/21 21:37:49 Thanks! This works. On 2014/08/21 17:27:02, aiolo
323 SetThrottleState(ACTIVE_AND_LOADING); 325 SetThrottleState(ACTIVE_AND_LOADING);
324 } else if (is_active()) { 326 } else if (is_active()) {
325 SetThrottleState(UNTHROTTLED); 327 SetThrottleState(UNTHROTTLED);
326 } else if (is_paused_) { 328 } else if (is_paused_) {
327 SetThrottleState(PAUSED); 329 SetThrottleState(PAUSED);
328 } else if (!scheduler_->active_clients_loaded()) { 330 } else if (!scheduler_->active_clients_loaded()) {
329 SetThrottleState(THROTTLED); 331 SetThrottleState(THROTTLED);
330 } else if (is_loaded_ && scheduler_->should_coalesce()) { 332 } else if (is_loaded_ && scheduler_->should_coalesce()) {
331 SetThrottleState(COALESCED); 333 SetThrottleState(COALESCED);
332 } else if (!is_active()) { 334 } else if (!is_active()) {
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
724 726
725 ClientMap::iterator client_it = client_map_.find(request->client_id()); 727 ClientMap::iterator client_it = client_map_.find(request->client_id());
726 if (client_it == client_map_.end()) { 728 if (client_it == client_map_.end()) {
727 return; 729 return;
728 } 730 }
729 731
730 Client* client = client_it->second; 732 Client* client = client_it->second;
731 client->RemoveRequest(request); 733 client->RemoveRequest(request);
732 } 734 }
733 735
734 void ResourceScheduler::OnClientCreated(int child_id, int route_id) { 736 void ResourceScheduler::OnClientCreated(int child_id,
737 int route_id,
738 bool is_visible) {
735 DCHECK(CalledOnValidThread()); 739 DCHECK(CalledOnValidThread());
736 ClientId client_id = MakeClientId(child_id, route_id); 740 ClientId client_id = MakeClientId(child_id, route_id);
737 DCHECK(!ContainsKey(client_map_, client_id)); 741 DCHECK(!ContainsKey(client_map_, client_id));
738 742
739 Client* client = new Client(this); 743 Client* client = new Client(this, is_visible);
740 client_map_[client_id] = client; 744 client_map_[client_id] = client;
741 745
742 // TODO(aiolos): set Client visibility/audibility when signals are added 746 // TODO(aiolos): set Client visibility/audibility when signals are added
743 // this will UNTHROTTLE Clients as needed 747 // this will UNTHROTTLE Clients as needed
744 client->UpdateThrottleState(); 748 client->UpdateThrottleState();
745 } 749 }
746 750
747 void ResourceScheduler::OnClientDeleted(int child_id, int route_id) { 751 void ResourceScheduler::OnClientDeleted(int child_id, int route_id) {
748 DCHECK(CalledOnValidThread()); 752 DCHECK(CalledOnValidThread());
749 ClientId client_id = MakeClientId(child_id, route_id); 753 ClientId client_id = MakeClientId(child_id, route_id);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
826 } 830 }
827 831
828 void ResourceScheduler::OnLoadingStateChanged(int child_id, 832 void ResourceScheduler::OnLoadingStateChanged(int child_id,
829 int route_id, 833 int route_id,
830 bool is_loaded) { 834 bool is_loaded) {
831 Client* client = GetClient(child_id, route_id); 835 Client* client = GetClient(child_id, route_id);
832 DCHECK(client); 836 DCHECK(client);
833 client->OnLoadingStateChanged(is_loaded); 837 client->OnLoadingStateChanged(is_loaded);
834 } 838 }
835 839
840 bool ResourceScheduler::IsClientVisibleForTesting(int child_id, int route_id) {
841 Client* client = GetClient(child_id, route_id);
842 DCHECK(client);
843 return client->IsVisible();
844 }
845
836 ResourceScheduler::Client* ResourceScheduler::GetClient(int child_id, 846 ResourceScheduler::Client* ResourceScheduler::GetClient(int child_id,
837 int route_id) { 847 int route_id) {
838 ClientId client_id = MakeClientId(child_id, route_id); 848 ClientId client_id = MakeClientId(child_id, route_id);
839 ClientMap::iterator client_it = client_map_.find(client_id); 849 ClientMap::iterator client_it = client_map_.find(client_id);
840 if (client_it == client_map_.end()) { 850 if (client_it == client_map_.end()) {
841 return NULL; 851 return NULL;
842 } 852 }
843 return client_it->second; 853 return client_it->second;
844 } 854 }
845 855
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
960 client->ReprioritizeRequest( 970 client->ReprioritizeRequest(
961 request, old_priority_params, new_priority_params); 971 request, old_priority_params, new_priority_params);
962 } 972 }
963 973
964 ResourceScheduler::ClientId ResourceScheduler::MakeClientId( 974 ResourceScheduler::ClientId ResourceScheduler::MakeClientId(
965 int child_id, int route_id) { 975 int child_id, int route_id) {
966 return (static_cast<ResourceScheduler::ClientId>(child_id) << 32) | route_id; 976 return (static_cast<ResourceScheduler::ClientId>(child_id) << 32) | route_id;
967 } 977 }
968 978
969 } // namespace content 979 } // 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