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

Side by Side Diff: content/common/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: Created 9 years, 5 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
« content/common/url_fetcher.h ('K') | « content/common/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/url_fetcher.h" 5 #include "content/common/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 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 // Where should responses be saved? 265 // Where should responses be saved?
266 ResponseDestinationType response_destination_; 266 ResponseDestinationType response_destination_;
267 267
268 // If |automatically_retry_on_5xx_| is false, 5xx responses will be 268 // If |automatically_retry_on_5xx_| is false, 5xx responses will be
269 // propagated to the observer, if it is true URLFetcher will automatically 269 // propagated to the observer, if it is true URLFetcher will automatically
270 // re-execute the request, after the back-off delay has expired. 270 // re-execute the request, after the back-off delay has expired.
271 // true by default. 271 // true by default.
272 bool automatically_retry_on_5xx_; 272 bool automatically_retry_on_5xx_;
273 // Maximum retries allowed. 273 // Maximum retries allowed.
274 int max_retries_; 274 int max_retries_;
275 // Back-off time delay. 0 by default.
276 base::TimeDelta backoff_delay_;
275 277
276 static base::LazyInstance<Registry> g_registry; 278 static base::LazyInstance<Registry> g_registry;
277 279
278 friend class URLFetcher; 280 friend class URLFetcher;
279 DISALLOW_COPY_AND_ASSIGN(Core); 281 DISALLOW_COPY_AND_ASSIGN(Core);
280 }; 282 };
281 283
282 URLFetcher::Core::Registry::Registry() {} 284 URLFetcher::Core::Registry::Registry() {}
283 URLFetcher::Core::Registry::~Registry() {} 285 URLFetcher::Core::Registry::~Registry() {}
284 286
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 // static 411 // static
410 URLFetcher::Factory* URLFetcher::factory_ = NULL; 412 URLFetcher::Factory* URLFetcher::factory_ = NULL;
411 413
412 void URLFetcher::Delegate::OnURLFetchComplete( 414 void URLFetcher::Delegate::OnURLFetchComplete(
413 const URLFetcher* source, 415 const URLFetcher* source,
414 const GURL& url, 416 const GURL& url,
415 const net::URLRequestStatus& status, 417 const net::URLRequestStatus& status,
416 int response_code, 418 int response_code,
417 const net::ResponseCookies& cookies, 419 const net::ResponseCookies& cookies,
418 const std::string& data) { 420 const std::string& data) {
419 NOTREACHED() << "If you don't implemnt this, the no-params version " 421 NOTREACHED() << "If you don't implement this, the no-params version "
420 << "should also be implemented, in which case this " 422 << "should also be implemented, in which case this "
421 << "method won't be called..."; 423 << "method won't be called...";
422 } 424 }
423 425
424 // TODO(skerner): This default implementation will be removed, and the 426 // TODO(skerner): This default implementation will be removed, and the
425 // method made pure virtual, once all users of URLFetcher are updated 427 // method made pure virtual, once all users of URLFetcher are updated
426 // to not expect response data as a string argument. Once this is removed, 428 // to not expect response data as a string argument. Once this is removed,
427 // the method URLFetcher::GetResponseStringRef() can be removed as well. 429 // the method URLFetcher::GetResponseStringRef() can be removed as well.
428 // crbug.com/83592 tracks this. 430 // crbug.com/83592 tracks this.
429 void URLFetcher::Delegate::OnURLFetchComplete(const URLFetcher* source) { 431 void URLFetcher::Delegate::OnURLFetchComplete(const URLFetcher* source) {
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 ReleaseRequest(); 637 ReleaseRequest();
636 638
637 base::TimeDelta backoff_delay; 639 base::TimeDelta backoff_delay;
638 // Checks the response from server. 640 // Checks the response from server.
639 if (response_code_ >= 500 || 641 if (response_code_ >= 500 ||
640 status.os_error() == net::ERR_TEMPORARILY_THROTTLED) { 642 status.os_error() == net::ERR_TEMPORARILY_THROTTLED) {
641 // When encountering a server error, we will send the request again 643 // When encountering a server error, we will send the request again
642 // after backoff time. 644 // after backoff time.
643 ++num_retries_; 645 ++num_retries_;
644 646
645 // Note that backoff_delay_ may be 0 because (a) the URLRequestThrottler 647 // Note that backoff_delay may be 0 because (a) the URLRequestThrottler
646 // code does not necessarily back off on the first error, and (b) it 648 // code does not necessarily back off on the first error, and (b) it
647 // only backs off on some of the 5xx status codes. 649 // only backs off on some of the 5xx status codes.
648 backoff_delay = backoff_release_time - base::TimeTicks::Now(); 650 backoff_delay = backoff_release_time - base::TimeTicks::Now();
649 if (backoff_delay < base::TimeDelta()) 651 if (backoff_delay < base::TimeDelta())
650 backoff_delay = base::TimeDelta(); 652 backoff_delay = base::TimeDelta();
651 653
652 if (automatically_retry_on_5xx_ && 654 if (automatically_retry_on_5xx_ &&
653 num_retries_ <= max_retries_) { 655 num_retries_ <= max_retries_) {
654 StartURLRequestWhenAppropriate(); 656 StartURLRequestWhenAppropriate();
655 return; 657 return;
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
786 } 788 }
787 789
788 void URLFetcher::Core::OnCompletedURLRequest( 790 void URLFetcher::Core::OnCompletedURLRequest(
789 const net::URLRequestStatus& status, 791 const net::URLRequestStatus& status,
790 base::TimeDelta backoff_delay) { 792 base::TimeDelta backoff_delay) {
791 DCHECK(delegate_loop_proxy_->BelongsToCurrentThread()); 793 DCHECK(delegate_loop_proxy_->BelongsToCurrentThread());
792 794
793 // Save the status and backoff_delay so that delegates can read it. 795 // Save the status and backoff_delay so that delegates can read it.
794 if (delegate_) { 796 if (delegate_) {
795 status_ = status; 797 status_ = status;
796 fetcher_->backoff_delay_ = backoff_delay; 798 backoff_delay_ = backoff_delay;
willchan no longer on Chromium 2011/06/30 15:50:24 It's never read, only written. How do tests use th
wtc 2011/06/30 21:36:02 It's never read in this file. But it can be read
797 InformDelegateFetchIsComplete(); 799 InformDelegateFetchIsComplete();
798 } 800 }
799 } 801 }
800 802
801 void URLFetcher::Core::InformDelegateFetchIsComplete() { 803 void URLFetcher::Core::InformDelegateFetchIsComplete() {
802 delegate_->OnURLFetchComplete(fetcher_); 804 delegate_->OnURLFetchComplete(fetcher_);
803 } 805 }
804 806
805 void URLFetcher::Core::NotifyMalformedContent() { 807 void URLFetcher::Core::NotifyMalformedContent() {
806 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); 808 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
899 } 901 }
900 902
901 int URLFetcher::max_retries() const { 903 int URLFetcher::max_retries() const {
902 return core_->max_retries_; 904 return core_->max_retries_;
903 } 905 }
904 906
905 void URLFetcher::set_max_retries(int max_retries) { 907 void URLFetcher::set_max_retries(int max_retries) {
906 core_->max_retries_ = max_retries; 908 core_->max_retries_ = max_retries;
907 } 909 }
908 910
911 base::TimeDelta URLFetcher::backoff_delay() const {
912 return core_->backoff_delay_;
913 }
914
915 void URLFetcher::set_backoff_delay(base::TimeDelta backoff_delay) {
916 core_->backoff_delay_ = backoff_delay;
917 }
918
909 void URLFetcher::SaveResponseToTemporaryFile( 919 void URLFetcher::SaveResponseToTemporaryFile(
910 scoped_refptr<base::MessageLoopProxy> file_message_loop_proxy) { 920 scoped_refptr<base::MessageLoopProxy> file_message_loop_proxy) {
911 core_->file_message_loop_proxy_ = file_message_loop_proxy; 921 core_->file_message_loop_proxy_ = file_message_loop_proxy;
912 core_->response_destination_ = TEMP_FILE; 922 core_->response_destination_ = TEMP_FILE;
913 } 923 }
914 924
915 net::HttpResponseHeaders* URLFetcher::response_headers() const { 925 net::HttpResponseHeaders* URLFetcher::response_headers() const {
916 return core_->response_headers_; 926 return core_->response_headers_;
917 } 927 }
918 928
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
1016 } 1026 }
1017 1027
1018 // static 1028 // static
1019 int URLFetcher::GetNumFetcherCores() { 1029 int URLFetcher::GetNumFetcherCores() {
1020 return Core::g_registry.Get().size(); 1030 return Core::g_registry.Get().size();
1021 } 1031 }
1022 1032
1023 URLFetcher::Delegate* URLFetcher::delegate() const { 1033 URLFetcher::Delegate* URLFetcher::delegate() const {
1024 return core_->delegate(); 1034 return core_->delegate();
1025 } 1035 }
OLDNEW
« content/common/url_fetcher.h ('K') | « content/common/url_fetcher.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698