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 "chrome/browser/signin/gaia_cookie_manager_service_factory.h"
13 #include "components/keyed_service/core/keyed_service.h"
14 #include "components/signin/core/common/signin_pref_names.h"
15 #include "content/public/browser/browser_context.h"
17 #if !defined(OS_CHROMEOS)
18 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
23 FakeSigninManager::FakeSigninManager(Profile
* profile
)
24 #if defined(OS_CHROMEOS)
26 ChromeSigninClientFactory::GetInstance()->GetForProfile(profile
)),
29 ChromeSigninClientFactory::GetInstance()->GetForProfile(profile
),
30 ProfileOAuth2TokenServiceFactory::GetForProfile(profile
),
31 AccountTrackerServiceFactory::GetForProfile(profile
),
32 GaiaCookieManagerServiceFactory::GetForProfile(profile
)),
38 FakeSigninManager::~FakeSigninManager() {
41 void FakeSigninManager::SignIn(const std::string
& username
) {
42 SetAuthenticatedUsername(username
);
43 FOR_EACH_OBSERVER(SigninManagerBase::Observer
,
45 GoogleSigninSucceeded(username
, username
, std::string()));
48 void FakeSigninManager::SignOut(
49 signin_metrics::ProfileSignout signout_source_metric
) {
50 const std::string account_id
= GetAuthenticatedAccountId();
51 const std::string username
= GetAuthenticatedUsername();
52 ClearAuthenticatedUsername();
53 profile_
->GetPrefs()->ClearPref(prefs::kGoogleServicesUsername
);
54 FOR_EACH_OBSERVER(SigninManagerBase::Observer
,
56 GoogleSignedOut(account_id
, username
));
60 KeyedService
* FakeSigninManager::Build(content::BrowserContext
* context
) {
61 return new FakeSigninManager(Profile::FromBrowserContext(context
));