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

Side by Side Diff: content/common/net/url_fetcher.cc

Issue 7282032: Move backoff_delay_ to the inner Core class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: set_backoff_delay has been renamed. Created 9 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « content/common/net/url_fetcher.h ('k') | 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/common/net/url_fetcher.h" 5 #include "content/common/net/url_fetcher.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/file_path.h" 10 #include "base/file_path.h"
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 // Where should responses be saved? 278 // Where should responses be saved?
279 ResponseDestinationType response_destination_; 279 ResponseDestinationType response_destination_;
280 280
281 // If |automatically_retry_on_5xx_| is false, 5xx responses will be 281 // If |automatically_retry_on_5xx_| is false, 5xx responses will be
282 // propagated to the observer, if it is true URLFetcher will automatically 282 // propagated to the observer, if it is true URLFetcher will automatically
283 // re-execute the request, after the back-off delay has expired. 283 // re-execute the request, after the back-off delay has expired.
284 // true by default. 284 // true by default.
285 bool automatically_retry_on_5xx_; 285 bool automatically_retry_on_5xx_;
286 // Maximum retries allowed. 286 // Maximum retries allowed.
287 int max_retries_; 287 int max_retries_;
288 // Back-off time delay. 0 by default.
289 base::TimeDelta backoff_delay_;
288 290
289 static base::LazyInstance<Registry> g_registry; 291 static base::LazyInstance<Registry> g_registry;
290 292
291 friend class URLFetcher; 293 friend class URLFetcher;
292 DISALLOW_COPY_AND_ASSIGN(Core); 294 DISALLOW_COPY_AND_ASSIGN(Core);
293 }; 295 };
294 296
295 URLFetcher::Core::Registry::Registry() {} 297 URLFetcher::Core::Registry::Registry() {}
296 URLFetcher::Core::Registry::~Registry() {} 298 URLFetcher::Core::Registry::~Registry() {}
297 299
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 // static 474 // static
473 URLFetcher::Factory* URLFetcher::factory_ = NULL; 475 URLFetcher::Factory* URLFetcher::factory_ = NULL;
474 476
475 void URLFetcher::Delegate::OnURLFetchComplete( 477 void URLFetcher::Delegate::OnURLFetchComplete(
476 const URLFetcher* source, 478 const URLFetcher* source,
477 const GURL& url, 479 const GURL& url,
478 const net::URLRequestStatus& status, 480 const net::URLRequestStatus& status,
479 int response_code, 481 int response_code,
480 const net::ResponseCookies& cookies, 482 const net::ResponseCookies& cookies,
481 const std::string& data) { 483 const std::string& data) {
482 NOTREACHED() << "If you don't implemnt this, the no-params version " 484 NOTREACHED() << "If you don't implement this, the no-params version "
483 << "should also be implemented, in which case this " 485 << "should also be implemented, in which case this "
484 << "method won't be called..."; 486 << "method won't be called...";
485 } 487 }
486 488
487 // TODO(skerner): This default implementation will be removed, and the 489 // TODO(skerner): This default implementation will be removed, and the
488 // method made pure virtual, once all users of URLFetcher are updated 490 // method made pure virtual, once all users of URLFetcher are updated
489 // to not expect response data as a string argument. Once this is removed, 491 // to not expect response data as a string argument. Once this is removed,
490 // the method URLFetcher::GetResponseStringRef() can be removed as well. 492 // the method URLFetcher::GetResponseStringRef() can be removed as well.
491 // crbug.com/83592 tracks this. 493 // crbug.com/83592 tracks this.
492 void URLFetcher::Delegate::OnURLFetchComplete(const URLFetcher* source) { 494 void URLFetcher::Delegate::OnURLFetchComplete(const URLFetcher* source) {
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
722 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); 724 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
723 base::TimeDelta backoff_delay; 725 base::TimeDelta backoff_delay;
724 726
725 // Checks the response from server. 727 // Checks the response from server.
726 if (response_code_ >= 500 || 728 if (response_code_ >= 500 ||
727 status_.error() == net::ERR_TEMPORARILY_THROTTLED) { 729 status_.error() == net::ERR_TEMPORARILY_THROTTLED) {
728 // When encountering a server error, we will send the request again 730 // When encountering a server error, we will send the request again
729 // after backoff time. 731 // after backoff time.
730 ++num_retries_; 732 ++num_retries_;
731 733
732 // Note that backoff_delay_ may be 0 because (a) the URLRequestThrottler 734 // Note that backoff_delay may be 0 because (a) the URLRequestThrottler
733 // code does not necessarily back off on the first error, and (b) it 735 // code does not necessarily back off on the first error, and (b) it
734 // only backs off on some of the 5xx status codes. 736 // only backs off on some of the 5xx status codes.
735 base::TimeTicks backoff_release_time = GetBackoffReleaseTime(); 737 base::TimeTicks backoff_release_time = GetBackoffReleaseTime();
736 backoff_delay = backoff_release_time - base::TimeTicks::Now(); 738 backoff_delay = backoff_release_time - base::TimeTicks::Now();
737 if (backoff_delay < base::TimeDelta()) 739 if (backoff_delay < base::TimeDelta())
738 backoff_delay = base::TimeDelta(); 740 backoff_delay = base::TimeDelta();
739 741
740 if (automatically_retry_on_5xx_ && 742 if (automatically_retry_on_5xx_ &&
741 num_retries_ <= max_retries_) { 743 num_retries_ <= max_retries_) {
742 StartOnIOThread(); 744 StartOnIOThread();
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
874 was_cancelled_ = true; 876 was_cancelled_ = true;
875 temp_file_writer_.reset(); 877 temp_file_writer_.reset();
876 } 878 }
877 879
878 void URLFetcher::Core::OnCompletedURLRequest( 880 void URLFetcher::Core::OnCompletedURLRequest(
879 base::TimeDelta backoff_delay) { 881 base::TimeDelta backoff_delay) {
880 DCHECK(delegate_loop_proxy_->BelongsToCurrentThread()); 882 DCHECK(delegate_loop_proxy_->BelongsToCurrentThread());
881 883
882 // Save the status and backoff_delay so that delegates can read it. 884 // Save the status and backoff_delay so that delegates can read it.
883 if (delegate_) { 885 if (delegate_) {
884 fetcher_->backoff_delay_ = backoff_delay; 886 backoff_delay_ = backoff_delay;
885 InformDelegateFetchIsComplete(); 887 InformDelegateFetchIsComplete();
886 } 888 }
887 } 889 }
888 890
889 void URLFetcher::Core::InformDelegateFetchIsComplete() { 891 void URLFetcher::Core::InformDelegateFetchIsComplete() {
890 CHECK(delegate_loop_proxy_->BelongsToCurrentThread()); 892 CHECK(delegate_loop_proxy_->BelongsToCurrentThread());
891 if (delegate_) { 893 if (delegate_) {
892 delegate_->OnURLFetchComplete(fetcher_); 894 delegate_->OnURLFetchComplete(fetcher_);
893 } 895 }
894 } 896 }
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
990 } 992 }
991 993
992 int URLFetcher::max_retries() const { 994 int URLFetcher::max_retries() const {
993 return core_->max_retries_; 995 return core_->max_retries_;
994 } 996 }
995 997
996 void URLFetcher::set_max_retries(int max_retries) { 998 void URLFetcher::set_max_retries(int max_retries) {
997 core_->max_retries_ = max_retries; 999 core_->max_retries_ = max_retries;
998 } 1000 }
999 1001
1002 base::TimeDelta URLFetcher::backoff_delay() const {
1003 return core_->backoff_delay_;
1004 }
1005
1006 void URLFetcher::set_backoff_delay_for_testing(
1007 base::TimeDelta backoff_delay) {
1008 core_->backoff_delay_ = backoff_delay;
1009 }
1010
1000 void URLFetcher::SaveResponseToTemporaryFile( 1011 void URLFetcher::SaveResponseToTemporaryFile(
1001 scoped_refptr<base::MessageLoopProxy> file_message_loop_proxy) { 1012 scoped_refptr<base::MessageLoopProxy> file_message_loop_proxy) {
1002 core_->file_message_loop_proxy_ = file_message_loop_proxy; 1013 core_->file_message_loop_proxy_ = file_message_loop_proxy;
1003 core_->response_destination_ = TEMP_FILE; 1014 core_->response_destination_ = TEMP_FILE;
1004 } 1015 }
1005 1016
1006 net::HttpResponseHeaders* URLFetcher::response_headers() const { 1017 net::HttpResponseHeaders* URLFetcher::response_headers() const {
1007 return core_->response_headers_; 1018 return core_->response_headers_;
1008 } 1019 }
1009 1020
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
1123 } 1134 }
1124 1135
1125 // static 1136 // static
1126 int URLFetcher::GetNumFetcherCores() { 1137 int URLFetcher::GetNumFetcherCores() {
1127 return Core::g_registry.Get().size(); 1138 return Core::g_registry.Get().size();
1128 } 1139 }
1129 1140
1130 URLFetcher::Delegate* URLFetcher::delegate() const { 1141 URLFetcher::Delegate* URLFetcher::delegate() const {
1131 return core_->delegate(); 1142 return core_->delegate();
1132 } 1143 }
OLDNEW
« no previous file with comments | « content/common/net/url_fetcher.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698