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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/login/enterprise_user_session_metrics.cc
diff --git a/chrome/browser/chromeos/login/enterprise_user_session_metrics.cc b/chrome/browser/chromeos/login/enterprise_user_session_metrics.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6235c570cbd27b02904916d2fdd4592c97624ce6
--- /dev/null
+++ b/chrome/browser/chromeos/login/enterprise_user_session_metrics.cc
@@ -0,0 +1,107 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/chromeos/login/enterprise_user_session_metrics.h"
+
+#include "base/logging.h"
+#include "base/metrics/histogram_macros.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
+#include "chrome/common/pref_names.h"
+#include "chromeos/login/auth/user_context.h"
+#include "components/prefs/pref_registry_simple.h"
+#include "components/prefs/pref_service.h"
+
+namespace {
+
+// Returns true if the device is enterprise managed, false otherwise.
+bool IsEnterpriseManaged() {
+ policy::BrowserPolicyConnectorChromeOS* connector =
+ g_browser_process->platform_part()->browser_policy_connector_chromeos();
+ 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
+}
+
+} // namespace
+
+namespace chromeos {
+namespace enterprise_user_session_metrics {
+
+void RegisterPrefs(PrefRegistrySimple* registry) {
+ registry->RegisterIntegerPref(prefs::kLastSessionType, 0);
+ registry->RegisterInt64Pref(prefs::kLastSessionLength, 0);
+}
+
+void RecordSignInEvent(SignInEventType sign_in_event_type) {
+ DCHECK(IsEnterpriseManaged());
+
+ UMA_HISTOGRAM_ENUMERATION("Enterprise.UserSession.Logins", sign_in_event_type,
+ SIGN_IN_EVENT_COUNT);
+}
+
+void RecordSignInEvent(const UserContext& user_context, bool is_auto_login) {
+ DCHECK(IsEnterpriseManaged());
+
+ const user_manager::UserType session_type = user_context.GetUserType();
+ if (session_type == user_manager::USER_TYPE_REGULAR) {
+ RecordSignInEvent(REGULAR_USER);
+ } else if (session_type == user_manager::USER_TYPE_PUBLIC_ACCOUNT) {
+ RecordSignInEvent(is_auto_login ? AUTOMATIC_PUBLIC_SESSSION
+ : MANUAL_PUBLIC_SESSION);
+ }
+
+ // Kiosk sign-ins are handled separately in AppLaunchController and other
+ // session types are ignored for now.
+}
+
+void StoreSessionLength(user_manager::UserType session_type,
+ const base::TimeDelta& session_length) {
+ DCHECK(IsEnterpriseManaged());
+
+ PrefService* local_state = g_browser_process->local_state();
+ local_state->SetInteger(prefs::kLastSessionType, session_type);
+ local_state->SetInt64(prefs::kLastSessionLength,
+ session_length.ToInternalValue());
+ local_state->CommitPendingWrite();
+}
+
+void RecordStoredSessionLength() {
+ DCHECK(IsEnterpriseManaged());
+
+ PrefService* local_state = g_browser_process->local_state();
+ if (!local_state->HasPrefPath(prefs::kLastSessionType) ||
+ !local_state->HasPrefPath(prefs::kLastSessionLength)) {
+ return;
+ }
+
+ const user_manager::UserType session_type =
+ static_cast<user_manager::UserType>(
+ local_state->GetInteger(prefs::kLastSessionType));
+ const base::TimeDelta session_length = base::TimeDelta::FromInternalValue(
+ local_state->GetInt64(prefs::kLastSessionLength));
+
+ local_state->ClearPref(prefs::kLastSessionType);
+ local_state->ClearPref(prefs::kLastSessionLength);
+
+ if (session_length.is_zero())
+ return;
+
+ std::string metric_name;
+ if (session_type == user_manager::USER_TYPE_REGULAR) {
+ metric_name = "Enterprise.RegularSession.SessionLength";
+ } else if (session_type == user_manager::USER_TYPE_PUBLIC_ACCOUNT) {
+ 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
+ } else {
+ // No session length metric for other session types.
+ return;
+ }
+
+ // Report session duration for the first 24 hours, split into 144 buckets
+ // (i.e. every 10 minute). Use counts rather than time to track in
+ // 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
+ UMA_HISTOGRAM_CUSTOM_COUNTS(metric_name, session_length.InMinutes(), 0,
+ base::TimeDelta::FromHours(24).InMinutes(), 144);
+}
+
+} // namespace enterprise_user_session_metrics
+} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698