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

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

Issue 2757033002: [Mac] UMA Metrics for the Default Touch Bar (Closed)
Patch Set: 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/gfx/vector_icons_public.h" 35 #include "ui/gfx/vector_icons_public.h"
35 #include "ui/vector_icons/vector_icons.h" 36 #include "ui/vector_icons/vector_icons.h"
36 37
37 namespace { 38 namespace {
38 39
40 // The touch bar actions that are being recorded in a histogram. These values
41 // should not be re-ordered or removed.
42 enum TouchBarAction {
43 BACK = 0,
44 FORWARD,
45 STOP,
46 RELOAD,
47 HOME,
48 SEARCH,
49 STAR,
50 NEW_TAB,
51 TOUCH_BAR_ACTION_COUNT
52 };
53
39 // The touch bar's identifier. 54 // The touch bar's identifier.
40 const NSTouchBarCustomizationIdentifier kBrowserWindowTouchBarId = 55 const NSTouchBarCustomizationIdentifier kBrowserWindowTouchBarId =
41 @"BrowserWindowTouchBarId"; 56 @"BrowserWindowTouchBarId";
42 57
43 // Touch bar items identifiers. 58 // Touch bar items identifiers.
44 const NSTouchBarItemIdentifier kBackForwardTouchId = @"BackForwardTouchId"; 59 const NSTouchBarItemIdentifier kBackForwardTouchId = @"BackForwardTouchId";
45 const NSTouchBarItemIdentifier kReloadOrStopTouchId = @"ReloadOrStopTouchId"; 60 const NSTouchBarItemIdentifier kReloadOrStopTouchId = @"ReloadOrStopTouchId";
46 const NSTouchBarItemIdentifier kHomeTouchId = @"HomeTouchId"; 61 const NSTouchBarItemIdentifier kHomeTouchId = @"HomeTouchId";
47 const NSTouchBarItemIdentifier kSearchTouchId = @"SearchTouchId"; 62 const NSTouchBarItemIdentifier kSearchTouchId = @"SearchTouchId";
48 const NSTouchBarItemIdentifier kStarTouchId = @"StarTouchId"; 63 const NSTouchBarItemIdentifier kStarTouchId = @"StarTouchId";
(...skipping 28 matching lines...) Expand all
77 int command, 92 int command,
78 SkColor color = kTouchBarDefaultIconColor) { 93 SkColor color = kTouchBarDefaultIconColor) {
79 NSButton* button = 94 NSButton* button =
80 [NSButton buttonWithImage:CreateNSImageFromIcon(icon, color) 95 [NSButton buttonWithImage:CreateNSImageFromIcon(icon, color)
81 target:owner 96 target:owner
82 action:@selector(executeCommand:)]; 97 action:@selector(executeCommand:)];
83 button.tag = command; 98 button.tag = command;
84 return button; 99 return button;
85 } 100 }
86 101
102 TouchBarAction TouchBarActionFromCommand(int command) {
103 switch (command) {
104 case IDC_BACK:
105 return TouchBarAction::BACK;
106 case IDC_FORWARD:
107 return TouchBarAction::FORWARD;
108 case IDC_STOP:
109 return TouchBarAction::STOP;
110 case IDC_RELOAD:
111 return TouchBarAction::RELOAD;
112 case IDC_HOME:
113 return TouchBarAction::HOME;
114 case IDC_FOCUS_LOCATION:
115 return TouchBarAction::SEARCH;
116 case IDC_BOOKMARK_PAGE:
117 return TouchBarAction::STAR;
118 case IDC_NEW_TAB:
119 return TouchBarAction::NEW_TAB;
120 default:
121 NOTREACHED();
122 return TouchBarAction::TOUCH_BAR_ACTION_COUNT;
123 }
124 }
125
126 // Logs the sample's UMA metrics into the DefaultTouchBar.Metrics histogram.
127 void LogTouchBarUMA(int command) {
128 UMA_HISTOGRAM_ENUMERATION("TouchBar.Default.Metrics",
129 TouchBarActionFromCommand(command),
130 TOUCH_BAR_ACTION_COUNT);
131 }
132
87 // A class registered for C++ notifications. This is used to detect changes in 133 // A class registered for C++ notifications. This is used to detect changes in
88 // the home button preferences and update the Touch Bar. 134 // the home button preferences and update the Touch Bar.
89 class HomePrefNotificationBridge { 135 class HomePrefNotificationBridge {
90 public: 136 public:
91 explicit HomePrefNotificationBridge(BrowserWindowController* bwc) 137 explicit HomePrefNotificationBridge(BrowserWindowController* bwc)
92 : bwc_(bwc) {} 138 : bwc_(bwc) {}
93 139
94 ~HomePrefNotificationBridge() {} 140 ~HomePrefNotificationBridge() {}
95 141
96 void UpdateTouchBar() { [bwc_ invalidateTouchBar]; } 142 void UpdateTouchBar() { [bwc_ invalidateTouchBar]; }
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 searchButton.imageHugsTitle = YES; 308 searchButton.imageHugsTitle = YES;
263 searchButton.tag = IDC_FOCUS_LOCATION; 309 searchButton.tag = IDC_FOCUS_LOCATION;
264 int width = showHomeButton_.GetValue() ? kSearchBtnWidthWithHomeBtn 310 int width = showHomeButton_.GetValue() ? kSearchBtnWidthWithHomeBtn
265 : kSearchBtnWidthWithoutHomeBtn; 311 : kSearchBtnWidthWithoutHomeBtn;
266 [searchButton.widthAnchor constraintEqualToConstant:width].active = YES; 312 [searchButton.widthAnchor constraintEqualToConstant:width].active = YES;
267 return searchButton; 313 return searchButton;
268 } 314 }
269 315
270 - (void)backOrForward:(id)sender { 316 - (void)backOrForward:(id)sender {
271 NSSegmentedControl* control = sender; 317 NSSegmentedControl* control = sender;
272 if ([control selectedSegment] == kBackSegmentIndex) 318 int command =
273 commandUpdater_->ExecuteCommand(IDC_BACK); 319 [control selectedSegment] == kBackSegmentIndex ? IDC_BACK : IDC_FORWARD;
274 else 320 LogTouchBarUMA(command);
275 commandUpdater_->ExecuteCommand(IDC_FORWARD); 321 commandUpdater_->ExecuteCommand(command);
276 } 322 }
277 323
278 - (void)executeCommand:(id)sender { 324 - (void)executeCommand:(id)sender {
279 commandUpdater_->ExecuteCommand([sender tag]); 325 int command = [sender tag];
326 LogTouchBarUMA(command);
327 commandUpdater_->ExecuteCommand(command);
280 } 328 }
281 329
282 @end 330 @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