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 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 DCHECK(!request_->GetUserData(kUserDataKey)); | 230 DCHECK(!request_->GetUserData(kUserDataKey)); |
231 request_->SetUserData(kUserDataKey, new UnownedPointer(this)); | 231 request_->SetUserData(kUserDataKey, new UnownedPointer(this)); |
232 } | 232 } |
233 | 233 |
234 ~ScheduledResourceRequest() override { | 234 ~ScheduledResourceRequest() override { |
235 request_->RemoveUserData(kUserDataKey); | 235 request_->RemoveUserData(kUserDataKey); |
236 scheduler_->RemoveRequest(this); | 236 scheduler_->RemoveRequest(this); |
237 } | 237 } |
238 | 238 |
239 static ScheduledResourceRequest* ForRequest(net::URLRequest* request) { | 239 static ScheduledResourceRequest* ForRequest(net::URLRequest* request) { |
240 UnownedPointer* pointer = | 240 return static_cast<UnownedPointer*>(request->GetUserData(kUserDataKey)) |
241 static_cast<UnownedPointer*>(request->GetUserData(kUserDataKey)); | 241 ->get(); |
242 return pointer ? pointer->get() : nullptr; | |
243 } | 242 } |
244 | 243 |
245 // Starts the request. If |start_mode| is START_ASYNC, the request will not | 244 // Starts the request. If |start_mode| is START_ASYNC, the request will not |
246 // be started immediately. | 245 // be started immediately. |
247 void Start(StartMode start_mode) { | 246 void Start(StartMode start_mode) { |
248 DCHECK(!ready_); | 247 DCHECK(!ready_); |
249 | 248 |
250 // If the request was cancelled, do nothing. | 249 // If the request was cancelled, do nothing. |
251 if (!request_->status().is_success()) | 250 if (!request_->status().is_success()) |
252 return; | 251 return; |
(...skipping 821 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1074 scheduled_resource_request->set_request_priority_params( | 1073 scheduled_resource_request->set_request_priority_params( |
1075 new_priority_params); | 1074 new_priority_params); |
1076 return; | 1075 return; |
1077 } | 1076 } |
1078 | 1077 |
1079 Client* client = client_it->second; | 1078 Client* client = client_it->second; |
1080 client->ReprioritizeRequest(scheduled_resource_request, old_priority_params, | 1079 client->ReprioritizeRequest(scheduled_resource_request, old_priority_params, |
1081 new_priority_params); | 1080 new_priority_params); |
1082 } | 1081 } |
1083 | 1082 |
1084 void ResourceScheduler::ReprioritizeRequest(net::URLRequest* request, | |
1085 net::RequestPriority new_priority) { | |
1086 int current_intra_priority = 0; | |
1087 auto* existing_request = ScheduledResourceRequest::ForRequest(request); | |
1088 if (existing_request) { | |
1089 current_intra_priority = | |
1090 existing_request->get_request_priority_params().intra_priority; | |
1091 } | |
1092 ReprioritizeRequest(request, new_priority, current_intra_priority); | |
1093 } | |
1094 | |
1095 ResourceScheduler::ClientId ResourceScheduler::MakeClientId( | 1083 ResourceScheduler::ClientId ResourceScheduler::MakeClientId( |
1096 int child_id, int route_id) { | 1084 int child_id, int route_id) { |
1097 return (static_cast<ResourceScheduler::ClientId>(child_id) << 32) | route_id; | 1085 return (static_cast<ResourceScheduler::ClientId>(child_id) << 32) | route_id; |
1098 } | 1086 } |
1099 | 1087 |
1100 } // namespace content | 1088 } // namespace content |
OLD | NEW |