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

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: Update comments. 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
« no previous file with comments | « no previous file | chrome/browser/usb/usb_chooser_bubble_delegate.cc » ('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 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 // Reasons the notification may be closed. These are used in histograms so do
35 // not remove/reorder entries. Only add at the end just before
36 // WEBUSB_NOTIFICATION_CLOSED_MAX. Also remember to update the enum listing in
37 // tools/metrics/histograms/histograms.xml.
38 enum WebUsbNotificationClosed {
39 // The notification was dismissed but not by the user (either automatically
40 // or because the device was unplugged).
41 WEBUSB_NOTIFICATION_CLOSED,
42 // The user closed the notification.
43 WEBUSB_NOTIFICATION_CLOSED_BY_USER,
44 // The user clicked on the notification.
45 WEBUSB_NOTIFICATION_CLOSED_CLICKED,
46 // Maximum value for the enum.
47 WEBUSB_NOTIFICATION_CLOSED_MAX
48 };
49
50 void RecordNotificationClosure(WebUsbNotificationClosed disposition) {
51 UMA_HISTOGRAM_ENUMERATION("WebUsb.NotificationClosed", disposition,
52 WEBUSB_NOTIFICATION_CLOSED_MAX);
53 }
54
33 Browser* GetBrowser() { 55 Browser* GetBrowser() {
34 chrome::ScopedTabbedBrowserDisplayer browser_displayer( 56 chrome::ScopedTabbedBrowserDisplayer browser_displayer(
35 ProfileManager::GetActiveUserProfile(), chrome::GetActiveDesktop()); 57 ProfileManager::GetActiveUserProfile(), chrome::GetActiveDesktop());
36 DCHECK(browser_displayer.browser()); 58 DCHECK(browser_displayer.browser());
37 return browser_displayer.browser(); 59 return browser_displayer.browser();
38 } 60 }
39 61
40 void OpenURL(const GURL& url) { 62 void OpenURL(const GURL& url) {
41 GetBrowser()->OpenURL( 63 GetBrowser()->OpenURL(
42 content::OpenURLParams(url, content::Referrer(), NEW_FOREGROUND_TAB, 64 content::OpenURLParams(url, content::Referrer(), NEW_FOREGROUND_TAB,
43 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, true)); 65 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, true));
44 } 66 }
45 67
46 // Delegate for webusb notification 68 // Delegate for webusb notification
47 class WebUsbNotificationDelegate : public message_center::NotificationDelegate { 69 class WebUsbNotificationDelegate : public message_center::NotificationDelegate {
48 public: 70 public:
49 WebUsbNotificationDelegate(const GURL& landing_page, 71 WebUsbNotificationDelegate(const GURL& landing_page,
50 const std::string& notification_id) 72 const std::string& notification_id)
51 : landing_page_(landing_page), notification_id_(notification_id) {} 73 : landing_page_(landing_page), notification_id_(notification_id) {}
52 74
53 void Click() override { 75 void Click() override {
76 clicked_ = true;
54 OpenURL(landing_page_); 77 OpenURL(landing_page_);
55 message_center::MessageCenter::Get()->RemoveNotification( 78 message_center::MessageCenter::Get()->RemoveNotification(
56 notification_id_, false /* by_user */); 79 notification_id_, false /* by_user */);
57 } 80 }
58 81
82 void Close(bool by_user) override {
83 if (clicked_)
84 RecordNotificationClosure(WEBUSB_NOTIFICATION_CLOSED_CLICKED);
85 else if (by_user)
86 RecordNotificationClosure(WEBUSB_NOTIFICATION_CLOSED_BY_USER);
87 else
88 RecordNotificationClosure(WEBUSB_NOTIFICATION_CLOSED);
89 }
90
59 private: 91 private:
60 ~WebUsbNotificationDelegate() override = default; 92 ~WebUsbNotificationDelegate() override = default;
61 93
62 GURL landing_page_; 94 GURL landing_page_;
63 std::string notification_id_; 95 std::string notification_id_;
96 bool clicked_ = false;
64 97
65 DISALLOW_COPY_AND_ASSIGN(WebUsbNotificationDelegate); 98 DISALLOW_COPY_AND_ASSIGN(WebUsbNotificationDelegate);
66 }; 99 };
67 100
68 } // namespace 101 } // namespace
69 102
70 ChromeWebUsbBrowserClient::ChromeWebUsbBrowserClient() {} 103 ChromeWebUsbBrowserClient::ChromeWebUsbBrowserClient() {}
71 104
72 ChromeWebUsbBrowserClient::~ChromeWebUsbBrowserClient() {} 105 ChromeWebUsbBrowserClient::~ChromeWebUsbBrowserClient() {}
73 106
(...skipping 29 matching lines...) Expand all
103 } 136 }
104 137
105 void ChromeWebUsbBrowserClient::OnDeviceRemoved( 138 void ChromeWebUsbBrowserClient::OnDeviceRemoved(
106 const std::string& notification_id) { 139 const std::string& notification_id) {
107 message_center::MessageCenter* message_center = 140 message_center::MessageCenter* message_center =
108 message_center::MessageCenter::Get(); 141 message_center::MessageCenter::Get();
109 if (message_center->FindVisibleNotificationById(notification_id)) { 142 if (message_center->FindVisibleNotificationById(notification_id)) {
110 message_center->RemoveNotification(notification_id, false /* by_user */); 143 message_center->RemoveNotification(notification_id, false /* by_user */);
111 } 144 }
112 } 145 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/usb/usb_chooser_bubble_delegate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698