Chromium Code Reviews| Index: google_apis/gaia/oauth2_token_service.cc |
| diff --git a/google_apis/gaia/oauth2_token_service.cc b/google_apis/gaia/oauth2_token_service.cc |
| index 0834c60d65e487bb51345d4174453737e5285b94..05ff5e571f6af1e2958cce78c53d554c81e669d5 100644 |
| --- a/google_apis/gaia/oauth2_token_service.cc |
| +++ b/google_apis/gaia/oauth2_token_service.cc |
| @@ -77,6 +77,7 @@ class OAuth2TokenService::Fetcher : public OAuth2AccessTokenConsumer { |
| net::URLRequestContextGetter* getter, |
| const std::string& chrome_client_id, |
| const std::string& chrome_client_secret, |
| + const std::string& account_id, |
|
Roger Tawa OOO till Jul 10th
2013/08/29 15:41:40
nit: for consistency, put account_id ahead of chro
fgorski
2013/08/29 23:04:14
Done.
|
| const std::string& refresh_token, |
| const OAuth2TokenService::ScopeSet& scopes, |
| base::WeakPtr<RequestImpl> waiting_request); |
| @@ -89,6 +90,7 @@ class OAuth2TokenService::Fetcher : public OAuth2AccessTokenConsumer { |
| const OAuth2TokenService::ScopeSet& GetScopeSet() const; |
| const std::string& GetRefreshToken() const; |
| + const std::string& GetAccountId() const; |
| // The error result from this fetcher. |
| const GoogleServiceAuthError& error() const { return error_; } |
| @@ -104,6 +106,7 @@ class OAuth2TokenService::Fetcher : public OAuth2AccessTokenConsumer { |
| net::URLRequestContextGetter* getter, |
| const std::string& chrome_client_id, |
| const std::string& chrome_client_secret, |
| + const std::string& account_id, |
| const std::string& refresh_token, |
| const OAuth2TokenService::ScopeSet& scopes, |
| base::WeakPtr<RequestImpl> waiting_request); |
| @@ -119,6 +122,7 @@ class OAuth2TokenService::Fetcher : public OAuth2AccessTokenConsumer { |
| // (whichever comes first). |
| OAuth2TokenService* const oauth2_token_service_; |
| scoped_refptr<net::URLRequestContextGetter> getter_; |
| + const std::string account_id_; |
| const std::string refresh_token_; |
| const OAuth2TokenService::ScopeSet scopes_; |
| std::vector<base::WeakPtr<RequestImpl> > waiting_requests_; |
| @@ -146,6 +150,7 @@ OAuth2TokenService::Fetcher* OAuth2TokenService::Fetcher::CreateAndStart( |
| net::URLRequestContextGetter* getter, |
| const std::string& chrome_client_id, |
| const std::string& chrome_client_secret, |
| + const std::string& account_id, |
| const std::string& refresh_token, |
| const OAuth2TokenService::ScopeSet& scopes, |
| base::WeakPtr<RequestImpl> waiting_request) { |
| @@ -154,6 +159,7 @@ OAuth2TokenService::Fetcher* OAuth2TokenService::Fetcher::CreateAndStart( |
| getter, |
| chrome_client_id, |
| chrome_client_secret, |
| + account_id, |
| refresh_token, |
| scopes, |
| waiting_request); |
| @@ -166,11 +172,13 @@ OAuth2TokenService::Fetcher::Fetcher( |
| net::URLRequestContextGetter* getter, |
| const std::string& chrome_client_id, |
| const std::string& chrome_client_secret, |
| + const std::string& account_id, |
| const std::string& refresh_token, |
| const OAuth2TokenService::ScopeSet& scopes, |
| base::WeakPtr<RequestImpl> waiting_request) |
| : oauth2_token_service_(oauth2_token_service), |
| getter_(getter), |
| + account_id_(account_id), |
| refresh_token_(refresh_token), |
| scopes_(scopes), |
| retry_number_(0), |
| @@ -297,6 +305,10 @@ const std::string& OAuth2TokenService::Fetcher::GetRefreshToken() const { |
| return refresh_token_; |
| } |
| +const std::string& OAuth2TokenService::Fetcher::GetAccountId() const { |
| + return account_id_; |
| +} |
| + |
| OAuth2TokenService::Request::Request() { |
| } |
| @@ -326,14 +338,22 @@ void OAuth2TokenService::RemoveObserver(Observer* observer) { |
| observer_list_.RemoveObserver(observer); |
| } |
| -bool OAuth2TokenService::RefreshTokenIsAvailable() { |
| - return !GetRefreshToken().empty(); |
| +bool OAuth2TokenService::RefreshTokenIsAvailable( |
| + const std::string& account_id) { |
| + DCHECK(CalledOnValidThread()); |
| + return !GetRefreshToken(account_id).empty(); |
| +} |
| + |
| +std::vector<std::string> OAuth2TokenService::GetAccounts() { |
| + return std::vector<std::string>(); |
| } |
| scoped_ptr<OAuth2TokenService::Request> OAuth2TokenService::StartRequest( |
| + const std::string& account_id, |
| const OAuth2TokenService::ScopeSet& scopes, |
| OAuth2TokenService::Consumer* consumer) { |
| return StartRequestForClientWithContext( |
| + account_id, |
| GetRequestContext(), |
| GaiaUrls::GetInstance()->oauth2_chrome_client_id(), |
| GaiaUrls::GetInstance()->oauth2_chrome_client_secret(), |
| @@ -343,11 +363,13 @@ scoped_ptr<OAuth2TokenService::Request> OAuth2TokenService::StartRequest( |
| scoped_ptr<OAuth2TokenService::Request> |
| OAuth2TokenService::StartRequestForClient( |
| + const std::string& account_id, |
| const std::string& client_id, |
| const std::string& client_secret, |
| const OAuth2TokenService::ScopeSet& scopes, |
| OAuth2TokenService::Consumer* consumer) { |
| return StartRequestForClientWithContext( |
| + account_id, |
| GetRequestContext(), |
| client_id, |
| client_secret, |
| @@ -357,10 +379,12 @@ OAuth2TokenService::StartRequestForClient( |
| scoped_ptr<OAuth2TokenService::Request> |
| OAuth2TokenService::StartRequestWithContext( |
| + const std::string& account_id, |
| net::URLRequestContextGetter* getter, |
| const ScopeSet& scopes, |
| Consumer* consumer) { |
| return StartRequestForClientWithContext( |
| + account_id, |
| getter, |
| GaiaUrls::GetInstance()->oauth2_chrome_client_id(), |
| GaiaUrls::GetInstance()->oauth2_chrome_client_secret(), |
| @@ -370,6 +394,7 @@ OAuth2TokenService::StartRequestWithContext( |
| scoped_ptr<OAuth2TokenService::Request> |
| OAuth2TokenService::StartRequestForClientWithContext( |
| + const std::string& account_id, |
| net::URLRequestContextGetter* getter, |
| const std::string& client_id, |
| const std::string& client_secret, |
| @@ -379,7 +404,7 @@ OAuth2TokenService::StartRequestForClientWithContext( |
| scoped_ptr<RequestImpl> request(new RequestImpl(consumer)); |
| - if (!RefreshTokenIsAvailable()) { |
| + if (!RefreshTokenIsAvailable(account_id)) { |
| base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind( |
| &RequestImpl::InformConsumer, |
| request->AsWeakPtr(), |
| @@ -393,6 +418,7 @@ OAuth2TokenService::StartRequestForClientWithContext( |
| StartCacheLookupRequest(request.get(), scopes, consumer); |
| } else { |
| FetchOAuth2Token(request.get(), |
| + account_id, |
| getter, |
| client_id, |
| client_secret, |
| @@ -402,11 +428,12 @@ OAuth2TokenService::StartRequestForClientWithContext( |
| } |
| void OAuth2TokenService::FetchOAuth2Token(RequestImpl* request, |
| + const std::string& account_id, |
| net::URLRequestContextGetter* getter, |
| const std::string& client_id, |
| const std::string& client_secret, |
| const ScopeSet& scopes) { |
| - std::string refresh_token = GetRefreshToken(); |
| + std::string refresh_token = GetRefreshToken(account_id); |
| // If there is already a pending fetcher for |scopes| and |refresh_token|, |
| // simply register this |request| for those results rather than starting |
| @@ -424,6 +451,7 @@ void OAuth2TokenService::FetchOAuth2Token(RequestImpl* request, |
| getter, |
| client_id, |
| client_secret, |
| + account_id, |
| refresh_token, |
| scopes, |
| request->AsWeakPtr()); |
| @@ -454,7 +482,7 @@ void OAuth2TokenService::OnFetchComplete(Fetcher* fetcher) { |
| // Update the auth error state so auth errors are appropriately communicated |
| // to the user. |
| - UpdateAuthError(fetcher->error()); |
| + UpdateAuthError(fetcher->GetAccountId(), fetcher->error()); |
| // Note |fetcher| is recorded in |pending_fetcher_| mapped to its refresh |
| // token and scope set. This is guaranteed as follows; here a Fetcher is said |
| @@ -492,12 +520,14 @@ void OAuth2TokenService::OnFetchComplete(Fetcher* fetcher) { |
| bool OAuth2TokenService::HasCacheEntry( |
| const OAuth2TokenService::ScopeSet& scopes) { |
| + // TODO(fgorski): Update keying of the cache to include account_id. |
| const CacheEntry* cache_entry = GetCacheEntry(scopes); |
| return cache_entry && cache_entry->access_token.length(); |
| } |
| const OAuth2TokenService::CacheEntry* OAuth2TokenService::GetCacheEntry( |
| const OAuth2TokenService::ScopeSet& scopes) { |
| + // TODO(fgorski): Update keying of the cache to include account_id. |
| DCHECK(CalledOnValidThread()); |
| TokenCache::iterator token_iterator = token_cache_.find(scopes); |
| if (token_iterator == token_cache_.end()) |
| @@ -512,6 +542,7 @@ const OAuth2TokenService::CacheEntry* OAuth2TokenService::GetCacheEntry( |
| bool OAuth2TokenService::RemoveCacheEntry( |
| const OAuth2TokenService::ScopeSet& scopes, |
| const std::string& token_to_remove) { |
| + // TODO(fgorski): Update keying of the cache to include account_id. |
| DCHECK(CalledOnValidThread()); |
| TokenCache::iterator token_iterator = token_cache_.find(scopes); |
| if (token_iterator != token_cache_.end() && |
| @@ -527,6 +558,7 @@ void OAuth2TokenService::RegisterCacheEntry( |
| const OAuth2TokenService::ScopeSet& scopes, |
| const std::string& access_token, |
| const base::Time& expiration_date) { |
| + // TODO(fgorski): Update keying of the cache to include account_id. |
| DCHECK(CalledOnValidThread()); |
| CacheEntry& token = token_cache_[scopes]; |
| @@ -534,7 +566,9 @@ void OAuth2TokenService::RegisterCacheEntry( |
| token.expiration_date = expiration_date; |
| } |
| -void OAuth2TokenService::UpdateAuthError(const GoogleServiceAuthError& error) { |
| +void OAuth2TokenService::UpdateAuthError( |
| + const std::string& account_id, |
| + const GoogleServiceAuthError& error) { |
| // Default implementation does nothing. |
| } |
| @@ -593,10 +627,6 @@ void OAuth2TokenService::FireRefreshTokensLoaded() { |
| FOR_EACH_OBSERVER(Observer, observer_list_, OnRefreshTokensLoaded()); |
| } |
| -void OAuth2TokenService::FireRefreshTokensCleared() { |
| - FOR_EACH_OBSERVER(Observer, observer_list_, OnRefreshTokensCleared()); |
| -} |
| - |
| int OAuth2TokenService::cache_size_for_testing() const { |
| return token_cache_.size(); |
| } |