Upstream version 5.34.92.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / signin / fake_signin_manager.cc
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 // static
25 BrowserContextKeyedService* FakeSigninManagerBase::Build(
26     content::BrowserContext* profile) {
27 #if defined(OS_CHROMEOS)
28   return new FakeSigninManagerBase();
29 #else
30   return new FakeSigninManager(static_cast<Profile*>(profile));
31 #endif
32 }
33
34 #if !defined (OS_CHROMEOS)
35
36 FakeSigninManager::FakeSigninManager(Profile* profile)
37     : SigninManager(scoped_ptr<SigninManagerDelegate>(
38         new ChromeSigninManagerDelegate(profile))) {
39 }
40
41 FakeSigninManager::~FakeSigninManager() {
42 }
43
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");
52 }
53
54 void FakeSigninManager::CompletePendingSignin() {
55   SetAuthenticatedUsername(GetUsernameForAuthInProgress());
56   set_auth_in_progress(std::string());
57 }
58
59 void FakeSigninManager::SignOut() {
60   if (IsSignoutProhibited())
61     return;
62   set_auth_in_progress(std::string());
63   const std::string& username = authenticated_username_;
64   authenticated_username_.clear();
65
66   // TODO(blundell): Eliminate this notification send once crbug.com/333997 is
67   // fixed.
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));
73
74   FOR_EACH_OBSERVER(SigninManagerBase::Observer, observer_list_,
75                     GoogleSignedOut(username));
76 }
77
78 #endif  // !defined (OS_CHROMEOS)