Componentize HistoryURLProvider/ScoredHistoryMatch.
[chromium-blink-merge.git] / chrome / browser / metrics / signin_status_metrics_provider_chromeos.cc
blob08e5af8f7fec082dc7b50e38240bcd4db5406cfc
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"
11 namespace {
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()) {
20 return true;
22 return false;
25 } // namespace
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.
42 ResetSigninStatus();
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,
55 bool logged_in_now) {
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;
64 } else {
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
67 // error.
68 return ERROR_GETTING_SIGNIN_STATUS;