| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h" |
| 6 |
| 7 // static |
| 8 BrowserContextKeyedService* FakeProfileOAuth2TokenService::Build( |
| 9 content::BrowserContext* profile) { |
| 10 return new FakeProfileOAuth2TokenService(); |
| 11 } |
| 12 |
| 13 FakeProfileOAuth2TokenService::FakeProfileOAuth2TokenService() { |
| 14 } |
| 15 |
| 16 FakeProfileOAuth2TokenService::~FakeProfileOAuth2TokenService() { |
| 17 } |
| 18 |
| 19 void FakeProfileOAuth2TokenService::Shutdown() { |
| 20 // Do not call the base class handler because it assumes that Initialize() |
| 21 // is always called before Shutdown() and that's not the case for this mock. |
| 22 } |
| 23 |
| 24 void FakeProfileOAuth2TokenService::IssueRefreshToken( |
| 25 const std::string& token) { |
| 26 refresh_token_ = token; |
| 27 if (refresh_token_.empty()) { |
| 28 FireRefreshTokenRevoked("account_id", |
| 29 GoogleServiceAuthError::AuthErrorNone()); |
| 30 } else { |
| 31 FireRefreshTokenAvailable("account_id"); |
| 32 } |
| 33 } |
| 34 |
| 35 void FakeProfileOAuth2TokenService::IssueTokenForScope( |
| 36 const ScopeSet& scope, |
| 37 const std::string& access_token, |
| 38 const base::Time& expiration) { |
| 39 CompleteRequests(scope, |
| 40 GoogleServiceAuthError::AuthErrorNone(), |
| 41 access_token, |
| 42 expiration); |
| 43 } |
| 44 |
| 45 void FakeProfileOAuth2TokenService::IssueErrorForScope( |
| 46 const ScopeSet& scope, |
| 47 const GoogleServiceAuthError& error) { |
| 48 CompleteRequests(scope, error, std::string(), base::Time()); |
| 49 } |
| 50 |
| 51 void FakeProfileOAuth2TokenService::CompleteRequests( |
| 52 const ScopeSet& scope, |
| 53 const GoogleServiceAuthError& error, |
| 54 const std::string& access_token, |
| 55 const base::Time& expiration) { |
| 56 std::vector<FakeProfileOAuth2TokenService::PendingRequest> requests = |
| 57 GetPendingRequests(); |
| 58 // Walk the requests and notify the callbacks. |
| 59 for (std::vector<PendingRequest>::iterator it = pending_requests_.begin(); |
| 60 it != pending_requests_.end(); ++it) { |
| 61 if (it->request && it->scopes == scope) |
| 62 it->request->InformConsumer(error, access_token, expiration); |
| 63 } |
| 64 } |
| 65 |
| 66 std::string FakeProfileOAuth2TokenService::GetRefreshToken() { |
| 67 return refresh_token_; |
| 68 } |
| 69 |
| 70 net::URLRequestContextGetter* |
| 71 FakeProfileOAuth2TokenService::GetRequestContext() { |
| 72 return NULL; |
| 73 } |
| 74 |
| 75 std::vector<FakeProfileOAuth2TokenService::PendingRequest> |
| 76 FakeProfileOAuth2TokenService::GetPendingRequests() { |
| 77 std::vector<PendingRequest> valid_requests; |
| 78 for (std::vector<PendingRequest>::iterator it = pending_requests_.begin(); |
| 79 it != pending_requests_.end(); ++it) { |
| 80 if (it->request) |
| 81 valid_requests.push_back(*it); |
| 82 } |
| 83 return valid_requests; |
| 84 } |
| 85 |
| 86 void FakeProfileOAuth2TokenService::FetchOAuth2Token( |
| 87 RequestImpl* request, |
| 88 net::URLRequestContextGetter* getter, |
| 89 const std::string& client_id, |
| 90 const std::string& client_secret, |
| 91 const ScopeSet& scopes) { |
| 92 PendingRequest pending_request; |
| 93 pending_request.client_id = client_id; |
| 94 pending_request.client_secret = client_secret; |
| 95 pending_request.scopes = scopes; |
| 96 pending_request.request = request->AsWeakPtr(); |
| 97 pending_requests_.push_back(pending_request); |
| 98 } |
| OLD | NEW |