Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(395)

Side by Side Diff: chrome/browser/signin/signin_manager_base.h

Issue 12502017: signin: pull basic SigninManager functionality into new SigninManagerBase class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: deal with new enterprise_platform_keys_private_api Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/signin/signin_manager.cc ('k') | chrome/browser/signin/signin_manager_base.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 // TODO(tim): Remove SignOut here, it belongs in the derived class.
107 // Bug 174927.
108 virtual void SignOut();
109
110 // Returns true if there's a signin in progress.
111 virtual bool AuthInProgress() const;
112
113 SigninGlobalError* signin_global_error() {
114 return signin_global_error_.get();
115 }
116
117 const SigninGlobalError* signin_global_error() const {
118 return signin_global_error_.get();
119 }
120
121 // ProfileKeyedService implementation.
122 virtual void Shutdown() OVERRIDE;
123
124 // Methods to register or remove SigninDiagnosticObservers
125 void AddSigninDiagnosticsObserver(
126 signin_internals_util::SigninDiagnosticsObserver* observer);
127 void RemoveSigninDiagnosticsObserver(
128 signin_internals_util::SigninDiagnosticsObserver* observer);
129
130 protected:
131 // Lets different platforms initialize TokenService in their own way.
132 virtual void InitTokenService();
133
134 // Pointer to parent profile (protected so FakeSigninManager can access
135 // it).
136 Profile* profile_;
137
138 // Used to show auth errors in the wrench menu. The SigninGlobalError is
139 // different than most GlobalErrors in that its lifetime is controlled by
140 // SigninManager (so we can expose a reference for use in the wrench menu).
141 scoped_ptr<SigninGlobalError> signin_global_error_;
142
143 // Helper methods to notify all registered diagnostics observers with.
144 void NotifyDiagnosticsObservers(
145 const signin_internals_util::UntimedSigninStatusField& field,
146 const std::string& value);
147 void NotifyDiagnosticsObservers(
148 const signin_internals_util::TimedSigninStatusField& field,
149 const std::string& value);
150
151 private:
152 friend class FakeSigninManagerBase;
153 friend class FakeSigninManager;
154 void OnGoogleServicesUsernamePatternChanged();
155
156 void OnSigninAllowedPrefChanged();
157
158 // Helper object to listen for changes to signin preferences stored in non-
159 // profile-specific local prefs (like kGoogleServicesUsernamePattern).
160 PrefChangeRegistrar local_state_pref_registrar_;
161
162 // Helper object to listen for changes to the signin allowed preference.
163 BooleanPrefMember signin_allowed_;
164
165 // Actual username after successful authentication.
166 std::string authenticated_username_;
167
168 // The list of SigninDiagnosticObservers.
169 ObserverList<signin_internals_util::SigninDiagnosticsObserver, true>
170 signin_diagnostics_observers_;
171
172 base::WeakPtrFactory<SigninManagerBase> weak_pointer_factory_;
173
174 DISALLOW_COPY_AND_ASSIGN(SigninManagerBase);
175 };
176
177 #endif // CHROME_BROWSER_SIGNIN_SIGNIN_MANAGER_BASE_H_
OLDNEW
« no previous file with comments | « chrome/browser/signin/signin_manager.cc ('k') | chrome/browser/signin/signin_manager_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698