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

Unified Diff: chrome/browser/history/web_history_service.cc

Issue 12880014: Get OAuth2TokenService working on Android. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Change args to const refs. Created 7 years, 9 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
Index: chrome/browser/history/web_history_service.cc
diff --git a/chrome/browser/history/web_history_service.cc b/chrome/browser/history/web_history_service.cc
index 4ef92322266af4150b8fa30503380ea2725f36f5..76d25557598623b230f8c40e2ce7cab7aef3b521 100644
--- a/chrome/browser/history/web_history_service.cc
+++ b/chrome/browser/history/web_history_service.cc
@@ -63,6 +63,7 @@ class RequestImpl : public WebHistoryService::Request,
: profile_(profile),
url_(GURL(url)),
response_code_(0),
+ auth_retry_count_(0),
callback_(callback) {
}
@@ -80,6 +81,19 @@ class RequestImpl : public WebHistoryService::Request,
virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE {
DCHECK_EQ(source, url_fetcher_.get());
response_code_ = url_fetcher_->GetResponseCode();
+
+ // If the response code indicates that the token might not be valid,
+ // invalidate the token and try again.
+ if (response_code_ == net::HTTP_UNAUTHORIZED && ++auth_retry_count_ <= 1) {
+ OAuth2TokenService::ScopeSet oauth_scopes;
+ oauth_scopes.insert(kHistoryOAuthScope);
+ OAuth2TokenServiceFactory::GetForProfile(profile_)->InvalidateToken(
+ oauth_scopes, access_token_);
+
+ access_token_ = std::string();
+ Start();
+ return;
+ }
url_fetcher_->GetResponseAsString(&response_body_);
url_fetcher_.reset();
callback_.Run(this, true);
@@ -92,6 +106,7 @@ class RequestImpl : public WebHistoryService::Request,
const base::Time& expiration_time) OVERRIDE {
token_request_.reset();
DCHECK(!access_token.empty());
+ access_token_ = access_token;
// Got an access token -- start the actual API request.
url_fetcher_.reset(CreateUrlFetcher(access_token));
@@ -139,6 +154,9 @@ class RequestImpl : public WebHistoryService::Request,
// The OAuth2 access token request.
scoped_ptr<OAuth2TokenService::Request> token_request_;
+ // The current OAuth2 access token.
+ std::string access_token_;
+
// Handles the actual API requests after the OAuth token is acquired.
scoped_ptr<net::URLFetcher> url_fetcher_;
@@ -148,6 +166,10 @@ class RequestImpl : public WebHistoryService::Request,
// Holds the response body received from the server.
std::string response_body_;
+ // The number of times this request has already been retried due to
+ // authorization problems.
+ int auth_retry_count_;
+
// The callback to execute when the query is complete.
CompletionCallback callback_;
};

Powered by Google App Engine
This is Rietveld 408576698