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

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: Fix for isherman 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 <memory> 7 #include <memory>
8 8
9 #include "base/mac/mac_util.h" 9 #include "base/mac/mac_util.h"
10 #import "base/mac/scoped_nsobject.h" 10 #import "base/mac/scoped_nsobject.h"
11 #import "base/mac/sdk_forward_declarations.h" 11 #import "base/mac/sdk_forward_declarations.h"
12 #include "base/metrics/histogram_macros.h"
12 #include "base/strings/sys_string_conversions.h" 13 #include "base/strings/sys_string_conversions.h"
13 #include "chrome/app/chrome_command_ids.h" 14 #include "chrome/app/chrome_command_ids.h"
14 #include "chrome/app/vector_icons/vector_icons.h" 15 #include "chrome/app/vector_icons/vector_icons.h"
15 #include "chrome/browser/command_updater.h" 16 #include "chrome/browser/command_updater.h"
16 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/search_engines/template_url_service_factory.h" 18 #include "chrome/browser/search_engines/template_url_service_factory.h"
18 #include "chrome/browser/ui/browser.h" 19 #include "chrome/browser/ui/browser.h"
19 #include "chrome/browser/ui/browser_command_controller.h" 20 #include "chrome/browser/ui/browser_command_controller.h"
20 #import "chrome/browser/ui/cocoa/browser_window_controller.h" 21 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
21 #include "chrome/common/chrome_features.h" 22 #include "chrome/common/chrome_features.h"
22 #include "chrome/common/pref_names.h" 23 #include "chrome/common/pref_names.h"
23 #include "chrome/grit/generated_resources.h" 24 #include "chrome/grit/generated_resources.h"
24 #include "components/omnibox/browser/vector_icons.h" 25 #include "components/omnibox/browser/vector_icons.h"
25 #include "components/prefs/pref_member.h" 26 #include "components/prefs/pref_member.h"
26 #include "components/search_engines/util.h" 27 #include "components/search_engines/util.h"
27 #include "components/toolbar/vector_icons.h" 28 #include "components/toolbar/vector_icons.h"
28 #include "ui/base/l10n/l10n_util.h" 29 #include "ui/base/l10n/l10n_util.h"
29 #include "ui/gfx/color_palette.h" 30 #include "ui/gfx/color_palette.h"
30 #include "ui/gfx/color_utils.h" 31 #include "ui/gfx/color_utils.h"
31 #include "ui/gfx/image/image.h" 32 #include "ui/gfx/image/image.h"
32 #include "ui/gfx/image/image_skia_util_mac.h" 33 #include "ui/gfx/image/image_skia_util_mac.h"
33 #include "ui/gfx/paint_vector_icon.h" 34 #include "ui/gfx/paint_vector_icon.h"
34 #include "ui/vector_icons/vector_icons.h" 35 #include "ui/vector_icons/vector_icons.h"
35 36
36 namespace { 37 namespace {
37 38
39 // The touch bar actions that are being recorded in a histogram. These values
40 // should not be re-ordered or removed.
41 enum TouchBarAction {
42 BACK = 0,
43 FORWARD,
44 STOP,
45 RELOAD,
46 HOME,
47 SEARCH,
48 STAR,
49 NEW_TAB,
50 TOUCH_BAR_ACTION_COUNT
51 };
52
38 // The touch bar's identifier. 53 // The touch bar's identifier.
39 const NSTouchBarCustomizationIdentifier kBrowserWindowTouchBarId = 54 const NSTouchBarCustomizationIdentifier kBrowserWindowTouchBarId =
40 @"BrowserWindowTouchBarId"; 55 @"BrowserWindowTouchBarId";
41 56
42 // Touch bar items identifiers. 57 // Touch bar items identifiers.
43 const NSTouchBarItemIdentifier kBackForwardTouchId = @"BackForwardTouchId"; 58 const NSTouchBarItemIdentifier kBackForwardTouchId = @"BackForwardTouchId";
44 const NSTouchBarItemIdentifier kReloadOrStopTouchId = @"ReloadOrStopTouchId"; 59 const NSTouchBarItemIdentifier kReloadOrStopTouchId = @"ReloadOrStopTouchId";
45 const NSTouchBarItemIdentifier kHomeTouchId = @"HomeTouchId"; 60 const NSTouchBarItemIdentifier kHomeTouchId = @"HomeTouchId";
46 const NSTouchBarItemIdentifier kSearchTouchId = @"SearchTouchId"; 61 const NSTouchBarItemIdentifier kSearchTouchId = @"SearchTouchId";
47 const NSTouchBarItemIdentifier kStarTouchId = @"StarTouchId"; 62 const NSTouchBarItemIdentifier kStarTouchId = @"StarTouchId";
(...skipping 28 matching lines...) Expand all
76 int command, 91 int command,
77 SkColor color = kTouchBarDefaultIconColor) { 92 SkColor color = kTouchBarDefaultIconColor) {
78 NSButton* button = 93 NSButton* button =
79 [NSButton buttonWithImage:CreateNSImageFromIcon(icon, color) 94 [NSButton buttonWithImage:CreateNSImageFromIcon(icon, color)
80 target:owner 95 target:owner
81 action:@selector(executeCommand:)]; 96 action:@selector(executeCommand:)];
82 button.tag = command; 97 button.tag = command;
83 return button; 98 return button;
84 } 99 }
85 100
101 TouchBarAction TouchBarActionFromCommand(int command) {
102 switch (command) {
103 case IDC_BACK:
104 return TouchBarAction::BACK;
105 case IDC_FORWARD:
106 return TouchBarAction::FORWARD;
107 case IDC_STOP:
108 return TouchBarAction::STOP;
109 case IDC_RELOAD:
110 return TouchBarAction::RELOAD;
111 case IDC_HOME:
112 return TouchBarAction::HOME;
113 case IDC_FOCUS_LOCATION:
114 return TouchBarAction::SEARCH;
115 case IDC_BOOKMARK_PAGE:
116 return TouchBarAction::STAR;
117 case IDC_NEW_TAB:
118 return TouchBarAction::NEW_TAB;
119 default:
120 NOTREACHED();
121 return TouchBarAction::TOUCH_BAR_ACTION_COUNT;
122 }
123 }
124
125 // Logs the sample's UMA metrics into the DefaultTouchBar.Metrics histogram.
126 void LogTouchBarUMA(int command) {
127 UMA_HISTOGRAM_ENUMERATION("TouchBar.Default.Metrics",
128 TouchBarActionFromCommand(command),
129 TOUCH_BAR_ACTION_COUNT);
130 }
131
86 // A class registered for C++ notifications. This is used to detect changes in 132 // A class registered for C++ notifications. This is used to detect changes in
87 // the home button preferences and update the Touch Bar. 133 // the home button preferences and update the Touch Bar.
88 class HomePrefNotificationBridge { 134 class HomePrefNotificationBridge {
89 public: 135 public:
90 explicit HomePrefNotificationBridge(BrowserWindowController* bwc) 136 explicit HomePrefNotificationBridge(BrowserWindowController* bwc)
91 : bwc_(bwc) {} 137 : bwc_(bwc) {}
92 138
93 ~HomePrefNotificationBridge() {} 139 ~HomePrefNotificationBridge() {}
94 140
95 void UpdateTouchBar() { [bwc_ invalidateTouchBar]; } 141 void UpdateTouchBar() { [bwc_ invalidateTouchBar]; }
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 searchButton.imageHugsTitle = YES; 307 searchButton.imageHugsTitle = YES;
262 searchButton.tag = IDC_FOCUS_LOCATION; 308 searchButton.tag = IDC_FOCUS_LOCATION;
263 int width = showHomeButton_.GetValue() ? kSearchBtnWidthWithHomeBtn 309 int width = showHomeButton_.GetValue() ? kSearchBtnWidthWithHomeBtn
264 : kSearchBtnWidthWithoutHomeBtn; 310 : kSearchBtnWidthWithoutHomeBtn;
265 [searchButton.widthAnchor constraintEqualToConstant:width].active = YES; 311 [searchButton.widthAnchor constraintEqualToConstant:width].active = YES;
266 return searchButton; 312 return searchButton;
267 } 313 }
268 314
269 - (void)backOrForward:(id)sender { 315 - (void)backOrForward:(id)sender {
270 NSSegmentedControl* control = sender; 316 NSSegmentedControl* control = sender;
271 if ([control selectedSegment] == kBackSegmentIndex) 317 int command =
272 commandUpdater_->ExecuteCommand(IDC_BACK); 318 [control selectedSegment] == kBackSegmentIndex ? IDC_BACK : IDC_FORWARD;
273 else 319 LogTouchBarUMA(command);
274 commandUpdater_->ExecuteCommand(IDC_FORWARD); 320 commandUpdater_->ExecuteCommand(command);
275 } 321 }
276 322
277 - (void)executeCommand:(id)sender { 323 - (void)executeCommand:(id)sender {
278 commandUpdater_->ExecuteCommand([sender tag]); 324 int command = [sender tag];
325 LogTouchBarUMA(command);
326 commandUpdater_->ExecuteCommand(command);
279 } 327 }
280 328
281 @end 329 @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