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

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, 5 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"
19 10
20 FakeSigninManagerBase::FakeSigninManagerBase(Profile* profile) 11 FakeSigninManagerBase::FakeSigninManagerBase(
21 : SigninManagerBase( 12 SigninClient* client,
22 ChromeSigninClientFactory::GetForProfile(profile), 13 AccountTrackerService* account_tracker_service)
23 AccountTrackerServiceFactory::GetForProfile(profile)) {} 14 : SigninManagerBase(client, account_tracker_service) {}
24 15
25 FakeSigninManagerBase::~FakeSigninManagerBase() { 16 FakeSigninManagerBase::~FakeSigninManagerBase() {}
26 }
27 17
28 // static 18 #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 19
44 #if !defined (OS_CHROMEOS) 20 FakeSigninManager::FakeSigninManager(
21 SigninClient* client,
22 ProfileOAuth2TokenService* token_service,
23 AccountTrackerService* account_tracker_service,
24 GaiaCookieManagerService* cookie_manager_service)
25 : SigninManager(client,
26 token_service,
27 account_tracker_service,
28 cookie_manager_service) {}
45 29
46 FakeSigninManager::FakeSigninManager(Profile* profile) 30 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 31
56 void FakeSigninManager::StartSignInWithRefreshToken( 32 void FakeSigninManager::StartSignInWithRefreshToken(
57 const std::string& refresh_token, 33 const std::string& refresh_token,
58 const std::string& gaia_id, 34 const std::string& gaia_id,
59 const std::string& username, 35 const std::string& username,
60 const std::string& password, 36 const std::string& password,
61 const OAuthTokenFetchedCallback& oauth_fetched_callback) { 37 const OAuthTokenFetchedCallback& oauth_fetched_callback) {
62 set_auth_in_progress( 38 set_auth_in_progress(
63 account_tracker_service()->SeedAccountInfo(gaia_id, username)); 39 account_tracker_service()->SeedAccountInfo(gaia_id, username));
64 set_password(password); 40 set_password(password);
65 username_ = username; 41 username_ = username;
66 42
67 if (!oauth_fetched_callback.is_null()) 43 if (!oauth_fetched_callback.is_null())
68 oauth_fetched_callback.Run(refresh_token); 44 oauth_fetched_callback.Run(refresh_token);
69 } 45 }
70 46
71
72 void FakeSigninManager::CompletePendingSignin() { 47 void FakeSigninManager::CompletePendingSignin() {
73 SetAuthenticatedAccountId(GetAccountIdForAuthInProgress()); 48 SetAuthenticatedAccountId(GetAccountIdForAuthInProgress());
74 set_auth_in_progress(std::string()); 49 set_auth_in_progress(std::string());
75 FOR_EACH_OBSERVER(SigninManagerBase::Observer, 50 FOR_EACH_OBSERVER(
76 observer_list_, 51 SigninManagerBase::Observer, observer_list_,
77 GoogleSigninSucceeded(authenticated_account_id_, 52 GoogleSigninSucceeded(authenticated_account_id_, username_, password_));
78 username_,
79 password_));
80 } 53 }
81 54
82 void FakeSigninManager::SignIn(const std::string& gaia_id, 55 void FakeSigninManager::SignIn(const std::string& gaia_id,
83 const std::string& username, 56 const std::string& username,
84 const std::string& password) { 57 const std::string& password) {
85 StartSignInWithRefreshToken( 58 StartSignInWithRefreshToken(std::string(), gaia_id, username, password,
86 std::string(), gaia_id, username, password, 59 OAuthTokenFetchedCallback());
87 OAuthTokenFetchedCallback());
88 CompletePendingSignin(); 60 CompletePendingSignin();
89 } 61 }
90 62
91 void FakeSigninManager::FailSignin(const GoogleServiceAuthError& error) { 63 void FakeSigninManager::FailSignin(const GoogleServiceAuthError& error) {
92 FOR_EACH_OBSERVER(SigninManagerBase::Observer, 64 FOR_EACH_OBSERVER(SigninManagerBase::Observer, observer_list_,
93 observer_list_,
94 GoogleSigninFailed(error)); 65 GoogleSigninFailed(error));
95 } 66 }
96 67
97 void FakeSigninManager::SignOut( 68 void FakeSigninManager::SignOut(
98 signin_metrics::ProfileSignout signout_source_metric) { 69 signin_metrics::ProfileSignout signout_source_metric) {
99 if (IsSignoutProhibited()) 70 if (IsSignoutProhibited())
100 return; 71 return;
101 set_auth_in_progress(std::string()); 72 set_auth_in_progress(std::string());
102 set_password(std::string()); 73 set_password(std::string());
103 const std::string account_id = GetAuthenticatedAccountId(); 74 const std::string account_id = GetAuthenticatedAccountId();
104 const std::string username = GetAuthenticatedUsername(); 75 const std::string username = GetAuthenticatedUsername();
105 authenticated_account_id_.clear(); 76 authenticated_account_id_.clear();
106 77
107 FOR_EACH_OBSERVER(SigninManagerBase::Observer, observer_list_, 78 FOR_EACH_OBSERVER(SigninManagerBase::Observer, observer_list_,
108 GoogleSignedOut(account_id, username)); 79 GoogleSignedOut(account_id, username));
109 } 80 }
110 81
111 #endif // !defined (OS_CHROMEOS) 82 #endif // !defined (OS_CHROMEOS)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698