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 |