OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 "chrome/browser/signin/oauth2_token_service.h" | 5 #include "chrome/browser/signin/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 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 const std::string& refresh_token, | 164 const std::string& refresh_token, |
165 const OAuth2TokenService::ScopeSet& scopes, | 165 const OAuth2TokenService::ScopeSet& scopes, |
166 base::WeakPtr<RequestImpl> waiting_request) | 166 base::WeakPtr<RequestImpl> waiting_request) |
167 : oauth2_token_service_(oauth2_token_service), | 167 : oauth2_token_service_(oauth2_token_service), |
168 getter_(getter), | 168 getter_(getter), |
169 refresh_token_(refresh_token), | 169 refresh_token_(refresh_token), |
170 scopes_(scopes), | 170 scopes_(scopes), |
171 retry_number_(0), | 171 retry_number_(0), |
172 error_(GoogleServiceAuthError::SERVICE_UNAVAILABLE) { | 172 error_(GoogleServiceAuthError::SERVICE_UNAVAILABLE) { |
173 DCHECK(oauth2_token_service_); | 173 DCHECK(oauth2_token_service_); |
174 DCHECK(getter_); | 174 DCHECK(getter_.get()); |
175 DCHECK(refresh_token_.length()); | 175 DCHECK(refresh_token_.length()); |
176 waiting_requests_.push_back(waiting_request); | 176 waiting_requests_.push_back(waiting_request); |
177 } | 177 } |
178 | 178 |
179 OAuth2TokenService::Fetcher::~Fetcher() { | 179 OAuth2TokenService::Fetcher::~Fetcher() { |
180 // Inform the waiting requests if it has not done so. | 180 // Inform the waiting requests if it has not done so. |
181 if (waiting_requests_.size()) | 181 if (waiting_requests_.size()) |
182 InformWaitingRequests(); | 182 InformWaitingRequests(); |
183 } | 183 } |
184 | 184 |
185 void OAuth2TokenService::Fetcher::Start() { | 185 void OAuth2TokenService::Fetcher::Start() { |
186 fetcher_.reset(new OAuth2AccessTokenFetcher(this, getter_)); | 186 fetcher_.reset(new OAuth2AccessTokenFetcher(this, getter_.get())); |
187 fetcher_->Start(GaiaUrls::GetInstance()->oauth2_chrome_client_id(), | 187 fetcher_->Start(GaiaUrls::GetInstance()->oauth2_chrome_client_id(), |
188 GaiaUrls::GetInstance()->oauth2_chrome_client_secret(), | 188 GaiaUrls::GetInstance()->oauth2_chrome_client_secret(), |
189 refresh_token_, | 189 refresh_token_, |
190 std::vector<std::string>(scopes_.begin(), scopes_.end())); | 190 std::vector<std::string>(scopes_.begin(), scopes_.end())); |
191 retry_timer_.Stop(); | 191 retry_timer_.Stop(); |
192 } | 192 } |
193 | 193 |
194 void OAuth2TokenService::Fetcher::OnGetTokenSuccess( | 194 void OAuth2TokenService::Fetcher::OnGetTokenSuccess( |
195 const std::string& access_token, | 195 const std::string& access_token, |
196 const base::Time& expiration_date) { | 196 const base::Time& expiration_date) { |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 // Makes sure there is a pending fetcher for |scopes| and |refresh_token|. | 340 // Makes sure there is a pending fetcher for |scopes| and |refresh_token|. |
341 // Adds |request| to the waiting request list of this fetcher so |request| | 341 // Adds |request| to the waiting request list of this fetcher so |request| |
342 // will be called back when this fetcher finishes fetching. | 342 // will be called back when this fetcher finishes fetching. |
343 FetchParameters fetch_parameters = std::make_pair(refresh_token, scopes); | 343 FetchParameters fetch_parameters = std::make_pair(refresh_token, scopes); |
344 std::map<FetchParameters, Fetcher*>::iterator iter = | 344 std::map<FetchParameters, Fetcher*>::iterator iter = |
345 pending_fetchers_.find(fetch_parameters); | 345 pending_fetchers_.find(fetch_parameters); |
346 if (iter != pending_fetchers_.end()) { | 346 if (iter != pending_fetchers_.end()) { |
347 iter->second->AddWaitingRequest(request->AsWeakPtr()); | 347 iter->second->AddWaitingRequest(request->AsWeakPtr()); |
348 return request.PassAs<Request>(); | 348 return request.PassAs<Request>(); |
349 } | 349 } |
350 pending_fetchers_[fetch_parameters] = Fetcher::CreateAndStart( | 350 pending_fetchers_[fetch_parameters] = |
351 this, request_context_getter_, refresh_token, scopes, | 351 Fetcher::CreateAndStart(this, |
352 request->AsWeakPtr()); | 352 request_context_getter_.get(), |
| 353 refresh_token, |
| 354 scopes, |
| 355 request->AsWeakPtr()); |
353 return request.PassAs<Request>(); | 356 return request.PassAs<Request>(); |
354 } | 357 } |
355 | 358 |
356 scoped_ptr<OAuth2TokenService::Request> | 359 scoped_ptr<OAuth2TokenService::Request> |
357 OAuth2TokenService::StartCacheLookupRequest( | 360 OAuth2TokenService::StartCacheLookupRequest( |
358 const OAuth2TokenService::ScopeSet& scopes, | 361 const OAuth2TokenService::ScopeSet& scopes, |
359 OAuth2TokenService::Consumer* consumer) { | 362 OAuth2TokenService::Consumer* consumer) { |
360 CHECK(HasCacheEntry(scopes)); | 363 CHECK(HasCacheEntry(scopes)); |
361 const CacheEntry* cache_entry = GetCacheEntry(scopes); | 364 const CacheEntry* cache_entry = GetCacheEntry(scopes); |
362 scoped_ptr<RequestImpl> request(new RequestImpl(consumer)); | 365 scoped_ptr<RequestImpl> request(new RequestImpl(consumer)); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 } | 468 } |
466 | 469 |
467 void OAuth2TokenService::ClearCache() { | 470 void OAuth2TokenService::ClearCache() { |
468 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 471 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
469 token_cache_.clear(); | 472 token_cache_.clear(); |
470 } | 473 } |
471 | 474 |
472 int OAuth2TokenService::cache_size_for_testing() const { | 475 int OAuth2TokenService::cache_size_for_testing() const { |
473 return token_cache_.size(); | 476 return token_cache_.size(); |
474 } | 477 } |
OLD | NEW |