Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1944)

Side by Side Diff: components/signin/core/browser/fake_signin_manager.cc

Issue 1257623002: Componentize FakeSigninManager and SigninManager prefs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review comment Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "components/signin/core/browser/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"
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"
17 #include "chrome/common/pref_names.h"
18 #include "components/signin/core/browser/account_tracker_service.h" 9 #include "components/signin/core/browser/account_tracker_service.h"
10 #include "components/signin/core/browser/signin_metrics.h"
19 11
20 FakeSigninManagerBase::FakeSigninManagerBase(Profile* profile) 12 FakeSigninManagerBase::FakeSigninManagerBase(
21 : SigninManagerBase( 13 SigninClient* client,
22 ChromeSigninClientFactory::GetForProfile(profile), 14 AccountTrackerService* account_tracker_service)
23 AccountTrackerServiceFactory::GetForProfile(profile)) {} 15 : SigninManagerBase(client, account_tracker_service) {}
24 16
25 FakeSigninManagerBase::~FakeSigninManagerBase() { 17 FakeSigninManagerBase::~FakeSigninManagerBase() {}
26 }
27 18
28 // static 19 #if !defined(OS_CHROMEOS)
29 scoped_ptr<KeyedService> FakeSigninManagerBase::Build(
30 content::BrowserContext* context) {
31 scoped_ptr<SigninManagerBase> manager;
32 Profile* profile = static_cast<Profile*>(context);
33 #if defined(OS_CHROMEOS)
34 manager.reset(new FakeSigninManagerBase(profile));
35 #else
36 manager.reset(new FakeSigninManager(profile));
37 #endif
38 manager->Initialize(NULL);
39 SigninManagerFactory::GetInstance()
40 ->NotifyObserversOfSigninManagerCreationForTesting(manager.get());
41 return manager.Pass();
42 }
43 20
44 #if !defined (OS_CHROMEOS) 21 FakeSigninManager::FakeSigninManager(
22 SigninClient* client,
23 ProfileOAuth2TokenService* token_service,
24 AccountTrackerService* account_tracker_service,
25 GaiaCookieManagerService* cookie_manager_service)
26 : SigninManager(client,
27 token_service,
28 account_tracker_service,
29 cookie_manager_service) {}
45 30
46 FakeSigninManager::FakeSigninManager(Profile* profile) 31 FakeSigninManager::~FakeSigninManager() {}
47 : SigninManager(
48 ChromeSigninClientFactory::GetForProfile(profile),
49 ProfileOAuth2TokenServiceFactory::GetForProfile(profile),
50 AccountTrackerServiceFactory::GetForProfile(profile),
51 GaiaCookieManagerServiceFactory::GetForProfile(profile)) {}
52
53 FakeSigninManager::~FakeSigninManager() {
54 }
55 32
56 void FakeSigninManager::StartSignInWithRefreshToken( 33 void FakeSigninManager::StartSignInWithRefreshToken(
57 const std::string& refresh_token, 34 const std::string& refresh_token,
58 const std::string& gaia_id, 35 const std::string& gaia_id,
59 const std::string& username, 36 const std::string& username,
60 const std::string& password, 37 const std::string& password,
61 const OAuthTokenFetchedCallback& oauth_fetched_callback) { 38 const OAuthTokenFetchedCallback& oauth_fetched_callback) {
62 set_auth_in_progress( 39 set_auth_in_progress(
63 account_tracker_service()->SeedAccountInfo(gaia_id, username)); 40 account_tracker_service()->SeedAccountInfo(gaia_id, username));
64 set_password(password); 41 set_password(password);
65 username_ = username; 42 username_ = username;
66 43
67 if (!oauth_fetched_callback.is_null()) 44 if (!oauth_fetched_callback.is_null())
68 oauth_fetched_callback.Run(refresh_token); 45 oauth_fetched_callback.Run(refresh_token);
69 } 46 }
70 47
71
72 void FakeSigninManager::CompletePendingSignin() { 48 void FakeSigninManager::CompletePendingSignin() {
73 SetAuthenticatedAccountId(GetAccountIdForAuthInProgress()); 49 SetAuthenticatedAccountId(GetAccountIdForAuthInProgress());
74 set_auth_in_progress(std::string()); 50 set_auth_in_progress(std::string());
75 FOR_EACH_OBSERVER(SigninManagerBase::Observer, 51 FOR_EACH_OBSERVER(
76 observer_list_, 52 SigninManagerBase::Observer, observer_list_,
77 GoogleSigninSucceeded(authenticated_account_id_, 53 GoogleSigninSucceeded(authenticated_account_id_, username_, password_));
78 username_,
79 password_));
80 } 54 }
81 55
82 void FakeSigninManager::SignIn(const std::string& gaia_id, 56 void FakeSigninManager::SignIn(const std::string& gaia_id,
83 const std::string& username, 57 const std::string& username,
84 const std::string& password) { 58 const std::string& password) {
85 StartSignInWithRefreshToken( 59 StartSignInWithRefreshToken(std::string(), gaia_id, username, password,
86 std::string(), gaia_id, username, password, 60 OAuthTokenFetchedCallback());
87 OAuthTokenFetchedCallback());
88 CompletePendingSignin(); 61 CompletePendingSignin();
89 } 62 }
90 63
64 void FakeSigninManager::ForceSignOut() {
65 prohibit_signout_ = false;
66 SignOut(signin_metrics::SIGNOUT_TEST);
67 }
68
91 void FakeSigninManager::FailSignin(const GoogleServiceAuthError& error) { 69 void FakeSigninManager::FailSignin(const GoogleServiceAuthError& error) {
92 FOR_EACH_OBSERVER(SigninManagerBase::Observer, 70 FOR_EACH_OBSERVER(SigninManagerBase::Observer, observer_list_,
93 observer_list_,
94 GoogleSigninFailed(error)); 71 GoogleSigninFailed(error));
95 } 72 }
96 73
97 void FakeSigninManager::SignOut( 74 void FakeSigninManager::SignOut(
98 signin_metrics::ProfileSignout signout_source_metric) { 75 signin_metrics::ProfileSignout signout_source_metric) {
99 if (IsSignoutProhibited()) 76 if (IsSignoutProhibited())
100 return; 77 return;
101 set_auth_in_progress(std::string()); 78 set_auth_in_progress(std::string());
102 set_password(std::string()); 79 set_password(std::string());
103 const std::string account_id = GetAuthenticatedAccountId(); 80 const std::string account_id = GetAuthenticatedAccountId();
104 const std::string username = GetAuthenticatedUsername(); 81 const std::string username = GetAuthenticatedUsername();
105 authenticated_account_id_.clear(); 82 authenticated_account_id_.clear();
106 83
107 FOR_EACH_OBSERVER(SigninManagerBase::Observer, observer_list_, 84 FOR_EACH_OBSERVER(SigninManagerBase::Observer, observer_list_,
108 GoogleSignedOut(account_id, username)); 85 GoogleSignedOut(account_id, username));
109 } 86 }
110 87
111 #endif // !defined (OS_CHROMEOS) 88 #endif // !defined (OS_CHROMEOS)
OLDNEW
« no previous file with comments | « components/signin/core/browser/fake_signin_manager.h ('k') | components/signin/core/browser/signin_manager_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698