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

Unified Diff: ash/metrics/screen_event_task_switch_metric_recorder.cc

Issue 1153633006: Added UMA statistics for changing the active window via click or touch events. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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: ash/metrics/screen_event_task_switch_metric_recorder.cc
diff --git a/ash/metrics/screen_event_task_switch_metric_recorder.cc b/ash/metrics/screen_event_task_switch_metric_recorder.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ef365d99127cff0ecdcf90479e2e049a5f256aa6
--- /dev/null
+++ b/ash/metrics/screen_event_task_switch_metric_recorder.cc
@@ -0,0 +1,56 @@
+// Copyright 2015 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 "ash/metrics/screen_event_task_switch_metric_recorder.h"
+
+#include "ash/metrics/user_metrics_recorder.h"
+#include "ash/shell.h"
+#include "ash/wm/mru_window_tracker.h"
+#include "ui/wm/public/activation_client.h"
+
+namespace ash {
+
+namespace {
+
+// Returns true if |window| is considered a task window.
+bool IsATaskWindow(aura::Window* window) {
+ return Shell::GetInstance()
+ ->metrics()
+ ->task_switch_metrics_recorder()
+ .IsATaskWindow(window);
+}
+
+// Returns the last active task window if one exists or nullptr otherwise.
+aura::Window* GetLastActiveTaskWindow() {
+ MruWindowTracker::WindowList window_list =
+ Shell::GetInstance()->mru_window_tracker()->BuildMruWindowList();
+ return window_list.empty() ? nullptr : window_list[0];
+}
+
+} // namespace
+
+ScreenEventTaskSwitchMetricRecorder::ScreenEventTaskSwitchMetricRecorder(
+ UserMetricsRecorder* user_metrics_recorder)
+ : user_metrics_recorder_(user_metrics_recorder) {
+}
+
+ScreenEventTaskSwitchMetricRecorder::~ScreenEventTaskSwitchMetricRecorder() {
+}
+
+void ScreenEventTaskSwitchMetricRecorder::
+ BeforeWindowActivatedByPreTargetHandler() {
+ active_window_before_activation_ = GetLastActiveTaskWindow();
+}
+
+void ScreenEventTaskSwitchMetricRecorder::OnWindowActivatedByPreTargetHandler(
+ aura::Window* gained_active,
+ aura::Window* lost_active) {
+ if (IsATaskWindow(gained_active) &&
+ active_window_before_activation_ != gained_active) {
+ Shell::GetInstance()->metrics()->RecordUserMetricsAction(
+ UMA_SCREEN_EVENT_SWITCH_TASK);
+ }
+}
+
+} // namespace ash

Powered by Google App Engine
This is Rietveld 408576698