| 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 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 | 411 |
| 412 pending_requests_.Erase(request); | 412 pending_requests_.Erase(request); |
| 413 pending_requests_.Insert(request); | 413 pending_requests_.Insert(request); |
| 414 | 414 |
| 415 if (new_priority_params.priority > old_priority_params.priority) { | 415 if (new_priority_params.priority > old_priority_params.priority) { |
| 416 // Check if this request is now able to load at its new priority. | 416 // Check if this request is now able to load at its new priority. |
| 417 LoadAnyStartablePendingRequests(); | 417 LoadAnyStartablePendingRequests(); |
| 418 } | 418 } |
| 419 } | 419 } |
| 420 | 420 |
| 421 void ReprioritizeRequests( |
| 422 const std::vector<std::pair<ScheduledResourceRequest*, |
| 423 RequestPriorityParams>>& change_requests) { |
| 424 bool do_load = false; |
| 425 |
| 426 for (auto& change_request : change_requests) { |
| 427 ScheduledResourceRequest* resource_request(change_request.first); |
| 428 const RequestPriorityParams& priority_params(change_request.second); |
| 429 |
| 430 bool is_queued = pending_requests_.IsQueued(resource_request); |
| 431 |
| 432 do_load |= is_queued && (priority_params.priority > |
| 433 resource_request->url_request()->priority()); |
| 434 |
| 435 resource_request->url_request()->SetPriority(priority_params.priority); |
| 436 resource_request->set_request_priority_params(priority_params); |
| 437 SetRequestAttributes(resource_request, |
| 438 DetermineRequestAttributes(resource_request)); |
| 439 |
| 440 if (!is_queued) |
| 441 continue; |
| 442 |
| 443 pending_requests_.Erase(resource_request); |
| 444 pending_requests_.Insert(resource_request); |
| 445 } |
| 446 |
| 447 // Check if any requests are now able to load at their new priorities. |
| 448 if (do_load) |
| 449 LoadAnyStartablePendingRequests(); |
| 450 } |
| 451 |
| 421 private: | 452 private: |
| 422 enum ShouldStartReqResult { | 453 enum ShouldStartReqResult { |
| 423 DO_NOT_START_REQUEST_AND_STOP_SEARCHING, | 454 DO_NOT_START_REQUEST_AND_STOP_SEARCHING, |
| 424 DO_NOT_START_REQUEST_AND_KEEP_SEARCHING, | 455 DO_NOT_START_REQUEST_AND_KEEP_SEARCHING, |
| 425 START_REQUEST, | 456 START_REQUEST, |
| 426 }; | 457 }; |
| 427 | 458 |
| 428 void InsertInFlightRequest(ScheduledResourceRequest* request) { | 459 void InsertInFlightRequest(ScheduledResourceRequest* request) { |
| 429 in_flight_requests_.insert(request); | 460 in_flight_requests_.insert(request); |
| 430 SetRequestAttributes(request, DetermineRequestAttributes(request)); | 461 SetRequestAttributes(request, DetermineRequestAttributes(request)); |
| (...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 909 scheduled_resource_request->set_request_priority_params( | 940 scheduled_resource_request->set_request_priority_params( |
| 910 new_priority_params); | 941 new_priority_params); |
| 911 return; | 942 return; |
| 912 } | 943 } |
| 913 | 944 |
| 914 Client* client = client_it->second; | 945 Client* client = client_it->second; |
| 915 client->ReprioritizeRequest(scheduled_resource_request, old_priority_params, | 946 client->ReprioritizeRequest(scheduled_resource_request, old_priority_params, |
| 916 new_priority_params); | 947 new_priority_params); |
| 917 } | 948 } |
| 918 | 949 |
| 950 void ResourceScheduler::ReprioritizeRequests( |
| 951 const std::vector<PriorityChangeRequest>& change_requests) { |
| 952 std::map<Client*, std::vector< |
| 953 std::pair<ScheduledResourceRequest*, RequestPriorityParams> > > |
| 954 client_requests; |
| 955 for (auto& change_request : change_requests) { |
| 956 if (change_request.request->load_flags() & net::LOAD_IGNORE_LIMITS) { |
| 957 // Requests with the IGNORE_LIMITS flag must stay at MAXIMUM_PRIORITY. |
| 958 continue; |
| 959 } |
| 960 |
| 961 auto* scheduled_resource_request = |
| 962 ScheduledResourceRequest::ForRequest(change_request.request); |
| 963 |
| 964 // Downloads don't use the resource scheduler. |
| 965 if (!scheduled_resource_request) { |
| 966 change_request.request->SetPriority(change_request.priority); |
| 967 continue; |
| 968 } |
| 969 |
| 970 RequestPriorityParams new_priority_params( |
| 971 change_request.priority, change_request.intra_priority); |
| 972 RequestPriorityParams old_priority_params = |
| 973 scheduled_resource_request->get_request_priority_params(); |
| 974 |
| 975 if (old_priority_params == new_priority_params) |
| 976 continue; |
| 977 |
| 978 ClientMap::iterator client_it = |
| 979 client_map_.find(scheduled_resource_request->client_id()); |
| 980 if (client_it == client_map_.end()) { |
| 981 // The client was likely deleted shortly before we received this IPC. |
| 982 change_request.request->SetPriority(new_priority_params.priority); |
| 983 scheduled_resource_request->set_request_priority_params( |
| 984 new_priority_params); |
| 985 continue; |
| 986 } |
| 987 |
| 988 client_requests[client_it->second].push_back(std::make_pair( |
| 989 scheduled_resource_request, new_priority_params)); |
| 990 } |
| 991 |
| 992 for (auto& client_entry : client_requests) |
| 993 client_entry.first->ReprioritizeRequests(client_entry.second); |
| 994 } |
| 995 |
| 996 |
| 919 ResourceScheduler::ClientId ResourceScheduler::MakeClientId( | 997 ResourceScheduler::ClientId ResourceScheduler::MakeClientId( |
| 920 int child_id, int route_id) { | 998 int child_id, int route_id) { |
| 921 return (static_cast<ResourceScheduler::ClientId>(child_id) << 32) | route_id; | 999 return (static_cast<ResourceScheduler::ClientId>(child_id) << 32) | route_id; |
| 922 } | 1000 } |
| 923 | 1001 |
| 924 } // namespace content | 1002 } // namespace content |
| OLD | NEW |