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

Side by Side Diff: net/url_request/url_request_http_job.cc

Issue 1153093002: Implement URLRequestBackoffManager for managing Backoff headers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 months 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
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 "net/url_request/url_request_http_job.h" 5 #include "net/url_request/url_request_http_job.h"
6 6
7 #include "base/base_switches.h" 7 #include "base/base_switches.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 done_(false), 188 done_(false),
189 bytes_observed_in_packets_(0), 189 bytes_observed_in_packets_(0),
190 request_time_snapshot_(), 190 request_time_snapshot_(),
191 final_packet_time_(), 191 final_packet_time_(),
192 filter_context_(new HttpFilterContext(this)), 192 filter_context_(new HttpFilterContext(this)),
193 on_headers_received_callback_( 193 on_headers_received_callback_(
194 base::Bind(&URLRequestHttpJob::OnHeadersReceivedCallback, 194 base::Bind(&URLRequestHttpJob::OnHeadersReceivedCallback,
195 base::Unretained(this))), 195 base::Unretained(this))),
196 awaiting_callback_(false), 196 awaiting_callback_(false),
197 http_user_agent_settings_(http_user_agent_settings), 197 http_user_agent_settings_(http_user_agent_settings),
198 backoff_manager_(request->context()->backoff_manager()),
198 weak_factory_(this) { 199 weak_factory_(this) {
199 URLRequestThrottlerManager* manager = request->context()->throttler_manager(); 200 URLRequestThrottlerManager* manager = request->context()->throttler_manager();
200 if (manager) 201 if (manager)
201 throttling_entry_ = manager->RegisterRequestUrl(request->url()); 202 throttling_entry_ = manager->RegisterRequestUrl(request->url());
202 203
203 ResetTimer(); 204 ResetTimer();
204 } 205 }
205 206
206 URLRequestHttpJob::~URLRequestHttpJob() { 207 URLRequestHttpJob::~URLRequestHttpJob() {
207 CHECK(!awaiting_callback_); 208 CHECK(!awaiting_callback_);
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 DCHECK(request_headers); 295 DCHECK(request_headers);
295 DCHECK_NE(URLRequestStatus::CANCELED, GetStatus().status()); 296 DCHECK_NE(URLRequestStatus::CANCELED, GetStatus().status());
296 if (network_delegate()) { 297 if (network_delegate()) {
297 network_delegate()->NotifyBeforeSendProxyHeaders( 298 network_delegate()->NotifyBeforeSendProxyHeaders(
298 request_, 299 request_,
299 proxy_info, 300 proxy_info,
300 request_headers); 301 request_headers);
301 } 302 }
302 } 303 }
303 304
305 void URLRequestHttpJob::NotifyBeforeNetworkStart(bool* defer) {
306 if (!request_)
307 return;
308 if (backoff_manager_) {
309 if (backoff_manager_->ShouldRejectRequest(request()->url(),
310 request()->request_time())) {
311 *defer = true;
312 base::MessageLoop::current()->PostTask(
313 FROM_HERE,
314 base::Bind(&URLRequestHttpJob::OnStartCompleted,
315 weak_factory_.GetWeakPtr(), ERR_TEMPORARY_BACKOFF));
316 return;
317 }
318 }
319 URLRequestJob::NotifyBeforeNetworkStart(defer);
320 }
321
304 void URLRequestHttpJob::NotifyHeadersComplete() { 322 void URLRequestHttpJob::NotifyHeadersComplete() {
305 DCHECK(!response_info_); 323 DCHECK(!response_info_);
306 324
307 response_info_ = transaction_->GetResponseInfo(); 325 response_info_ = transaction_->GetResponseInfo();
308 326
309 // Save boolean, as we'll need this info at destruction time, and filters may 327 // Save boolean, as we'll need this info at destruction time, and filters may
310 // also need this info. 328 // also need this info.
311 is_cached_content_ = response_info_->was_cached; 329 is_cached_content_ = response_info_->was_cached;
312 330
313 if (!is_cached_content_ && throttling_entry_.get()) 331 if (!is_cached_content_ && throttling_entry_.get())
314 throttling_entry_->UpdateWithResponse(GetResponseCode()); 332 throttling_entry_->UpdateWithResponse(GetResponseCode());
315 333
334 if (!is_cached_content_ && backoff_manager_)
335 backoff_manager_->UpdateWithResponse(request()->url(), GetResponseHeaders(),
336 request()->request_time());
337
316 // The ordering of these calls is not important. 338 // The ordering of these calls is not important.
317 ProcessStrictTransportSecurityHeader(); 339 ProcessStrictTransportSecurityHeader();
318 ProcessPublicKeyPinsHeader(); 340 ProcessPublicKeyPinsHeader();
319 341
320 // Handle the server notification of a new SDCH dictionary. 342 // Handle the server notification of a new SDCH dictionary.
321 SdchManager* sdch_manager(request()->context()->sdch_manager()); 343 SdchManager* sdch_manager(request()->context()->sdch_manager());
322 if (sdch_manager) { 344 if (sdch_manager) {
323 SdchProblemCode rv = sdch_manager->IsInSupportedDomain(request()->url()); 345 SdchProblemCode rv = sdch_manager->IsInSupportedDomain(request()->url());
324 if (rv != SDCH_OK) { 346 if (rv != SDCH_OK) {
325 // If SDCH is just disabled, it is not a real error. 347 // If SDCH is just disabled, it is not a real error.
(...skipping 1184 matching lines...) Expand 10 before | Expand all | Expand 10 after
1510 return override_response_headers_.get() ? 1532 return override_response_headers_.get() ?
1511 override_response_headers_.get() : 1533 override_response_headers_.get() :
1512 transaction_->GetResponseInfo()->headers.get(); 1534 transaction_->GetResponseInfo()->headers.get();
1513 } 1535 }
1514 1536
1515 void URLRequestHttpJob::NotifyURLRequestDestroyed() { 1537 void URLRequestHttpJob::NotifyURLRequestDestroyed() {
1516 awaiting_callback_ = false; 1538 awaiting_callback_ = false;
1517 } 1539 }
1518 1540
1519 } // namespace net 1541 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698