Chromium Code Reviews| 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..2b583dc1551db22f34e3843dacfef820cce6d128 100644 |
| --- a/chrome/browser/history/web_history_service.cc |
| +++ b/chrome/browser/history/web_history_service.cc |
| @@ -63,23 +63,36 @@ class RequestImpl : public WebHistoryService::Request, |
| : profile_(profile), |
| url_(GURL(url)), |
| response_code_(0), |
| + auth_retry_count_(0), |
| callback_(callback) { |
| } |
| // Tells the request to do its thang. |
| - void Start() { |
| + void Start(bool invalidate_token) { |
| OAuth2TokenService::ScopeSet oauth_scopes; |
| oauth_scopes.insert(kHistoryOAuthScope); |
| OAuth2TokenService* token_service = |
| OAuth2TokenServiceFactory::GetForProfile(profile_); |
| - token_request_ = token_service->StartRequest(oauth_scopes, this); |
| + if (invalidate_token) { |
| + token_request_ = token_service->InvalidateTokenAndStartRequest( |
| + oauth_scopes, this, access_token_); |
|
Roger Tawa OOO till Jul 10th
2013/03/25 19:14:35
Is there a reason to have a method to invalidate a
Patrick Dubroy
2013/03/25 21:15:49
Done.
|
| + } else { |
| + token_request_ = token_service->StartRequest(oauth_scopes, this); |
| + } |
| } |
| // content::URLFetcherDelegate interface. |
| 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, get a |
| + // new token and try again. |
| + if (response_code_ == net::HTTP_UNAUTHORIZED && ++auth_retry_count_ <= 1) { |
| + Start(true); |
|
Roger Tawa OOO till Jul 10th
2013/03/25 19:14:35
Seems like you could just invalidate the token her
Patrick Dubroy
2013/03/25 21:15:49
Done.
|
| + return; |
| + } |
| url_fetcher_->GetResponseAsString(&response_body_); |
| url_fetcher_.reset(); |
| callback_.Run(this, true); |
| @@ -92,6 +105,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 +153,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 +165,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_; |
| }; |
| @@ -243,7 +264,7 @@ scoped_ptr<WebHistoryService::Request> WebHistoryService::QueryHistory( |
| scoped_ptr<RequestImpl> request( |
| new RequestImpl(profile_, GetQueryUrl(options), completion_callback)); |
| - request->Start(); |
| + request->Start(false); |
| return request.PassAs<Request>(); |
| } |
| @@ -280,7 +301,7 @@ scoped_ptr<WebHistoryService::Request> WebHistoryService::ExpireHistory( |
| scoped_ptr<RequestImpl> request( |
| new RequestImpl(profile_, kHistoryDeleteHistoryUrl, callback)); |
| request->set_post_data(post_data); |
| - request->Start(); |
| + request->Start(false); |
| return request.PassAs<Request>(); |
| } |