Chromium Code Reviews| Index: chrome/browser/chrome_webusb_browser_client.cc |
| diff --git a/chrome/browser/chrome_webusb_browser_client.cc b/chrome/browser/chrome_webusb_browser_client.cc |
| index 24a63f29f81320b87f1cac3260878c09647449f0..29428149f1eb0c6898b9aefc55eb4db594bfcd3c 100644 |
| --- a/chrome/browser/chrome_webusb_browser_client.cc |
| +++ b/chrome/browser/chrome_webusb_browser_client.cc |
| @@ -7,6 +7,7 @@ |
| #include <utility> |
| #include "base/macros.h" |
| +#include "base/metrics/histogram_macros.h" |
| #include "base/strings/utf_string_conversions.h" |
| #include "chrome/browser/net/referrer.h" |
| #include "chrome/browser/profiles/profile_manager.h" |
| @@ -30,6 +31,23 @@ namespace { |
| const char kWebUsbDetectorNotificationID[] = "webusb.detector"; |
| +enum WebUsbNotificationClosed { |
|
asargent_no_longer_on_chrome
2016/01/21 18:54:15
nit: We typically include a comment above enums us
|
| + // The notification was dismissed but not by the user (either automatically |
| + // or because the device was unplugged). |
| + WEBUSB_NOTIFICATION_CLOSED, |
| + // The user closed the notification. |
| + WEBUSB_NOTIFICATION_CLOSED_BY_USER, |
| + // The user clicked on the notification. |
| + WEBUSB_NOTIFICATION_CLOSED_CLICKED, |
| + // Maximum value for the enum. |
| + WEBUSB_NOTIFICATION_CLOSED_MAX |
| +}; |
| + |
| +void RecordNotificationClosure(WebUsbNotificationClosed disposition) { |
| + UMA_HISTOGRAM_ENUMERATION("WebUsb.NotificationClosed", disposition, |
| + WEBUSB_NOTIFICATION_CLOSED_MAX); |
| +} |
| + |
| Browser* GetBrowser() { |
| chrome::ScopedTabbedBrowserDisplayer browser_displayer( |
| ProfileManager::GetActiveUserProfile(), chrome::GetActiveDesktop()); |
| @@ -51,16 +69,27 @@ class WebUsbNotificationDelegate : public message_center::NotificationDelegate { |
| : landing_page_(landing_page), notification_id_(notification_id) {} |
| void Click() override { |
| + clicked_ = true; |
| OpenURL(landing_page_); |
| message_center::MessageCenter::Get()->RemoveNotification( |
| notification_id_, false /* by_user */); |
| } |
| + void Close(bool by_user) override { |
| + if (clicked_) |
| + RecordNotificationClosure(WEBUSB_NOTIFICATION_CLOSED_CLICKED); |
| + else if (by_user) |
| + RecordNotificationClosure(WEBUSB_NOTIFICATION_CLOSED_BY_USER); |
| + else |
| + RecordNotificationClosure(WEBUSB_NOTIFICATION_CLOSED); |
| + } |
| + |
| private: |
| ~WebUsbNotificationDelegate() override = default; |
| GURL landing_page_; |
| std::string notification_id_; |
| + bool clicked_ = false; |
| DISALLOW_COPY_AND_ASSIGN(WebUsbNotificationDelegate); |
| }; |