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

Unified Diff: chrome/service/cloud_print/cloud_print_url_fetcher.cc

Issue 4194001: Implement exponential back-off mechanism and enforce it at the URLRequestHttpJob level. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 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 side-by-side diff with in-line comments
Download patch
Index: chrome/service/cloud_print/cloud_print_url_fetcher.cc
===================================================================
--- chrome/service/cloud_print/cloud_print_url_fetcher.cc (revision 66188)
+++ chrome/service/cloud_print/cloud_print_url_fetcher.cc (working copy)
@@ -7,24 +7,24 @@
#include "base/string_util.h"
#include "base/values.h"
#include "chrome/common/net/http_return.h"
-#include "chrome/common/net/url_fetcher_protect.h"
#include "chrome/service/cloud_print/cloud_print_consts.h"
#include "chrome/service/cloud_print/cloud_print_helpers.h"
#include "chrome/service/net/service_url_request_context.h"
#include "googleurl/src/gurl.h"
+#include "net/url_request/request_throttler_manager.h"
#include "net/url_request/url_request_status.h"
CloudPrintURLFetcher::CloudPrintURLFetcher()
: delegate_(NULL),
- protect_entry_(NULL),
+ request_throttler_manager_(Singleton<RequestThrottlerManager>::get()),
num_retries_(0) {
}
void CloudPrintURLFetcher::StartGetRequest(const GURL& url,
Delegate* delegate,
const std::string& auth_token,
- const std::string& retry_policy) {
- StartRequestHelper(url, URLFetcher::GET, delegate, auth_token, retry_policy,
+ int max_retries) {
+ StartRequestHelper(url, URLFetcher::GET, delegate, auth_token, max_retries,
std::string(), std::string());
}
@@ -32,10 +32,10 @@
const GURL& url,
Delegate* delegate,
const std::string& auth_token,
- const std::string& retry_policy,
+ int max_retries,
const std::string& post_data_mime_type,
const std::string& post_data) {
- StartRequestHelper(url, URLFetcher::POST, delegate, auth_token, retry_policy,
+ StartRequestHelper(url, URLFetcher::POST, delegate, auth_token, max_retries,
post_data_mime_type, post_data);
}
@@ -88,11 +88,18 @@
}
// Retry the request if needed.
if (action == RETRY_REQUEST) {
- int64 back_off_time =
- protect_entry_->UpdateBackoff(URLFetcherProtectEntry::FAILURE);
+ scoped_refptr<RequestThrottlerEntryInterface> entry =
+ request_throttler_manager_->RegisterRequestUrl(url);
+ // If the response code is greater than or equal to 500, then the back-off
+ // period has been increased at the network level; otherwise, explicitly
+ // call ReceivedContentWasMalformed() to count the current request as a
+ // failure and increase the back-off period.
+ if (response_code < 500)
+ entry->ReceivedContentWasMalformed();
+
++num_retries_;
- int max_retries = protect_entry_->max_retries();
- if ((-1 != max_retries) && (num_retries_ > max_retries)) {
+ if ((-1 != source->max_retries()) &&
+ (num_retries_ > source->max_retries())) {
// Retry limit reached. Give up.
delegate_->OnRequestGiveUp();
} else {
@@ -101,10 +108,8 @@
MessageLoop::current()->PostDelayedTask(
FROM_HERE,
NewRunnableMethod(this, &CloudPrintURLFetcher::StartRequestNow),
- back_off_time);
+ entry->GetRecommendedDelayForNextRequest());
Jói 2010/11/17 16:39:18 Same comment here on the sliding window - doesn't
yzshen 2010/11/19 23:51:36 I realize that we don't even need to wait here, si
}
- } else {
- protect_entry_->UpdateBackoff(URLFetcherProtectEntry::SUCCESS);
}
}
@@ -113,7 +118,7 @@
URLFetcher::RequestType request_type,
Delegate* delegate,
const std::string& auth_token,
- const std::string& retry_policy,
+ int max_retries,
const std::string& post_data_mime_type,
const std::string& post_data) {
DCHECK(delegate);
@@ -121,6 +126,7 @@
request_->set_request_context(GetRequestContextGetter());
// Since we implement our own retry logic, disable the retry in URLFetcher.
request_->set_automatically_retry_on_5xx(false);
+ request_->set_max_retries(max_retries);
delegate_ = delegate;
std::string headers = "Authorization: GoogleLogin auth=";
headers += auth_token;
@@ -130,13 +136,13 @@
if (request_type == URLFetcher::POST) {
request_->set_upload_data(post_data_mime_type, post_data);
}
- // Initialize the retry policy for this request.
- protect_entry_ =
- URLFetcherProtectManager::GetInstance()->Register(retry_policy);
+
+ scoped_refptr<RequestThrottlerEntryInterface> entry =
+ request_throttler_manager_->RegisterRequestUrl(url);
MessageLoop::current()->PostDelayedTask(
FROM_HERE,
NewRunnableMethod(this, &CloudPrintURLFetcher::StartRequestNow),
- protect_entry_->UpdateBackoff(URLFetcherProtectEntry::SEND));
+ entry->GetRecommendedDelayForNextRequest());
}
void CloudPrintURLFetcher::StartRequestNow() {

Powered by Google App Engine
This is Rietveld 408576698