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

Side by Side Diff: ash/wm/window_cycle_controller.cc

Issue 1126333005: Added metrics to track the time between task switches done via Alt+Tab and Alt+Shift+Tab. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changed "window_list.size() > 0" to "window.empty()". 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 unified diff | Download patch
« no previous file with comments | « ash/wm/window_cycle_controller.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/wm/window_cycle_controller.h" 5 #include "ash/wm/window_cycle_controller.h"
6 6
7 #include "ash/metrics/user_metrics_recorder.h"
7 #include "ash/session/session_state_delegate.h" 8 #include "ash/session/session_state_delegate.h"
8 #include "ash/shell.h" 9 #include "ash/shell.h"
9 #include "ash/wm/mru_window_tracker.h" 10 #include "ash/wm/mru_window_tracker.h"
10 #include "ash/wm/window_cycle_list.h" 11 #include "ash/wm/window_cycle_list.h"
11 #include "base/metrics/histogram.h" 12 #include "base/metrics/histogram.h"
13 #include "ui/aura/window.h"
12 #include "ui/events/event.h" 14 #include "ui/events/event.h"
13 #include "ui/events/event_handler.h" 15 #include "ui/events/event_handler.h"
14 16
15 namespace ash { 17 namespace ash {
16 18
17 namespace { 19 namespace {
18 20
21 // Returns the most recently active window from the |window_list| or nullptr
22 // if the list is empty.
23 aura::Window* GetActiveWindow(const MruWindowTracker::WindowList& window_list) {
24 return window_list.empty() ? nullptr : window_list[0];
25 }
26
19 // Filter to watch for the termination of a keyboard gesture to cycle through 27 // Filter to watch for the termination of a keyboard gesture to cycle through
20 // multiple windows. 28 // multiple windows.
21 class WindowCycleEventFilter : public ui::EventHandler { 29 class WindowCycleEventFilter : public ui::EventHandler {
22 public: 30 public:
23 WindowCycleEventFilter(); 31 WindowCycleEventFilter();
24 ~WindowCycleEventFilter() override; 32 ~WindowCycleEventFilter() override;
25 33
26 // Overridden from ui::EventHandler: 34 // Overridden from ui::EventHandler:
27 void OnKeyEvent(ui::KeyEvent* event) override; 35 void OnKeyEvent(ui::KeyEvent* event) override;
28 36
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 if (!CanCycle()) 78 if (!CanCycle())
71 return; 79 return;
72 80
73 if (!IsCycling()) 81 if (!IsCycling())
74 StartCycling(); 82 StartCycling();
75 83
76 Step(direction); 84 Step(direction);
77 } 85 }
78 86
79 void WindowCycleController::StartCycling() { 87 void WindowCycleController::StartCycling() {
80 window_cycle_list_.reset(new WindowCycleList(ash::Shell::GetInstance()-> 88 MruWindowTracker::WindowList window_list =
81 mru_window_tracker()->BuildMruWindowList())); 89 Shell::GetInstance()->mru_window_tracker()->BuildMruWindowList();
90
91 active_window_before_window_cycle_ = GetActiveWindow(window_list);
92
93 window_cycle_list_.reset(new WindowCycleList(window_list));
82 event_handler_.reset(new WindowCycleEventFilter()); 94 event_handler_.reset(new WindowCycleEventFilter());
83 cycle_start_time_ = base::Time::Now(); 95 cycle_start_time_ = base::Time::Now();
84 Shell::GetInstance()->metrics()->RecordUserMetricsAction(UMA_WINDOW_CYCLE); 96 Shell::GetInstance()->metrics()->RecordUserMetricsAction(UMA_WINDOW_CYCLE);
85 } 97 }
86 98
87 ////////////////////////////////////////////////////////////////////////////// 99 //////////////////////////////////////////////////////////////////////////////
88 // WindowCycleController, private: 100 // WindowCycleController, private:
89 101
90 void WindowCycleController::Step(Direction direction) { 102 void WindowCycleController::Step(Direction direction) {
91 DCHECK(window_cycle_list_.get()); 103 DCHECK(window_cycle_list_.get());
92 window_cycle_list_->Step(direction); 104 window_cycle_list_->Step(direction);
93 } 105 }
94 106
95 void WindowCycleController::StopCycling() { 107 void WindowCycleController::StopCycling() {
96 window_cycle_list_.reset(); 108 window_cycle_list_.reset();
109
110 aura::Window* active_window_after_window_cycle = GetActiveWindow(
111 Shell::GetInstance()->mru_window_tracker()->BuildMruWindowList());
112
97 // Remove our key event filter. 113 // Remove our key event filter.
98 event_handler_.reset(); 114 event_handler_.reset();
99 UMA_HISTOGRAM_MEDIUM_TIMES("Ash.WindowCycleController.CycleTime", 115 UMA_HISTOGRAM_MEDIUM_TIMES("Ash.WindowCycleController.CycleTime",
100 base::Time::Now() - cycle_start_time_); 116 base::Time::Now() - cycle_start_time_);
117
118 if (active_window_after_window_cycle != nullptr &&
119 active_window_before_window_cycle_ != active_window_after_window_cycle) {
120 Shell::GetInstance()
121 ->metrics()
122 ->task_switch_metrics_recorder()
123 .OnTaskSwitch(TaskSwitchMetricsRecorder::kWindowCycleController);
124 }
125 active_window_before_window_cycle_ = nullptr;
101 } 126 }
102 127
103 } // namespace ash 128 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/window_cycle_controller.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698