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

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: Move UMA macro usage into helper functions. 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 {
asargent_no_longer_on_chrome 2016/01/21 18:54:15 nit: We typically include a comment above enums us
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
46 void RecordNotificationClosure(WebUsbNotificationClosed disposition) {
47 UMA_HISTOGRAM_ENUMERATION("WebUsb.NotificationClosed", disposition,
48 WEBUSB_NOTIFICATION_CLOSED_MAX);
49 }
50
33 Browser* GetBrowser() { 51 Browser* GetBrowser() {
34 chrome::ScopedTabbedBrowserDisplayer browser_displayer( 52 chrome::ScopedTabbedBrowserDisplayer browser_displayer(
35 ProfileManager::GetActiveUserProfile(), chrome::GetActiveDesktop()); 53 ProfileManager::GetActiveUserProfile(), chrome::GetActiveDesktop());
36 DCHECK(browser_displayer.browser()); 54 DCHECK(browser_displayer.browser());
37 return browser_displayer.browser(); 55 return browser_displayer.browser();
38 } 56 }
39 57
40 void OpenURL(const GURL& url) { 58 void OpenURL(const GURL& url) {
41 GetBrowser()->OpenURL( 59 GetBrowser()->OpenURL(
42 content::OpenURLParams(url, content::Referrer(), NEW_FOREGROUND_TAB, 60 content::OpenURLParams(url, content::Referrer(), NEW_FOREGROUND_TAB,
43 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, true)); 61 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, true));
44 } 62 }
45 63
46 // Delegate for webusb notification 64 // Delegate for webusb notification
47 class WebUsbNotificationDelegate : public message_center::NotificationDelegate { 65 class WebUsbNotificationDelegate : public message_center::NotificationDelegate {
48 public: 66 public:
49 WebUsbNotificationDelegate(const GURL& landing_page, 67 WebUsbNotificationDelegate(const GURL& landing_page,
50 const std::string& notification_id) 68 const std::string& notification_id)
51 : landing_page_(landing_page), notification_id_(notification_id) {} 69 : landing_page_(landing_page), notification_id_(notification_id) {}
52 70
53 void Click() override { 71 void Click() override {
72 clicked_ = true;
54 OpenURL(landing_page_); 73 OpenURL(landing_page_);
55 message_center::MessageCenter::Get()->RemoveNotification( 74 message_center::MessageCenter::Get()->RemoveNotification(
56 notification_id_, false /* by_user */); 75 notification_id_, false /* by_user */);
57 } 76 }
58 77
78 void Close(bool by_user) override {
79 if (clicked_)
80 RecordNotificationClosure(WEBUSB_NOTIFICATION_CLOSED_CLICKED);
81 else if (by_user)
82 RecordNotificationClosure(WEBUSB_NOTIFICATION_CLOSED_BY_USER);
83 else
84 RecordNotificationClosure(WEBUSB_NOTIFICATION_CLOSED);
85 }
86
59 private: 87 private:
60 ~WebUsbNotificationDelegate() override = default; 88 ~WebUsbNotificationDelegate() override = default;
61 89
62 GURL landing_page_; 90 GURL landing_page_;
63 std::string notification_id_; 91 std::string notification_id_;
92 bool clicked_ = false;
64 93
65 DISALLOW_COPY_AND_ASSIGN(WebUsbNotificationDelegate); 94 DISALLOW_COPY_AND_ASSIGN(WebUsbNotificationDelegate);
66 }; 95 };
67 96
68 } // namespace 97 } // namespace
69 98
70 ChromeWebUsbBrowserClient::ChromeWebUsbBrowserClient() {} 99 ChromeWebUsbBrowserClient::ChromeWebUsbBrowserClient() {}
71 100
72 ChromeWebUsbBrowserClient::~ChromeWebUsbBrowserClient() {} 101 ChromeWebUsbBrowserClient::~ChromeWebUsbBrowserClient() {}
73 102
(...skipping 29 matching lines...) Expand all
103 } 132 }
104 133
105 void ChromeWebUsbBrowserClient::OnDeviceRemoved( 134 void ChromeWebUsbBrowserClient::OnDeviceRemoved(
106 const std::string& notification_id) { 135 const std::string& notification_id) {
107 message_center::MessageCenter* message_center = 136 message_center::MessageCenter* message_center =
108 message_center::MessageCenter::Get(); 137 message_center::MessageCenter::Get();
109 if (message_center->FindVisibleNotificationById(notification_id)) { 138 if (message_center->FindVisibleNotificationById(notification_id)) {
110 message_center->RemoveNotification(notification_id, false /* by_user */); 139 message_center->RemoveNotification(notification_id, false /* by_user */);
111 } 140 }
112 } 141 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/usb/usb_chooser_bubble_delegate.cc » ('j') | tools/metrics/histograms/histograms.xml » ('J')

Powered by Google App Engine
This is Rietveld 408576698