OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/signin/fake_signin_manager.h" | 5 #include "chrome/browser/signin/fake_signin_manager.h" |
6 | 6 |
7 #include "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/signin/account_tracker_service_factory.h" | 10 #include "chrome/browser/signin/account_tracker_service_factory.h" |
11 #include "chrome/browser/signin/chrome_signin_client_factory.h" | 11 #include "chrome/browser/signin/chrome_signin_client_factory.h" |
12 #include "chrome/browser/signin/gaia_cookie_manager_service_factory.h" | 12 #include "chrome/browser/signin/gaia_cookie_manager_service_factory.h" |
13 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 13 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
14 #include "chrome/browser/signin/signin_manager_factory.h" | 14 #include "chrome/browser/signin/signin_manager_factory.h" |
15 #include "chrome/browser/ui/global_error/global_error_service.h" | 15 #include "chrome/browser/ui/global_error/global_error_service.h" |
16 #include "chrome/browser/ui/global_error/global_error_service_factory.h" | 16 #include "chrome/browser/ui/global_error/global_error_service_factory.h" |
| 17 #include "chrome/common/pref_names.h" |
| 18 #include "components/signin/core/browser/account_tracker_service.h" |
17 | 19 |
18 FakeSigninManagerBase::FakeSigninManagerBase(Profile* profile) | 20 FakeSigninManagerBase::FakeSigninManagerBase(Profile* profile) |
19 : SigninManagerBase( | 21 : SigninManagerBase( |
20 ChromeSigninClientFactory::GetInstance()->GetForProfile(profile)) {} | 22 ChromeSigninClientFactory::GetForProfile(profile), |
| 23 AccountTrackerServiceFactory::GetForProfile(profile)) {} |
21 | 24 |
22 FakeSigninManagerBase::~FakeSigninManagerBase() { | 25 FakeSigninManagerBase::~FakeSigninManagerBase() { |
23 } | 26 } |
24 | 27 |
25 // static | 28 // static |
26 KeyedService* FakeSigninManagerBase::Build(content::BrowserContext* context) { | 29 KeyedService* FakeSigninManagerBase::Build(content::BrowserContext* context) { |
27 SigninManagerBase* manager; | 30 SigninManagerBase* manager; |
28 Profile* profile = static_cast<Profile*>(context); | 31 Profile* profile = static_cast<Profile*>(context); |
29 #if defined(OS_CHROMEOS) | 32 #if defined(OS_CHROMEOS) |
30 manager = new FakeSigninManagerBase(profile); | 33 manager = new FakeSigninManagerBase(profile); |
31 #else | 34 #else |
32 manager = new FakeSigninManager(profile); | 35 manager = new FakeSigninManager(profile); |
33 #endif | 36 #endif |
34 manager->Initialize(NULL); | 37 manager->Initialize(NULL); |
35 SigninManagerFactory::GetInstance() | 38 SigninManagerFactory::GetInstance() |
36 ->NotifyObserversOfSigninManagerCreationForTesting(manager); | 39 ->NotifyObserversOfSigninManagerCreationForTesting(manager); |
37 return manager; | 40 return manager; |
38 } | 41 } |
39 | 42 |
40 #if !defined (OS_CHROMEOS) | 43 #if !defined (OS_CHROMEOS) |
41 | 44 |
42 FakeSigninManager::FakeSigninManager(Profile* profile) | 45 FakeSigninManager::FakeSigninManager(Profile* profile) |
43 : SigninManager( | 46 : SigninManager( |
44 ChromeSigninClientFactory::GetInstance()->GetForProfile(profile), | 47 ChromeSigninClientFactory::GetForProfile(profile), |
45 ProfileOAuth2TokenServiceFactory::GetForProfile(profile), | 48 ProfileOAuth2TokenServiceFactory::GetForProfile(profile), |
46 AccountTrackerServiceFactory::GetForProfile(profile), | 49 AccountTrackerServiceFactory::GetForProfile(profile), |
47 GaiaCookieManagerServiceFactory::GetForProfile(profile)) {} | 50 GaiaCookieManagerServiceFactory::GetForProfile(profile)) {} |
48 | 51 |
49 FakeSigninManager::~FakeSigninManager() { | 52 FakeSigninManager::~FakeSigninManager() { |
50 } | 53 } |
51 | 54 |
52 void FakeSigninManager::StartSignInWithRefreshToken( | 55 void FakeSigninManager::StartSignInWithRefreshToken( |
53 const std::string& refresh_token, | 56 const std::string& refresh_token, |
| 57 const std::string& gaia_id, |
54 const std::string& username, | 58 const std::string& username, |
55 const std::string& password, | 59 const std::string& password, |
56 const OAuthTokenFetchedCallback& oauth_fetched_callback) { | 60 const OAuthTokenFetchedCallback& oauth_fetched_callback) { |
57 set_auth_in_progress(username); | 61 set_auth_in_progress( |
| 62 account_tracker_service()->SeedAccountInfo(gaia_id, username)); |
58 set_password(password); | 63 set_password(password); |
| 64 username_ = username; |
| 65 |
59 if (!oauth_fetched_callback.is_null()) | 66 if (!oauth_fetched_callback.is_null()) |
60 oauth_fetched_callback.Run(refresh_token); | 67 oauth_fetched_callback.Run(refresh_token); |
61 } | 68 } |
62 | 69 |
63 | 70 |
64 void FakeSigninManager::CompletePendingSignin() { | 71 void FakeSigninManager::CompletePendingSignin() { |
65 SetAuthenticatedUsername(GetUsernameForAuthInProgress()); | 72 SetAuthenticatedAccountId(GetAccountIdForAuthInProgress()); |
66 set_auth_in_progress(std::string()); | 73 set_auth_in_progress(std::string()); |
67 FOR_EACH_OBSERVER(SigninManagerBase::Observer, | 74 FOR_EACH_OBSERVER(SigninManagerBase::Observer, |
68 observer_list_, | 75 observer_list_, |
69 GoogleSigninSucceeded(authenticated_username_, | 76 GoogleSigninSucceeded(authenticated_account_id_, |
70 authenticated_username_, | 77 username_, |
71 password_)); | 78 password_)); |
72 } | 79 } |
73 | 80 |
74 void FakeSigninManager::SignIn(const std::string& username, | 81 void FakeSigninManager::SignIn(const std::string& gaia_id, |
| 82 const std::string& username, |
75 const std::string& password) { | 83 const std::string& password) { |
76 StartSignInWithRefreshToken( | 84 StartSignInWithRefreshToken( |
77 std::string(), username, password, OAuthTokenFetchedCallback()); | 85 std::string(), gaia_id, username, password, |
| 86 OAuthTokenFetchedCallback()); |
78 CompletePendingSignin(); | 87 CompletePendingSignin(); |
79 } | 88 } |
80 | 89 |
81 void FakeSigninManager::FailSignin(const GoogleServiceAuthError& error) { | 90 void FakeSigninManager::FailSignin(const GoogleServiceAuthError& error) { |
82 FOR_EACH_OBSERVER(SigninManagerBase::Observer, | 91 FOR_EACH_OBSERVER(SigninManagerBase::Observer, |
83 observer_list_, | 92 observer_list_, |
84 GoogleSigninFailed(error)); | 93 GoogleSigninFailed(error)); |
85 } | 94 } |
86 | 95 |
87 void FakeSigninManager::SignOut( | 96 void FakeSigninManager::SignOut( |
88 signin_metrics::ProfileSignout signout_source_metric) { | 97 signin_metrics::ProfileSignout signout_source_metric) { |
89 if (IsSignoutProhibited()) | 98 if (IsSignoutProhibited()) |
90 return; | 99 return; |
91 set_auth_in_progress(std::string()); | 100 set_auth_in_progress(std::string()); |
92 set_password(std::string()); | 101 set_password(std::string()); |
93 const std::string account_id = GetAuthenticatedAccountId(); | 102 const std::string account_id = GetAuthenticatedAccountId(); |
94 const std::string username = GetAuthenticatedUsername(); | 103 const std::string username = GetAuthenticatedUsername(); |
95 ClearAuthenticatedUsername(); | 104 authenticated_account_id_.clear(); |
96 | 105 |
97 FOR_EACH_OBSERVER(SigninManagerBase::Observer, observer_list_, | 106 FOR_EACH_OBSERVER(SigninManagerBase::Observer, observer_list_, |
98 GoogleSignedOut(account_id, username)); | 107 GoogleSignedOut(account_id, username)); |
99 } | 108 } |
100 | 109 |
101 #endif // !defined (OS_CHROMEOS) | 110 #endif // !defined (OS_CHROMEOS) |
OLD | NEW |