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
3 // found in the LICENSE file.
5 #include "chrome/browser/metrics/signin_status_metrics_provider_chromeos.h"
7 #include "chrome/browser/browser_process.h"
8 #include "chrome/browser/profiles/profile_manager.h"
9 #include "chromeos/login/login_state.h"
13 // Returns true if user is signed in to a non-guest profile.
14 bool IsSignedInNonGuest() {
15 ProfileManager
* profile_manager
= g_browser_process
->profile_manager();
16 if (profile_manager
&&
17 profile_manager
->IsLoggedIn() &&
18 chromeos::LoginState::Get() &&
19 !chromeos::LoginState::Get()->IsGuestSessionUser()) {
27 SigninStatusMetricsProviderChromeOS::SigninStatusMetricsProviderChromeOS() {
28 SetCurrentSigninStatus();
31 SigninStatusMetricsProviderChromeOS::~SigninStatusMetricsProviderChromeOS() {
34 void SigninStatusMetricsProviderChromeOS::ProvideGeneralMetrics(
35 metrics::ChromeUserMetricsExtension
* uma_proto
) {
36 // Compare the current logged-in status with the recorded one and compute
37 // sign-in status that should be reported.
38 RecordSigninStatusHistogram(ComputeSigninStatusToUpload(
39 signin_status(), IsSignedInNonGuest()));
40 // After reporting the sign-in status for previous UMA session, start fresh
41 // again regardless what was the status before.
43 SetCurrentSigninStatus();
46 void SigninStatusMetricsProviderChromeOS::SetCurrentSigninStatus() {
47 if (IsSignedInNonGuest())
48 SetSigninStatus(ALL_PROFILES_SIGNED_IN
);
49 SetSigninStatus(ALL_PROFILES_NOT_SIGNED_IN
);
52 SigninStatusMetricsProviderBase::SigninStatus
53 SigninStatusMetricsProviderChromeOS::ComputeSigninStatusToUpload(
54 SigninStatusMetricsProviderBase::SigninStatus recorded_status
,
56 if ((recorded_status
== ALL_PROFILES_SIGNED_IN
&& logged_in_now
) ||
57 (recorded_status
== ALL_PROFILES_NOT_SIGNED_IN
&& !logged_in_now
)) {
58 // If the status hasn't changed since we last recorded, report as it is.
59 return recorded_status
;
60 } else if (recorded_status
== ALL_PROFILES_NOT_SIGNED_IN
&& logged_in_now
) {
61 // It possible that the browser goes from not signed-in to signed-in (i.e.
62 // user performed a login action through the login manager.)
63 return MIXED_SIGNIN_STATUS
;
65 // There should not be other possibilities, for example the browser on
66 // ChromeOS can not go from signed-in to not signed-in. Record it as an
68 return ERROR_GETTING_SIGNIN_STATUS
;