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

Side by Side Diff: chrome/browser/chromeos/login/enterprise_user_session_metrics.cc

Issue 2692163003: cros: Add enterprise user session metrics (Closed)
Patch Set: fix crash on browser exit w/o login Created 3 years, 10 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
OLDNEW
(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 "base/logging.h"
8 #include "base/metrics/histogram_macros.h"
9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
11 #include "chrome/common/pref_names.h"
12 #include "chromeos/login/auth/user_context.h"
13 #include "components/prefs/pref_registry_simple.h"
14 #include "components/prefs/pref_service.h"
15
16 namespace {
17
18 // Returns true if the device is enterprise managed, false otherwise.
19 bool IsEnterpriseManaged() {
20 policy::BrowserPolicyConnectorChromeOS* connector =
21 g_browser_process->platform_part()->browser_policy_connector_chromeos();
22 return connector->IsEnterpriseManaged();
achuithb 2017/02/15 10:54:57 Any reason to not have this all be one line? retur
xiyuan 2017/02/15 19:08:10 Done. Also updated the same util function in AppLa
23 }
24
25 } // namespace
26
27 namespace chromeos {
28 namespace enterprise_user_session_metrics {
29
30 void RegisterPrefs(PrefRegistrySimple* registry) {
31 registry->RegisterIntegerPref(prefs::kLastSessionType, 0);
32 registry->RegisterInt64Pref(prefs::kLastSessionLength, 0);
33 }
34
35 void RecordSignInEvent(SignInEventType sign_in_event_type) {
36 DCHECK(IsEnterpriseManaged());
37
38 UMA_HISTOGRAM_ENUMERATION("Enterprise.UserSession.Logins", sign_in_event_type,
39 SIGN_IN_EVENT_COUNT);
40 }
41
42 void RecordSignInEvent(const UserContext& user_context, bool is_auto_login) {
43 DCHECK(IsEnterpriseManaged());
44
45 const user_manager::UserType session_type = user_context.GetUserType();
46 if (session_type == user_manager::USER_TYPE_REGULAR) {
47 RecordSignInEvent(REGULAR_USER);
48 } else if (session_type == user_manager::USER_TYPE_PUBLIC_ACCOUNT) {
49 RecordSignInEvent(is_auto_login ? AUTOMATIC_PUBLIC_SESSSION
50 : MANUAL_PUBLIC_SESSION);
51 }
52
53 // Kiosk sign-ins are handled separately in AppLaunchController and other
54 // session types are ignored for now.
55 }
56
57 void StoreSessionLength(user_manager::UserType session_type,
58 const base::TimeDelta& session_length) {
59 DCHECK(IsEnterpriseManaged());
60
61 PrefService* local_state = g_browser_process->local_state();
62 local_state->SetInteger(prefs::kLastSessionType, session_type);
63 local_state->SetInt64(prefs::kLastSessionLength,
64 session_length.ToInternalValue());
65 local_state->CommitPendingWrite();
66 }
67
68 void RecordStoredSessionLength() {
69 DCHECK(IsEnterpriseManaged());
70
71 PrefService* local_state = g_browser_process->local_state();
72 if (!local_state->HasPrefPath(prefs::kLastSessionType) ||
73 !local_state->HasPrefPath(prefs::kLastSessionLength)) {
74 return;
75 }
76
77 const user_manager::UserType session_type =
78 static_cast<user_manager::UserType>(
79 local_state->GetInteger(prefs::kLastSessionType));
80 const base::TimeDelta session_length = base::TimeDelta::FromInternalValue(
81 local_state->GetInt64(prefs::kLastSessionLength));
82
83 local_state->ClearPref(prefs::kLastSessionType);
84 local_state->ClearPref(prefs::kLastSessionLength);
85
86 if (session_length.is_zero())
87 return;
88
89 std::string metric_name;
90 if (session_type == user_manager::USER_TYPE_REGULAR) {
91 metric_name = "Enterprise.RegularSession.SessionLength";
92 } else if (session_type == user_manager::USER_TYPE_PUBLIC_ACCOUNT) {
93 metric_name = "Enterprise.PublicSession.SessionLength";
Ilya Sherman 2017/02/15 00:16:57 Metric names used with histogram macros must be ru
xiyuan 2017/02/15 19:08:10 Acknowledged. Changed use UMA_HISTOGRAM_SPARSE_SLO
94 } else {
95 // No session length metric for other session types.
96 return;
97 }
98
99 // Report session duration for the first 24 hours, split into 144 buckets
100 // (i.e. every 10 minute). Use counts rather than time to track in
101 // minutes.
Ilya Sherman 2017/02/15 00:16:57 Note that histogram buckets are logarithmically sp
xiyuan 2017/02/15 19:08:10 Always has something to learn. :) Changed to UMA_H
102 UMA_HISTOGRAM_CUSTOM_COUNTS(metric_name, session_length.InMinutes(), 0,
103 base::TimeDelta::FromHours(24).InMinutes(), 144);
104 }
105
106 } // namespace enterprise_user_session_metrics
107 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698