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

Side by Side Diff: components/signin/core/browser/signin_manager.cc

Issue 338993007: Track when and how a profile is signed out via UMA. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: SignOut() param in Android tests Created 6 years, 6 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include "components/signin/core/browser/signin_manager.h" 5 #include "components/signin/core/browser/signin_manager.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
11 #include "base/strings/string_split.h" 11 #include "base/strings/string_split.h"
12 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "base/time/time.h" 14 #include "base/time/time.h"
15 #include "components/signin/core/browser/profile_oauth2_token_service.h" 15 #include "components/signin/core/browser/profile_oauth2_token_service.h"
16 #include "components/signin/core/browser/signin_account_id_helper.h" 16 #include "components/signin/core/browser/signin_account_id_helper.h"
17 #include "components/signin/core/browser/signin_client.h" 17 #include "components/signin/core/browser/signin_client.h"
18 #include "components/signin/core/browser/signin_internals_util.h" 18 #include "components/signin/core/browser/signin_internals_util.h"
19 #include "components/signin/core/browser/signin_manager_cookie_helper.h" 19 #include "components/signin/core/browser/signin_manager_cookie_helper.h"
20 #include "components/signin/core/browser/signin_metrics.h"
20 #include "components/signin/core/common/signin_pref_names.h" 21 #include "components/signin/core/common/signin_pref_names.h"
21 #include "google_apis/gaia/gaia_auth_util.h" 22 #include "google_apis/gaia/gaia_auth_util.h"
22 #include "google_apis/gaia/gaia_urls.h" 23 #include "google_apis/gaia/gaia_urls.h"
23 #include "net/base/escape.h" 24 #include "net/base/escape.h"
24 #include "third_party/icu/source/i18n/unicode/regex.h" 25 #include "third_party/icu/source/i18n/unicode/regex.h"
25 26
26 using namespace signin_internals_util; 27 using namespace signin_internals_util;
27 28
28 namespace { 29 namespace {
29 30
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 type_ = SIGNIN_TYPE_NONE; 165 type_ = SIGNIN_TYPE_NONE;
165 temp_refresh_token_.clear(); 166 temp_refresh_token_.clear();
166 } 167 }
167 168
168 void SigninManager::HandleAuthError(const GoogleServiceAuthError& error) { 169 void SigninManager::HandleAuthError(const GoogleServiceAuthError& error) {
169 ClearTransientSigninData(); 170 ClearTransientSigninData();
170 171
171 FOR_EACH_OBSERVER(Observer, observer_list_, GoogleSigninFailed(error)); 172 FOR_EACH_OBSERVER(Observer, observer_list_, GoogleSigninFailed(error));
172 } 173 }
173 174
174 void SigninManager::SignOut() { 175 void SigninManager::SignOut(
176 signin_metrics::ProfileSignout signout_source_metric) {
175 DCHECK(IsInitialized()); 177 DCHECK(IsInitialized());
176 178
179 signin_metrics::LogSignout(signout_source_metric);
177 if (GetAuthenticatedUsername().empty()) { 180 if (GetAuthenticatedUsername().empty()) {
178 if (AuthInProgress()) { 181 if (AuthInProgress()) {
179 // If the user is in the process of signing in, then treat a call to 182 // If the user is in the process of signing in, then treat a call to
180 // SignOut as a cancellation request. 183 // SignOut as a cancellation request.
181 GoogleServiceAuthError error(GoogleServiceAuthError::REQUEST_CANCELED); 184 GoogleServiceAuthError error(GoogleServiceAuthError::REQUEST_CANCELED);
182 HandleAuthError(error); 185 HandleAuthError(error);
183 } else { 186 } else {
184 // Clean up our transient data and exit if we aren't signed in. 187 // Clean up our transient data and exit if we aren't signed in.
185 // This avoids a perf regression from clearing out the TokenDB if 188 // This avoids a perf regression from clearing out the TokenDB if
186 // SignOut() is invoked on startup to clean up any incomplete previous 189 // SignOut() is invoked on startup to clean up any incomplete previous
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 signin_allowed_.Init(prefs::kSigninAllowed, 231 signin_allowed_.Init(prefs::kSigninAllowed,
229 client_->GetPrefs(), 232 client_->GetPrefs(),
230 base::Bind(&SigninManager::OnSigninAllowedPrefChanged, 233 base::Bind(&SigninManager::OnSigninAllowedPrefChanged,
231 base::Unretained(this))); 234 base::Unretained(this)));
232 235
233 std::string user = 236 std::string user =
234 client_->GetPrefs()->GetString(prefs::kGoogleServicesUsername); 237 client_->GetPrefs()->GetString(prefs::kGoogleServicesUsername);
235 if ((!user.empty() && !IsAllowedUsername(user)) || !IsSigninAllowed()) { 238 if ((!user.empty() && !IsAllowedUsername(user)) || !IsSigninAllowed()) {
236 // User is signed in, but the username is invalid - the administrator must 239 // User is signed in, but the username is invalid - the administrator must
237 // have changed the policy since the last signin, so sign out the user. 240 // have changed the policy since the last signin, so sign out the user.
238 SignOut(); 241 SignOut(signin_metrics::SIGNIN_PREF_CHANGED_DURING_SIGNIN);
239 } 242 }
240 243
241 InitTokenService(); 244 InitTokenService();
242 account_id_helper_.reset( 245 account_id_helper_.reset(
243 new SigninAccountIdHelper(client_, token_service_, this)); 246 new SigninAccountIdHelper(client_, token_service_, this));
244 } 247 }
245 248
246 void SigninManager::Shutdown() { 249 void SigninManager::Shutdown() {
247 if (merge_session_helper_) 250 if (merge_session_helper_)
248 merge_session_helper_->CancelAll(); 251 merge_session_helper_->CancelAll();
249 252
250 local_state_pref_registrar_.RemoveAll(); 253 local_state_pref_registrar_.RemoveAll();
251 account_id_helper_.reset(); 254 account_id_helper_.reset();
252 SigninManagerBase::Shutdown(); 255 SigninManagerBase::Shutdown();
253 } 256 }
254 257
255 void SigninManager::OnGoogleServicesUsernamePatternChanged() { 258 void SigninManager::OnGoogleServicesUsernamePatternChanged() {
256 if (!GetAuthenticatedUsername().empty() && 259 if (!GetAuthenticatedUsername().empty() &&
257 !IsAllowedUsername(GetAuthenticatedUsername())) { 260 !IsAllowedUsername(GetAuthenticatedUsername())) {
258 // Signed in user is invalid according to the current policy so sign 261 // Signed in user is invalid according to the current policy so sign
259 // the user out. 262 // the user out.
260 SignOut(); 263 SignOut(signin_metrics::GOOGLE_SERVICE_NAME_PATTERN_CHANGED);
261 } 264 }
262 } 265 }
263 266
264 bool SigninManager::IsSigninAllowed() const { 267 bool SigninManager::IsSigninAllowed() const {
265 return signin_allowed_.GetValue(); 268 return signin_allowed_.GetValue();
266 } 269 }
267 270
268 void SigninManager::OnSigninAllowedPrefChanged() { 271 void SigninManager::OnSigninAllowedPrefChanged() {
269 if (!IsSigninAllowed()) 272 if (!IsSigninAllowed())
270 SignOut(); 273 SignOut(signin_metrics::SIGNOUT_PREF_CHANGED);
271 } 274 }
272 275
273 // static 276 // static
274 bool SigninManager::IsUsernameAllowedByPolicy(const std::string& username, 277 bool SigninManager::IsUsernameAllowedByPolicy(const std::string& username,
275 const std::string& policy) { 278 const std::string& policy) {
276 if (policy.empty()) 279 if (policy.empty())
277 return true; 280 return true;
278 281
279 // Patterns like "*@foo.com" are not accepted by our regex engine (since they 282 // Patterns like "*@foo.com" are not accepted by our regex engine (since they
280 // are not valid regular expressions - they should instead be ".*@foo.com"). 283 // are not valid regular expressions - they should instead be ".*@foo.com").
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 364
362 password_.clear(); // Don't need it anymore. 365 password_.clear(); // Don't need it anymore.
363 DisableOneClickSignIn(client_->GetPrefs()); // Don't ever offer again. 366 DisableOneClickSignIn(client_->GetPrefs()); // Don't ever offer again.
364 } 367 }
365 368
366 void SigninManager::ProhibitSignout(bool prohibit_signout) { 369 void SigninManager::ProhibitSignout(bool prohibit_signout) {
367 prohibit_signout_ = prohibit_signout; 370 prohibit_signout_ = prohibit_signout;
368 } 371 }
369 372
370 bool SigninManager::IsSignoutProhibited() const { return prohibit_signout_; } 373 bool SigninManager::IsSignoutProhibited() const { return prohibit_signout_; }
OLDNEW
« no previous file with comments | « components/signin/core/browser/signin_manager.h ('k') | components/signin/core/browser/signin_metrics.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698