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

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

Issue 14630003: signin: move SigninManagerBase::Signout to SigninManager. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: apocalypse Created 7 years, 7 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
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 // The signin manager encapsulates some functionality tracking 5 // The signin manager encapsulates some functionality tracking
6 // which user is signed in. 6 // which user is signed in.
7 // 7 //
8 // **NOTE** on semantics of SigninManager: 8 // **NOTE** on semantics of SigninManager:
9 // 9 //
10 // Once a signin is successful, the username becomes "established" and will not 10 // Once a signin is successful, the username becomes "established" and will not
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 55
56 // Details for the Notification type NOTIFICATION_GOOGLE_SIGNED_OUT. 56 // Details for the Notification type NOTIFICATION_GOOGLE_SIGNED_OUT.
57 struct GoogleServiceSignoutDetails { 57 struct GoogleServiceSignoutDetails {
58 explicit GoogleServiceSignoutDetails(const std::string& in_username) 58 explicit GoogleServiceSignoutDetails(const std::string& in_username)
59 : username(in_username) {} 59 : username(in_username) {}
60 std::string username; 60 std::string username;
61 }; 61 };
62 62
63 class SigninManagerBase : public ProfileKeyedService { 63 class SigninManagerBase : public ProfileKeyedService {
64 public: 64 public:
65 // Returns true if the username is allowed based on the policy string.
66 static bool IsAllowedUsername(const std::string& username,
67 const std::string& policy);
68
69 SigninManagerBase(); 65 SigninManagerBase();
70 virtual ~SigninManagerBase(); 66 virtual ~SigninManagerBase();
71 67
72 // If user was signed in, load tokens from DB if available. 68 // If user was signed in, load tokens from DB if available.
73 void Initialize(Profile* profile); 69 virtual void Initialize(Profile* profile);
74 bool IsInitialized() const; 70 bool IsInitialized() const;
75 71
76 // Returns true if the passed username is allowed by policy. Virtual for
77 // mocking in tests.
78 virtual bool IsAllowedUsername(const std::string& username) const;
79
80 // Returns true if a signin to Chrome is allowed (by policy or pref). 72 // Returns true if a signin to Chrome is allowed (by policy or pref).
81 bool IsSigninAllowed() const; 73 // TODO(tim): kSigninAllowed is defined for all platforms in pref_names.h.
82 74 // If kSigninAllowed pref was non-Chrome OS-only, this method wouldn't be
83 // Checks if signin is allowed for the profile that owns |io_data|. This must 75 // needed, but as is we provide this method to let all interested code
84 // be invoked on the IO thread, and can be used to check if signin is enabled 76 // code query the value in one way, versus half using PrefService directly
85 // on that thread. 77 // and the other half using SigninManager.
86 static bool IsSigninAllowedOnIOThread(ProfileIOData* io_data); 78 virtual bool IsSigninAllowed() const;
87 79
88 // If a user has previously established a username and SignOut has not been 80 // If a user has previously established a username and SignOut has not been
89 // called, this will return the username. 81 // called, this will return the username.
90 // Otherwise, it will return an empty string. 82 // Otherwise, it will return an empty string.
91 const std::string& GetAuthenticatedUsername() const; 83 const std::string& GetAuthenticatedUsername() const;
92 84
93 // Sets the user name. Note: |username| should be already authenticated as 85 // Sets the user name. Note: |username| should be already authenticated as
94 // this is a sticky operation (in contrast to StartSignIn). 86 // this is a sticky operation (in contrast to StartSignIn).
95 // TODO(tim): Remove this in favor of passing username on construction by 87 // TODO(tim): Remove this in favor of passing username on construction by
96 // (by platform / depending on StartBehavior). Bug 88109. 88 // (by platform / depending on StartBehavior). Bug 88109.
97 void SetAuthenticatedUsername(const std::string& username); 89 void SetAuthenticatedUsername(const std::string& username);
98 90
99 // Sign a user out, removing the preference, erasing all keys
100 // associated with the user, and canceling all auth in progress.
101 // TODO(tim): Remove SignOut here, it belongs in the derived class.
102 // Bug 174927.
103 virtual void SignOut();
104
105 // Returns true if there's a signin in progress. 91 // Returns true if there's a signin in progress.
106 virtual bool AuthInProgress() const; 92 virtual bool AuthInProgress() const;
107 93
108 SigninGlobalError* signin_global_error() { 94 SigninGlobalError* signin_global_error() {
109 return signin_global_error_.get(); 95 return signin_global_error_.get();
110 } 96 }
111 97
112 const SigninGlobalError* signin_global_error() const { 98 const SigninGlobalError* signin_global_error() const {
113 return signin_global_error_.get(); 99 return signin_global_error_.get();
114 } 100 }
115 101
116 // ProfileKeyedService implementation. 102 // ProfileKeyedService implementation.
117 virtual void Shutdown() OVERRIDE; 103 virtual void Shutdown() OVERRIDE;
118 104
119 // Methods to register or remove SigninDiagnosticObservers 105 // Methods to register or remove SigninDiagnosticObservers
120 void AddSigninDiagnosticsObserver( 106 void AddSigninDiagnosticsObserver(
121 signin_internals_util::SigninDiagnosticsObserver* observer); 107 signin_internals_util::SigninDiagnosticsObserver* observer);
122 void RemoveSigninDiagnosticsObserver( 108 void RemoveSigninDiagnosticsObserver(
123 signin_internals_util::SigninDiagnosticsObserver* observer); 109 signin_internals_util::SigninDiagnosticsObserver* observer);
124 110
125 protected: 111 protected:
126 // Lets different platforms initialize TokenService in their own way. 112 // Lets different platforms initialize TokenService in their own way.
127 virtual void InitTokenService(); 113 virtual void InitTokenService();
128 114
115 // Used by subclass to clear authenticated_username_ instead of using
116 // SetAuthenticatedUsername, which enforces special preconditions due
117 // to the fact that it is part of the public API and called by clients.
118 void clear_authenticated_username();
119
129 // Pointer to parent profile (protected so FakeSigninManager can access 120 // Pointer to parent profile (protected so FakeSigninManager can access
130 // it). 121 // it).
131 Profile* profile_; 122 Profile* profile_;
132 123
133 // Used to show auth errors in the wrench menu. The SigninGlobalError is 124 // Used to show auth errors in the wrench menu. The SigninGlobalError is
134 // different than most GlobalErrors in that its lifetime is controlled by 125 // different than most GlobalErrors in that its lifetime is controlled by
135 // SigninManager (so we can expose a reference for use in the wrench menu). 126 // SigninManager (so we can expose a reference for use in the wrench menu).
136 scoped_ptr<SigninGlobalError> signin_global_error_; 127 scoped_ptr<SigninGlobalError> signin_global_error_;
137 128
138 // Helper methods to notify all registered diagnostics observers with. 129 // Helper methods to notify all registered diagnostics observers with.
139 void NotifyDiagnosticsObservers( 130 void NotifyDiagnosticsObservers(
140 const signin_internals_util::UntimedSigninStatusField& field, 131 const signin_internals_util::UntimedSigninStatusField& field,
141 const std::string& value); 132 const std::string& value);
142 void NotifyDiagnosticsObservers( 133 void NotifyDiagnosticsObservers(
143 const signin_internals_util::TimedSigninStatusField& field, 134 const signin_internals_util::TimedSigninStatusField& field,
144 const std::string& value); 135 const std::string& value);
145 136
146 private: 137 private:
147 friend class FakeSigninManagerBase; 138 friend class FakeSigninManagerBase;
148 friend class FakeSigninManager; 139 friend class FakeSigninManager;
149 void OnGoogleServicesUsernamePatternChanged();
150
151 void OnSigninAllowedPrefChanged();
152
153 // Helper object to listen for changes to signin preferences stored in non-
154 // profile-specific local prefs (like kGoogleServicesUsernamePattern).
155 PrefChangeRegistrar local_state_pref_registrar_;
156
157 // Helper object to listen for changes to the signin allowed preference.
158 BooleanPrefMember signin_allowed_;
159 140
160 // Actual username after successful authentication. 141 // Actual username after successful authentication.
161 std::string authenticated_username_; 142 std::string authenticated_username_;
162 143
163 // The list of SigninDiagnosticObservers. 144 // The list of SigninDiagnosticObservers.
164 ObserverList<signin_internals_util::SigninDiagnosticsObserver, true> 145 ObserverList<signin_internals_util::SigninDiagnosticsObserver, true>
165 signin_diagnostics_observers_; 146 signin_diagnostics_observers_;
166 147
167 base::WeakPtrFactory<SigninManagerBase> weak_pointer_factory_; 148 base::WeakPtrFactory<SigninManagerBase> weak_pointer_factory_;
168 149
169 DISALLOW_COPY_AND_ASSIGN(SigninManagerBase); 150 DISALLOW_COPY_AND_ASSIGN(SigninManagerBase);
170 }; 151 };
171 152
172 #endif // CHROME_BROWSER_SIGNIN_SIGNIN_MANAGER_BASE_H_ 153 #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