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

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

Issue 2683233008: Add "Search" key press/hold UMA metrics. (Closed)
Patch Set: use enum 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
« no previous file with comments | « ash/common/accelerators/accelerator_router.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/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_macros.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 18 matching lines...) Expand all
39 40
40 AcceleratorRouter::AcceleratorRouter() {} 41 AcceleratorRouter::AcceleratorRouter() {}
41 42
42 AcceleratorRouter::~AcceleratorRouter() {} 43 AcceleratorRouter::~AcceleratorRouter() {}
43 44
44 bool AcceleratorRouter::ProcessAccelerator(WmWindow* target, 45 bool AcceleratorRouter::ProcessAccelerator(WmWindow* target,
45 const ui::KeyEvent& key_event, 46 const ui::KeyEvent& key_event,
46 const ui::Accelerator& accelerator) { 47 const ui::Accelerator& accelerator) {
47 // Callers should never supply null. 48 // Callers should never supply null.
48 DCHECK(target); 49 DCHECK(target);
50 RecordSearchKeyStats(accelerator);
49 // Special hardware keys like brightness and volume are handled in 51 // Special hardware keys like brightness and volume are handled in
50 // special way. However, some windows can override this behavior 52 // special way. However, some windows can override this behavior
51 // (e.g. Chrome v1 apps by default and Chrome v2 apps with 53 // (e.g. Chrome v1 apps by default and Chrome v2 apps with
52 // permission) by setting a window property. 54 // permission) by setting a window property.
53 if (IsSystemKey(key_event.key_code()) && 55 if (IsSystemKey(key_event.key_code()) &&
54 !CanConsumeSystemKeys(target, key_event)) { 56 !CanConsumeSystemKeys(target, key_event)) {
55 // System keys are always consumed regardless of whether they trigger an 57 // System keys are always consumed regardless of whether they trigger an
56 // accelerator to prevent windows from seeing unexpected key up events. 58 // accelerator to prevent windows from seeing unexpected key up events.
57 WmShell::Get()->accelerator_controller()->Process(accelerator); 59 WmShell::Get()->accelerator_controller()->Process(accelerator);
58 return true; 60 return true;
59 } 61 }
60 if (!ShouldProcessAcceleratorNow(target, key_event, accelerator)) 62 if (!ShouldProcessAcceleratorNow(target, key_event, accelerator))
61 return false; 63 return false;
62 return WmShell::Get()->accelerator_controller()->Process(accelerator); 64 return WmShell::Get()->accelerator_controller()->Process(accelerator);
63 } 65 }
64 66
67 void AcceleratorRouter::RecordSearchKeyStats(
68 const ui::Accelerator& accelerator) {
69 if (accelerator.IsCmdDown()) {
70 if (search_key_state_ == RELEASED) {
71 search_key_state_ = PRESSED;
72 search_key_pressed_timestamp_ = base::TimeTicks::Now();
73 }
74
75 if (accelerator.key_code() != ui::KeyboardCode::VKEY_COMMAND &&
76 search_key_state_ == PRESSED) {
77 search_key_state_ = RECORDED;
78 UMA_HISTOGRAM_TIMES(
79 "Keyboard.Shortcuts.CrosSearchKeyDelay",
80 base::TimeTicks::Now() - search_key_pressed_timestamp_);
81 }
82 } else {
83 search_key_state_ = RELEASED;
84 }
85 }
86
65 bool AcceleratorRouter::CanConsumeSystemKeys(WmWindow* target, 87 bool AcceleratorRouter::CanConsumeSystemKeys(WmWindow* target,
66 const ui::KeyEvent& event) { 88 const ui::KeyEvent& event) {
67 // Uses the top level window so if the target is a web contents window the 89 // Uses the top level window so if the target is a web contents window the
68 // containing parent window will be checked for the property. 90 // containing parent window will be checked for the property.
69 WmWindow* top_level = target->GetToplevelWindowForFocus(); 91 WmWindow* top_level = target->GetToplevelWindowForFocus();
70 return top_level && top_level->GetWindowState()->can_consume_system_keys(); 92 return top_level && top_level->GetWindowState()->can_consume_system_keys();
71 } 93 }
72 94
73 bool AcceleratorRouter::ShouldProcessAcceleratorNow( 95 bool AcceleratorRouter::ShouldProcessAcceleratorNow(
74 WmWindow* target, 96 WmWindow* target,
(...skipping 28 matching lines...) Expand all
103 125
104 // Handle preferred accelerators (such as ALT-TAB) before sending 126 // Handle preferred accelerators (such as ALT-TAB) before sending
105 // to the target. 127 // to the target.
106 if (accelerator_controller->IsPreferred(accelerator)) 128 if (accelerator_controller->IsPreferred(accelerator))
107 return true; 129 return true;
108 130
109 return WmShell::Get()->GetAppListTargetVisibility(); 131 return WmShell::Get()->GetAppListTargetVisibility();
110 } 132 }
111 133
112 } // namespace ash 134 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/accelerators/accelerator_router.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698