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

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: 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/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 enum WebUsbPermissionRevoked {
29 // Permission to access a USB device was revoked by the user.
30 WEBUSB_PERMISSION_REVOKED = 0,
31 // Permission to access an ephemeral USB device was revoked by the user.
32 WEBUSB_PERMISSION_REVOKED_EPHEMERAL,
33 // Maximum value for the enum.
34 WEBUSB_PERMISSION_REVOKED_MAX
35 };
36
37 void RecordPermissionRevocation(WebUsbPermissionRevoked kind) {
38 UMA_HISTOGRAM_ENUMERATION("WebUsb.PermissionRevoked", kind,
39 WEBUSB_PERMISSION_REVOKED_MAX);
40 }
41
27 bool CanStorePersistentEntry(const scoped_refptr<const UsbDevice>& device) { 42 bool CanStorePersistentEntry(const scoped_refptr<const UsbDevice>& device) {
28 return !device->serial_number().empty(); 43 return !device->serial_number().empty();
29 } 44 }
30 45
31 const base::DictionaryValue* FindForDevice( 46 const base::DictionaryValue* FindForDevice(
32 const std::vector<scoped_ptr<base::DictionaryValue>>& device_list, 47 const std::vector<scoped_ptr<base::DictionaryValue>>& device_list,
33 const scoped_refptr<const UsbDevice>& device) { 48 const scoped_refptr<const UsbDevice>& device) {
34 const std::string utf8_serial_number = 49 const std::string utf8_serial_number =
35 base::UTF16ToUTF8(device->serial_number()); 50 base::UTF16ToUTF8(device->serial_number());
36 51
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 return objects; 124 return objects;
110 } 125 }
111 126
112 void UsbChooserContext::RevokeObjectPermission( 127 void UsbChooserContext::RevokeObjectPermission(
113 const GURL& requesting_origin, 128 const GURL& requesting_origin,
114 const GURL& embedding_origin, 129 const GURL& embedding_origin,
115 const base::DictionaryValue& object) { 130 const base::DictionaryValue& object) {
116 std::string guid; 131 std::string guid;
117 if (object.GetString(kGuidKey, &guid)) { 132 if (object.GetString(kGuidKey, &guid)) {
118 RevokeDevicePermission(requesting_origin, embedding_origin, guid); 133 RevokeDevicePermission(requesting_origin, embedding_origin, guid);
134 RecordPermissionRevocation(WEBUSB_PERMISSION_REVOKED_EPHEMERAL);
119 } else { 135 } else {
120 ChooserContextBase::RevokeObjectPermission(requesting_origin, 136 ChooserContextBase::RevokeObjectPermission(requesting_origin,
121 embedding_origin, object); 137 embedding_origin, object);
138 RecordPermissionRevocation(WEBUSB_PERMISSION_REVOKED);
122 } 139 }
123 } 140 }
124 141
125 void UsbChooserContext::GrantDevicePermission(const GURL& requesting_origin, 142 void UsbChooserContext::GrantDevicePermission(const GURL& requesting_origin,
126 const GURL& embedding_origin, 143 const GURL& embedding_origin,
127 const std::string& guid) { 144 const std::string& guid) {
128 scoped_refptr<UsbDevice> device = usb_service_->GetDevice(guid); 145 scoped_refptr<UsbDevice> device = usb_service_->GetDevice(guid);
129 if (!device) 146 if (!device)
130 return; 147 return;
131 148
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 bool UsbChooserContext::IsValidObject(const base::DictionaryValue& object) { 202 bool UsbChooserContext::IsValidObject(const base::DictionaryValue& object) {
186 return object.size() == 4 && object.HasKey(kDeviceNameKey) && 203 return object.size() == 4 && object.HasKey(kDeviceNameKey) &&
187 object.HasKey(kVendorIdKey) && object.HasKey(kProductIdKey) && 204 object.HasKey(kVendorIdKey) && object.HasKey(kProductIdKey) &&
188 object.HasKey(kSerialNumberKey); 205 object.HasKey(kSerialNumberKey);
189 } 206 }
190 207
191 void UsbChooserContext::OnDeviceRemoved(scoped_refptr<UsbDevice> device) { 208 void UsbChooserContext::OnDeviceRemoved(scoped_refptr<UsbDevice> device) {
192 for (auto& map_entry : ephemeral_devices_) 209 for (auto& map_entry : ephemeral_devices_)
193 map_entry.second.erase(device->guid()); 210 map_entry.second.erase(device->guid());
194 } 211 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698