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

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

Issue 5276007: Implement exponential back-off mechanism. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: pull latest to merge Created 10 years 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 | Annotate | Revision Log
« no previous file with comments | « net/url_request/url_request_http_job.h ('k') | net/url_request/url_request_throttler_entry.h » ('j') | 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/command_line.h" 8 #include "base/command_line.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 15 matching lines...) Expand all
26 #include "net/http/http_response_headers.h" 26 #include "net/http/http_response_headers.h"
27 #include "net/http/http_response_info.h" 27 #include "net/http/http_response_info.h"
28 #include "net/http/http_transaction.h" 28 #include "net/http/http_transaction.h"
29 #include "net/http/http_transaction_factory.h" 29 #include "net/http/http_transaction_factory.h"
30 #include "net/http/http_util.h" 30 #include "net/http/http_util.h"
31 #include "net/url_request/https_prober.h" 31 #include "net/url_request/https_prober.h"
32 #include "net/url_request/url_request.h" 32 #include "net/url_request/url_request.h"
33 #include "net/url_request/url_request_context.h" 33 #include "net/url_request/url_request_context.h"
34 #include "net/url_request/url_request_error_job.h" 34 #include "net/url_request/url_request_error_job.h"
35 #include "net/url_request/url_request_redirect_job.h" 35 #include "net/url_request/url_request_redirect_job.h"
36 #include "net/url_request/url_request_throttler_header_adapter.h"
37 #include "net/url_request/url_request_throttler_manager.h"
36 38
37 static const char kAvailDictionaryHeader[] = "Avail-Dictionary"; 39 static const char kAvailDictionaryHeader[] = "Avail-Dictionary";
38 40
39 // TODO(darin): make sure the port blocking code is not lost 41 // TODO(darin): make sure the port blocking code is not lost
40 // static 42 // static
41 URLRequestJob* URLRequestHttpJob::Factory(URLRequest* request, 43 URLRequestJob* URLRequestHttpJob::Factory(URLRequest* request,
42 const std::string& scheme) { 44 const std::string& scheme) {
43 DCHECK(scheme == "http" || scheme == "https"); 45 DCHECK(scheme == "http" || scheme == "https");
44 46
45 int port = request->url().IntPort(); 47 int port = request->url().IntPort();
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 ALLOW_THIS_IN_INITIALIZER_LIST(can_get_cookies_callback_( 86 ALLOW_THIS_IN_INITIALIZER_LIST(can_get_cookies_callback_(
85 this, &URLRequestHttpJob::OnCanGetCookiesCompleted)), 87 this, &URLRequestHttpJob::OnCanGetCookiesCompleted)),
86 ALLOW_THIS_IN_INITIALIZER_LIST(can_set_cookie_callback_( 88 ALLOW_THIS_IN_INITIALIZER_LIST(can_set_cookie_callback_(
87 this, &URLRequestHttpJob::OnCanSetCookieCompleted)), 89 this, &URLRequestHttpJob::OnCanSetCookieCompleted)),
88 ALLOW_THIS_IN_INITIALIZER_LIST(start_callback_( 90 ALLOW_THIS_IN_INITIALIZER_LIST(start_callback_(
89 this, &URLRequestHttpJob::OnStartCompleted)), 91 this, &URLRequestHttpJob::OnStartCompleted)),
90 ALLOW_THIS_IN_INITIALIZER_LIST(read_callback_( 92 ALLOW_THIS_IN_INITIALIZER_LIST(read_callback_(
91 this, &URLRequestHttpJob::OnReadCompleted)), 93 this, &URLRequestHttpJob::OnReadCompleted)),
92 read_in_progress_(false), 94 read_in_progress_(false),
93 transaction_(NULL), 95 transaction_(NULL),
96 throttling_entry_(net::URLRequestThrottlerManager::GetInstance()->
97 RegisterRequestUrl(request->url())),
94 sdch_dictionary_advertised_(false), 98 sdch_dictionary_advertised_(false),
95 sdch_test_activated_(false), 99 sdch_test_activated_(false),
96 sdch_test_control_(false), 100 sdch_test_control_(false),
97 is_cached_content_(false) { 101 is_cached_content_(false) {
98 } 102 }
99 103
100 URLRequestHttpJob::~URLRequestHttpJob() { 104 URLRequestHttpJob::~URLRequestHttpJob() {
101 DCHECK(!sdch_test_control_ || !sdch_test_activated_); 105 DCHECK(!sdch_test_control_ || !sdch_test_activated_);
102 if (!IsCachedContent()) { 106 if (!IsCachedContent()) {
103 if (sdch_test_control_) 107 if (sdch_test_control_)
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 566
563 void URLRequestHttpJob::NotifyHeadersComplete() { 567 void URLRequestHttpJob::NotifyHeadersComplete() {
564 DCHECK(!response_info_); 568 DCHECK(!response_info_);
565 569
566 response_info_ = transaction_->GetResponseInfo(); 570 response_info_ = transaction_->GetResponseInfo();
567 571
568 // Save boolean, as we'll need this info at destruction time, and filters may 572 // Save boolean, as we'll need this info at destruction time, and filters may
569 // also need this info. 573 // also need this info.
570 is_cached_content_ = response_info_->was_cached; 574 is_cached_content_ = response_info_->was_cached;
571 575
576 if (!is_cached_content_) {
577 net::URLRequestThrottlerHeaderAdapter response_adapter(
578 response_info_->headers);
579 throttling_entry_->UpdateWithResponse(&response_adapter);
580 }
581
572 ProcessStrictTransportSecurityHeader(); 582 ProcessStrictTransportSecurityHeader();
573 583
574 if (SdchManager::Global() && 584 if (SdchManager::Global() &&
575 SdchManager::Global()->IsInSupportedDomain(request_->url())) { 585 SdchManager::Global()->IsInSupportedDomain(request_->url())) {
576 static const std::string name = "Get-Dictionary"; 586 static const std::string name = "Get-Dictionary";
577 std::string url_text; 587 std::string url_text;
578 void* iter = NULL; 588 void* iter = NULL;
579 // TODO(jar): We need to not fetch dictionaries the first time they are 589 // TODO(jar): We need to not fetch dictionaries the first time they are
580 // seen, but rather wait until we can justify their usefulness. 590 // seen, but rather wait until we can justify their usefulness.
581 // For now, we will only fetch the first dictionary, which will at least 591 // For now, we will only fetch the first dictionary, which will at least
(...skipping 29 matching lines...) Expand all
611 context_ = NULL; 621 context_ = NULL;
612 } 622 }
613 623
614 void URLRequestHttpJob::StartTransaction() { 624 void URLRequestHttpJob::StartTransaction() {
615 // NOTE: This method assumes that request_info_ is already setup properly. 625 // NOTE: This method assumes that request_info_ is already setup properly.
616 626
617 // If we already have a transaction, then we should restart the transaction 627 // If we already have a transaction, then we should restart the transaction
618 // with auth provided by username_ and password_. 628 // with auth provided by username_ and password_.
619 629
620 int rv; 630 int rv;
631
621 if (transaction_.get()) { 632 if (transaction_.get()) {
622 rv = transaction_->RestartWithAuth(username_, password_, &start_callback_); 633 rv = transaction_->RestartWithAuth(username_, password_, &start_callback_);
623 username_.clear(); 634 username_.clear();
624 password_.clear(); 635 password_.clear();
625 } else { 636 } else {
626 DCHECK(request_->context()); 637 DCHECK(request_->context());
627 DCHECK(request_->context()->http_transaction_factory()); 638 DCHECK(request_->context()->http_transaction_factory());
628 639
629 rv = request_->context()->http_transaction_factory()->CreateTransaction( 640 rv = request_->context()->http_transaction_factory()->CreateTransaction(
630 &transaction_); 641 &transaction_);
631 if (rv == net::OK) { 642 if (rv == net::OK) {
632 rv = transaction_->Start( 643 if (!throttling_entry_->IsDuringExponentialBackoff()) {
633 &request_info_, &start_callback_, request_->net_log()); 644 rv = transaction_->Start(
645 &request_info_, &start_callback_, request_->net_log());
646 } else {
647 // Special error code for the exponential back-off module.
648 rv = net::ERR_TEMPORARILY_THROTTLED;
649 }
634 // Make sure the context is alive for the duration of the 650 // Make sure the context is alive for the duration of the
635 // transaction. 651 // transaction.
636 context_ = request_->context(); 652 context_ = request_->context();
637 } 653 }
638 } 654 }
639 655
640 if (rv == net::ERR_IO_PENDING) 656 if (rv == net::ERR_IO_PENDING)
641 return; 657 return;
642 658
643 // The transaction started synchronously, but we need to notify the 659 // The transaction started synchronously, but we need to notify the
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
916 HTTPSProberDelegate* delegate = 932 HTTPSProberDelegate* delegate =
917 new HTTPSProberDelegate(request_info_.url.host(), max_age, 933 new HTTPSProberDelegate(request_info_.url.host(), max_age,
918 include_subdomains, 934 include_subdomains,
919 ctx->transport_security_state()); 935 ctx->transport_security_state());
920 if (!prober->ProbeHost(request_info_.url.host(), request()->context(), 936 if (!prober->ProbeHost(request_info_.url.host(), request()->context(),
921 delegate)) { 937 delegate)) {
922 delete delegate; 938 delete delegate;
923 } 939 }
924 } 940 }
925 } 941 }
OLDNEW
« no previous file with comments | « net/url_request/url_request_http_job.h ('k') | net/url_request/url_request_throttler_entry.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698