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

Side by Side Diff: ash/common/accelerators/accelerator_router.cc

Issue 2683233008: Add "Search" key press/hold UMA metrics. (Closed)
Patch Set: add zalcorn@ to histogram owner Created 3 years, 10 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
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/common/accelerators/accelerator_router.h" 5 #include "ash/common/accelerators/accelerator_router.h"
6 6
7 #include "ash/common/accelerators/accelerator_controller.h" 7 #include "ash/common/accelerators/accelerator_controller.h"
8 #include "ash/common/wm/window_state.h" 8 #include "ash/common/wm/window_state.h"
9 #include "ash/common/wm_shell.h" 9 #include "ash/common/wm_shell.h"
10 #include "ash/common/wm_window.h" 10 #include "ash/common/wm_window.h"
11 #include "base/metrics/histogram.h"
11 #include "base/stl_util.h" 12 #include "base/stl_util.h"
12 #include "ui/base/accelerators/accelerator.h" 13 #include "ui/base/accelerators/accelerator.h"
13 #include "ui/events/event.h" 14 #include "ui/events/event.h"
14 15
15 namespace ash { 16 namespace ash {
16 17
17 namespace { 18 namespace {
18 19
19 // Returns true if |key_code| is a key usually handled directly by the shell. 20 // Returns true if |key_code| is a key usually handled directly by the shell.
20 bool IsSystemKey(ui::KeyboardCode key_code) { 21 bool IsSystemKey(ui::KeyboardCode key_code) {
(...skipping 21 matching lines...) Expand all
42 43
43 AcceleratorRouter::AcceleratorRouter() {} 44 AcceleratorRouter::AcceleratorRouter() {}
44 45
45 AcceleratorRouter::~AcceleratorRouter() {} 46 AcceleratorRouter::~AcceleratorRouter() {}
46 47
47 bool AcceleratorRouter::ProcessAccelerator(WmWindow* target, 48 bool AcceleratorRouter::ProcessAccelerator(WmWindow* target,
48 const ui::KeyEvent& key_event, 49 const ui::KeyEvent& key_event,
49 const ui::Accelerator& accelerator) { 50 const ui::Accelerator& accelerator) {
50 // Callers should never supply null. 51 // Callers should never supply null.
51 DCHECK(target); 52 DCHECK(target);
53 RecordSearchKeyStats(accelerator);
52 // Special hardware keys like brightness and volume are handled in 54 // Special hardware keys like brightness and volume are handled in
53 // special way. However, some windows can override this behavior 55 // special way. However, some windows can override this behavior
54 // (e.g. Chrome v1 apps by default and Chrome v2 apps with 56 // (e.g. Chrome v1 apps by default and Chrome v2 apps with
55 // permission) by setting a window property. 57 // permission) by setting a window property.
56 if (IsSystemKey(key_event.key_code()) && 58 if (IsSystemKey(key_event.key_code()) &&
57 !CanConsumeSystemKeys(target, key_event)) { 59 !CanConsumeSystemKeys(target, key_event)) {
58 // System keys are always consumed regardless of whether they trigger an 60 // System keys are always consumed regardless of whether they trigger an
59 // accelerator to prevent windows from seeing unexpected key up events. 61 // accelerator to prevent windows from seeing unexpected key up events.
60 WmShell::Get()->accelerator_controller()->Process(accelerator); 62 WmShell::Get()->accelerator_controller()->Process(accelerator);
61 return true; 63 return true;
62 } 64 }
63 if (!ShouldProcessAcceleratorNow(target, key_event, accelerator)) 65 if (!ShouldProcessAcceleratorNow(target, key_event, accelerator))
64 return false; 66 return false;
65 return WmShell::Get()->accelerator_controller()->Process(accelerator); 67 return WmShell::Get()->accelerator_controller()->Process(accelerator);
66 } 68 }
67 69
70 void AcceleratorRouter::RecordSearchKeyStats(
71 const ui::Accelerator& accelerator) {
72 if (accelerator.IsCmdDown()) {
73 if (!search_key_pressed_) {
74 search_key_pressed_ = true;
75 search_key_pressed_recorded_ = false;
76 search_key_pressed_timestamp_ = base::TimeTicks::Now();
77 }
78
79 if (accelerator.key_code() != ui::KeyboardCode::VKEY_COMMAND &&
80 !search_key_pressed_recorded_) {
81 search_key_pressed_recorded_ = true;
82 UMA_HISTOGRAM_TIMES(
83 "Keyboard.Shortcuts.CrosSearchKeyDelay",
84 base::TimeTicks::Now() - search_key_pressed_timestamp_);
85 }
86 } else {
87 search_key_pressed_ = false;
88 }
89 }
90
68 bool AcceleratorRouter::CanConsumeSystemKeys(WmWindow* target, 91 bool AcceleratorRouter::CanConsumeSystemKeys(WmWindow* target,
69 const ui::KeyEvent& event) { 92 const ui::KeyEvent& event) {
70 // Uses the top level window so if the target is a web contents window the 93 // Uses the top level window so if the target is a web contents window the
71 // containing parent window will be checked for the property. 94 // containing parent window will be checked for the property.
72 WmWindow* top_level = target->GetToplevelWindowForFocus(); 95 WmWindow* top_level = target->GetToplevelWindowForFocus();
73 return top_level && top_level->GetWindowState()->can_consume_system_keys(); 96 return top_level && top_level->GetWindowState()->can_consume_system_keys();
74 } 97 }
75 98
76 bool AcceleratorRouter::ShouldProcessAcceleratorNow( 99 bool AcceleratorRouter::ShouldProcessAcceleratorNow(
77 WmWindow* target, 100 WmWindow* target,
(...skipping 28 matching lines...) Expand all
106 129
107 // Handle preferred accelerators (such as ALT-TAB) before sending 130 // Handle preferred accelerators (such as ALT-TAB) before sending
108 // to the target. 131 // to the target.
109 if (accelerator_controller->IsPreferred(accelerator)) 132 if (accelerator_controller->IsPreferred(accelerator))
110 return true; 133 return true;
111 134
112 return WmShell::Get()->GetAppListTargetVisibility(); 135 return WmShell::Get()->GetAppListTargetVisibility();
113 } 136 }
114 137
115 } // namespace ash 138 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698