• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
FakeSigninManagerBase()18 FakeSigninManagerBase::FakeSigninManagerBase() {
19 }
20 
~FakeSigninManagerBase()21 FakeSigninManagerBase::~FakeSigninManagerBase() {
22 }
23 
24 // static
Build(content::BrowserContext * profile)25 BrowserContextKeyedService* FakeSigninManagerBase::Build(
26     content::BrowserContext* profile) {
27   return new FakeSigninManagerBase();
28 }
29 
30 #if !defined (OS_CHROMEOS)
31 
FakeSigninManager(Profile * profile)32 FakeSigninManager::FakeSigninManager(Profile* profile)
33     : SigninManager(scoped_ptr<SigninManagerDelegate>(
34         new ChromeSigninManagerDelegate(profile))) {
35 }
36 
~FakeSigninManager()37 FakeSigninManager::~FakeSigninManager() {
38 }
39 
StartSignInWithCredentials(const std::string & session_index,const std::string & username,const std::string & password,const OAuthTokenFetchedCallback & oauth_fetched_callback)40 void FakeSigninManager::StartSignInWithCredentials(
41     const std::string& session_index,
42     const std::string& username,
43     const std::string& password,
44     const OAuthTokenFetchedCallback& oauth_fetched_callback) {
45   set_auth_in_progress(username);
46   if (!oauth_fetched_callback.is_null())
47     oauth_fetched_callback.Run("fake_oauth_token");
48 }
49 
CompletePendingSignin()50 void FakeSigninManager::CompletePendingSignin() {
51   SetAuthenticatedUsername(GetUsernameForAuthInProgress());
52   set_auth_in_progress(std::string());
53 }
54 
SignOut()55 void FakeSigninManager::SignOut() {
56   if (IsSignoutProhibited())
57     return;
58   set_auth_in_progress(std::string());
59   authenticated_username_.clear();
60   content::NotificationService::current()->Notify(
61       chrome::NOTIFICATION_GOOGLE_SIGNED_OUT,
62       content::Source<Profile>(profile_),
63       content::NotificationService::NoDetails());
64 }
65 
66 // static
Build(content::BrowserContext * profile)67 BrowserContextKeyedService* FakeSigninManager::Build(
68     content::BrowserContext* profile) {
69   return new FakeSigninManager(static_cast<Profile*>(profile));
70 }
71 
72 #endif  // !defined (OS_CHROMEOS)
73