1 // Copyright 2014 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/services/gcm/fake_signin_manager.h"
7 #include "base/observer_list.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 "components/keyed_service/core/keyed_service.h"
13 #include "components/signin/core/common/signin_pref_names.h"
14 #include "content/public/browser/browser_context.h"
16 #if !defined(OS_CHROMEOS)
17 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
22 FakeSigninManager::FakeSigninManager(Profile
* profile
)
23 #if defined(OS_CHROMEOS)
25 ChromeSigninClientFactory::GetInstance()->GetForProfile(profile
)),
28 ChromeSigninClientFactory::GetInstance()->GetForProfile(profile
),
29 ProfileOAuth2TokenServiceFactory::GetForProfile(profile
),
30 AccountTrackerServiceFactory::GetForProfile(profile
)),
36 FakeSigninManager::~FakeSigninManager() {
39 void FakeSigninManager::SignIn(const std::string
& username
) {
40 SetAuthenticatedUsername(username
);
41 FOR_EACH_OBSERVER(SigninManagerBase::Observer
,
43 GoogleSigninSucceeded(username
, username
, std::string()));
46 void FakeSigninManager::SignOut(
47 signin_metrics::ProfileSignout signout_source_metric
) {
48 const std::string account_id
= GetAuthenticatedAccountId();
49 const std::string username
= GetAuthenticatedUsername();
50 ClearAuthenticatedUsername();
51 profile_
->GetPrefs()->ClearPref(prefs::kGoogleServicesUsername
);
52 FOR_EACH_OBSERVER(SigninManagerBase::Observer
,
54 GoogleSignedOut(account_id
, username
));
58 KeyedService
* FakeSigninManager::Build(content::BrowserContext
* context
) {
59 return new FakeSigninManager(Profile::FromBrowserContext(context
));