OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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 "ash/metrics/desktop_task_switch_metric_recorder.h" |
| 6 |
| 7 #include "ash/metrics/user_metrics_recorder.h" |
| 8 #include "ash/shell.h" |
| 9 #include "ui/wm/public/activation_client.h" |
| 10 |
| 11 namespace ash { |
| 12 |
| 13 namespace { |
| 14 |
| 15 // Returns true if |window| is considered a task window. |
| 16 bool IsATaskWindow(aura::Window* window) { |
| 17 return Shell::GetInstance() |
| 18 ->metrics() |
| 19 ->task_switch_metrics_recorder() |
| 20 .IsATaskWindow(window); |
| 21 } |
| 22 |
| 23 } // namespace |
| 24 |
| 25 DesktopTaskSwitchMetricRecorder::DesktopTaskSwitchMetricRecorder() |
| 26 : last_active_task_window_(nullptr) { |
| 27 Shell::GetInstance()->activation_client()->AddObserver(this); |
| 28 } |
| 29 |
| 30 DesktopTaskSwitchMetricRecorder::~DesktopTaskSwitchMetricRecorder() { |
| 31 Shell::GetInstance()->activation_client()->RemoveObserver(this); |
| 32 } |
| 33 |
| 34 void DesktopTaskSwitchMetricRecorder::OnWindowActivated( |
| 35 aura::client::ActivationChangeObserver::ActivationReason reason, |
| 36 aura::Window* gained_active, |
| 37 aura::Window* lost_active) { |
| 38 if (IsATaskWindow(gained_active)) { |
| 39 if (last_active_task_window_ != gained_active && |
| 40 reason == aura::client::ActivationChangeObserver::ActivationReason:: |
| 41 kInputEvent) { |
| 42 Shell::GetInstance()->metrics()->RecordUserMetricsAction( |
| 43 UMA_DESKTOP_SWITCH_TASK); |
| 44 } |
| 45 last_active_task_window_ = gained_active; |
| 46 } |
| 47 } |
| 48 |
| 49 } // namespace ash |
OLD | NEW |