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. 4 5 #include "chrome/browser/services/gcm/fake_signin_manager.h" 6 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/chrome_signin_client_factory.h" 11 #include "components/keyed_service/core/keyed_service.h" 12 #include "components/signin/core/common/signin_pref_names.h" 13 #include "content/public/browser/browser_context.h" 14 15 #if !defined(OS_CHROMEOS) 16 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 17 #endif 18 19 namespace gcm { 20 21 FakeSigninManager::FakeSigninManager(Profile* profile) 22 #if defined(OS_CHROMEOS) 23 : SigninManagerBase( 24 ChromeSigninClientFactory::GetInstance()->GetForProfile(profile)), 25 #else 26 : SigninManager( 27 ChromeSigninClientFactory::GetInstance()->GetForProfile(profile), 28 ProfileOAuth2TokenServiceFactory::GetForProfile(profile)), 29 #endif 30 profile_(profile) { 31 Initialize(NULL); 32 } 33 34 FakeSigninManager::~FakeSigninManager() { 35 } 36 37 void FakeSigninManager::SignIn(const std::string& username) { 38 SetAuthenticatedUsername(username); 39 FOR_EACH_OBSERVER(Observer, 40 observer_list_, 41 GoogleSigninSucceeded(username, username, std::string())); 42 } 43 44 void FakeSigninManager::SignOut( 45 signin_metrics::ProfileSignout signout_source_metric) { 46 const std::string account_id = GetAuthenticatedAccountId(); 47 const std::string username = GetAuthenticatedUsername(); 48 clear_authenticated_username(); 49 profile_->GetPrefs()->ClearPref(prefs::kGoogleServicesUsername); 50 FOR_EACH_OBSERVER(Observer, 51 observer_list_, 52 GoogleSignedOut(account_id, username)); 53 } 54 55 // static 56 KeyedService* FakeSigninManager::Build(content::BrowserContext* context) { 57 return new FakeSigninManager(Profile::FromBrowserContext(context)); 58 } 59 60 } // namespace gcm 61