1 // Copyright 2020 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 "components/signin/internal/identity_manager/test_profile_oauth2_token_service_delegate_chromeos.h"
6
7 #include "google_apis/gaia/oauth2_access_token_fetcher.h"
8 #include "services/network/public/cpp/shared_url_loader_factory.h"
9
10 namespace signin {
11
12 TestProfileOAuth2TokenServiceDelegateChromeOS::
TestProfileOAuth2TokenServiceDelegateChromeOS(AccountTrackerService * account_tracker_service,chromeos::AccountManager * account_manager,bool is_regular_profile)13 TestProfileOAuth2TokenServiceDelegateChromeOS(
14 AccountTrackerService* account_tracker_service,
15 chromeos::AccountManager* account_manager,
16 bool is_regular_profile) {
17 if (!network::TestNetworkConnectionTracker::HasInstance()) {
18 owned_tracker_ = network::TestNetworkConnectionTracker::CreateInstance();
19 }
20
21 delegate_ = std::make_unique<ProfileOAuth2TokenServiceDelegateChromeOS>(
22 account_tracker_service,
23 network::TestNetworkConnectionTracker::GetInstance(), account_manager,
24 is_regular_profile);
25 delegate_->AddObserver(this);
26 }
27
28 TestProfileOAuth2TokenServiceDelegateChromeOS::
~TestProfileOAuth2TokenServiceDelegateChromeOS()29 ~TestProfileOAuth2TokenServiceDelegateChromeOS() {
30 delegate_->RemoveObserver(this);
31 }
32
33 std::unique_ptr<OAuth2AccessTokenFetcher>
CreateAccessTokenFetcher(const CoreAccountId & account_id,scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,OAuth2AccessTokenConsumer * consumer)34 TestProfileOAuth2TokenServiceDelegateChromeOS::CreateAccessTokenFetcher(
35 const CoreAccountId& account_id,
36 scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
37 OAuth2AccessTokenConsumer* consumer) {
38 return delegate_->CreateAccessTokenFetcher(account_id, url_loader_factory,
39 consumer);
40 }
41
RefreshTokenIsAvailable(const CoreAccountId & account_id) const42 bool TestProfileOAuth2TokenServiceDelegateChromeOS::RefreshTokenIsAvailable(
43 const CoreAccountId& account_id) const {
44 return delegate_->RefreshTokenIsAvailable(account_id);
45 }
46
UpdateAuthError(const CoreAccountId & account_id,const GoogleServiceAuthError & error)47 void TestProfileOAuth2TokenServiceDelegateChromeOS::UpdateAuthError(
48 const CoreAccountId& account_id,
49 const GoogleServiceAuthError& error) {
50 delegate_->UpdateAuthError(account_id, error);
51 }
52
53 GoogleServiceAuthError
GetAuthError(const CoreAccountId & account_id) const54 TestProfileOAuth2TokenServiceDelegateChromeOS::GetAuthError(
55 const CoreAccountId& account_id) const {
56 return delegate_->GetAuthError(account_id);
57 }
58
59 std::vector<CoreAccountId>
GetAccounts() const60 TestProfileOAuth2TokenServiceDelegateChromeOS::GetAccounts() const {
61 return delegate_->GetAccounts();
62 }
63
LoadCredentials(const CoreAccountId & primary_account_id)64 void TestProfileOAuth2TokenServiceDelegateChromeOS::LoadCredentials(
65 const CoreAccountId& primary_account_id) {
66 // In tests |LoadCredentials| may be called twice, in this case we call
67 // |FireRefreshTokensLoaded| again to notify that credentials are loaded.
68 if (load_credentials_state() ==
69 signin::LoadCredentialsState::LOAD_CREDENTIALS_FINISHED_WITH_SUCCESS) {
70 FireRefreshTokensLoaded();
71 return;
72 }
73
74 if (load_credentials_state() !=
75 signin::LoadCredentialsState::LOAD_CREDENTIALS_NOT_STARTED) {
76 return;
77 }
78
79 set_load_credentials_state(
80 signin::LoadCredentialsState::LOAD_CREDENTIALS_IN_PROGRESS);
81 delegate_->LoadCredentials(primary_account_id);
82 }
83
UpdateCredentials(const CoreAccountId & account_id,const std::string & refresh_token)84 void TestProfileOAuth2TokenServiceDelegateChromeOS::UpdateCredentials(
85 const CoreAccountId& account_id,
86 const std::string& refresh_token) {
87 delegate_->UpdateCredentials(account_id, refresh_token);
88 }
89
90 scoped_refptr<network::SharedURLLoaderFactory>
GetURLLoaderFactory() const91 TestProfileOAuth2TokenServiceDelegateChromeOS::GetURLLoaderFactory() const {
92 return delegate_->GetURLLoaderFactory();
93 }
94
RevokeCredentials(const CoreAccountId & account_id)95 void TestProfileOAuth2TokenServiceDelegateChromeOS::RevokeCredentials(
96 const CoreAccountId& account_id) {
97 delegate_->RevokeCredentials(account_id);
98 }
99
RevokeAllCredentials()100 void TestProfileOAuth2TokenServiceDelegateChromeOS::RevokeAllCredentials() {
101 delegate_->RevokeAllCredentials();
102 }
103
104 const net::BackoffEntry*
BackoffEntry() const105 TestProfileOAuth2TokenServiceDelegateChromeOS::BackoffEntry() const {
106 return delegate_->BackoffEntry();
107 }
108
OnRefreshTokenAvailable(const CoreAccountId & account_id)109 void TestProfileOAuth2TokenServiceDelegateChromeOS::OnRefreshTokenAvailable(
110 const CoreAccountId& account_id) {
111 FireRefreshTokenAvailable(account_id);
112 }
113
OnRefreshTokenRevoked(const CoreAccountId & account_id)114 void TestProfileOAuth2TokenServiceDelegateChromeOS::OnRefreshTokenRevoked(
115 const CoreAccountId& account_id) {
116 FireRefreshTokenRevoked(account_id);
117 }
118
OnEndBatchChanges()119 void TestProfileOAuth2TokenServiceDelegateChromeOS::OnEndBatchChanges() {
120 FireEndBatchChanges();
121 }
122
OnRefreshTokensLoaded()123 void TestProfileOAuth2TokenServiceDelegateChromeOS::OnRefreshTokensLoaded() {
124 set_load_credentials_state(
125 signin::LoadCredentialsState::LOAD_CREDENTIALS_FINISHED_WITH_SUCCESS);
126 FireRefreshTokensLoaded();
127 }
128
OnAuthErrorChanged(const CoreAccountId & account_id,const GoogleServiceAuthError & auth_error)129 void TestProfileOAuth2TokenServiceDelegateChromeOS::OnAuthErrorChanged(
130 const CoreAccountId& account_id,
131 const GoogleServiceAuthError& auth_error) {
132 FireAuthErrorChanged(account_id, auth_error);
133 }
134
135 } // namespace signin
136