OLD | NEW |
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/metrics/histogram.h" |
10 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
11 #include "base/strings/string_split.h" | 12 #include "base/strings/string_split.h" |
12 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
13 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
14 #include "base/time/time.h" | 15 #include "base/time/time.h" |
15 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 16 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
16 #include "components/signin/core/browser/signin_account_id_helper.h" | 17 #include "components/signin/core/browser/signin_account_id_helper.h" |
17 #include "components/signin/core/browser/signin_client.h" | 18 #include "components/signin/core/browser/signin_client.h" |
18 #include "components/signin/core/browser/signin_internals_util.h" | 19 #include "components/signin/core/browser/signin_internals_util.h" |
19 #include "components/signin/core/browser/signin_manager_cookie_helper.h" | 20 #include "components/signin/core/browser/signin_manager_cookie_helper.h" |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 } | 195 } |
195 | 196 |
196 if (prohibit_signout_) { | 197 if (prohibit_signout_) { |
197 DVLOG(1) << "Ignoring attempt to sign out while signout is prohibited"; | 198 DVLOG(1) << "Ignoring attempt to sign out while signout is prohibited"; |
198 return; | 199 return; |
199 } | 200 } |
200 | 201 |
201 ClearTransientSigninData(); | 202 ClearTransientSigninData(); |
202 | 203 |
203 const std::string username = GetAuthenticatedUsername(); | 204 const std::string username = GetAuthenticatedUsername(); |
| 205 const base::Time signin_time = |
| 206 base::Time::FromInternalValue( |
| 207 client_->GetPrefs()->GetInt64(prefs::kSignedInTime)); |
204 clear_authenticated_username(); | 208 clear_authenticated_username(); |
205 client_->GetPrefs()->ClearPref(prefs::kGoogleServicesUsername); | 209 client_->GetPrefs()->ClearPref(prefs::kGoogleServicesUsername); |
| 210 client_->GetPrefs()->ClearPref(prefs::kSignedInTime); |
206 client_->ClearSigninScopedDeviceId(); | 211 client_->ClearSigninScopedDeviceId(); |
207 | 212 |
208 // Erase (now) stale information from AboutSigninInternals. | 213 // Erase (now) stale information from AboutSigninInternals. |
209 NotifyDiagnosticsObservers(USERNAME, ""); | 214 NotifyDiagnosticsObservers(USERNAME, ""); |
210 | 215 |
| 216 // Determine the duration the user was logged in and log that to UMA. |
| 217 if (!signin_time.is_null()) { |
| 218 base::TimeDelta signed_in_duration = base::Time::Now() - signin_time; |
| 219 UMA_HISTOGRAM_COUNTS("Signin.SignedInDurationBeforeSignout", |
| 220 signed_in_duration.InMinutes()); |
| 221 } |
| 222 |
211 // Revoke all tokens before sending signed_out notification, because there | 223 // Revoke all tokens before sending signed_out notification, because there |
212 // may be components that don't listen for token service events when the | 224 // may be components that don't listen for token service events when the |
213 // profile is not connected to an account. | 225 // profile is not connected to an account. |
214 LOG(WARNING) << "Revoking refresh token on server. Reason: sign out, " | 226 LOG(WARNING) << "Revoking refresh token on server. Reason: sign out, " |
215 << "IsSigninAllowed: " << IsSigninAllowed(); | 227 << "IsSigninAllowed: " << IsSigninAllowed(); |
216 token_service_->RevokeAllCredentials(); | 228 token_service_->RevokeAllCredentials(); |
217 | 229 |
218 FOR_EACH_OBSERVER(Observer, observer_list_, GoogleSignedOut(username)); | 230 FOR_EACH_OBSERVER(Observer, observer_list_, GoogleSignedOut(username)); |
219 } | 231 } |
220 | 232 |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 | 358 |
347 if (client_->ShouldMergeSigninCredentialsIntoCookieJar()) | 359 if (client_->ShouldMergeSigninCredentialsIntoCookieJar()) |
348 merge_session_helper_->LogIn(GetAuthenticatedUsername()); | 360 merge_session_helper_->LogIn(GetAuthenticatedUsername()); |
349 } | 361 } |
350 | 362 |
351 void SigninManager::OnExternalSigninCompleted(const std::string& username) { | 363 void SigninManager::OnExternalSigninCompleted(const std::string& username) { |
352 OnSignedIn(username); | 364 OnSignedIn(username); |
353 } | 365 } |
354 | 366 |
355 void SigninManager::OnSignedIn(const std::string& username) { | 367 void SigninManager::OnSignedIn(const std::string& username) { |
| 368 client_->GetPrefs()->SetInt64(prefs::kSignedInTime, |
| 369 base::Time::Now().ToInternalValue()); |
356 SetAuthenticatedUsername(username); | 370 SetAuthenticatedUsername(username); |
357 possibly_invalid_username_.clear(); | 371 possibly_invalid_username_.clear(); |
358 | 372 |
359 FOR_EACH_OBSERVER( | 373 FOR_EACH_OBSERVER( |
360 Observer, | 374 Observer, |
361 observer_list_, | 375 observer_list_, |
362 GoogleSigninSucceeded(GetAuthenticatedUsername(), password_)); | 376 GoogleSigninSucceeded(GetAuthenticatedUsername(), password_)); |
363 | 377 |
364 client_->GoogleSigninSucceeded(GetAuthenticatedUsername(), password_); | 378 client_->GoogleSigninSucceeded(GetAuthenticatedUsername(), password_); |
365 | 379 |
366 password_.clear(); // Don't need it anymore. | 380 password_.clear(); // Don't need it anymore. |
367 DisableOneClickSignIn(client_->GetPrefs()); // Don't ever offer again. | 381 DisableOneClickSignIn(client_->GetPrefs()); // Don't ever offer again. |
368 } | 382 } |
369 | 383 |
370 void SigninManager::ProhibitSignout(bool prohibit_signout) { | 384 void SigninManager::ProhibitSignout(bool prohibit_signout) { |
371 prohibit_signout_ = prohibit_signout; | 385 prohibit_signout_ = prohibit_signout; |
372 } | 386 } |
373 | 387 |
374 bool SigninManager::IsSignoutProhibited() const { return prohibit_signout_; } | 388 bool SigninManager::IsSignoutProhibited() const { return prohibit_signout_; } |
OLD | NEW |