OLD | NEW |
| (Empty) |
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/signin_manager_fake.h" | |
6 | |
7 #include "base/callback_helpers.h" | |
8 #include "base/prefs/pref_service.h" | |
9 #include "chrome/browser/profiles/profile.h" | |
10 #include "chrome/browser/signin/signin_global_error.h" | |
11 #include "chrome/browser/ui/global_error/global_error_service.h" | |
12 #include "chrome/browser/ui/global_error/global_error_service_factory.h" | |
13 #include "chrome/common/chrome_notification_types.h" | |
14 #include "chrome/common/pref_names.h" | |
15 #include "content/public/browser/notification_service.h" | |
16 | |
17 FakeSigninManager::FakeSigninManager(Profile* profile) | |
18 : auth_in_progress_(false) { | |
19 profile_ = profile; | |
20 signin_global_error_.reset(new SigninGlobalError(this, profile)); | |
21 GlobalErrorServiceFactory::GetForProfile(profile_)->AddGlobalError( | |
22 signin_global_error_.get()); | |
23 signin_allowed_.Init(prefs::kSigninAllowed, profile_->GetPrefs(), | |
24 base::Bind(&SigninManager::OnSigninAllowedPrefChanged, | |
25 base::Unretained(this))); | |
26 } | |
27 | |
28 FakeSigninManager::~FakeSigninManager() { | |
29 if (signin_global_error_.get()) { | |
30 GlobalErrorServiceFactory::GetForProfile(profile_)->RemoveGlobalError( | |
31 signin_global_error_.get()); | |
32 signin_global_error_.reset(); | |
33 } | |
34 } | |
35 | |
36 void FakeSigninManager::StartSignIn(const std::string& username, | |
37 const std::string& password, | |
38 const std::string& login_token, | |
39 const std::string& login_captcha) { | |
40 SetAuthenticatedUsername(username); | |
41 } | |
42 | |
43 void FakeSigninManager::StartSignInWithCredentials( | |
44 const std::string& session_index, | |
45 const std::string& username, | |
46 const std::string& password) { | |
47 SetAuthenticatedUsername(username); | |
48 } | |
49 | |
50 void FakeSigninManager::StartSignInWithOAuth(const std::string& username, | |
51 const std::string& password) { | |
52 SetAuthenticatedUsername(username); | |
53 } | |
54 | |
55 void FakeSigninManager::SignOut() { | |
56 if (IsSignoutProhibited()) | |
57 return; | |
58 authenticated_username_.clear(); | |
59 content::NotificationService::current()->Notify( | |
60 chrome::NOTIFICATION_GOOGLE_SIGNED_OUT, | |
61 content::Source<Profile>(profile_), | |
62 content::NotificationService::NoDetails()); | |
63 } | |
64 | |
65 void FakeSigninManager::ForceSignOut() { | |
66 // Allow signing out now. | |
67 prohibit_signout_ = false; | |
68 SignOut(); | |
69 } | |
70 | |
71 bool FakeSigninManager::AuthInProgress() const { | |
72 return auth_in_progress_; | |
73 } | |
74 | |
75 // static | |
76 ProfileKeyedService* FakeSigninManager::Build(Profile* profile) { | |
77 return new FakeSigninManager(profile); | |
78 } | |
OLD | NEW |