Chromium Code Reviews| Index: chrome/browser/ui/cocoa/browser_window_touch_bar.mm |
| diff --git a/chrome/browser/ui/cocoa/browser_window_touch_bar.mm b/chrome/browser/ui/cocoa/browser_window_touch_bar.mm |
| index 274ff4cb49db3577037cbb36c933f521362718c7..9fed0249fc2274511629f9ca476595b52d0d8b71 100644 |
| --- a/chrome/browser/ui/cocoa/browser_window_touch_bar.mm |
| +++ b/chrome/browser/ui/cocoa/browser_window_touch_bar.mm |
| @@ -9,6 +9,7 @@ |
| #include "base/mac/mac_util.h" |
| #import "base/mac/scoped_nsobject.h" |
| #import "base/mac/sdk_forward_declarations.h" |
| +#include "base/metrics/histogram_macros.h" |
| #include "base/strings/sys_string_conversions.h" |
| #include "chrome/app/chrome_command_ids.h" |
| #include "chrome/app/vector_icons/vector_icons.h" |
| @@ -35,6 +36,20 @@ |
| namespace { |
| +// The touch bar actions that are being recorded in a histogram. These values |
| +// should not be re-ordered or removed. |
| +enum TouchBarAction { |
| + BACK = 0, |
| + FORWARD, |
| + STOP, |
| + RELOAD, |
| + HOME, |
| + SEARCH, |
| + STAR, |
| + NEW_TAB, |
| + TOUCH_BAR_ACTION_COUNT |
| +}; |
| + |
| // The touch bar's identifier. |
| const NSTouchBarCustomizationIdentifier kBrowserWindowTouchBarId = |
| @"BrowserWindowTouchBarId"; |
| @@ -83,6 +98,33 @@ NSButton* CreateTouchBarButton(const gfx::VectorIcon& icon, |
| return button; |
| } |
| +// Logs the sample's UMA metrics into the DefaultTouchBar.Metrics histogram. |
| +void LogTouchBarUMA(int command) { |
| + TouchBarAction action; |
| + if (command == IDC_BACK) |
|
Robert Sesek
2017/03/13 21:05:25
Would this be better as a switch?
spqchan
2017/03/14 00:04:33
Done.
|
| + action = TouchBarAction::BACK; |
| + else if (command == IDC_FORWARD) |
| + action = TouchBarAction::FORWARD; |
| + else if (command == IDC_STOP) |
| + action = TouchBarAction::STOP; |
| + else if (command == IDC_RELOAD) |
| + action = TouchBarAction::RELOAD; |
| + else if (command == IDC_HOME) |
| + action = TouchBarAction::HOME; |
| + else if (command == IDC_FOCUS_LOCATION) |
| + action = TouchBarAction::SEARCH; |
| + else if (command == IDC_BOOKMARK_PAGE) |
| + action = TouchBarAction::STAR; |
| + else if (command == IDC_NEW_TAB) |
| + action = TouchBarAction::NEW_TAB; |
| + else |
| + action = TouchBarAction::TOUCH_BAR_ACTION_COUNT; |
| + |
| + DCHECK_NE(action, TouchBarAction::TOUCH_BAR_ACTION_COUNT); |
| + UMA_HISTOGRAM_ENUMERATION("TouchBar.Default.Metrics", action, |
| + TOUCH_BAR_ACTION_COUNT); |
| +} |
| + |
| // A class registered for C++ notifications. This is used to detect changes in |
| // the home button preferences and update the Touch Bar. |
| class HomePrefNotificationBridge { |
| @@ -268,14 +310,16 @@ class HomePrefNotificationBridge { |
| - (void)backOrForward:(id)sender { |
| NSSegmentedControl* control = sender; |
| - if ([control selectedSegment] == kBackSegmentIndex) |
| - commandUpdater_->ExecuteCommand(IDC_BACK); |
| - else |
| - commandUpdater_->ExecuteCommand(IDC_FORWARD); |
| + int command = |
| + [control selectedSegment] == kBackSegmentIndex ? IDC_BACK : IDC_FORWARD; |
| + LogTouchBarUMA(command); |
| + commandUpdater_->ExecuteCommand(command); |
| } |
| - (void)executeCommand:(id)sender { |
| - commandUpdater_->ExecuteCommand([sender tag]); |
| + int command = [sender tag]; |
| + LogTouchBarUMA(command); |
| + commandUpdater_->ExecuteCommand(command); |
| } |
| @end |