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.
5 #include "components/signin/ios/browser/fake_profile_oauth2_token_service_ios_delegate.h"
6 #include "google_apis/gaia/oauth2_access_token_fetcher_impl.h"
8 FakeProfileOAuth2TokenServiceIOSDelegate::
9 FakeProfileOAuth2TokenServiceIOSDelegate(
11 ProfileOAuth2TokenServiceIOSProvider* provider,
12 AccountTrackerService* account_tracker_service,
13 SigninErrorController* signin_error_controller)
14 : ProfileOAuth2TokenServiceIOSDelegate(client,
16 account_tracker_service,
17 signin_error_controller) {}
19 FakeProfileOAuth2TokenServiceIOSDelegate::
20 ~FakeProfileOAuth2TokenServiceIOSDelegate() {}
22 OAuth2AccessTokenFetcher*
23 FakeProfileOAuth2TokenServiceIOSDelegate::CreateAccessTokenFetcher(
24 const std::string& account_id,
25 net::URLRequestContextGetter* getter,
26 OAuth2AccessTokenConsumer* consumer) {
27 std::map<std::string, std::string>::const_iterator it =
28 refresh_tokens_.find(account_id);
29 DCHECK(it != refresh_tokens_.end());
30 std::string refresh_token(it->second);
31 return new OAuth2AccessTokenFetcherImpl(consumer, getter, refresh_token);
34 bool FakeProfileOAuth2TokenServiceIOSDelegate::RefreshTokenIsAvailable(
35 const std::string& account_id) const {
36 return !GetRefreshToken(account_id).empty();
39 std::string FakeProfileOAuth2TokenServiceIOSDelegate::GetRefreshToken(
40 const std::string& account_id) const {
41 std::map<std::string, std::string>::const_iterator it =
42 refresh_tokens_.find(account_id);
43 if (it != refresh_tokens_.end())
48 std::vector<std::string>
49 FakeProfileOAuth2TokenServiceIOSDelegate::GetAccounts() {
50 std::vector<std::string> account_ids;
51 for (std::map<std::string, std::string>::const_iterator iter =
52 refresh_tokens_.begin();
53 iter != refresh_tokens_.end(); ++iter) {
54 account_ids.push_back(iter->first);
59 void FakeProfileOAuth2TokenServiceIOSDelegate::RevokeAllCredentials() {
60 std::vector<std::string> account_ids = GetAccounts();
61 for (std::vector<std::string>::const_iterator it = account_ids.begin();
62 it != account_ids.end(); it++) {
63 RevokeCredentials(*it);
67 void FakeProfileOAuth2TokenServiceIOSDelegate::LoadCredentials(
68 const std::string& primary_account_id) {
69 FireRefreshTokensLoaded();
72 void FakeProfileOAuth2TokenServiceIOSDelegate::UpdateCredentials(
73 const std::string& account_id,
74 const std::string& refresh_token) {
75 IssueRefreshTokenForUser(account_id, refresh_token);
78 void FakeProfileOAuth2TokenServiceIOSDelegate::AddOrUpdateAccount(
79 const std::string& account_id) {
80 UpdateCredentials(account_id, "fake_refresh_token");
83 void FakeProfileOAuth2TokenServiceIOSDelegate::RemoveAccount(
84 const std::string& account_id) {
85 IssueRefreshTokenForUser(account_id, "");
88 void FakeProfileOAuth2TokenServiceIOSDelegate::IssueRefreshTokenForUser(
89 const std::string& account_id,
90 const std::string& token) {
91 ScopedBatchChange batch(this);
93 refresh_tokens_.erase(account_id);
94 FireRefreshTokenRevoked(account_id);
96 refresh_tokens_[account_id] = token;
97 FireRefreshTokenAvailable(account_id);
101 void FakeProfileOAuth2TokenServiceIOSDelegate::RevokeCredentials(
102 const std::string& account_id) {
103 IssueRefreshTokenForUser(account_id, std::string());