| 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..3fa5ff232f0a44db74c3ce78efefb7dc2c9ae824 100644
|
| --- a/google_apis/gaia/oauth2_token_service.cc
|
| +++ b/google_apis/gaia/oauth2_token_service.cc
|
| @@ -75,6 +75,7 @@ class OAuth2TokenService::Fetcher : public OAuth2AccessTokenConsumer {
|
| // The given |oauth2_token_service| will be informed when fetching is done.
|
| static Fetcher* CreateAndStart(OAuth2TokenService* oauth2_token_service,
|
| net::URLRequestContextGetter* getter,
|
| + const std::string& account_id,
|
| const std::string& chrome_client_id,
|
| const std::string& chrome_client_secret,
|
| const std::string& refresh_token,
|
| @@ -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_;
|
| @@ -144,6 +148,7 @@ class OAuth2TokenService::Fetcher : public OAuth2AccessTokenConsumer {
|
| OAuth2TokenService::Fetcher* OAuth2TokenService::Fetcher::CreateAndStart(
|
| OAuth2TokenService* oauth2_token_service,
|
| net::URLRequestContextGetter* getter,
|
| + const std::string& account_id,
|
| const std::string& chrome_client_id,
|
| const std::string& chrome_client_secret,
|
| const std::string& refresh_token,
|
| @@ -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
|
| @@ -422,6 +449,7 @@ void OAuth2TokenService::FetchOAuth2Token(RequestImpl* request,
|
| pending_fetchers_[fetch_parameters] =
|
| Fetcher::CreateAndStart(this,
|
| getter,
|
| + account_id,
|
| client_id,
|
| client_secret,
|
| refresh_token,
|
| @@ -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();
|
| }
|
|
|