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 "chrome/browser/signin/fake_signin_manager.h"
7 #include "base/callback_helpers.h"
8 #include "base/prefs/pref_service.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/signin/account_tracker_service_factory.h"
11 #include "chrome/browser/signin/chrome_signin_client_factory.h"
12 #include "chrome/browser/signin/gaia_cookie_manager_service_factory.h"
13 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
14 #include "chrome/browser/signin/signin_manager_factory.h"
15 #include "chrome/browser/ui/global_error/global_error_service.h"
16 #include "chrome/browser/ui/global_error/global_error_service_factory.h"
18 FakeSigninManagerBase::FakeSigninManagerBase(Profile
* profile
)
20 ChromeSigninClientFactory::GetInstance()->GetForProfile(profile
)) {}
22 FakeSigninManagerBase::~FakeSigninManagerBase() {
26 KeyedService
* FakeSigninManagerBase::Build(content::BrowserContext
* context
) {
27 SigninManagerBase
* manager
;
28 Profile
* profile
= static_cast<Profile
*>(context
);
29 #if defined(OS_CHROMEOS)
30 manager
= new FakeSigninManagerBase(profile
);
32 manager
= new FakeSigninManager(profile
);
34 manager
->Initialize(NULL
);
35 SigninManagerFactory::GetInstance()
36 ->NotifyObserversOfSigninManagerCreationForTesting(manager
);
40 #if !defined (OS_CHROMEOS)
42 FakeSigninManager::FakeSigninManager(Profile
* profile
)
44 ChromeSigninClientFactory::GetInstance()->GetForProfile(profile
),
45 ProfileOAuth2TokenServiceFactory::GetForProfile(profile
),
46 AccountTrackerServiceFactory::GetForProfile(profile
),
47 GaiaCookieManagerServiceFactory::GetForProfile(profile
)) {}
49 FakeSigninManager::~FakeSigninManager() {
52 void FakeSigninManager::StartSignInWithRefreshToken(
53 const std::string
& refresh_token
,
54 const std::string
& username
,
55 const std::string
& password
,
56 const OAuthTokenFetchedCallback
& oauth_fetched_callback
) {
57 set_auth_in_progress(username
);
58 set_password(password
);
59 if (!oauth_fetched_callback
.is_null())
60 oauth_fetched_callback
.Run(refresh_token
);
64 void FakeSigninManager::CompletePendingSignin() {
65 SetAuthenticatedUsername(GetUsernameForAuthInProgress());
66 set_auth_in_progress(std::string());
67 FOR_EACH_OBSERVER(SigninManagerBase::Observer
,
69 GoogleSigninSucceeded(authenticated_username_
,
70 authenticated_username_
,
74 void FakeSigninManager::SignIn(const std::string
& username
,
75 const std::string
& password
) {
76 StartSignInWithRefreshToken(
77 std::string(), username
, password
, OAuthTokenFetchedCallback());
78 CompletePendingSignin();
81 void FakeSigninManager::FailSignin(const GoogleServiceAuthError
& error
) {
82 FOR_EACH_OBSERVER(SigninManagerBase::Observer
,
84 GoogleSigninFailed(error
));
87 void FakeSigninManager::SignOut(
88 signin_metrics::ProfileSignout signout_source_metric
) {
89 if (IsSignoutProhibited())
91 set_auth_in_progress(std::string());
92 set_password(std::string());
93 const std::string account_id
= GetAuthenticatedAccountId();
94 const std::string username
= GetAuthenticatedUsername();
95 ClearAuthenticatedUsername();
97 FOR_EACH_OBSERVER(SigninManagerBase::Observer
, observer_list_
,
98 GoogleSignedOut(account_id
, username
));
101 #endif // !defined (OS_CHROMEOS)