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

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: Disable unit test on Android -- it doesn't make sense. 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 91f102174180cee369cc544a2d441a61d5dec847..0a792307ca2e513b7aa3a167a1bb23e020a1433f 100644
--- a/chrome/browser/history/web_history_service.cc
+++ b/chrome/browser/history/web_history_service.cc
@@ -64,6 +64,7 @@ class RequestImpl : public WebHistoryService::Request,
: profile_(profile),
url_(GURL(url)),
response_code_(0),
+ auth_retry_count_(0),
callback_(callback) {
}
@@ -81,6 +82,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);
@@ -93,6 +107,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));
@@ -140,6 +155,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_;
@@ -149,6 +167,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