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

Unified Diff: chrome/browser/chrome_to_mobile_service.cc

Issue 10909115: Revert 155317 - Adjust ChromeToMobile error logging and mitigation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/chrome_to_mobile_service.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chrome_to_mobile_service.cc
===================================================================
--- chrome/browser/chrome_to_mobile_service.cc (revision 155363)
+++ chrome/browser/chrome_to_mobile_service.cc (working copy)
@@ -43,7 +43,6 @@
#include "google_apis/gaia/oauth2_access_token_fetcher.h"
#include "net/base/escape.h"
#include "net/base/load_flags.h"
-#include "net/http/http_status_code.h"
#include "net/url_request/url_fetcher.h"
#include "net/url_request/url_request_context_getter.h"
#include "sync/notifier/invalidation_util.h"
@@ -51,11 +50,16 @@
namespace {
// The maximum number of retries for the URLFetcher requests.
-const size_t kMaxRetries = 5;
+const size_t kMaxRetries = 1;
-// The number of hours to delay before retrying certain failed operations.
-const size_t kDelayHours = 1;
+// 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 sync invalidation object ID for Chrome to Mobile's mobile device list.
// This corresponds with cloud print's server-side invalidation object ID.
// Meaning: "U" == "User", "CM" == "Chrome to Mobile", "MLST" == "Mobile LiST".
@@ -318,8 +322,7 @@
TokenService::TokenAvailableDetails* token_details =
content::Details<TokenService::TokenAvailableDetails>(details).ptr();
// Invalidate the cloud print access token on Gaia login token updates.
- if (token_details->service() == GaiaConstants::kGaiaOAuth2LoginRefreshToken ||
- token_details->service() == GaiaConstants::kGaiaOAuth2LoginAccessToken)
+ if (token_details->service() == GaiaConstants::kGaiaOAuth2LoginRefreshToken)
access_token_.clear();
}
@@ -343,20 +346,12 @@
void ChromeToMobileService::OnGetTokenFailure(
const GoogleServiceAuthError& error) {
- LogMetric(BAD_TOKEN);
- access_token_.clear();
access_token_fetcher_.reset();
auth_retry_timer_.Stop();
- base::TimeDelta delay = std::max(base::TimeDelta::FromHours(kDelayHours),
- auth_retry_timer_.GetCurrentDelay() * 2);
- auth_retry_timer_.Start(FROM_HERE, delay, this,
- &ChromeToMobileService::RequestAccessToken);
-
- // Clear the mobile list, which may be (or become) out of date.
- ListValue empty;
- profile_->GetPrefs()->Set(prefs::kChromeToMobileDeviceList, empty);
- UpdateCommandState();
+ auth_retry_timer_.Start(
+ FROM_HERE, base::TimeDelta::FromHours(kAuthRetryDelayHours),
+ this, &ChromeToMobileService::RequestAccessToken);
}
void ChromeToMobileService::OnNotificationsEnabled() {
@@ -491,16 +486,10 @@
registrar_.Add(this, chrome::NOTIFICATION_TOKEN_AVAILABLE,
content::Source<TokenService>(token_service));
- // Deny concurrent requests.
- if (access_token_fetcher_.get())
+ // Deny concurrent requests and bail without a valid Gaia login refresh token.
+ if (access_token_fetcher_.get() || !token_service->HasOAuthLoginToken())
return;
- // Handle invalid login refresh tokens as a failure.
- if (!token_service->HasOAuthLoginToken()) {
- OnGetTokenFailure(GoogleServiceAuthError(GoogleServiceAuthError::NONE));
- return;
- }
-
auth_retry_timer_.Stop();
access_token_fetcher_.reset(
new OAuth2AccessTokenFetcher(this, profile_->GetRequestContext()));
@@ -512,7 +501,6 @@
}
void ChromeToMobileService::RequestDeviceSearch() {
- search_retry_timer_.Stop();
if (access_token_.empty()) {
// Enqueue this task to perform after obtaining an access token.
task_queue_.push(base::Bind(&ChromeToMobileService::RequestDeviceSearch,
@@ -534,7 +522,6 @@
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
DCHECK_EQ(source->GetURL(), GetSearchURL(cloud_print_url_));
- ListValue mobiles;
std::string data;
ListValue* list = NULL;
DictionaryValue* dictionary = NULL;
@@ -542,6 +529,7 @@
scoped_ptr<Value> json(base::JSONReader::Read(data));
if (json.get() && json->GetAsDictionary(&dictionary) && dictionary &&
dictionary->GetList(cloud_print::kPrinterListValue, &list)) {
+ ListValue mobiles;
std::string type, name, id;
DictionaryValue* printer = NULL;
DictionaryValue* mobile = NULL;
@@ -562,49 +550,29 @@
}
}
}
- } else if (source->GetResponseCode() == net::HTTP_FORBIDDEN) {
- LogMetric(BAD_SEARCH_AUTH);
- // Invalidate the access token and retry a delayed search on access errors.
- access_token_.clear();
- search_retry_timer_.Stop();
- base::TimeDelta delay = std::max(base::TimeDelta::FromHours(kDelayHours),
- search_retry_timer_.GetCurrentDelay() * 2);
- search_retry_timer_.Start(FROM_HERE, delay, this,
- &ChromeToMobileService::RequestDeviceSearch);
- } else {
- LogMetric(BAD_SEARCH_OTHER);
- }
- // Update the cached mobile device list in profile prefs.
- profile_->GetPrefs()->Set(prefs::kChromeToMobileDeviceList, mobiles);
- if (HasMobiles())
- LogMetric(DEVICES_AVAILABLE);
- UpdateCommandState();
+ // Update the cached mobile device list in profile prefs.
+ profile_->GetPrefs()->Set(prefs::kChromeToMobileDeviceList, mobiles);
+
+ if (HasMobiles())
+ LogMetric(DEVICES_AVAILABLE);
+ UpdateCommandState();
+ }
}
void ChromeToMobileService::HandleSubmitResponse(
const net::URLFetcher* source) {
// Get the success value from the cloud print server response data.
std::string data;
- bool success = false;
source->GetResponseAsString(&data);
+ bool success = false;
DictionaryValue* dictionary = NULL;
scoped_ptr<Value> json(base::JSONReader::Read(data));
- if (json.get() && json->GetAsDictionary(&dictionary) && dictionary) {
+ if (json.get() && json->GetAsDictionary(&dictionary) && dictionary)
dictionary->GetBoolean("success", &success);
- int error_code = -1;
- if (dictionary->GetInteger("errorCode", &error_code))
- LogMetric(error_code == 407 ? BAD_SEND_407 : BAD_SEND_ERROR);
- } else if (source->GetResponseCode() == net::HTTP_FORBIDDEN) {
- LogMetric(BAD_SEND_AUTH);
- } else {
- LogMetric(BAD_SEND_OTHER);
- }
// Log each URL and [DELAYED_]SNAPSHOT job submission response.
LogMetric(success ? SEND_SUCCESS : SEND_ERROR);
- LOG_IF(INFO, !success) << "ChromeToMobile send failed (" <<
- source->GetResponseCode() << "): " << data;
// Get the observer for this job submission response.
base::WeakPtr<Observer> observer;
« no previous file with comments | « chrome/browser/chrome_to_mobile_service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698