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

Side by Side Diff: chrome/browser/usb/usb_chooser_context.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_context.h" 5 #include "chrome/browser/usb/usb_chooser_context.h"
6 6
7 #include <utility> 7 #include <utility>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/metrics/histogram_macros.h"
10 #include "base/stl_util.h" 11 #include "base/stl_util.h"
11 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
12 #include "base/values.h" 13 #include "base/values.h"
13 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
14 #include "device/core/device_client.h" 15 #include "device/core/device_client.h"
15 #include "device/usb/usb_device.h" 16 #include "device/usb/usb_device.h"
16 17
17 using device::UsbDevice; 18 using device::UsbDevice;
18 19
19 namespace { 20 namespace {
20 21
21 const char kDeviceNameKey[] = "name"; 22 const char kDeviceNameKey[] = "name";
22 const char kGuidKey[] = "ephemeral-guid"; 23 const char kGuidKey[] = "ephemeral-guid";
23 const char kProductIdKey[] = "product-id"; 24 const char kProductIdKey[] = "product-id";
24 const char kSerialNumberKey[] = "serial-number"; 25 const char kSerialNumberKey[] = "serial-number";
25 const char kVendorIdKey[] = "vendor-id"; 26 const char kVendorIdKey[] = "vendor-id";
26 27
28 // Reasons a permission may be closed. These are used in histograms so do not
29 // remove/reorder entries. Only add at the end just before
30 // WEBUSB_PERMISSION_REVOKED_MAX. Also remember to update the enum listing in
31 // tools/metrics/histograms/histograms.xml.
32 enum WebUsbPermissionRevoked {
33 // Permission to access a USB device was revoked by the user.
34 WEBUSB_PERMISSION_REVOKED = 0,
35 // Permission to access an ephemeral USB device was revoked by the user.
36 WEBUSB_PERMISSION_REVOKED_EPHEMERAL,
37 // Maximum value for the enum.
38 WEBUSB_PERMISSION_REVOKED_MAX
39 };
40
41 void RecordPermissionRevocation(WebUsbPermissionRevoked kind) {
42 UMA_HISTOGRAM_ENUMERATION("WebUsb.PermissionRevoked", kind,
43 WEBUSB_PERMISSION_REVOKED_MAX);
44 }
45
27 bool CanStorePersistentEntry(const scoped_refptr<const UsbDevice>& device) { 46 bool CanStorePersistentEntry(const scoped_refptr<const UsbDevice>& device) {
28 return !device->serial_number().empty(); 47 return !device->serial_number().empty();
29 } 48 }
30 49
31 const base::DictionaryValue* FindForDevice( 50 const base::DictionaryValue* FindForDevice(
32 const std::vector<scoped_ptr<base::DictionaryValue>>& device_list, 51 const std::vector<scoped_ptr<base::DictionaryValue>>& device_list,
33 const scoped_refptr<const UsbDevice>& device) { 52 const scoped_refptr<const UsbDevice>& device) {
34 const std::string utf8_serial_number = 53 const std::string utf8_serial_number =
35 base::UTF16ToUTF8(device->serial_number()); 54 base::UTF16ToUTF8(device->serial_number());
36 55
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 return objects; 128 return objects;
110 } 129 }
111 130
112 void UsbChooserContext::RevokeObjectPermission( 131 void UsbChooserContext::RevokeObjectPermission(
113 const GURL& requesting_origin, 132 const GURL& requesting_origin,
114 const GURL& embedding_origin, 133 const GURL& embedding_origin,
115 const base::DictionaryValue& object) { 134 const base::DictionaryValue& object) {
116 std::string guid; 135 std::string guid;
117 if (object.GetString(kGuidKey, &guid)) { 136 if (object.GetString(kGuidKey, &guid)) {
118 RevokeDevicePermission(requesting_origin, embedding_origin, guid); 137 RevokeDevicePermission(requesting_origin, embedding_origin, guid);
138 RecordPermissionRevocation(WEBUSB_PERMISSION_REVOKED_EPHEMERAL);
119 } else { 139 } else {
120 ChooserContextBase::RevokeObjectPermission(requesting_origin, 140 ChooserContextBase::RevokeObjectPermission(requesting_origin,
121 embedding_origin, object); 141 embedding_origin, object);
142 RecordPermissionRevocation(WEBUSB_PERMISSION_REVOKED);
122 } 143 }
123 } 144 }
124 145
125 void UsbChooserContext::GrantDevicePermission(const GURL& requesting_origin, 146 void UsbChooserContext::GrantDevicePermission(const GURL& requesting_origin,
126 const GURL& embedding_origin, 147 const GURL& embedding_origin,
127 const std::string& guid) { 148 const std::string& guid) {
128 scoped_refptr<UsbDevice> device = usb_service_->GetDevice(guid); 149 scoped_refptr<UsbDevice> device = usb_service_->GetDevice(guid);
129 if (!device) 150 if (!device)
130 return; 151 return;
131 152
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 bool UsbChooserContext::IsValidObject(const base::DictionaryValue& object) { 206 bool UsbChooserContext::IsValidObject(const base::DictionaryValue& object) {
186 return object.size() == 4 && object.HasKey(kDeviceNameKey) && 207 return object.size() == 4 && object.HasKey(kDeviceNameKey) &&
187 object.HasKey(kVendorIdKey) && object.HasKey(kProductIdKey) && 208 object.HasKey(kVendorIdKey) && object.HasKey(kProductIdKey) &&
188 object.HasKey(kSerialNumberKey); 209 object.HasKey(kSerialNumberKey);
189 } 210 }
190 211
191 void UsbChooserContext::OnDeviceRemoved(scoped_refptr<UsbDevice> device) { 212 void UsbChooserContext::OnDeviceRemoved(scoped_refptr<UsbDevice> device) {
192 for (auto& map_entry : ephemeral_devices_) 213 for (auto& map_entry : ephemeral_devices_)
193 map_entry.second.erase(device->guid()); 214 map_entry.second.erase(device->guid());
194 } 215 }
OLDNEW
« no previous file with comments | « chrome/browser/usb/usb_chooser_bubble_delegate.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698