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.
5 #include "chrome/browser/signin/fake_signin_manager.h"
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"
18 FakeSigninManagerBase::FakeSigninManagerBase() {
21 FakeSigninManagerBase::~FakeSigninManagerBase() {
25 BrowserContextKeyedService* FakeSigninManagerBase::Build(
26 content::BrowserContext* profile) {
27 #if defined(OS_CHROMEOS)
28 return new FakeSigninManagerBase();
30 return new FakeSigninManager(static_cast<Profile*>(profile));
34 #if !defined (OS_CHROMEOS)
36 FakeSigninManager::FakeSigninManager(Profile* profile)
37 : SigninManager(scoped_ptr<SigninManagerDelegate>(
38 new ChromeSigninManagerDelegate(profile))) {
41 FakeSigninManager::~FakeSigninManager() {
44 void FakeSigninManager::StartSignInWithCredentials(
45 const std::string& session_index,
46 const std::string& username,
47 const std::string& password,
48 const OAuthTokenFetchedCallback& oauth_fetched_callback) {
49 set_auth_in_progress(username);
50 if (!oauth_fetched_callback.is_null())
51 oauth_fetched_callback.Run("fake_oauth_token");
54 void FakeSigninManager::CompletePendingSignin() {
55 SetAuthenticatedUsername(GetUsernameForAuthInProgress());
56 set_auth_in_progress(std::string());
59 void FakeSigninManager::SignOut() {
60 if (IsSignoutProhibited())
62 set_auth_in_progress(std::string());
63 const std::string& username = authenticated_username_;
64 authenticated_username_.clear();
66 // TODO(blundell): Eliminate this notification send once crbug.com/333997 is
68 GoogleServiceSignoutDetails details(username);
69 content::NotificationService::current()->Notify(
70 chrome::NOTIFICATION_GOOGLE_SIGNED_OUT,
71 content::Source<Profile>(profile_),
72 content::Details<const GoogleServiceSignoutDetails>(&details));
74 FOR_EACH_OBSERVER(SigninManagerBase::Observer, observer_list_,
75 GoogleSignedOut(username));
78 #endif // !defined (OS_CHROMEOS)