Chromium Code Reviews| Index: ash/metrics/user_metrics_recorder.cc |
| diff --git a/ash/metrics/user_metrics_recorder.cc b/ash/metrics/user_metrics_recorder.cc |
| index c1c9e631aeaeff5ec581bd8a35b96c74bd6f5340..52bb671226873b53b4d05303ed5f73f059b3412c 100644 |
| --- a/ash/metrics/user_metrics_recorder.cc |
| +++ b/ash/metrics/user_metrics_recorder.cc |
| @@ -4,11 +4,13 @@ |
| #include "ash/metrics/user_metrics_recorder.h" |
| +#include "ash/session/session_state_delegate.h" |
| #include "ash/shelf/shelf_layout_manager.h" |
| #include "ash/shelf/shelf_view.h" |
| #include "ash/shelf/shelf_widget.h" |
| #include "ash/shell.h" |
| #include "ash/shell_window_ids.h" |
| +#include "ash/system/tray/system_tray_delegate.h" |
| #include "ash/wm/window_state.h" |
| #include "base/metrics/histogram.h" |
| #include "base/metrics/user_metrics.h" |
| @@ -64,6 +66,31 @@ ActiveWindowStateType GetActiveWindowState() { |
| return active_window_state_type; |
| } |
| +// Returns true if Kiosk mode is active. |
|
pkotwicz
2015/04/21 16:15:17
Nit: "Kiosk mode" -> "kiosk mode"
bruthig
2015/04/24 20:00:11
Done.
|
| +bool IsKioskModeActive() { |
| + return Shell::GetInstance()->system_tray_delegate()->GetUserLoginStatus() == |
| + user::LOGGED_IN_KIOSK_APP; |
| +} |
| + |
| +// Returns true if there is an active user and their session isn't currently |
| +// locked. |
| +bool IsUserActive() { |
| + switch (Shell::GetInstance()->system_tray_delegate()->GetUserLoginStatus()) { |
| + case user::LOGGED_IN_NONE: |
| + case user::LOGGED_IN_LOCKED: |
| + return false; |
| + case user::LOGGED_IN_USER: |
| + case user::LOGGED_IN_OWNER: |
| + case user::LOGGED_IN_GUEST: |
| + case user::LOGGED_IN_PUBLIC: |
| + case user::LOGGED_IN_SUPERVISED: |
| + case user::LOGGED_IN_KIOSK_APP: |
| + return true; |
| + } |
| + NOTREACHED(); |
| + return false; |
| +} |
| + |
| // Array of window container ids that contain visible windows to be counted for |
| // UMA statistics. Note the containers are ordered from top most visible |
| // container to the lowest to allow the |GetNumVisibleWindows| method to short |
| @@ -124,10 +151,12 @@ int GetNumVisibleWindowsInPrimaryDisplay() { |
| } // namespace |
| UserMetricsRecorder::UserMetricsRecorder() { |
| - timer_.Start(FROM_HERE, |
| - base::TimeDelta::FromSeconds(kAshPeriodicMetricsTimeInSeconds), |
| - this, |
| - &UserMetricsRecorder::RecordPeriodicMetrics); |
| + StartTimer(); |
| +} |
| + |
| +UserMetricsRecorder::UserMetricsRecorder(bool record_periodic_metrics) { |
| + if (record_periodic_metrics) |
| + StartTimer(); |
| } |
| UserMetricsRecorder::~UserMetricsRecorder() { |
| @@ -520,6 +549,7 @@ void UserMetricsRecorder::RecordPeriodicMetrics() { |
| ShelfLayoutManager* manager = |
| ShelfLayoutManager::ForShelf(Shell::GetPrimaryRootWindow()); |
| if (manager) { |
| + // TODO(bruthig): Consider tracking the time spent in each alignment. |
| UMA_HISTOGRAM_ENUMERATION("Ash.ShelfAlignmentOverTime", |
| manager->SelectValueForShelfAlignment( |
| SHELF_ALIGNMENT_UMA_ENUM_VALUE_BOTTOM, |
| @@ -529,12 +559,28 @@ void UserMetricsRecorder::RecordPeriodicMetrics() { |
| SHELF_ALIGNMENT_UMA_ENUM_VALUE_COUNT); |
| } |
| - UMA_HISTOGRAM_COUNTS_100("Ash.NumberOfVisibleWindowsInPrimaryDisplay", |
| - GetNumVisibleWindowsInPrimaryDisplay()); |
| + if (IsUserActiveInMultiWindowEnvironment()) { |
| + UMA_HISTOGRAM_COUNTS_100("Ash.NumberOfVisibleWindowsInPrimaryDisplay", |
| + GetNumVisibleWindowsInPrimaryDisplay()); |
| + } |
| + // TODO(bruthig): Find out if this should only be logged when the user is |
| + // active. |
| + // TODO(bruthig): Consider tracking how long a particular type of window is |
| + // active at a time. |
| UMA_HISTOGRAM_ENUMERATION("Ash.ActiveWindowShowTypeOverTime", |
| GetActiveWindowState(), |
| ACTIVE_WINDOW_STATE_TYPE_COUNT); |
| } |
| +bool UserMetricsRecorder::IsUserActiveInMultiWindowEnvironment() const { |
| + return IsUserActive() && !IsKioskModeActive(); |
| +} |
| + |
| +void UserMetricsRecorder::StartTimer() { |
| + timer_.Start(FROM_HERE, |
| + base::TimeDelta::FromSeconds(kAshPeriodicMetricsTimeInSeconds), |
| + this, &UserMetricsRecorder::RecordPeriodicMetrics); |
| +} |
| + |
| } // namespace ash |