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

Side by Side Diff: chrome/browser/usb/usb_chooser_bubble_delegate.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
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/usb/usb_chooser_bubble_delegate.h" 5 #include "chrome/browser/usb/usb_chooser_bubble_delegate.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/metrics/histogram_macros.h"
11 #include "base/stl_util.h" 12 #include "base/stl_util.h"
12 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/usb/usb_chooser_context.h" 14 #include "chrome/browser/usb/usb_chooser_context.h"
14 #include "chrome/browser/usb/usb_chooser_context_factory.h" 15 #include "chrome/browser/usb/usb_chooser_context_factory.h"
15 #include "components/bubble/bubble_controller.h" 16 #include "components/bubble/bubble_controller.h"
16 #include "content/public/browser/render_frame_host.h" 17 #include "content/public/browser/render_frame_host.h"
17 #include "content/public/browser/web_contents.h" 18 #include "content/public/browser/web_contents.h"
18 #include "device/core/device_client.h" 19 #include "device/core/device_client.h"
19 #include "device/devices_app/usb/type_converters.h" 20 #include "device/devices_app/usb/type_converters.h"
20 #include "device/usb/usb_device.h" 21 #include "device/usb/usb_device.h"
21 #include "device/usb/usb_device_filter.h" 22 #include "device/usb/usb_device_filter.h"
22 #include "url/gurl.h" 23 #include "url/gurl.h"
23 24
24 namespace { 25 namespace {
25 26
27 // Reasons the chooser may be closed. These are used in histograms so do not
28 // remove/reorder entries. Only add at the end just before
29 // WEBUSB_CHOOSER_CLOSED_MAX. Also remember to update the enum listing in
30 // tools/metrics/histograms/histograms.xml.
31 enum WebUsbChooserClosed {
32 // The user cancelled the permission prompt without selecting a device.
33 WEBUSB_CHOOSER_CLOSED_CANCELLED = 0,
34 // The user probably cancelled the permission prompt without selecting a
35 // device because there were no devices to select.
36 WEBUSB_CHOOSER_CLOSED_CANCELLED_NO_DEVICES,
37 // The user granted permission to access a device.
38 WEBUSB_CHOOSER_CLOSED_PERMISSION_GRANTED,
39 // The user granted permission to access a device but that permission will be
40 // revoked when the device is disconnected.
41 WEBUSB_CHOOSER_CLOSED_EPHEMERAL_PERMISSION_GRANTED,
42 // Maximum value for the enum.
43 WEBUSB_CHOOSER_CLOSED_MAX
44 };
45
46 void RecordChooserClosure(WebUsbChooserClosed disposition) {
47 UMA_HISTOGRAM_ENUMERATION("WebUsb.ChooserClosed", disposition,
48 WEBUSB_CHOOSER_CLOSED_MAX);
49 }
50
26 // Check if the origin is in the description set. 51 // Check if the origin is in the description set.
27 bool FindOriginInDescriptorSet(const device::WebUsbDescriptorSet* set, 52 bool FindOriginInDescriptorSet(const device::WebUsbDescriptorSet* set,
28 const GURL& origin) { 53 const GURL& origin) {
29 if (!set) 54 if (!set)
30 return false; 55 return false;
31 56
32 if (ContainsValue(set->origins, origin)) 57 if (ContainsValue(set->origins, origin))
33 return true; 58 return true;
34 59
35 for (const auto& config : set->configurations) { 60 for (const auto& config : set->configurations) {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 UsbChooserContextFactory::GetForProfile(profile); 123 UsbChooserContextFactory::GetForProfile(profile);
99 chooser_context->GrantDevicePermission( 124 chooser_context->GrantDevicePermission(
100 render_frame_host_->GetLastCommittedURL().GetOrigin(), embedding_origin, 125 render_frame_host_->GetLastCommittedURL().GetOrigin(), embedding_origin,
101 devices_[index].first->guid()); 126 devices_[index].first->guid());
102 127
103 device::usb::DeviceInfoPtr device_info_ptr = 128 device::usb::DeviceInfoPtr device_info_ptr =
104 device::usb::DeviceInfo::From(*devices_[index].first); 129 device::usb::DeviceInfo::From(*devices_[index].first);
105 callback_.Run(std::move(device_info_ptr)); 130 callback_.Run(std::move(device_info_ptr));
106 callback_.reset(); // Reset |callback_| so that it is only run once. 131 callback_.reset(); // Reset |callback_| so that it is only run once.
107 132
133 RecordChooserClosure(devices_[index].first->serial_number().empty()
134 ? WEBUSB_CHOOSER_CLOSED_EPHEMERAL_PERMISSION_GRANTED
135 : WEBUSB_CHOOSER_CLOSED_PERMISSION_GRANTED);
136
108 if (bubble_controller_) 137 if (bubble_controller_)
109 bubble_controller_->CloseBubble(BUBBLE_CLOSE_ACCEPTED); 138 bubble_controller_->CloseBubble(BUBBLE_CLOSE_ACCEPTED);
110 } 139 }
111 140
112 void UsbChooserBubbleDelegate::Cancel() { 141 void UsbChooserBubbleDelegate::Cancel() {
142 RecordChooserClosure(devices_.size() == 0
143 ? WEBUSB_CHOOSER_CLOSED_CANCELLED_NO_DEVICES
144 : WEBUSB_CHOOSER_CLOSED_CANCELLED);
145
113 if (bubble_controller_) 146 if (bubble_controller_)
114 bubble_controller_->CloseBubble(BUBBLE_CLOSE_CANCELED); 147 bubble_controller_->CloseBubble(BUBBLE_CLOSE_CANCELED);
115 } 148 }
116 149
117 void UsbChooserBubbleDelegate::Close() {} 150 void UsbChooserBubbleDelegate::Close() {}
118 151
119 void UsbChooserBubbleDelegate::OnDeviceAdded( 152 void UsbChooserBubbleDelegate::OnDeviceAdded(
120 scoped_refptr<device::UsbDevice> device) { 153 scoped_refptr<device::UsbDevice> device) {
121 if (device::UsbDeviceFilter::MatchesAny(device, filters_) && 154 if (device::UsbDeviceFilter::MatchesAny(device, filters_) &&
122 FindOriginInDescriptorSet( 155 FindOriginInDescriptorSet(
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 } 187 }
155 } 188 }
156 if (observer()) 189 if (observer())
157 observer()->OnOptionsInitialized(); 190 observer()->OnOptionsInitialized();
158 } 191 }
159 192
160 void UsbChooserBubbleDelegate::set_bubble_controller( 193 void UsbChooserBubbleDelegate::set_bubble_controller(
161 BubbleReference bubble_controller) { 194 BubbleReference bubble_controller) {
162 bubble_controller_ = bubble_controller; 195 bubble_controller_ = bubble_controller;
163 } 196 }
OLDNEW
« no previous file with comments | « chrome/browser/chrome_webusb_browser_client.cc ('k') | chrome/browser/usb/usb_chooser_context.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698