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 // The signin manager encapsulates some functionality tracking | |
6 // which user is signed in. | |
7 // | |
8 // **NOTE** on semantics of SigninManager: | |
9 // | |
10 // Once a signin is successful, the username becomes "established" and will not | |
11 // be cleared until a SignOut operation is performed (persists across | |
12 // restarts). Until that happens, the signin manager can still be used to | |
13 // refresh credentials, but changing the username is not permitted. | |
14 // | |
15 // On Chrome OS, because of the existence of other components that handle login | |
16 // and signin at a higher level, all that is needed from a SigninManager is | |
17 // caching / handling of the "authenticated username" field, and TokenService | |
18 // initialization, so that components that depend on these two things | |
19 // (i.e on desktop) can continue using it / don't need to change. For this | |
20 // reason, SigninManagerBase is all that exists on Chrome OS. For desktop, | |
21 // see signin/signin_manager.h. | |
22 | |
23 #ifndef CHROME_BROWSER_SIGNIN_SIGNIN_MANAGER_BASE_H_ | |
24 #define CHROME_BROWSER_SIGNIN_SIGNIN_MANAGER_BASE_H_ | |
25 | |
26 #include <string> | |
27 | |
28 #include "base/compiler_specific.h" | |
29 #include "base/gtest_prod_util.h" | |
30 #include "base/logging.h" | |
31 #include "base/memory/scoped_ptr.h" | |
32 #include "base/observer_list.h" | |
33 #include "base/prefs/pref_change_registrar.h" | |
34 #include "base/prefs/pref_member.h" | |
35 #include "chrome/browser/profiles/profile.h" | |
36 #include "chrome/browser/profiles/profile_keyed_service.h" | |
37 #include "chrome/browser/signin/signin_internals_util.h" | |
38 | |
39 class CookieSettings; | |
40 class ProfileIOData; | |
41 class PrefService; | |
42 class SigninGlobalError; | |
43 | |
44 // Details for the Notification type GOOGLE_SIGNIN_SUCCESSFUL. | |
45 // A listener might use this to make note of a username / password | |
46 // pair for encryption keys. | |
47 struct GoogleServiceSigninSuccessDetails { | |
48 GoogleServiceSigninSuccessDetails(const std::string& in_username, | |
49 const std::string& in_password) | |
50 : username(in_username), | |
51 password(in_password) {} | |
52 std::string username; | |
53 std::string password; | |
54 }; | |
55 | |
56 // Details for the Notification type NOTIFICATION_GOOGLE_SIGNED_OUT. | |
57 struct GoogleServiceSignoutDetails { | |
58 explicit GoogleServiceSignoutDetails(const std::string& in_username) | |
59 : username(in_username) {} | |
60 std::string username; | |
61 }; | |
62 | |
63 class SigninManagerBase : public ProfileKeyedService { | |
64 public: | |
65 // Returns true if the cookie policy for the given profile allows cookies | |
66 // for the Google signin domain. | |
67 static bool AreSigninCookiesAllowed(Profile* profile); | |
68 static bool AreSigninCookiesAllowed(CookieSettings* cookie_settings); | |
69 | |
70 // Returns true if the username is allowed based on the policy string. | |
71 static bool IsAllowedUsername(const std::string& username, | |
72 const std::string& policy); | |
73 | |
74 SigninManagerBase(); | |
75 virtual ~SigninManagerBase(); | |
76 | |
77 // If user was signed in, load tokens from DB if available. | |
78 void Initialize(Profile* profile); | |
79 bool IsInitialized() const; | |
80 | |
81 // Returns true if the passed username is allowed by policy. Virtual for | |
82 // mocking in tests. | |
83 virtual bool IsAllowedUsername(const std::string& username) const; | |
84 | |
85 // Returns true if a signin to Chrome is allowed (by policy or pref). | |
86 bool IsSigninAllowed() const; | |
87 | |
88 // Checks if signin is allowed for the profile that owns |io_data|. This must | |
89 // be invoked on the IO thread, and can be used to check if signin is enabled | |
90 // on that thread. | |
91 static bool IsSigninAllowedOnIOThread(ProfileIOData* io_data); | |
92 | |
93 // If a user has previously established a username and SignOut has not been | |
94 // called, this will return the username. | |
95 // Otherwise, it will return an empty string. | |
96 const std::string& GetAuthenticatedUsername() const; | |
97 | |
98 // Sets the user name. Note: |username| should be already authenticated as | |
99 // this is a sticky operation (in contrast to StartSignIn). | |
100 // TODO(tim): Remove this in favor of passing username on construction by | |
101 // (by platform / depending on StartBehavior). Bug 88109. | |
102 void SetAuthenticatedUsername(const std::string& username); | |
103 | |
104 // Sign a user out, removing the preference, erasing all keys | |
105 // associated with the user, and canceling all auth in progress. | |
106 virtual void SignOut(); | |
Andrew T Wilson (Slow)
2013/04/09 15:39:25
I'm uneasy that we are still leaving this enabled
| |
107 | |
108 // Returns true if there's a signin in progress. | |
109 virtual bool AuthInProgress() const; | |
110 | |
111 SigninGlobalError* signin_global_error() { | |
112 return signin_global_error_.get(); | |
113 } | |
114 | |
115 const SigninGlobalError* signin_global_error() const { | |
116 return signin_global_error_.get(); | |
117 } | |
118 | |
119 // ProfileKeyedService implementation. | |
120 virtual void Shutdown() OVERRIDE; | |
121 | |
122 // Methods to register or remove SigninDiagnosticObservers | |
123 void AddSigninDiagnosticsObserver( | |
124 signin_internals_util::SigninDiagnosticsObserver* observer); | |
125 void RemoveSigninDiagnosticsObserver( | |
126 signin_internals_util::SigninDiagnosticsObserver* observer); | |
127 | |
128 protected: | |
129 // Lets different platforms initialize TokenService in their own way. | |
130 virtual void InitTokenService(); | |
131 | |
132 // Lets different SigninManagers control whether the potentially slow | |
133 // SignOut path (clearing TokenService, etc) is worth running. | |
134 virtual bool ShouldSignOut(); | |
135 | |
136 // Pointer to parent profile (protected so FakeSigninManager can access | |
137 // it). | |
138 Profile* profile_; | |
139 | |
140 // Used to show auth errors in the wrench menu. The SigninGlobalError is | |
141 // different than most GlobalErrors in that its lifetime is controlled by | |
142 // SigninManager (so we can expose a reference for use in the wrench menu). | |
143 scoped_ptr<SigninGlobalError> signin_global_error_; | |
144 | |
145 // Helper methods to notify all registered diagnostics observers with. | |
146 void NotifyDiagnosticsObservers( | |
147 const signin_internals_util::UntimedSigninStatusField& field, | |
148 const std::string& value); | |
149 void NotifyDiagnosticsObservers( | |
150 const signin_internals_util::TimedSigninStatusField& field, | |
151 const std::string& value); | |
152 | |
153 private: | |
154 friend class FakeSigninManagerBase; | |
155 friend class FakeSigninManager; | |
156 void OnGoogleServicesUsernamePatternChanged(); | |
157 | |
158 void OnSigninAllowedPrefChanged(); | |
159 | |
160 // Helper object to listen for changes to signin preferences stored in non- | |
161 // profile-specific local prefs (like kGoogleServicesUsernamePattern). | |
162 PrefChangeRegistrar local_state_pref_registrar_; | |
163 | |
164 // Helper object to listen for changes to the signin allowed preference. | |
165 BooleanPrefMember signin_allowed_; | |
166 | |
167 // Actual username after successful authentication. | |
168 std::string authenticated_username_; | |
169 | |
170 // The list of SigninDiagnosticObservers. | |
171 ObserverList<signin_internals_util::SigninDiagnosticsObserver, true> | |
172 signin_diagnostics_observers_; | |
173 | |
174 base::WeakPtrFactory<SigninManagerBase> weak_pointer_factory_; | |
175 | |
176 DISALLOW_COPY_AND_ASSIGN(SigninManagerBase); | |
177 }; | |
178 | |
179 #endif // CHROME_BROWSER_SIGNIN_SIGNIN_MANAGER_BASE_H_ | |
OLD | NEW |