OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/signin/fake_signin_manager.h" | 5 #include "chrome/browser/signin/fake_signin_manager.h" |
6 | 6 |
7 #include "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/signin/signin_global_error.h" | 10 #include "chrome/browser/signin/signin_global_error.h" |
11 #include "chrome/browser/ui/global_error/global_error_service.h" | 11 #include "chrome/browser/ui/global_error/global_error_service.h" |
12 #include "chrome/browser/ui/global_error/global_error_service_factory.h" | 12 #include "chrome/browser/ui/global_error/global_error_service_factory.h" |
13 #include "chrome/common/chrome_notification_types.h" | 13 #include "chrome/common/chrome_notification_types.h" |
14 #include "chrome/common/pref_names.h" | 14 #include "chrome/common/pref_names.h" |
15 #include "content/public/browser/notification_service.h" | 15 #include "content/public/browser/notification_service.h" |
16 | 16 |
17 FakeSigninManager::FakeSigninManager(Profile* profile) { | 17 FakeSigninManagerBase::FakeSigninManagerBase(Profile* profile) { |
18 profile_ = profile; | 18 profile_ = profile; |
19 signin_global_error_.reset(new SigninGlobalError(this, profile)); | 19 signin_global_error_.reset(new SigninGlobalError(this, profile)); |
20 GlobalErrorServiceFactory::GetForProfile(profile_)->AddGlobalError( | 20 GlobalErrorServiceFactory::GetForProfile(profile_)->AddGlobalError( |
21 signin_global_error_.get()); | 21 signin_global_error_.get()); |
22 signin_allowed_.Init(prefs::kSigninAllowed, profile_->GetPrefs(), | 22 signin_allowed_.Init(prefs::kSigninAllowed, profile_->GetPrefs(), |
23 base::Bind(&SigninManager::OnSigninAllowedPrefChanged, | 23 base::Bind(&SigninManagerBase::OnSigninAllowedPrefChanged, |
24 base::Unretained(this))); | 24 base::Unretained(this))); |
25 } | 25 } |
26 | 26 |
27 FakeSigninManager::~FakeSigninManager() { | 27 FakeSigninManagerBase::~FakeSigninManagerBase() { |
28 if (signin_global_error_.get()) { | 28 if (signin_global_error_.get()) { |
29 GlobalErrorServiceFactory::GetForProfile(profile_)->RemoveGlobalError( | 29 GlobalErrorServiceFactory::GetForProfile(profile_)->RemoveGlobalError( |
30 signin_global_error_.get()); | 30 signin_global_error_.get()); |
31 signin_global_error_.reset(); | 31 signin_global_error_.reset(); |
32 } | 32 } |
33 } | 33 } |
34 | 34 |
| 35 void FakeSigninManagerBase::SignOut() { |
| 36 authenticated_username_.clear(); |
| 37 content::NotificationService::current()->Notify( |
| 38 chrome::NOTIFICATION_GOOGLE_SIGNED_OUT, |
| 39 content::Source<Profile>(profile_), |
| 40 content::NotificationService::NoDetails()); |
| 41 } |
| 42 |
| 43 // static |
| 44 ProfileKeyedService* FakeSigninManagerBase::Build(Profile* profile) { |
| 45 return new FakeSigninManagerBase(profile); |
| 46 } |
| 47 |
| 48 #if !defined (OS_CHROMEOS) |
| 49 |
| 50 FakeSigninManager::FakeSigninManager(Profile* profile) { |
| 51 Initialize(profile); |
| 52 } |
| 53 |
| 54 FakeSigninManager::~FakeSigninManager() { |
| 55 } |
| 56 |
| 57 void FakeSigninManager::InitTokenService() { |
| 58 } |
| 59 |
35 void FakeSigninManager::StartSignIn(const std::string& username, | 60 void FakeSigninManager::StartSignIn(const std::string& username, |
36 const std::string& password, | 61 const std::string& password, |
37 const std::string& login_token, | 62 const std::string& login_token, |
38 const std::string& login_captcha) { | 63 const std::string& login_captcha) { |
39 SetAuthenticatedUsername(username); | 64 SetAuthenticatedUsername(username); |
40 } | 65 } |
41 | 66 |
42 void FakeSigninManager::StartSignInWithCredentials( | 67 void FakeSigninManager::StartSignInWithCredentials( |
43 const std::string& session_index, | 68 const std::string& session_index, |
44 const std::string& username, | 69 const std::string& username, |
45 const std::string& password) { | 70 const std::string& password) { |
46 SetAuthenticatedUsername(username); | 71 SetAuthenticatedUsername(username); |
47 } | 72 } |
48 | 73 |
49 void FakeSigninManager::StartSignInWithOAuth(const std::string& username, | 74 void FakeSigninManager::StartSignInWithOAuth(const std::string& username, |
50 const std::string& password) { | 75 const std::string& password) { |
51 SetAuthenticatedUsername(username); | 76 SetAuthenticatedUsername(username); |
52 } | 77 } |
53 | 78 |
54 void FakeSigninManager::SignOut() { | 79 void FakeSigninManager::SignOut() { |
55 if (IsSignoutProhibited()) | 80 if (IsSignoutProhibited()) |
56 return; | 81 return; |
57 authenticated_username_.clear(); | 82 authenticated_username_.clear(); |
58 content::NotificationService::current()->Notify( | 83 content::NotificationService::current()->Notify( |
59 chrome::NOTIFICATION_GOOGLE_SIGNED_OUT, | 84 chrome::NOTIFICATION_GOOGLE_SIGNED_OUT, |
60 content::Source<Profile>(profile_), | 85 content::Source<Profile>(profile_), |
61 content::NotificationService::NoDetails()); | 86 content::NotificationService::NoDetails()); |
62 } | 87 } |
63 | 88 |
64 void FakeSigninManager::ForceSignOut() { | |
65 // Allow signing out now. | |
66 prohibit_signout_ = false; | |
67 SignOut(); | |
68 } | |
69 | |
70 // static | 89 // static |
71 ProfileKeyedService* FakeSigninManager::Build(Profile* profile) { | 90 ProfileKeyedService* FakeSigninManager::Build(Profile* profile) { |
72 return new FakeSigninManager(profile); | 91 return new FakeSigninManager(profile); |
73 } | 92 } |
| 93 |
| 94 #endif // !defined (OS_CHROMEOS) |
OLD | NEW |