summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authormsw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-20 21:07:48 +0000
committermsw@chromium.org <msw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-20 21:07:48 +0000
commitd1e535af433f6620de233f7e08619f8b0340d3bb (patch)
tree492c346acf1b0beae25797c07ce018f03555804d /chrome
parentf5fb0b881ef3a0aaacb05e4192e151c1383ff910 (diff)
downloadchromium_src-d1e535af433f6620de233f7e08619f8b0340d3bb.zip
chromium_src-d1e535af433f6620de233f7e08619f8b0340d3bb.tar.gz
chromium_src-d1e535af433f6620de233f7e08619f8b0340d3bb.tar.bz2
Revise Chrome To Mobile request timing.
Chrome To Mobile's cloud print search QPS is too damn high! Do not automatically refresh the mobile device list. (attempt requests on new browser windows, icon clicks) Only allow search requests once per day per user. Reduce search and auth URLFetcher max retries (10 -> 1). Also increase authentication retry delay (5min -> 6hrs). NOTE: This may not be sufficient, further action TBD. BUG=102709 TEST=C2M doesn't update listed devices as frequently. Review URL: http://codereview.chromium.org/9732005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@127780 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/chrome_to_mobile_service.cc39
-rw-r--r--chrome/browser/chrome_to_mobile_service.h9
2 files changed, 30 insertions, 18 deletions
diff --git a/chrome/browser/chrome_to_mobile_service.cc b/chrome/browser/chrome_to_mobile_service.cc
index d8b1140..e3f525d 100644
--- a/chrome/browser/chrome_to_mobile_service.cc
+++ b/chrome/browser/chrome_to_mobile_service.cc
@@ -34,13 +34,19 @@
namespace {
// The maximum number of retries for the URLFetcher requests.
-size_t kMaxRetries = 10;
+const size_t kMaxRetries = 1;
-// The number of seconds between automated URLFetcher requests.
-size_t kRetryDelay = 300;
+// The number of hours to delay before retrying authentication on failure.
+const size_t kAuthRetryDelayHours = 6;
+
+// The number of hours before subsequent search requests are allowed.
+// This value is used to throttle expensive cloud print search requests.
+// Note that this limitation does not hold across application restarts.
+const int kSearchRequestDelayHours = 24;
// The cloud print OAuth2 scope and 'printer' type of compatible mobile devices.
-const char kOAuthScope[] = "https://www.googleapis.com/auth/cloudprint";
+const char kCloudPrintOAuthScope[] =
+ "https://www.googleapis.com/auth/cloudprint";
const char kTypeAndroidChromeSnapshot[] = "ANDROID_CHROME_SNAPSHOT";
// The Chrome To Mobile requestor type; used by the service for filtering.
@@ -231,7 +237,7 @@ void ChromeToMobileService::OnGetTokenSuccess(
const std::string& access_token) {
DCHECK(!access_token.empty());
access_token_fetcher_.reset();
- request_timer_.Stop();
+ auth_retry_timer_.Stop();
access_token_ = access_token;
RequestMobileListUpdate();
}
@@ -239,9 +245,10 @@ void ChromeToMobileService::OnGetTokenSuccess(
void ChromeToMobileService::OnGetTokenFailure(
const GoogleServiceAuthError& error) {
access_token_fetcher_.reset();
- request_timer_.Stop();
- request_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(kRetryDelay),
- this, &ChromeToMobileService::RefreshAccessToken);
+ auth_retry_timer_.Stop();
+ auth_retry_timer_.Start(
+ FROM_HERE, base::TimeDelta::FromHours(kAuthRetryDelayHours),
+ this, &ChromeToMobileService::RefreshAccessToken);
}
void ChromeToMobileService::CreateUniqueTempDir() {
@@ -275,10 +282,10 @@ void ChromeToMobileService::RefreshAccessToken() {
if (token.empty())
return;
- request_timer_.Stop();
+ auth_retry_timer_.Stop();
access_token_fetcher_.reset(
new OAuth2AccessTokenFetcher(this, profile_->GetRequestContext()));
- std::vector<std::string> scopes(1, kOAuthScope);
+ std::vector<std::string> scopes(1, kCloudPrintOAuthScope);
GaiaUrls* gaia_urls = GaiaUrls::GetInstance();
access_token_fetcher_->Start(gaia_urls->oauth2_chrome_client_id(),
gaia_urls->oauth2_chrome_client_secret(), token, scopes);
@@ -286,13 +293,21 @@ void ChromeToMobileService::RefreshAccessToken() {
void ChromeToMobileService::RequestSearch() {
DCHECK(!access_token_.empty());
+
+ // Deny requests while another request is currently pending.
if (search_request_.get())
return;
+ // Deny requests before the delay period has passed since the last request.
+ base::TimeDelta elapsed_time = base::TimeTicks::Now() - previous_search_time_;
+ if (elapsed_time.InHours() < kSearchRequestDelayHours)
+ return;
+
RequestData data;
data.type = SEARCH;
search_request_.reset(CreateRequest(data));
search_request_->Start();
+ previous_search_time_ = base::TimeTicks::Now();
}
void ChromeToMobileService::HandleSearchResponse() {
@@ -324,10 +339,6 @@ void ChromeToMobileService::HandleSearchResponse() {
browser->command_updater()->UpdateCommandEnabled(
IDC_CHROME_TO_MOBILE_PAGE, !mobiles_.empty());
}
-
- request_timer_.Stop();
- request_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(kRetryDelay),
- this, &ChromeToMobileService::RequestSearch);
}
void ChromeToMobileService::HandleSubmitResponse(
diff --git a/chrome/browser/chrome_to_mobile_service.h b/chrome/browser/chrome_to_mobile_service.h
index a68d9e8..e216f86 100644
--- a/chrome/browser/chrome_to_mobile_service.h
+++ b/chrome/browser/chrome_to_mobile_service.h
@@ -135,12 +135,13 @@ class ChromeToMobileService : public ProfileKeyedService,
RequestObserverMap;
RequestObserverMap request_observer_map_;
- // The pending URL requests.
+ // The pending OAuth access token request and a timer for retrying on failure.
scoped_ptr<OAuth2AccessTokenFetcher> access_token_fetcher_;
- scoped_ptr<content::URLFetcher> search_request_;
+ base::OneShotTimer<ChromeToMobileService> auth_retry_timer_;
- // A timer for authentication retries and mobile device list updates.
- base::OneShotTimer<ChromeToMobileService> request_timer_;
+ // The pending mobile device search request; and the time of the last request.
+ scoped_ptr<content::URLFetcher> search_request_;
+ base::TimeTicks previous_search_time_;
DISALLOW_COPY_AND_ASSIGN(ChromeToMobileService);
};