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 3 // found in the LICENSE file. 4 5 #include "chrome/browser/signin/fake_signin_manager.h" 6 7 #include "base/callback_helpers.h" 8 #include "base/prefs/pref_service.h" 9 #include "chrome/browser/chrome_notification_types.h" 10 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/signin/chrome_signin_manager_delegate.h" 12 #include "chrome/browser/signin/signin_global_error.h" 13 #include "chrome/browser/ui/global_error/global_error_service.h" 14 #include "chrome/browser/ui/global_error/global_error_service_factory.h" 15 #include "chrome/common/pref_names.h" 16 #include "content/public/browser/notification_service.h" 17 18 FakeSigninManagerBase::FakeSigninManagerBase() { 19 } 20 21 FakeSigninManagerBase::~FakeSigninManagerBase() { 22 } 23 24 void FakeSigninManagerBase::InitTokenService() { 25 } 26 27 // static 28 BrowserContextKeyedService* FakeSigninManagerBase::Build( 29 content::BrowserContext* profile) { 30 return new FakeSigninManagerBase(); 31 } 32 33 #if !defined (OS_CHROMEOS) 34 35 FakeSigninManager::FakeSigninManager(Profile* profile) 36 : SigninManager(scoped_ptr<SigninManagerDelegate>( 37 new ChromeSigninManagerDelegate(profile))) { 38 } 39 40 FakeSigninManager::~FakeSigninManager() { 41 } 42 43 void FakeSigninManager::InitTokenService() { 44 } 45 46 void FakeSigninManager::StartSignIn(const std::string& username, 47 const std::string& password, 48 const std::string& login_token, 49 const std::string& login_captcha) { 50 SetAuthenticatedUsername(username); 51 } 52 53 void FakeSigninManager::StartSignInWithCredentials( 54 const std::string& session_index, 55 const std::string& username, 56 const std::string& password, 57 const OAuthTokenFetchedCallback& oauth_fetched_callback) { 58 set_auth_in_progress(username); 59 if (!oauth_fetched_callback.is_null()) 60 oauth_fetched_callback.Run("fake_oauth_token"); 61 } 62 63 void FakeSigninManager::CompletePendingSignin() { 64 SetAuthenticatedUsername(GetUsernameForAuthInProgress()); 65 set_auth_in_progress(std::string()); 66 } 67 68 void FakeSigninManager::SignOut() { 69 if (IsSignoutProhibited()) 70 return; 71 set_auth_in_progress(std::string()); 72 authenticated_username_.clear(); 73 content::NotificationService::current()->Notify( 74 chrome::NOTIFICATION_GOOGLE_SIGNED_OUT, 75 content::Source<Profile>(profile_), 76 content::NotificationService::NoDetails()); 77 } 78 79 // static 80 BrowserContextKeyedService* FakeSigninManager::Build( 81 content::BrowserContext* profile) { 82 return new FakeSigninManager(static_cast<Profile*>(profile)); 83 } 84 85 #endif // !defined (OS_CHROMEOS) 86