1 // Copyright (c) 2012 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/core/browser/fake_signin_manager.h"
7 #include "base/callback_helpers.h"
8 #include "base/prefs/pref_service.h"
9 #include "components/signin/core/browser/account_tracker_service.h"
10 #include "components/signin/core/browser/signin_metrics.h"
12 FakeSigninManagerBase::FakeSigninManagerBase(
14 AccountTrackerService
* account_tracker_service
)
15 : SigninManagerBase(client
, account_tracker_service
) {}
17 FakeSigninManagerBase::~FakeSigninManagerBase() {}
19 #if !defined(OS_CHROMEOS)
21 FakeSigninManager::FakeSigninManager(
23 ProfileOAuth2TokenService
* token_service
,
24 AccountTrackerService
* account_tracker_service
,
25 GaiaCookieManagerService
* cookie_manager_service
)
26 : SigninManager(client
,
28 account_tracker_service
,
29 cookie_manager_service
) {}
31 FakeSigninManager::~FakeSigninManager() {}
33 void FakeSigninManager::StartSignInWithRefreshToken(
34 const std::string
& refresh_token
,
35 const std::string
& gaia_id
,
36 const std::string
& username
,
37 const std::string
& password
,
38 const OAuthTokenFetchedCallback
& oauth_fetched_callback
) {
40 account_tracker_service()->SeedAccountInfo(gaia_id
, username
));
41 set_password(password
);
44 if (!oauth_fetched_callback
.is_null())
45 oauth_fetched_callback
.Run(refresh_token
);
48 void FakeSigninManager::CompletePendingSignin() {
49 SetAuthenticatedAccountId(GetAccountIdForAuthInProgress());
50 set_auth_in_progress(std::string());
52 SigninManagerBase::Observer
, observer_list_
,
53 GoogleSigninSucceeded(authenticated_account_id_
, username_
, password_
));
56 void FakeSigninManager::SignIn(const std::string
& gaia_id
,
57 const std::string
& username
,
58 const std::string
& password
) {
59 StartSignInWithRefreshToken(std::string(), gaia_id
, username
, password
,
60 OAuthTokenFetchedCallback());
61 CompletePendingSignin();
64 void FakeSigninManager::ForceSignOut() {
65 prohibit_signout_
= false;
66 SignOut(signin_metrics::SIGNOUT_TEST
);
69 void FakeSigninManager::FailSignin(const GoogleServiceAuthError
& error
) {
70 FOR_EACH_OBSERVER(SigninManagerBase::Observer
, observer_list_
,
71 GoogleSigninFailed(error
));
74 void FakeSigninManager::SignOut(
75 signin_metrics::ProfileSignout signout_source_metric
) {
76 if (IsSignoutProhibited())
78 set_auth_in_progress(std::string());
79 set_password(std::string());
80 const std::string account_id
= GetAuthenticatedAccountId();
81 const std::string username
= GetAuthenticatedAccountInfo().email
;
82 authenticated_account_id_
.clear();
84 FOR_EACH_OBSERVER(SigninManagerBase::Observer
, observer_list_
,
85 GoogleSignedOut(account_id
, username
));
88 #endif // !defined (OS_CHROMEOS)