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

Side by Side Diff: chrome/browser/ui/cocoa/browser_window_touch_bar.mm

Issue 2742633002: [Mac] UMA Metrics for the Default Touch Bar (Closed)
Patch Set: nit Created 3 years, 9 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 | « no previous file | 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 #import "chrome/browser/ui/cocoa/browser_window_touch_bar.h" 5 #import "chrome/browser/ui/cocoa/browser_window_touch_bar.h"
6 6
7 #include "base/mac/mac_util.h" 7 #include "base/mac/mac_util.h"
8 #import "base/mac/scoped_nsobject.h" 8 #import "base/mac/scoped_nsobject.h"
9 #import "base/mac/sdk_forward_declarations.h" 9 #import "base/mac/sdk_forward_declarations.h"
10 #include "base/metrics/histogram_macros.h"
10 #include "base/strings/sys_string_conversions.h" 11 #include "base/strings/sys_string_conversions.h"
11 #include "chrome/app/chrome_command_ids.h" 12 #include "chrome/app/chrome_command_ids.h"
12 #include "chrome/app/vector_icons/vector_icons.h" 13 #include "chrome/app/vector_icons/vector_icons.h"
13 #include "chrome/browser/command_updater.h" 14 #include "chrome/browser/command_updater.h"
14 #include "chrome/browser/search_engines/template_url_service_factory.h" 15 #include "chrome/browser/search_engines/template_url_service_factory.h"
15 #include "chrome/browser/ui/browser.h" 16 #include "chrome/browser/ui/browser.h"
16 #include "chrome/browser/ui/browser_command_controller.h" 17 #include "chrome/browser/ui/browser_command_controller.h"
17 #include "chrome/common/chrome_features.h" 18 #include "chrome/common/chrome_features.h"
18 #include "chrome/grit/generated_resources.h" 19 #include "chrome/grit/generated_resources.h"
19 #include "components/omnibox/browser/vector_icons.h" 20 #include "components/omnibox/browser/vector_icons.h"
20 #include "components/search_engines/util.h" 21 #include "components/search_engines/util.h"
21 #include "components/toolbar/vector_icons.h" 22 #include "components/toolbar/vector_icons.h"
22 #include "ui/base/l10n/l10n_util.h" 23 #include "ui/base/l10n/l10n_util.h"
23 #include "ui/gfx/color_palette.h" 24 #include "ui/gfx/color_palette.h"
24 #include "ui/gfx/color_utils.h" 25 #include "ui/gfx/color_utils.h"
25 #include "ui/gfx/image/image.h" 26 #include "ui/gfx/image/image.h"
26 #include "ui/gfx/image/image_skia_util_mac.h" 27 #include "ui/gfx/image/image_skia_util_mac.h"
27 #include "ui/gfx/paint_vector_icon.h" 28 #include "ui/gfx/paint_vector_icon.h"
28 #include "ui/gfx/vector_icons_public.h" 29 #include "ui/gfx/vector_icons_public.h"
29 #include "ui/vector_icons/vector_icons.h" 30 #include "ui/vector_icons/vector_icons.h"
30 31
31 namespace { 32 namespace {
32 33
34 // The touch bar actions that are being recorded in a histogram. These values
35 // should not be re-ordered or removed.
36 enum TouchBarAction {
37 BACK = 0,
38 FORWARD,
39 STOP,
40 RELOAD,
41 SEARCH,
42 STAR,
43 NEW_TAB,
44 TOUCH_BAR_ACTION_COUNT
45 };
46
33 // The touch bar's identifier. 47 // The touch bar's identifier.
34 const NSTouchBarCustomizationIdentifier kBrowserWindowTouchBarId = 48 const NSTouchBarCustomizationIdentifier kBrowserWindowTouchBarId =
35 @"BrowserWindowTouchBarId"; 49 @"BrowserWindowTouchBarId";
36 50
37 // Touch bar items identifiers. 51 // Touch bar items identifiers.
38 const NSTouchBarItemIdentifier kBackForwardTouchId = @"BackForwardTouchId"; 52 const NSTouchBarItemIdentifier kBackForwardTouchId = @"BackForwardTouchId";
39 const NSTouchBarItemIdentifier kReloadOrStopTouchId = @"ReloadOrStopTouchId"; 53 const NSTouchBarItemIdentifier kReloadOrStopTouchId = @"ReloadOrStopTouchId";
40 const NSTouchBarItemIdentifier kSearchTouchId = @"SearchTouchId"; 54 const NSTouchBarItemIdentifier kSearchTouchId = @"SearchTouchId";
41 const NSTouchBarItemIdentifier kStarTouchId = @"StarTouchId"; 55 const NSTouchBarItemIdentifier kStarTouchId = @"StarTouchId";
42 const NSTouchBarItemIdentifier kNewTabTouchId = @"NewTabTouchId"; 56 const NSTouchBarItemIdentifier kNewTabTouchId = @"NewTabTouchId";
(...skipping 26 matching lines...) Expand all
69 int command, 83 int command,
70 SkColor color = kTouchBarDefaultIconColor) { 84 SkColor color = kTouchBarDefaultIconColor) {
71 NSButton* button = 85 NSButton* button =
72 [NSButton buttonWithImage:CreateNSImageFromIcon(icon, color) 86 [NSButton buttonWithImage:CreateNSImageFromIcon(icon, color)
73 target:owner 87 target:owner
74 action:@selector(executeCommand:)]; 88 action:@selector(executeCommand:)];
75 button.tag = command; 89 button.tag = command;
76 return button; 90 return button;
77 } 91 }
78 92
93 // Logs the sample's UMA metrics into the DefaultTouchBar.Metrics histogram.
94 void LogTouchBarUMA(int command) {
95 TouchBarAction action;
96 if (command == IDC_BACK)
97 action = TouchBarAction::BACK;
98 else if (command == IDC_FORWARD)
99 action = TouchBarAction::FORWARD;
100 else if (command == IDC_STOP)
101 action = TouchBarAction::STOP;
102 else if (command == IDC_RELOAD)
103 action = TouchBarAction::RELOAD;
104 else if (command == IDC_FOCUS_LOCATION)
105 action = TouchBarAction::SEARCH;
106 else if (command == IDC_BOOKMARK_PAGE)
107 action = TouchBarAction::STAR;
108 else if (command == IDC_NEW_TAB)
109 action = TouchBarAction::NEW_TAB;
110 else
111 action = TouchBarAction::TOUCH_BAR_ACTION_COUNT;
112
113 DCHECK_NE(action, TouchBarAction::TOUCH_BAR_ACTION_COUNT);
114 UMA_HISTOGRAM_ENUMERATION("DefaultTouchBar.Metrics", action,
Robert Sesek 2017/03/09 18:11:55 Since we may have multiple touch bars, how about s
Ilya Sherman 2017/03/09 20:13:44 +1 -- let's choose a fairly general top-level cate
spqchan 2017/03/13 20:58:05 Sure thing
115 TOUCH_BAR_ACTION_COUNT);
116 }
117
79 } // namespace 118 } // namespace
80 119
81 @interface BrowserWindowTouchBar () { 120 @interface BrowserWindowTouchBar () {
82 // Used to execute commands such as navigating back and forward. 121 // Used to execute commands such as navigating back and forward.
83 CommandUpdater* commandUpdater_; // Weak, owned by Browser. 122 CommandUpdater* commandUpdater_; // Weak, owned by Browser.
84 123
85 // The browser associated with the touch bar. 124 // The browser associated with the touch bar.
86 Browser* browser_; // Weak. 125 Browser* browser_; // Weak.
87 } 126 }
88 127
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 searchButton.imageHugsTitle = YES; 247 searchButton.imageHugsTitle = YES;
209 searchButton.tag = IDC_FOCUS_LOCATION; 248 searchButton.tag = IDC_FOCUS_LOCATION;
210 [searchButton.widthAnchor 249 [searchButton.widthAnchor
211 constraintEqualToConstant:kTouchBarSearchButtonWidth] 250 constraintEqualToConstant:kTouchBarSearchButtonWidth]
212 .active = YES; 251 .active = YES;
213 return searchButton; 252 return searchButton;
214 } 253 }
215 254
216 - (void)backOrForward:(id)sender { 255 - (void)backOrForward:(id)sender {
217 NSSegmentedControl* control = sender; 256 NSSegmentedControl* control = sender;
218 if ([control selectedSegment] == kBackSegmentIndex) 257 if ([control selectedSegment] == kBackSegmentIndex) {
219 commandUpdater_->ExecuteCommand(IDC_BACK); 258 commandUpdater_->ExecuteCommand(IDC_BACK);
220 else 259 LogTouchBarUMA(IDC_BACK);
260 } else {
221 commandUpdater_->ExecuteCommand(IDC_FORWARD); 261 commandUpdater_->ExecuteCommand(IDC_FORWARD);
262 LogTouchBarUMA(IDC_FORWARD);
263 }
222 } 264 }
223 265
224 - (void)executeCommand:(id)sender { 266 - (void)executeCommand:(id)sender {
225 commandUpdater_->ExecuteCommand([sender tag]); 267 int command = [sender tag];
268 LogTouchBarUMA(command);
Robert Sesek 2017/03/09 18:11:55 In -backOrForward, the UMA is logged before the Ex
spqchan 2017/03/13 20:58:05 Done.
269 commandUpdater_->ExecuteCommand(command);
226 } 270 }
227 271
228 @end 272 @end
OLDNEW
« no previous file with comments | « no previous file | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698