| 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 "content/browser/loader/resource_scheduler.h" | 5 #include "content/browser/loader/resource_scheduler.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 876 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 887 : priority_requests_delayable_( | 887 : priority_requests_delayable_( |
| 888 base::FeatureList::IsEnabled(kPrioritySupportedRequestsDelayable)), | 888 base::FeatureList::IsEnabled(kPrioritySupportedRequestsDelayable)), |
| 889 yielding_scheduler_enabled_( | 889 yielding_scheduler_enabled_( |
| 890 base::FeatureList::IsEnabled(kNetworkSchedulerYielding)), | 890 base::FeatureList::IsEnabled(kNetworkSchedulerYielding)), |
| 891 max_requests_before_yielding_(base::GetFieldTrialParamByFeatureAsInt( | 891 max_requests_before_yielding_(base::GetFieldTrialParamByFeatureAsInt( |
| 892 kNetworkSchedulerYielding, | 892 kNetworkSchedulerYielding, |
| 893 kMaxRequestsBeforeYieldingParam, | 893 kMaxRequestsBeforeYieldingParam, |
| 894 kMaxRequestsBeforeYieldingDefault)) {} | 894 kMaxRequestsBeforeYieldingDefault)) {} |
| 895 | 895 |
| 896 ResourceScheduler::~ResourceScheduler() { | 896 ResourceScheduler::~ResourceScheduler() { |
| 897 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 897 DCHECK(unowned_requests_.empty()); | 898 DCHECK(unowned_requests_.empty()); |
| 898 DCHECK(client_map_.empty()); | 899 DCHECK(client_map_.empty()); |
| 899 } | 900 } |
| 900 | 901 |
| 901 std::unique_ptr<ResourceThrottle> ResourceScheduler::ScheduleRequest( | 902 std::unique_ptr<ResourceThrottle> ResourceScheduler::ScheduleRequest( |
| 902 int child_id, | 903 int child_id, |
| 903 int route_id, | 904 int route_id, |
| 904 bool is_async, | 905 bool is_async, |
| 905 net::URLRequest* url_request) { | 906 net::URLRequest* url_request) { |
| 906 DCHECK(CalledOnValidThread()); | 907 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 907 ClientId client_id = MakeClientId(child_id, route_id); | 908 ClientId client_id = MakeClientId(child_id, route_id); |
| 908 std::unique_ptr<ScheduledResourceRequest> request( | 909 std::unique_ptr<ScheduledResourceRequest> request( |
| 909 new ScheduledResourceRequest( | 910 new ScheduledResourceRequest( |
| 910 client_id, url_request, this, | 911 client_id, url_request, this, |
| 911 RequestPriorityParams(url_request->priority(), 0), is_async)); | 912 RequestPriorityParams(url_request->priority(), 0), is_async)); |
| 912 | 913 |
| 913 ClientMap::iterator it = client_map_.find(client_id); | 914 ClientMap::iterator it = client_map_.find(client_id); |
| 914 if (it == client_map_.end()) { | 915 if (it == client_map_.end()) { |
| 915 // There are several ways this could happen: | 916 // There are several ways this could happen: |
| 916 // 1. <a ping> requests don't have a route_id. | 917 // 1. <a ping> requests don't have a route_id. |
| 917 // 2. Most unittests don't send the IPCs needed to register Clients. | 918 // 2. Most unittests don't send the IPCs needed to register Clients. |
| 918 // 3. The tab is closed while a RequestResource IPC is in flight. | 919 // 3. The tab is closed while a RequestResource IPC is in flight. |
| 919 unowned_requests_.insert(request.get()); | 920 unowned_requests_.insert(request.get()); |
| 920 request->Start(START_SYNC); | 921 request->Start(START_SYNC); |
| 921 return std::move(request); | 922 return std::move(request); |
| 922 } | 923 } |
| 923 | 924 |
| 924 Client* client = it->second; | 925 Client* client = it->second; |
| 925 client->ScheduleRequest(url_request, request.get()); | 926 client->ScheduleRequest(url_request, request.get()); |
| 926 return std::move(request); | 927 return std::move(request); |
| 927 } | 928 } |
| 928 | 929 |
| 929 void ResourceScheduler::RemoveRequest(ScheduledResourceRequest* request) { | 930 void ResourceScheduler::RemoveRequest(ScheduledResourceRequest* request) { |
| 930 DCHECK(CalledOnValidThread()); | 931 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 931 if (base::ContainsKey(unowned_requests_, request)) { | 932 if (base::ContainsKey(unowned_requests_, request)) { |
| 932 unowned_requests_.erase(request); | 933 unowned_requests_.erase(request); |
| 933 return; | 934 return; |
| 934 } | 935 } |
| 935 | 936 |
| 936 ClientMap::iterator client_it = client_map_.find(request->client_id()); | 937 ClientMap::iterator client_it = client_map_.find(request->client_id()); |
| 937 if (client_it == client_map_.end()) { | 938 if (client_it == client_map_.end()) { |
| 938 return; | 939 return; |
| 939 } | 940 } |
| 940 | 941 |
| 941 Client* client = client_it->second; | 942 Client* client = client_it->second; |
| 942 client->RemoveRequest(request); | 943 client->RemoveRequest(request); |
| 943 } | 944 } |
| 944 | 945 |
| 945 void ResourceScheduler::OnClientCreated(int child_id, | 946 void ResourceScheduler::OnClientCreated(int child_id, |
| 946 int route_id) { | 947 int route_id) { |
| 947 DCHECK(CalledOnValidThread()); | 948 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 948 ClientId client_id = MakeClientId(child_id, route_id); | 949 ClientId client_id = MakeClientId(child_id, route_id); |
| 949 DCHECK(!base::ContainsKey(client_map_, client_id)); | 950 DCHECK(!base::ContainsKey(client_map_, client_id)); |
| 950 | 951 |
| 951 Client* client = | 952 Client* client = |
| 952 new Client(priority_requests_delayable_, yielding_scheduler_enabled_, | 953 new Client(priority_requests_delayable_, yielding_scheduler_enabled_, |
| 953 max_requests_before_yielding_); | 954 max_requests_before_yielding_); |
| 954 client_map_[client_id] = client; | 955 client_map_[client_id] = client; |
| 955 } | 956 } |
| 956 | 957 |
| 957 void ResourceScheduler::OnClientDeleted(int child_id, int route_id) { | 958 void ResourceScheduler::OnClientDeleted(int child_id, int route_id) { |
| 958 DCHECK(CalledOnValidThread()); | 959 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 959 ClientId client_id = MakeClientId(child_id, route_id); | 960 ClientId client_id = MakeClientId(child_id, route_id); |
| 960 ClientMap::iterator it = client_map_.find(client_id); | 961 ClientMap::iterator it = client_map_.find(client_id); |
| 961 DCHECK(it != client_map_.end()); | 962 DCHECK(it != client_map_.end()); |
| 962 | 963 |
| 963 Client* client = it->second; | 964 Client* client = it->second; |
| 964 // ResourceDispatcherHost cancels all requests except for cross-renderer | 965 // ResourceDispatcherHost cancels all requests except for cross-renderer |
| 965 // navigations, async revalidations and detachable requests after | 966 // navigations, async revalidations and detachable requests after |
| 966 // OnClientDeleted() returns. | 967 // OnClientDeleted() returns. |
| 967 RequestSet client_unowned_requests = client->StartAndRemoveAllRequests(); | 968 RequestSet client_unowned_requests = client->StartAndRemoveAllRequests(); |
| 968 for (RequestSet::iterator it = client_unowned_requests.begin(); | 969 for (RequestSet::iterator it = client_unowned_requests.begin(); |
| 969 it != client_unowned_requests.end(); ++it) { | 970 it != client_unowned_requests.end(); ++it) { |
| 970 unowned_requests_.insert(*it); | 971 unowned_requests_.insert(*it); |
| 971 } | 972 } |
| 972 | 973 |
| 973 delete client; | 974 delete client; |
| 974 client_map_.erase(it); | 975 client_map_.erase(it); |
| 975 } | 976 } |
| 976 | 977 |
| 977 void ResourceScheduler::OnLoadingStateChanged(int child_id, | 978 void ResourceScheduler::OnLoadingStateChanged(int child_id, |
| 978 int route_id, | 979 int route_id, |
| 979 bool is_loaded) { | 980 bool is_loaded) { |
| 980 Client* client = GetClient(child_id, route_id); | 981 Client* client = GetClient(child_id, route_id); |
| 981 DCHECK(client); | 982 DCHECK(client); |
| 982 client->OnLoadingStateChanged(is_loaded); | 983 client->OnLoadingStateChanged(is_loaded); |
| 983 } | 984 } |
| 984 | 985 |
| 985 void ResourceScheduler::OnNavigate(int child_id, int route_id) { | 986 void ResourceScheduler::OnNavigate(int child_id, int route_id) { |
| 986 DCHECK(CalledOnValidThread()); | 987 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 987 ClientId client_id = MakeClientId(child_id, route_id); | 988 ClientId client_id = MakeClientId(child_id, route_id); |
| 988 | 989 |
| 989 ClientMap::iterator it = client_map_.find(client_id); | 990 ClientMap::iterator it = client_map_.find(client_id); |
| 990 if (it == client_map_.end()) { | 991 if (it == client_map_.end()) { |
| 991 // The client was likely deleted shortly before we received this IPC. | 992 // The client was likely deleted shortly before we received this IPC. |
| 992 return; | 993 return; |
| 993 } | 994 } |
| 994 | 995 |
| 995 Client* client = it->second; | 996 Client* client = it->second; |
| 996 client->OnNavigate(); | 997 client->OnNavigate(); |
| 997 } | 998 } |
| 998 | 999 |
| 999 void ResourceScheduler::OnWillInsertBody(int child_id, int route_id) { | 1000 void ResourceScheduler::OnWillInsertBody(int child_id, int route_id) { |
| 1000 DCHECK(CalledOnValidThread()); | 1001 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 1001 ClientId client_id = MakeClientId(child_id, route_id); | 1002 ClientId client_id = MakeClientId(child_id, route_id); |
| 1002 | 1003 |
| 1003 ClientMap::iterator it = client_map_.find(client_id); | 1004 ClientMap::iterator it = client_map_.find(client_id); |
| 1004 if (it == client_map_.end()) { | 1005 if (it == client_map_.end()) { |
| 1005 // The client was likely deleted shortly before we received this IPC. | 1006 // The client was likely deleted shortly before we received this IPC. |
| 1006 return; | 1007 return; |
| 1007 } | 1008 } |
| 1008 | 1009 |
| 1009 Client* client = it->second; | 1010 Client* client = it->second; |
| 1010 client->OnWillInsertBody(); | 1011 client->OnWillInsertBody(); |
| 1011 } | 1012 } |
| 1012 | 1013 |
| 1013 void ResourceScheduler::OnReceivedSpdyProxiedHttpResponse( | 1014 void ResourceScheduler::OnReceivedSpdyProxiedHttpResponse( |
| 1014 int child_id, | 1015 int child_id, |
| 1015 int route_id) { | 1016 int route_id) { |
| 1016 DCHECK(CalledOnValidThread()); | 1017 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 1017 ClientId client_id = MakeClientId(child_id, route_id); | 1018 ClientId client_id = MakeClientId(child_id, route_id); |
| 1018 | 1019 |
| 1019 ClientMap::iterator client_it = client_map_.find(client_id); | 1020 ClientMap::iterator client_it = client_map_.find(client_id); |
| 1020 if (client_it == client_map_.end()) { | 1021 if (client_it == client_map_.end()) { |
| 1021 return; | 1022 return; |
| 1022 } | 1023 } |
| 1023 | 1024 |
| 1024 Client* client = client_it->second; | 1025 Client* client = client_it->second; |
| 1025 client->OnReceivedSpdyProxiedHttpResponse(); | 1026 client->OnReceivedSpdyProxiedHttpResponse(); |
| 1026 } | 1027 } |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1093 } | 1094 } |
| 1094 ReprioritizeRequest(request, new_priority, current_intra_priority); | 1095 ReprioritizeRequest(request, new_priority, current_intra_priority); |
| 1095 } | 1096 } |
| 1096 | 1097 |
| 1097 ResourceScheduler::ClientId ResourceScheduler::MakeClientId( | 1098 ResourceScheduler::ClientId ResourceScheduler::MakeClientId( |
| 1098 int child_id, int route_id) { | 1099 int child_id, int route_id) { |
| 1099 return (static_cast<ResourceScheduler::ClientId>(child_id) << 32) | route_id; | 1100 return (static_cast<ResourceScheduler::ClientId>(child_id) << 32) | route_id; |
| 1100 } | 1101 } |
| 1101 | 1102 |
| 1102 } // namespace content | 1103 } // namespace content |
| OLD | NEW |