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

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

Issue 2488323002: Cache net::HostPortPair in ResourceScheduler::ScheduledResourceRequest (Closed)
Patch Set: make it const Created 4 years, 1 month 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 bool is_async) 171 bool is_async)
172 : client_id_(client_id), 172 : client_id_(client_id),
173 request_(request), 173 request_(request),
174 ready_(false), 174 ready_(false),
175 deferred_(false), 175 deferred_(false),
176 is_async_(is_async), 176 is_async_(is_async),
177 attributes_(kAttributeNone), 177 attributes_(kAttributeNone),
178 scheduler_(scheduler), 178 scheduler_(scheduler),
179 priority_(priority), 179 priority_(priority),
180 fifo_ordering_(0), 180 fifo_ordering_(0),
181 host_port_pair_(net::HostPortPair::FromURL(request->url())),
181 weak_ptr_factory_(this) { 182 weak_ptr_factory_(this) {
182 DCHECK(!request_->GetUserData(kUserDataKey)); 183 DCHECK(!request_->GetUserData(kUserDataKey));
183 request_->SetUserData(kUserDataKey, new UnownedPointer(this)); 184 request_->SetUserData(kUserDataKey, new UnownedPointer(this));
184 } 185 }
185 186
186 ~ScheduledResourceRequest() override { 187 ~ScheduledResourceRequest() override {
187 request_->RemoveUserData(kUserDataKey); 188 request_->RemoveUserData(kUserDataKey);
188 scheduler_->RemoveRequest(this); 189 scheduler_->RemoveRequest(this);
189 } 190 }
190 191
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 uint32_t fifo_ordering() const { return fifo_ordering_; } 237 uint32_t fifo_ordering() const { return fifo_ordering_; }
237 void set_fifo_ordering(uint32_t fifo_ordering) { 238 void set_fifo_ordering(uint32_t fifo_ordering) {
238 fifo_ordering_ = fifo_ordering; 239 fifo_ordering_ = fifo_ordering;
239 } 240 }
240 RequestAttributes attributes() const { 241 RequestAttributes attributes() const {
241 return attributes_; 242 return attributes_;
242 } 243 }
243 void set_attributes(RequestAttributes attributes) { 244 void set_attributes(RequestAttributes attributes) {
244 attributes_ = attributes; 245 attributes_ = attributes;
245 } 246 }
247 const net::HostPortPair host_port_pair() { return host_port_pair_; }
mmenke 2016/11/10 19:11:37 return by reference?
mmenke 2016/11/10 19:15:26 Also +1 const: const net::HostPortPair& host_port
Charlie Harrison 2016/11/10 19:15:41 Oops, typo. Done :)
Charlie Harrison 2016/11/10 19:17:10 Done.
246 248
247 private: 249 private:
248 class UnownedPointer : public base::SupportsUserData::Data { 250 class UnownedPointer : public base::SupportsUserData::Data {
249 public: 251 public:
250 explicit UnownedPointer(ScheduledResourceRequest* pointer) 252 explicit UnownedPointer(ScheduledResourceRequest* pointer)
251 : pointer_(pointer) {} 253 : pointer_(pointer) {}
252 254
253 ScheduledResourceRequest* get() const { return pointer_; } 255 ScheduledResourceRequest* get() const { return pointer_; }
254 256
255 private: 257 private:
(...skipping 13 matching lines...) Expand all
269 271
270 const ClientId client_id_; 272 const ClientId client_id_;
271 net::URLRequest* request_; 273 net::URLRequest* request_;
272 bool ready_; 274 bool ready_;
273 bool deferred_; 275 bool deferred_;
274 bool is_async_; 276 bool is_async_;
275 RequestAttributes attributes_; 277 RequestAttributes attributes_;
276 ResourceScheduler* scheduler_; 278 ResourceScheduler* scheduler_;
277 RequestPriorityParams priority_; 279 RequestPriorityParams priority_;
278 uint32_t fifo_ordering_; 280 uint32_t fifo_ordering_;
281 // Cached to excessive recomputation in ShouldKeepSearching.
282 const net::HostPortPair host_port_pair_;
279 283
280 base::WeakPtrFactory<ResourceScheduler::ScheduledResourceRequest> 284 base::WeakPtrFactory<ResourceScheduler::ScheduledResourceRequest>
281 weak_ptr_factory_; 285 weak_ptr_factory_;
282 286
283 DISALLOW_COPY_AND_ASSIGN(ScheduledResourceRequest); 287 DISALLOW_COPY_AND_ASSIGN(ScheduledResourceRequest);
284 }; 288 };
285 289
286 const void* const ResourceScheduler::ScheduledResourceRequest::kUserDataKey = 290 const void* const ResourceScheduler::ScheduledResourceRequest::kUserDataKey =
287 &ResourceScheduler::ScheduledResourceRequest::kUserDataKey; 291 &ResourceScheduler::ScheduledResourceRequest::kUserDataKey;
288 292
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 } 543 }
540 544
541 return attributes; 545 return attributes;
542 } 546 }
543 547
544 bool ShouldKeepSearching( 548 bool ShouldKeepSearching(
545 const net::HostPortPair& active_request_host) const { 549 const net::HostPortPair& active_request_host) const {
546 size_t same_host_count = 0; 550 size_t same_host_count = 0;
547 for (RequestSet::const_iterator it = in_flight_requests_.begin(); 551 for (RequestSet::const_iterator it = in_flight_requests_.begin();
548 it != in_flight_requests_.end(); ++it) { 552 it != in_flight_requests_.end(); ++it) {
549 net::HostPortPair host_port_pair = 553 net::HostPortPair host_port_pair = (*it)->host_port_pair();
mmenke 2016/11/10 19:11:37 Store as a const ref, or just inline? Not sure ho
Charlie Harrison 2016/11/10 19:15:41 Done.
550 net::HostPortPair::FromURL((*it)->url_request()->url());
551 if (active_request_host.Equals(host_port_pair)) { 554 if (active_request_host.Equals(host_port_pair)) {
552 same_host_count++; 555 same_host_count++;
553 if (same_host_count >= kMaxNumDelayableRequestsPerHostPerClient) 556 if (same_host_count >= kMaxNumDelayableRequestsPerHostPerClient)
554 return true; 557 return true;
555 } 558 }
556 } 559 }
557 return false; 560 return false;
558 } 561 }
559 562
560 void StartRequest(ScheduledResourceRequest* request, 563 void StartRequest(ScheduledResourceRequest* request,
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 // Syncronous requests could block the entire render, which could impact 606 // Syncronous requests could block the entire render, which could impact
604 // user-observable Clients. 607 // user-observable Clients.
605 if (!request->is_async()) 608 if (!request->is_async())
606 return START_REQUEST; 609 return START_REQUEST;
607 610
608 // TODO(simonjam): This may end up causing disk contention. We should 611 // TODO(simonjam): This may end up causing disk contention. We should
609 // experiment with throttling if that happens. 612 // experiment with throttling if that happens.
610 if (!url_request.url().SchemeIsHTTPOrHTTPS()) 613 if (!url_request.url().SchemeIsHTTPOrHTTPS())
611 return START_REQUEST; 614 return START_REQUEST;
612 615
613 net::HostPortPair host_port_pair = 616 net::HostPortPair host_port_pair = request->host_port_pair();
Charlie Harrison 2016/11/10 19:15:41 I also made this const &.
614 net::HostPortPair::FromURL(url_request.url());
615 617
616 if (!priority_requests_delayable_) { 618 if (!priority_requests_delayable_) {
617 if (using_spdy_proxy_ && url_request.url().SchemeIs(url::kHttpScheme)) 619 if (using_spdy_proxy_ && url_request.url().SchemeIs(url::kHttpScheme))
618 return START_REQUEST; 620 return START_REQUEST;
619 621
620 url::SchemeHostPort scheme_host_port(url_request.url()); 622 url::SchemeHostPort scheme_host_port(url_request.url());
621 623
622 net::HttpServerProperties& http_server_properties = 624 net::HttpServerProperties& http_server_properties =
623 *url_request.context()->http_server_properties(); 625 *url_request.context()->http_server_properties();
624 626
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
914 client->ReprioritizeRequest(scheduled_resource_request, old_priority_params, 916 client->ReprioritizeRequest(scheduled_resource_request, old_priority_params,
915 new_priority_params); 917 new_priority_params);
916 } 918 }
917 919
918 ResourceScheduler::ClientId ResourceScheduler::MakeClientId( 920 ResourceScheduler::ClientId ResourceScheduler::MakeClientId(
919 int child_id, int route_id) { 921 int child_id, int route_id) {
920 return (static_cast<ResourceScheduler::ClientId>(child_id) << 32) | route_id; 922 return (static_cast<ResourceScheduler::ClientId>(child_id) << 32) | route_id;
921 } 923 }
922 924
923 } // namespace content 925 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698