| 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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 // Creates a Fetcher and starts fetching an OAuth2 access token for | 121 // Creates a Fetcher and starts fetching an OAuth2 access token for |
| 122 // |account_id| and |scopes| in the request context obtained by |getter|. | 122 // |account_id| and |scopes| in the request context obtained by |getter|. |
| 123 // The given |oauth2_token_service| will be informed when fetching is done. | 123 // The given |oauth2_token_service| will be informed when fetching is done. |
| 124 static Fetcher* CreateAndStart(OAuth2TokenService* oauth2_token_service, | 124 static Fetcher* CreateAndStart(OAuth2TokenService* oauth2_token_service, |
| 125 const std::string& account_id, | 125 const std::string& account_id, |
| 126 net::URLRequestContextGetter* getter, | 126 net::URLRequestContextGetter* getter, |
| 127 const std::string& client_id, | 127 const std::string& client_id, |
| 128 const std::string& client_secret, | 128 const std::string& client_secret, |
| 129 const ScopeSet& scopes, | 129 const ScopeSet& scopes, |
| 130 base::WeakPtr<RequestImpl> waiting_request); | 130 base::WeakPtr<RequestImpl> waiting_request); |
| 131 virtual ~Fetcher(); | 131 ~Fetcher() override; |
| 132 | 132 |
| 133 // Add a request that is waiting for the result of this Fetcher. | 133 // Add a request that is waiting for the result of this Fetcher. |
| 134 void AddWaitingRequest(base::WeakPtr<RequestImpl> waiting_request); | 134 void AddWaitingRequest(base::WeakPtr<RequestImpl> waiting_request); |
| 135 | 135 |
| 136 // Returns count of waiting requests. | 136 // Returns count of waiting requests. |
| 137 size_t GetWaitingRequestCount() const; | 137 size_t GetWaitingRequestCount() const; |
| 138 | 138 |
| 139 const std::vector<base::WeakPtr<RequestImpl> >& waiting_requests() const { | 139 const std::vector<base::WeakPtr<RequestImpl> >& waiting_requests() const { |
| 140 return waiting_requests_; | 140 return waiting_requests_; |
| 141 } | 141 } |
| 142 | 142 |
| 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 virtual 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 virtual void OnGetTokenFailure( | 156 void OnGetTokenFailure(const GoogleServiceAuthError& error) override; |
| 157 const GoogleServiceAuthError& error) override; | |
| 158 | 157 |
| 159 private: | 158 private: |
| 160 Fetcher(OAuth2TokenService* oauth2_token_service, | 159 Fetcher(OAuth2TokenService* oauth2_token_service, |
| 161 const std::string& account_id, | 160 const std::string& account_id, |
| 162 net::URLRequestContextGetter* getter, | 161 net::URLRequestContextGetter* getter, |
| 163 const std::string& client_id, | 162 const std::string& client_id, |
| 164 const std::string& client_secret, | 163 const std::string& client_secret, |
| 165 const OAuth2TokenService::ScopeSet& scopes, | 164 const OAuth2TokenService::ScopeSet& scopes, |
| 166 base::WeakPtr<RequestImpl> waiting_request); | 165 base::WeakPtr<RequestImpl> waiting_request); |
| 167 void Start(); | 166 void Start(); |
| (...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 810 const std::string& account_id, | 809 const std::string& account_id, |
| 811 const ScopeSet& scopes) const { | 810 const ScopeSet& scopes) const { |
| 812 PendingFetcherMap::const_iterator iter = pending_fetchers_.find( | 811 PendingFetcherMap::const_iterator iter = pending_fetchers_.find( |
| 813 OAuth2TokenService::RequestParameters( | 812 OAuth2TokenService::RequestParameters( |
| 814 client_id, | 813 client_id, |
| 815 account_id, | 814 account_id, |
| 816 scopes)); | 815 scopes)); |
| 817 return iter == pending_fetchers_.end() ? | 816 return iter == pending_fetchers_.end() ? |
| 818 0 : iter->second->GetWaitingRequestCount(); | 817 0 : iter->second->GetWaitingRequestCount(); |
| 819 } | 818 } |
| OLD | NEW |