| 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/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 pending_requests_.Erase(request); | 340 pending_requests_.Erase(request); |
| 341 DCHECK(!ContainsKey(in_flight_requests_, request)); | 341 DCHECK(!ContainsKey(in_flight_requests_, request)); |
| 342 } else { | 342 } else { |
| 343 EraseInFlightRequest(request); | 343 EraseInFlightRequest(request); |
| 344 | 344 |
| 345 // Removing this request may have freed up another to load. | 345 // Removing this request may have freed up another to load. |
| 346 LoadAnyStartablePendingRequests(); | 346 LoadAnyStartablePendingRequests(); |
| 347 } | 347 } |
| 348 } | 348 } |
| 349 | 349 |
| 350 RequestSet RemoveAllRequests() { | 350 RequestSet StartAndRemoveAllRequests() { |
| 351 // First start any pending requests so that they will be moved into |
| 352 // in_flight_requests_. This may exceed the limits |
| 353 // kMaxNumDelayableRequestsPerClient, kMaxNumDelayableRequestsPerHost and |
| 354 // kMaxNumThrottledRequestsPerClient, so this method must not do anything |
| 355 // that depends on those limits before calling ClearInFlightRequests() |
| 356 // below. |
| 357 while (!pending_requests_.IsEmpty()) { |
| 358 ScheduledResourceRequest* request = |
| 359 *pending_requests_.GetNextHighestIterator(); |
| 360 pending_requests_.Erase(request); |
| 361 // StartRequest() may modify pending_requests_. TODO(ricea): Does it? |
| 362 StartRequest(request); |
| 363 } |
| 351 RequestSet unowned_requests; | 364 RequestSet unowned_requests; |
| 352 for (RequestSet::iterator it = in_flight_requests_.begin(); | 365 for (RequestSet::iterator it = in_flight_requests_.begin(); |
| 353 it != in_flight_requests_.end(); ++it) { | 366 it != in_flight_requests_.end(); ++it) { |
| 354 unowned_requests.insert(*it); | 367 unowned_requests.insert(*it); |
| 355 (*it)->set_classification(NORMAL_REQUEST); | 368 (*it)->set_classification(NORMAL_REQUEST); |
| 356 } | 369 } |
| 357 ClearInFlightRequests(); | 370 ClearInFlightRequests(); |
| 358 return unowned_requests; | 371 return unowned_requests; |
| 359 } | 372 } |
| 360 | 373 |
| (...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 952 | 965 |
| 953 void ResourceScheduler::OnClientDeleted(int child_id, int route_id) { | 966 void ResourceScheduler::OnClientDeleted(int child_id, int route_id) { |
| 954 DCHECK(CalledOnValidThread()); | 967 DCHECK(CalledOnValidThread()); |
| 955 ClientId client_id = MakeClientId(child_id, route_id); | 968 ClientId client_id = MakeClientId(child_id, route_id); |
| 956 DCHECK(ContainsKey(client_map_, client_id)); | 969 DCHECK(ContainsKey(client_map_, client_id)); |
| 957 ClientMap::iterator it = client_map_.find(client_id); | 970 ClientMap::iterator it = client_map_.find(client_id); |
| 958 if (it == client_map_.end()) | 971 if (it == client_map_.end()) |
| 959 return; | 972 return; |
| 960 | 973 |
| 961 Client* client = it->second; | 974 Client* client = it->second; |
| 962 // FYI, ResourceDispatcherHost cancels all of the requests after this function | 975 // ResourceDispatcherHost cancels all requests except for cross-renderer |
| 963 // is called. It should end up canceling all of the requests except for a | 976 // navigations, async revalidations and detachable requests after |
| 964 // cross-renderer navigation. | 977 // OnClientDeleted() returns. |
| 965 RequestSet client_unowned_requests = client->RemoveAllRequests(); | 978 RequestSet client_unowned_requests = client->StartAndRemoveAllRequests(); |
| 966 for (RequestSet::iterator it = client_unowned_requests.begin(); | 979 for (RequestSet::iterator it = client_unowned_requests.begin(); |
| 967 it != client_unowned_requests.end(); ++it) { | 980 it != client_unowned_requests.end(); ++it) { |
| 968 unowned_requests_.insert(*it); | 981 unowned_requests_.insert(*it); |
| 969 } | 982 } |
| 970 | 983 |
| 971 delete client; | 984 delete client; |
| 972 client_map_.erase(it); | 985 client_map_.erase(it); |
| 973 } | 986 } |
| 974 | 987 |
| 975 void ResourceScheduler::OnLoadingStateChanged(int child_id, | 988 void ResourceScheduler::OnLoadingStateChanged(int child_id, |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1189 client->ReprioritizeRequest( | 1202 client->ReprioritizeRequest( |
| 1190 request, old_priority_params, new_priority_params); | 1203 request, old_priority_params, new_priority_params); |
| 1191 } | 1204 } |
| 1192 | 1205 |
| 1193 ResourceScheduler::ClientId ResourceScheduler::MakeClientId( | 1206 ResourceScheduler::ClientId ResourceScheduler::MakeClientId( |
| 1194 int child_id, int route_id) { | 1207 int child_id, int route_id) { |
| 1195 return (static_cast<ResourceScheduler::ClientId>(child_id) << 32) | route_id; | 1208 return (static_cast<ResourceScheduler::ClientId>(child_id) << 32) | route_id; |
| 1196 } | 1209 } |
| 1197 | 1210 |
| 1198 } // namespace content | 1211 } // namespace content |
| OLD | NEW |