| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2015 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_delegate.h" |
| 6 |
| 7 FakeProfileOAuth2TokenServiceDelegate::FakeProfileOAuth2TokenServiceDelegate() { |
| 8 } |
| 9 |
| 10 FakeProfileOAuth2TokenServiceDelegate:: |
| 11 ~FakeProfileOAuth2TokenServiceDelegate() { |
| 12 } |
| 13 |
| 14 OAuth2AccessTokenFetcher* |
| 15 FakeProfileOAuth2TokenServiceDelegate::CreateAccessTokenFetcher( |
| 16 const std::string& account_id, |
| 17 net::URLRequestContextGetter* getter, |
| 18 OAuth2AccessTokenConsumer* consumer) { |
| 19 NOTREACHED(); |
| 20 return NULL; |
| 21 } |
| 22 |
| 23 bool FakeProfileOAuth2TokenServiceDelegate::RefreshTokenIsAvailable( |
| 24 const std::string& account_id) const { |
| 25 return !GetRefreshToken(account_id).empty(); |
| 26 } |
| 27 |
| 28 std::string FakeProfileOAuth2TokenServiceDelegate::GetRefreshToken( |
| 29 const std::string& account_id) const { |
| 30 std::map<std::string, std::string>::const_iterator it = |
| 31 refresh_tokens_.find(account_id); |
| 32 if (it != refresh_tokens_.end()) |
| 33 return it->second; |
| 34 return std::string(); |
| 35 } |
| 36 |
| 37 void FakeProfileOAuth2TokenServiceDelegate::UpdateAuthError( |
| 38 const std::string& account_id, |
| 39 const GoogleServiceAuthError& error) { |
| 40 } |
| 41 |
| 42 std::vector<std::string> FakeProfileOAuth2TokenServiceDelegate::GetAccounts() { |
| 43 std::vector<std::string> account_ids; |
| 44 for (std::map<std::string, std::string>::const_iterator iter = |
| 45 refresh_tokens_.begin(); |
| 46 iter != refresh_tokens_.end(); ++iter) { |
| 47 account_ids.push_back(iter->first); |
| 48 } |
| 49 return account_ids; |
| 50 } |
| 51 |
| 52 void FakeProfileOAuth2TokenServiceDelegate::RevokeAllCredentials() { |
| 53 } |
| 54 |
| 55 void FakeProfileOAuth2TokenServiceDelegate::LoadCredentials( |
| 56 const std::string& primary_account_id) { |
| 57 // Empty implementation as FakeProfileOAuth2TokenService does not have any |
| 58 // credentials to load. |
| 59 } |
| 60 |
| 61 void FakeProfileOAuth2TokenServiceDelegate::UpdateCredentials( |
| 62 const std::string& account_id, |
| 63 const std::string& refresh_token) { |
| 64 IssueRefreshTokenForUser(account_id, refresh_token); |
| 65 } |
| 66 |
| 67 void FakeProfileOAuth2TokenServiceDelegate::IssueRefreshTokenForUser( |
| 68 const std::string& account_id, |
| 69 const std::string& token) { |
| 70 ScopedBatchChange batch(this); |
| 71 if (token.empty()) { |
| 72 refresh_tokens_.erase(account_id); |
| 73 FireRefreshTokenRevoked(account_id); |
| 74 } else { |
| 75 refresh_tokens_[account_id] = token; |
| 76 FireRefreshTokenAvailable(account_id); |
| 77 // TODO(atwilson): Maybe we should also call FireRefreshTokensLoaded() here? |
| 78 } |
| 79 } |
| 80 |
| 81 net::URLRequestContextGetter* |
| 82 FakeProfileOAuth2TokenServiceDelegate::GetRequestContext() const { |
| 83 return NULL; |
| 84 } |
| 85 |
| 86 void FakeProfileOAuth2TokenServiceDelegate::IssueRefreshToken( |
| 87 const std::string& token) { |
| 88 IssueRefreshTokenForUser("account_id", token); |
| 89 } |
| 90 |
| 91 void FakeProfileOAuth2TokenServiceDelegate::IssueAllRefreshTokensLoaded() { |
| 92 FireRefreshTokensLoaded(); |
| 93 } |
| OLD | NEW |