OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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. |
| 4 |
| 5 #include "chrome/browser/chromeos/login/enterprise_user_session_metrics.h" |
| 6 |
| 7 #include <algorithm> |
| 8 |
| 9 #include "base/logging.h" |
| 10 #include "base/metrics/histogram_macros.h" |
| 11 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
| 13 #include "chrome/common/pref_names.h" |
| 14 #include "chromeos/login/auth/user_context.h" |
| 15 #include "components/prefs/pref_registry_simple.h" |
| 16 #include "components/prefs/pref_service.h" |
| 17 |
| 18 namespace { |
| 19 |
| 20 // Returns true if the device is enterprise managed, false otherwise. |
| 21 bool IsEnterpriseManaged() { |
| 22 return g_browser_process->platform_part() |
| 23 ->browser_policy_connector_chromeos() |
| 24 ->IsEnterpriseManaged(); |
| 25 } |
| 26 |
| 27 } // namespace |
| 28 |
| 29 namespace chromeos { |
| 30 namespace enterprise_user_session_metrics { |
| 31 |
| 32 void RegisterPrefs(PrefRegistrySimple* registry) { |
| 33 registry->RegisterIntegerPref(prefs::kLastSessionType, 0); |
| 34 registry->RegisterInt64Pref(prefs::kLastSessionLength, 0); |
| 35 } |
| 36 |
| 37 void RecordSignInEvent(SignInEventType sign_in_event_type) { |
| 38 DCHECK(IsEnterpriseManaged()); |
| 39 |
| 40 UMA_HISTOGRAM_ENUMERATION( |
| 41 "Enterprise.UserSession.Logins", static_cast<int>(sign_in_event_type), |
| 42 static_cast<int>(SignInEventType::SIGN_IN_EVENT_COUNT)); |
| 43 } |
| 44 |
| 45 void RecordSignInEvent(const UserContext& user_context, bool is_auto_login) { |
| 46 DCHECK(IsEnterpriseManaged()); |
| 47 |
| 48 const user_manager::UserType session_type = user_context.GetUserType(); |
| 49 if (session_type == user_manager::USER_TYPE_REGULAR) { |
| 50 RecordSignInEvent(SignInEventType::REGULAR_USER); |
| 51 } else if (session_type == user_manager::USER_TYPE_PUBLIC_ACCOUNT) { |
| 52 RecordSignInEvent(is_auto_login ? SignInEventType::AUTOMATIC_PUBLIC_SESSSION |
| 53 : SignInEventType::MANUAL_PUBLIC_SESSION); |
| 54 } |
| 55 |
| 56 // Kiosk sign-ins are handled separately in AppLaunchController and other |
| 57 // session types are ignored for now. |
| 58 } |
| 59 |
| 60 void StoreSessionLength(user_manager::UserType session_type, |
| 61 const base::TimeDelta& session_length) { |
| 62 DCHECK(IsEnterpriseManaged()); |
| 63 |
| 64 if (session_type != user_manager::USER_TYPE_REGULAR && |
| 65 session_type != user_manager::USER_TYPE_PUBLIC_ACCOUNT) { |
| 66 // No session length metric for other session types. |
| 67 return; |
| 68 } |
| 69 |
| 70 PrefService* local_state = g_browser_process->local_state(); |
| 71 local_state->SetInteger(prefs::kLastSessionType, session_type); |
| 72 local_state->SetInt64(prefs::kLastSessionLength, |
| 73 session_length.ToInternalValue()); |
| 74 local_state->CommitPendingWrite(); |
| 75 } |
| 76 |
| 77 void RecordStoredSessionLength() { |
| 78 DCHECK(IsEnterpriseManaged()); |
| 79 |
| 80 PrefService* local_state = g_browser_process->local_state(); |
| 81 if (!local_state->HasPrefPath(prefs::kLastSessionType) || |
| 82 !local_state->HasPrefPath(prefs::kLastSessionLength)) { |
| 83 return; |
| 84 } |
| 85 |
| 86 const user_manager::UserType session_type = |
| 87 static_cast<user_manager::UserType>( |
| 88 local_state->GetInteger(prefs::kLastSessionType)); |
| 89 const base::TimeDelta session_length = base::TimeDelta::FromInternalValue( |
| 90 local_state->GetInt64(prefs::kLastSessionLength)); |
| 91 |
| 92 local_state->ClearPref(prefs::kLastSessionType); |
| 93 local_state->ClearPref(prefs::kLastSessionLength); |
| 94 |
| 95 if (session_length.is_zero()) |
| 96 return; |
| 97 |
| 98 std::string metric_name; |
| 99 if (session_type == user_manager::USER_TYPE_REGULAR) { |
| 100 metric_name = "Enterprise.RegularUserSession.SessionLength"; |
| 101 } else if (session_type == user_manager::USER_TYPE_PUBLIC_ACCOUNT) { |
| 102 metric_name = "Enterprise.PublicSession.SessionLength"; |
| 103 } else { |
| 104 // NOTREACHED() since session length for other session types should not |
| 105 // be recorded. |
| 106 NOTREACHED(); |
| 107 return; |
| 108 } |
| 109 |
| 110 // Report session duration for the first 24 hours, split into 144 buckets |
| 111 // (i.e. every 10 minute). Note that sparse histogram is used here. It is |
| 112 // important to limit the number of buckets to something reasonable. |
| 113 const int floored = std::min(session_length.InMinutes(), |
| 114 base::TimeDelta::FromHours(24).InMinutes()) / |
| 115 10 * 10; |
| 116 UMA_HISTOGRAM_SPARSE_SLOWLY(metric_name, floored); |
| 117 } |
| 118 |
| 119 } // namespace enterprise_user_session_metrics |
| 120 } // namespace chromeos |
OLD | NEW |