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

Side by Side Diff: chrome/browser/chrome_webusb_browser_client.cc

Issue 1584283003: Add UMA histograms for WebUSB. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #include "chrome/browser/chrome_webusb_browser_client.h" 5 #include "chrome/browser/chrome_webusb_browser_client.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/metrics/histogram_macros.h"
10 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
11 #include "chrome/browser/net/referrer.h" 12 #include "chrome/browser/net/referrer.h"
12 #include "chrome/browser/profiles/profile_manager.h" 13 #include "chrome/browser/profiles/profile_manager.h"
13 #include "chrome/browser/ui/browser.h" 14 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/host_desktop.h" 15 #include "chrome/browser/ui/host_desktop.h"
15 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" 16 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h"
16 #include "chrome/grit/generated_resources.h" 17 #include "chrome/grit/generated_resources.h"
17 #include "chrome/grit/theme_resources.h" 18 #include "chrome/grit/theme_resources.h"
18 #include "content/public/common/origin_util.h" 19 #include "content/public/common/origin_util.h"
19 #include "ui/base/l10n/l10n_util.h" 20 #include "ui/base/l10n/l10n_util.h"
20 #include "ui/base/page_transition_types.h" 21 #include "ui/base/page_transition_types.h"
21 #include "ui/base/resource/resource_bundle.h" 22 #include "ui/base/resource/resource_bundle.h"
22 #include "ui/base/window_open_disposition.h" 23 #include "ui/base/window_open_disposition.h"
23 #include "ui/gfx/image/image.h" 24 #include "ui/gfx/image/image.h"
24 #include "ui/message_center/message_center.h" 25 #include "ui/message_center/message_center.h"
25 #include "ui/message_center/notification.h" 26 #include "ui/message_center/notification.h"
26 #include "ui/message_center/notification_delegate.h" 27 #include "ui/message_center/notification_delegate.h"
27 #include "url/gurl.h" 28 #include "url/gurl.h"
28 29
29 namespace { 30 namespace {
30 31
31 const char kWebUsbDetectorNotificationID[] = "webusb.detector"; 32 const char kWebUsbDetectorNotificationID[] = "webusb.detector";
32 33
34 enum WebUsbNotificationClosed {
35 // The notification was dismissed but not by the user (either automatically
36 // or because the device was unplugged).
37 WEBUSB_NOTIFICATION_CLOSED,
38 // The user closed the notification.
39 WEBUSB_NOTIFICATION_CLOSED_BY_USER,
40 // The user clicked on the notification.
41 WEBUSB_NOTIFICATION_CLOSED_CLICKED,
42 // Maximum value for the enum.
43 WEBUSB_NOTIFICATION_CLOSED_MAX
44 };
45
33 Browser* GetBrowser() { 46 Browser* GetBrowser() {
34 chrome::ScopedTabbedBrowserDisplayer browser_displayer( 47 chrome::ScopedTabbedBrowserDisplayer browser_displayer(
35 ProfileManager::GetActiveUserProfile(), chrome::GetActiveDesktop()); 48 ProfileManager::GetActiveUserProfile(), chrome::GetActiveDesktop());
36 DCHECK(browser_displayer.browser()); 49 DCHECK(browser_displayer.browser());
37 return browser_displayer.browser(); 50 return browser_displayer.browser();
38 } 51 }
39 52
40 void OpenURL(const GURL& url) { 53 void OpenURL(const GURL& url) {
41 GetBrowser()->OpenURL( 54 GetBrowser()->OpenURL(
42 content::OpenURLParams(url, content::Referrer(), NEW_FOREGROUND_TAB, 55 content::OpenURLParams(url, content::Referrer(), NEW_FOREGROUND_TAB,
43 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, true)); 56 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, true));
44 } 57 }
45 58
46 // Delegate for webusb notification 59 // Delegate for webusb notification
47 class WebUsbNotificationDelegate : public message_center::NotificationDelegate { 60 class WebUsbNotificationDelegate : public message_center::NotificationDelegate {
48 public: 61 public:
49 WebUsbNotificationDelegate(const GURL& landing_page, 62 WebUsbNotificationDelegate(const GURL& landing_page,
50 const std::string& notification_id) 63 const std::string& notification_id)
51 : landing_page_(landing_page), notification_id_(notification_id) {} 64 : landing_page_(landing_page), notification_id_(notification_id) {}
52 65
53 void Click() override { 66 void Click() override {
67 clicked_ = true;
54 OpenURL(landing_page_); 68 OpenURL(landing_page_);
55 message_center::MessageCenter::Get()->RemoveNotification( 69 message_center::MessageCenter::Get()->RemoveNotification(
56 notification_id_, false /* by_user */); 70 notification_id_, false /* by_user */);
57 } 71 }
58 72
73 void Close(bool by_user) override {
74 WebUsbNotificationClosed result;
75 if (clicked_) {
76 result = WEBUSB_NOTIFICATION_CLOSED_CLICKED;
77 } else if (by_user) {
78 result = WEBUSB_NOTIFICATION_CLOSED_BY_USER;
79 } else {
80 result = WEBUSB_NOTIFICATION_CLOSED;
81 }
82 UMA_HISTOGRAM_ENUMERATION("WebUsb.NotificationClosed", result,
83 WEBUSB_NOTIFICATION_CLOSED_MAX);
84 }
85
59 private: 86 private:
60 ~WebUsbNotificationDelegate() override = default; 87 ~WebUsbNotificationDelegate() override = default;
61 88
62 GURL landing_page_; 89 GURL landing_page_;
63 std::string notification_id_; 90 std::string notification_id_;
91 bool clicked_ = false;
64 92
65 DISALLOW_COPY_AND_ASSIGN(WebUsbNotificationDelegate); 93 DISALLOW_COPY_AND_ASSIGN(WebUsbNotificationDelegate);
66 }; 94 };
67 95
68 } // namespace 96 } // namespace
69 97
70 ChromeWebUsbBrowserClient::ChromeWebUsbBrowserClient() {} 98 ChromeWebUsbBrowserClient::ChromeWebUsbBrowserClient() {}
71 99
72 ChromeWebUsbBrowserClient::~ChromeWebUsbBrowserClient() {} 100 ChromeWebUsbBrowserClient::~ChromeWebUsbBrowserClient() {}
73 101
(...skipping 29 matching lines...) Expand all
103 } 131 }
104 132
105 void ChromeWebUsbBrowserClient::OnDeviceRemoved( 133 void ChromeWebUsbBrowserClient::OnDeviceRemoved(
106 const std::string& notification_id) { 134 const std::string& notification_id) {
107 message_center::MessageCenter* message_center = 135 message_center::MessageCenter* message_center =
108 message_center::MessageCenter::Get(); 136 message_center::MessageCenter::Get();
109 if (message_center->FindVisibleNotificationById(notification_id)) { 137 if (message_center->FindVisibleNotificationById(notification_id)) {
110 message_center->RemoveNotification(notification_id, false /* by_user */); 138 message_center->RemoveNotification(notification_id, false /* by_user */);
111 } 139 }
112 } 140 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/usb/usb_chooser_bubble_delegate.cc » ('j') | chrome/browser/usb/usb_chooser_bubble_delegate.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698