| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "google_apis/gaia/oauth2_token_service.h" | 5 #include "google_apis/gaia/oauth2_token_service.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 const GoogleServiceAuthError& error, | 71 const GoogleServiceAuthError& error, |
| 72 const std::string& access_token, | 72 const std::string& access_token, |
| 73 const base::Time& expiration_date) { | 73 const base::Time& expiration_date) { |
| 74 DCHECK(CalledOnValidThread()); | 74 DCHECK(CalledOnValidThread()); |
| 75 if (error.state() == GoogleServiceAuthError::NONE) | 75 if (error.state() == GoogleServiceAuthError::NONE) |
| 76 consumer_->OnGetTokenSuccess(this, access_token, expiration_date); | 76 consumer_->OnGetTokenSuccess(this, access_token, expiration_date); |
| 77 else | 77 else |
| 78 consumer_->OnGetTokenFailure(this, error); | 78 consumer_->OnGetTokenFailure(this, error); |
| 79 } | 79 } |
| 80 | 80 |
| 81 OAuth2TokenService::ScopedBacthChange::ScopedBacthChange( | 81 OAuth2TokenService::ScopedBatchChange::ScopedBatchChange( |
| 82 OAuth2TokenService* token_service) : token_service_(token_service) { | 82 OAuth2TokenService* token_service) : token_service_(token_service) { |
| 83 DCHECK(token_service_); | 83 DCHECK(token_service_); |
| 84 token_service_->StartBatchChanges(); | 84 token_service_->StartBatchChanges(); |
| 85 } | 85 } |
| 86 | 86 |
| 87 OAuth2TokenService::ScopedBacthChange::~ScopedBacthChange() { | 87 OAuth2TokenService::ScopedBatchChange::~ScopedBatchChange() { |
| 88 token_service_->EndBatchChanges(); | 88 token_service_->EndBatchChanges(); |
| 89 } | 89 } |
| 90 | 90 |
| 91 // Class that fetches an OAuth2 access token for a given account id and set of | 91 // Class that fetches an OAuth2 access token for a given account id and set of |
| 92 // scopes. | 92 // scopes. |
| 93 // | 93 // |
| 94 // It aims to meet OAuth2TokenService's requirements on token fetching. Retry | 94 // It aims to meet OAuth2TokenService's requirements on token fetching. Retry |
| 95 // mechanism is used to handle failures. | 95 // mechanism is used to handle failures. |
| 96 // | 96 // |
| 97 // To use this class, call CreateAndStart() to create and start a Fetcher. | 97 // To use this class, call CreateAndStart() to create and start a Fetcher. |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 void Cancel(); | 143 void Cancel(); |
| 144 | 144 |
| 145 const ScopeSet& GetScopeSet() const; | 145 const ScopeSet& GetScopeSet() const; |
| 146 const std::string& GetClientId() const; | 146 const std::string& GetClientId() const; |
| 147 const std::string& GetAccountId() const; | 147 const std::string& GetAccountId() const; |
| 148 | 148 |
| 149 // The error result from this fetcher. | 149 // The error result from this fetcher. |
| 150 const GoogleServiceAuthError& error() const { return error_; } | 150 const GoogleServiceAuthError& error() const { return error_; } |
| 151 | 151 |
| 152 protected: | 152 protected: |
| 153 // OAuth2AccessTokenConsumer | 153 // OAuth2AccessTokenConsumer |
| 154 void OnGetTokenSuccess(const std::string& access_token, | 154 void OnGetTokenSuccess(const std::string& access_token, |
| 155 const base::Time& expiration_date) override; | 155 const base::Time& expiration_date) override; |
| 156 void OnGetTokenFailure(const GoogleServiceAuthError& error) override; | 156 void OnGetTokenFailure(const GoogleServiceAuthError& error) override; |
| 157 | 157 |
| 158 private: | 158 private: |
| 159 Fetcher(OAuth2TokenService* oauth2_token_service, | 159 Fetcher(OAuth2TokenService* oauth2_token_service, |
| 160 const std::string& account_id, | 160 const std::string& account_id, |
| 161 net::URLRequestContextGetter* getter, | 161 net::URLRequestContextGetter* getter, |
| 162 const std::string& client_id, | 162 const std::string& client_id, |
| 163 const std::string& client_secret, | 163 const std::string& client_secret, |
| (...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 809 const std::string& account_id, | 809 const std::string& account_id, |
| 810 const ScopeSet& scopes) const { | 810 const ScopeSet& scopes) const { |
| 811 PendingFetcherMap::const_iterator iter = pending_fetchers_.find( | 811 PendingFetcherMap::const_iterator iter = pending_fetchers_.find( |
| 812 OAuth2TokenService::RequestParameters( | 812 OAuth2TokenService::RequestParameters( |
| 813 client_id, | 813 client_id, |
| 814 account_id, | 814 account_id, |
| 815 scopes)); | 815 scopes)); |
| 816 return iter == pending_fetchers_.end() ? | 816 return iter == pending_fetchers_.end() ? |
| 817 0 : iter->second->GetWaitingRequestCount(); | 817 0 : iter->second->GetWaitingRequestCount(); |
| 818 } | 818 } |
| OLD | NEW |