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

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

Issue 562273008: Add audio signal to the ResourceScheduler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 6 years, 2 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 #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 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 void ResourceScheduler::RequestQueue::Insert( 222 void ResourceScheduler::RequestQueue::Insert(
223 ScheduledResourceRequest* request) { 223 ScheduledResourceRequest* request) {
224 DCHECK(!ContainsKey(pointers_, request)); 224 DCHECK(!ContainsKey(pointers_, request));
225 request->set_fifo_ordering(MakeFifoOrderingId()); 225 request->set_fifo_ordering(MakeFifoOrderingId());
226 pointers_[request] = queue_.insert(request); 226 pointers_[request] = queue_.insert(request);
227 } 227 }
228 228
229 // Each client represents a tab. 229 // Each client represents a tab.
230 class ResourceScheduler::Client { 230 class ResourceScheduler::Client {
231 public: 231 public:
232 explicit Client(ResourceScheduler* scheduler, bool is_visible) 232 explicit Client(ResourceScheduler* scheduler,
233 : is_audible_(false), 233 bool is_visible,
234 bool is_audible)
235 : is_audible_(is_audible),
234 is_visible_(is_visible), 236 is_visible_(is_visible),
235 is_loaded_(false), 237 is_loaded_(false),
236 is_paused_(false), 238 is_paused_(false),
237 has_body_(false), 239 has_body_(false),
238 using_spdy_proxy_(false), 240 using_spdy_proxy_(false),
239 in_flight_delayable_count_(0), 241 in_flight_delayable_count_(0),
240 total_layout_blocking_count_(0), 242 total_layout_blocking_count_(0),
241 throttle_state_(ResourceScheduler::THROTTLED) { 243 throttle_state_(ResourceScheduler::THROTTLED) {
242 scheduler_ = scheduler; 244 scheduler_ = scheduler;
243 } 245 }
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 if (client_it == client_map_.end()) { 781 if (client_it == client_map_.end()) {
780 return; 782 return;
781 } 783 }
782 784
783 Client* client = client_it->second; 785 Client* client = client_it->second;
784 client->RemoveRequest(request); 786 client->RemoveRequest(request);
785 } 787 }
786 788
787 void ResourceScheduler::OnClientCreated(int child_id, 789 void ResourceScheduler::OnClientCreated(int child_id,
788 int route_id, 790 int route_id,
789 bool is_visible) { 791 bool is_visible,
792 bool is_audible) {
790 DCHECK(CalledOnValidThread()); 793 DCHECK(CalledOnValidThread());
791 ClientId client_id = MakeClientId(child_id, route_id); 794 ClientId client_id = MakeClientId(child_id, route_id);
792 DCHECK(!ContainsKey(client_map_, client_id)); 795 DCHECK(!ContainsKey(client_map_, client_id));
793 796
794 Client* client = new Client(this, is_visible); 797 Client* client = new Client(this, is_visible, is_audible);
795 client_map_[client_id] = client; 798 client_map_[client_id] = client;
796 799
797 // TODO(aiolos): set Client visibility/audibility when signals are added 800 // TODO(aiolos): set Client visibility/audibility when signals are added
798 // this will UNTHROTTLE Clients as needed 801 // this will UNTHROTTLE Clients as needed
799 client->UpdateThrottleState(); 802 client->UpdateThrottleState();
800 } 803 }
801 804
802 void ResourceScheduler::OnClientDeleted(int child_id, int route_id) { 805 void ResourceScheduler::OnClientDeleted(int child_id, int route_id) {
803 DCHECK(CalledOnValidThread()); 806 DCHECK(CalledOnValidThread());
804 ClientId client_id = MakeClientId(child_id, route_id); 807 ClientId client_id = MakeClientId(child_id, route_id);
805 DCHECK(ContainsKey(client_map_, client_id)); 808 DCHECK(ContainsKey(client_map_, client_id));
806 ClientMap::iterator it = client_map_.find(client_id); 809 ClientMap::iterator it = client_map_.find(client_id);
807 if (it == client_map_.end()) 810 if (it == client_map_.end())
808 return; 811 return;
809 812
810 Client* client = it->second; 813 Client* client = it->second;
811 // FYI, ResourceDispatcherHost cancels all of the requests after this function 814 // FYI, ResourceDispatcherHost cancels all of the requests after this function
812 // is called. It should end up canceling all of the requests except for a 815 // is called. It should end up canceling all of the requests except for a
813 // cross-renderer navigation. 816 // cross-renderer navigation.
814 RequestSet client_unowned_requests = client->RemoveAllRequests(); 817 RequestSet client_unowned_requests = client->RemoveAllRequests();
815 for (RequestSet::iterator it = client_unowned_requests.begin(); 818 for (RequestSet::iterator it = client_unowned_requests.begin();
816 it != client_unowned_requests.end(); ++it) { 819 it != client_unowned_requests.end(); ++it) {
817 unowned_requests_.insert(*it); 820 unowned_requests_.insert(*it);
818 } 821 }
819 822
820 delete client; 823 delete client;
821 client_map_.erase(it); 824 client_map_.erase(it);
822 } 825 }
823 826
827 void ResourceScheduler::OnLoadingStateChanged(int child_id,
828 int route_id,
829 bool is_loaded) {
830 Client* client = GetClient(child_id, route_id);
831 DCHECK(client);
832 client->OnLoadingStateChanged(is_loaded);
833 }
834
824 void ResourceScheduler::OnVisibilityChanged(int child_id, 835 void ResourceScheduler::OnVisibilityChanged(int child_id,
825 int route_id, 836 int route_id,
826 bool is_visible) { 837 bool is_visible) {
827 Client* client = GetClient(child_id, route_id); 838 Client* client = GetClient(child_id, route_id);
828 DCHECK(client); 839 DCHECK(client);
829 client->OnVisibilityChanged(is_visible); 840 client->OnVisibilityChanged(is_visible);
830 } 841 }
831 842
832 void ResourceScheduler::OnLoadingStateChanged(int child_id, 843 void ResourceScheduler::OnAudibilityChanged(int child_id,
833 int route_id, 844 int route_id,
834 bool is_loaded) { 845 bool is_audible) {
835 Client* client = GetClient(child_id, route_id); 846 Client* client = GetClient(child_id, route_id);
836 DCHECK(client); 847 // We might get this call after the client has been deleted.
837 client->OnLoadingStateChanged(is_loaded); 848 if (client)
849 client->OnAudibilityChanged(is_audible);
838 } 850 }
839 851
840 void ResourceScheduler::OnNavigate(int child_id, int route_id) { 852 void ResourceScheduler::OnNavigate(int child_id, int route_id) {
841 DCHECK(CalledOnValidThread()); 853 DCHECK(CalledOnValidThread());
842 ClientId client_id = MakeClientId(child_id, route_id); 854 ClientId client_id = MakeClientId(child_id, route_id);
843 855
844 ClientMap::iterator it = client_map_.find(client_id); 856 ClientMap::iterator it = client_map_.find(client_id);
845 if (it == client_map_.end()) { 857 if (it == client_map_.end()) {
846 // The client was likely deleted shortly before we received this IPC. 858 // The client was likely deleted shortly before we received this IPC.
847 return; 859 return;
(...skipping 25 matching lines...) Expand all
873 885
874 ClientMap::iterator client_it = client_map_.find(client_id); 886 ClientMap::iterator client_it = client_map_.find(client_id);
875 if (client_it == client_map_.end()) { 887 if (client_it == client_map_.end()) {
876 return; 888 return;
877 } 889 }
878 890
879 Client* client = client_it->second; 891 Client* client = client_it->second;
880 client->OnReceivedSpdyProxiedHttpResponse(); 892 client->OnReceivedSpdyProxiedHttpResponse();
881 } 893 }
882 894
883 void ResourceScheduler::OnAudibilityChanged(int child_id,
884 int route_id,
885 bool is_audible) {
886 Client* client = GetClient(child_id, route_id);
887 DCHECK(client);
888 client->OnAudibilityChanged(is_audible);
889 }
890
891 bool ResourceScheduler::IsClientVisibleForTesting(int child_id, int route_id) { 895 bool ResourceScheduler::IsClientVisibleForTesting(int child_id, int route_id) {
892 Client* client = GetClient(child_id, route_id); 896 Client* client = GetClient(child_id, route_id);
893 DCHECK(client); 897 DCHECK(client);
894 return client->is_visible(); 898 return client->is_visible();
895 } 899 }
896 900
897 ResourceScheduler::Client* ResourceScheduler::GetClient(int child_id, 901 ResourceScheduler::Client* ResourceScheduler::GetClient(int child_id,
898 int route_id) { 902 int route_id) {
899 ClientId client_id = MakeClientId(child_id, route_id); 903 ClientId client_id = MakeClientId(child_id, route_id);
900 ClientMap::iterator client_it = client_map_.find(client_id); 904 ClientMap::iterator client_it = client_map_.find(client_id);
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
1021 client->ReprioritizeRequest( 1025 client->ReprioritizeRequest(
1022 request, old_priority_params, new_priority_params); 1026 request, old_priority_params, new_priority_params);
1023 } 1027 }
1024 1028
1025 ResourceScheduler::ClientId ResourceScheduler::MakeClientId( 1029 ResourceScheduler::ClientId ResourceScheduler::MakeClientId(
1026 int child_id, int route_id) { 1030 int child_id, int route_id) {
1027 return (static_cast<ResourceScheduler::ClientId>(child_id) << 32) | route_id; 1031 return (static_cast<ResourceScheduler::ClientId>(child_id) << 32) | route_id;
1028 } 1032 }
1029 1033
1030 } // namespace content 1034 } // 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