| 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 #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 Loading... |
| 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 Loading... |
| 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 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 |
| OLD | NEW |