Chromium Code Reviews| 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/public/pref_change_registrar.h" | |
| 34 #include "base/prefs/public/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(); | |
| 107 | |
| 108 // Set the profile preference to turn off one-click sign-in so that it won't | |
| 109 // ever show it again in this profile (even if the user tries a new account). | |
| 110 static void DisableOneClickSignIn(Profile* profile); | |
|
Roger Tawa OOO till Jul 10th
2013/03/27 17:36:33
one-click is not used for chromeos, so should prob
tim (not reviewing)
2013/03/29 18:03:16
Actually I had already pulled it down but forgot t
| |
| 111 | |
| 112 SigninGlobalError* signin_global_error() { | |
| 113 return signin_global_error_.get(); | |
| 114 } | |
| 115 | |
| 116 const SigninGlobalError* signin_global_error() const { | |
| 117 return signin_global_error_.get(); | |
| 118 } | |
| 119 | |
| 120 // ProfileKeyedService implementation. | |
| 121 virtual void Shutdown() OVERRIDE; | |
| 122 | |
| 123 // Methods to register or remove SigninDiagnosticObservers | |
| 124 void AddSigninDiagnosticsObserver( | |
| 125 signin_internals_util::SigninDiagnosticsObserver* observer); | |
| 126 void RemoveSigninDiagnosticsObserver( | |
| 127 signin_internals_util::SigninDiagnosticsObserver* observer); | |
| 128 | |
| 129 protected: | |
| 130 // Lets different platforms initialize TokenService in their own way. | |
| 131 virtual void InitTokenService(); | |
| 132 | |
| 133 // Lets different SigninManagers control whether the potentially slow | |
| 134 // SignOut path (clearing TokenService, etc) is worth running. | |
| 135 virtual bool ShouldSignOut(); | |
| 136 | |
| 137 // Weak pointer to parent profile (protected so FakeSigninManager can access | |
| 138 // it). | |
|
Roger Tawa OOO till Jul 10th
2013/03/27 17:36:33
do we need to say weak here?
tim (not reviewing)
2013/03/29 18:03:16
Done.
| |
| 139 Profile* profile_; | |
| 140 | |
| 141 // Used to show auth errors in the wrench menu. The SigninGlobalError is | |
| 142 // different than most GlobalErrors in that its lifetime is controlled by | |
| 143 // SigninManager (so we can expose a reference for use in the wrench menu). | |
| 144 scoped_ptr<SigninGlobalError> signin_global_error_; | |
| 145 | |
| 146 // Helper methods to notify all registered diagnostics observers with. | |
| 147 void NotifyDiagnosticsObservers( | |
| 148 const signin_internals_util::UntimedSigninStatusField& field, | |
| 149 const std::string& value); | |
| 150 void NotifyDiagnosticsObservers( | |
| 151 const signin_internals_util::TimedSigninStatusField& field, | |
| 152 const std::string& value); | |
| 153 | |
| 154 private: | |
| 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 |