OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 // NETWORK_ERROR Note: | 5 // NETWORK_ERROR Note: |
6 // When a device can't be found in the BluetoothAdapter, that generally | 6 // When a device can't be found in the BluetoothAdapter, that generally |
7 // indicates that it's gone out of range. We reject with a NetworkError in that | 7 // indicates that it's gone out of range. We reject with a NetworkError in that |
8 // case. | 8 // case. |
9 // https://webbluetoothchrome.github.io/web-bluetooth/#dom-bluetoothdevice-conne
ctgatt | 9 // https://webbluetoothchrome.github.io/web-bluetooth/#dom-bluetoothdevice-conne
ctgatt |
10 | 10 |
11 #include "content/browser/bluetooth/bluetooth_dispatcher_host.h" | 11 #include "content/browser/bluetooth/bluetooth_dispatcher_host.h" |
12 | 12 |
13 #include "base/hash.h" | |
14 #include "base/metrics/histogram_macros.h" | |
15 #include "base/metrics/sparse_histogram.h" | |
16 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
17 #include "content/browser/bad_message.h" | 14 #include "content/browser/bad_message.h" |
| 15 #include "content/browser/bluetooth/bluetooth_metrics.h" |
18 #include "content/browser/frame_host/render_frame_host_impl.h" | 16 #include "content/browser/frame_host/render_frame_host_impl.h" |
19 #include "content/common/bluetooth/bluetooth_messages.h" | 17 #include "content/common/bluetooth/bluetooth_messages.h" |
20 #include "device/bluetooth/bluetooth_adapter.h" | 18 #include "device/bluetooth/bluetooth_adapter.h" |
21 #include "device/bluetooth/bluetooth_adapter_factory.h" | 19 #include "device/bluetooth/bluetooth_adapter_factory.h" |
22 #include "device/bluetooth/bluetooth_device.h" | 20 #include "device/bluetooth/bluetooth_device.h" |
23 #include "device/bluetooth/bluetooth_discovery_session.h" | 21 #include "device/bluetooth/bluetooth_discovery_session.h" |
24 #include "device/bluetooth/bluetooth_gatt_characteristic.h" | 22 #include "device/bluetooth/bluetooth_gatt_characteristic.h" |
25 #include "device/bluetooth/bluetooth_gatt_service.h" | 23 #include "device/bluetooth/bluetooth_gatt_service.h" |
26 | 24 |
27 using blink::WebBluetoothError; | 25 using blink::WebBluetoothError; |
| 26 using content::BluetoothMetrics; |
28 using device::BluetoothAdapter; | 27 using device::BluetoothAdapter; |
29 using device::BluetoothAdapterFactory; | 28 using device::BluetoothAdapterFactory; |
30 using device::BluetoothGattCharacteristic; | 29 using device::BluetoothGattCharacteristic; |
31 using device::BluetoothGattService; | 30 using device::BluetoothGattService; |
32 using device::BluetoothUUID; | 31 using device::BluetoothUUID; |
33 | 32 |
| 33 using UMAWebBluetoothFunction = |
| 34 content::BluetoothMetrics::UMAWebBluetoothFunction; |
| 35 using UMARequestDeviceOutcome = |
| 36 content::BluetoothMetrics::UMARequestDeviceOutcome; |
| 37 using UMAConnectGATTOutcome = content::BluetoothMetrics::UMAConnectGATTOutcome; |
| 38 using UMAGetPrimaryServiceOutcome = |
| 39 content::BluetoothMetrics::UMAGetPrimaryServiceOutcome; |
| 40 using UMAGATTError = content::BluetoothMetrics::UMAGATTError; |
| 41 |
34 namespace { | 42 namespace { |
35 | 43 |
36 // These types of errors aren't as common. We log them to understand | |
37 // how common they are and if we need to investigate more. | |
38 enum class BluetoothGATTError { | |
39 UNKNOWN, | |
40 FAILED, | |
41 IN_PROGRESS, | |
42 NOT_PAIRED, | |
43 // Add errors above this line and update corresponding histograms.xml enum. | |
44 MAX_ERROR, | |
45 }; | |
46 | |
47 enum class UMARequestDeviceOutcome { | |
48 SUCCESS = 0, | |
49 NO_BLUETOOTH_ADAPTER = 1, | |
50 NO_RENDER_FRAME = 2, | |
51 DISCOVERY_START_FAILED = 3, | |
52 DISCOVERY_STOP_FAILED = 4, | |
53 NO_MATCHING_DEVICES_FOUND = 5, | |
54 BLUETOOTH_ADAPTER_NOT_PRESENT = 6, | |
55 BLUETOOTH_ADAPTER_OFF = 7, | |
56 // NOTE: Add new requestDevice() outcomes immediately above this line. Make | |
57 // sure to update the enum list in | |
58 // tools/metrics/histogram/histograms.xml accordingly. | |
59 COUNT | |
60 }; | |
61 | |
62 void RecordRequestDeviceOutcome(UMARequestDeviceOutcome outcome) { | |
63 UMA_HISTOGRAM_ENUMERATION("Bluetooth.Web.RequestDevice.Outcome", | |
64 static_cast<int>(outcome), | |
65 static_cast<int>(UMARequestDeviceOutcome::COUNT)); | |
66 } | |
67 // TODO(ortuno): Remove once we have a macro to histogram strings. | |
68 // http://crbug.com/520284 | |
69 int HashUUID(const std::string& uuid) { | |
70 uint32 data = base::SuperFastHash(uuid.data(), uuid.size()); | |
71 | |
72 // Strip off the signed bit because UMA doesn't support negative values, | |
73 // but takes a signed int as input. | |
74 return static_cast<int>(data & 0x7fffffff); | |
75 } | |
76 | |
77 void RecordRequestDeviceFilters( | |
78 const std::vector<content::BluetoothScanFilter>& filters) { | |
79 UMA_HISTOGRAM_COUNTS_100("Bluetooth.Web.RequestDevice.Filters.Count", | |
80 filters.size()); | |
81 for (const content::BluetoothScanFilter& filter : filters) { | |
82 UMA_HISTOGRAM_COUNTS_100("Bluetooth.Web.RequestDevice.FilterSize", | |
83 filter.services.size()); | |
84 for (const BluetoothUUID& service : filter.services) { | |
85 // TODO(ortuno): Use a macro to histogram strings. | |
86 // http://crbug.com/520284 | |
87 UMA_HISTOGRAM_SPARSE_SLOWLY( | |
88 "Bluetooth.Web.RequestDevice.Filters.Services", | |
89 HashUUID(service.canonical_value())); | |
90 } | |
91 } | |
92 } | |
93 | |
94 void RecordRequestDeviceOptionalServices( | |
95 const std::vector<BluetoothUUID>& optional_services) { | |
96 UMA_HISTOGRAM_COUNTS_100("Bluetooth.Web.RequestDevice.OptionalServices.Count", | |
97 optional_services.size()); | |
98 for (const BluetoothUUID& service : optional_services) { | |
99 // TODO(ortuno): Use a macro to histogram strings. | |
100 // http://crbug.com/520284 | |
101 UMA_HISTOGRAM_SPARSE_SLOWLY( | |
102 "Bluetooth.Web.RequestDevice.OptionalServices.Services", | |
103 HashUUID(service.canonical_value())); | |
104 } | |
105 } | |
106 | |
107 void RecordUnionOfServices( | |
108 const std::vector<content::BluetoothScanFilter>& filters, | |
109 const std::vector<BluetoothUUID>& optional_services) { | |
110 std::set<BluetoothUUID> union_of_services(optional_services.begin(), | |
111 optional_services.end()); | |
112 | |
113 for (const content::BluetoothScanFilter& filter : filters) | |
114 union_of_services.insert(filter.services.begin(), filter.services.end()); | |
115 | |
116 UMA_HISTOGRAM_COUNTS_100("Bluetooth.Web.RequestDevice.UnionOfServices.Count", | |
117 union_of_services.size()); | |
118 } | |
119 | |
120 enum class UMAGetPrimaryServiceOutcome { | |
121 SUCCESS, | |
122 NO_DEVICE, | |
123 NOT_FOUND, | |
124 // Note: Add new GetPrimaryService outcomes immediately above this line. Make | |
125 // sure to update the enum list in tools/metrics/histograms/histograms.xml | |
126 // accordingly. | |
127 COUNT | |
128 }; | |
129 | |
130 void RecordGetPrimaryServiceService(const BluetoothUUID& service) { | |
131 UMA_HISTOGRAM_SPARSE_SLOWLY("Bluetooth.Web.GetPrimaryService.Services", | |
132 HashUUID(service.canonical_value())); | |
133 } | |
134 | |
135 void RecordGetPrimaryServiceOutcome(UMAGetPrimaryServiceOutcome outcome) { | |
136 UMA_HISTOGRAM_ENUMERATION( | |
137 "Bluetooth.Web.GetPrimaryService.Outcome", static_cast<int>(outcome), | |
138 static_cast<int>(UMAGetPrimaryServiceOutcome::COUNT)); | |
139 } | |
140 | |
141 enum class UMAConnectGATTOutcome { | |
142 SUCCESS, | |
143 NO_DEVICE, | |
144 UNKNOWN, | |
145 IN_PROGRESS, | |
146 FAILED, | |
147 AUTH_FAILED, | |
148 AUTH_CANCELED, | |
149 AUTH_REJECTED, | |
150 AUTH_TIMEOUT, | |
151 UNSUPPORTED_DEVICE, | |
152 // Note: Add new ConnectGATT outcomes immediately above this line. Make sure | |
153 // to update the enum list in tools/metrisc/histogram/histograms.xml | |
154 // accordingly. | |
155 COUNT | |
156 }; | |
157 | |
158 void RecordConnectGATTOutcome(UMAConnectGATTOutcome outcome) { | |
159 UMA_HISTOGRAM_ENUMERATION("Bluetooth.Web.ConnectGATT.Outcome", | |
160 static_cast<int>(outcome), | |
161 static_cast<int>(UMAConnectGATTOutcome::COUNT)); | |
162 } | |
163 | |
164 void RecordConnectGATTTimeSuccess(const base::TimeDelta& duration) { | |
165 UMA_HISTOGRAM_MEDIUM_TIMES("Bluetooth.Web.ConnectGATT.TimeSuccess", duration); | |
166 } | |
167 | |
168 void RecordConnectGATTTimeFailed(const base::TimeDelta& duration) { | |
169 UMA_HISTOGRAM_MEDIUM_TIMES("Bluetooth.Web.ConnectGATT.TimeFailed", duration); | |
170 } | |
171 | |
172 enum class UMAWebBluetoothFunction { | |
173 REQUEST_DEVICE, | |
174 CONNECT_GATT, | |
175 GET_PRIMARY_SERVICE, | |
176 GET_CHARACTERISTIC, | |
177 CHARACTERISTIC_READ_VALUE, | |
178 CHARACTERISTIC_WRITE_VALUE, | |
179 // NOTE: Add new actions immediately above this line. Make sure to update the | |
180 // enum list in tools/metrics/histogram/histograms.xml accordingly. | |
181 COUNT | |
182 }; | |
183 | |
184 void RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction function) { | |
185 UMA_HISTOGRAM_ENUMERATION("Bluetooth.Web.FunctionCall.Count", | |
186 static_cast<int>(function), | |
187 static_cast<int>(UMAWebBluetoothFunction::COUNT)); | |
188 } | |
189 | |
190 // TODO(ortuno): Once we have a chooser for scanning and the right | 44 // TODO(ortuno): Once we have a chooser for scanning and the right |
191 // callback for discovered services we should delete these constants. | 45 // callback for discovered services we should delete these constants. |
192 // https://crbug.com/436280 and https://crbug.com/484504 | 46 // https://crbug.com/436280 and https://crbug.com/484504 |
193 const int kDelayTime = 5; // 5 seconds for scanning and discovering | 47 const int kDelayTime = 5; // 5 seconds for scanning and discovering |
194 const int kTestingDelayTime = 0; // No need to wait during tests | 48 const int kTestingDelayTime = 0; // No need to wait during tests |
195 | 49 |
196 // Defined at | 50 // Defined at |
197 // https://webbluetoothchrome.github.io/web-bluetooth/#dfn-matches-a-filter | 51 // https://webbluetoothchrome.github.io/web-bluetooth/#dfn-matches-a-filter |
198 bool MatchesFilter(const std::set<BluetoothUUID>& device_uuids, | 52 bool MatchesFilter(const std::set<BluetoothUUID>& device_uuids, |
199 const content::BluetoothScanFilter& filter) { | 53 const content::BluetoothScanFilter& filter) { |
(...skipping 13 matching lines...) Expand all Loading... |
213 const std::set<BluetoothUUID> device_uuids(device_uuid_list.begin(), | 67 const std::set<BluetoothUUID> device_uuids(device_uuid_list.begin(), |
214 device_uuid_list.end()); | 68 device_uuid_list.end()); |
215 for (const content::BluetoothScanFilter& filter : filters) { | 69 for (const content::BluetoothScanFilter& filter : filters) { |
216 if (MatchesFilter(device_uuids, filter)) { | 70 if (MatchesFilter(device_uuids, filter)) { |
217 return true; | 71 return true; |
218 } | 72 } |
219 } | 73 } |
220 return false; | 74 return false; |
221 } | 75 } |
222 | 76 |
223 void AddToHistogram(BluetoothGATTError error) { | |
224 UMA_HISTOGRAM_ENUMERATION("Bluetooth.GATTErrors", static_cast<int>(error), | |
225 static_cast<int>(BluetoothGATTError::MAX_ERROR)); | |
226 } | |
227 | |
228 WebBluetoothError TranslateConnectError( | 77 WebBluetoothError TranslateConnectError( |
229 device::BluetoothDevice::ConnectErrorCode error_code) { | 78 device::BluetoothDevice::ConnectErrorCode error_code) { |
230 switch (error_code) { | 79 switch (error_code) { |
231 case device::BluetoothDevice::ERROR_UNKNOWN: | 80 case device::BluetoothDevice::ERROR_UNKNOWN: |
232 RecordConnectGATTOutcome(UMAConnectGATTOutcome::UNKNOWN); | 81 BluetoothMetrics::RecordConnectGATTOutcome( |
| 82 UMAConnectGATTOutcome::UNKNOWN); |
233 return WebBluetoothError::ConnectUnknownError; | 83 return WebBluetoothError::ConnectUnknownError; |
234 case device::BluetoothDevice::ERROR_INPROGRESS: | 84 case device::BluetoothDevice::ERROR_INPROGRESS: |
235 RecordConnectGATTOutcome(UMAConnectGATTOutcome::IN_PROGRESS); | 85 BluetoothMetrics::RecordConnectGATTOutcome( |
| 86 UMAConnectGATTOutcome::IN_PROGRESS); |
236 return WebBluetoothError::ConnectAlreadyInProgress; | 87 return WebBluetoothError::ConnectAlreadyInProgress; |
237 case device::BluetoothDevice::ERROR_FAILED: | 88 case device::BluetoothDevice::ERROR_FAILED: |
238 RecordConnectGATTOutcome(UMAConnectGATTOutcome::FAILED); | 89 BluetoothMetrics::RecordConnectGATTOutcome(UMAConnectGATTOutcome::FAILED); |
239 return WebBluetoothError::ConnectUnknownFailure; | 90 return WebBluetoothError::ConnectUnknownFailure; |
240 case device::BluetoothDevice::ERROR_AUTH_FAILED: | 91 case device::BluetoothDevice::ERROR_AUTH_FAILED: |
241 RecordConnectGATTOutcome(UMAConnectGATTOutcome::AUTH_FAILED); | 92 BluetoothMetrics::RecordConnectGATTOutcome( |
| 93 UMAConnectGATTOutcome::AUTH_FAILED); |
242 return WebBluetoothError::ConnectAuthFailed; | 94 return WebBluetoothError::ConnectAuthFailed; |
243 case device::BluetoothDevice::ERROR_AUTH_CANCELED: | 95 case device::BluetoothDevice::ERROR_AUTH_CANCELED: |
244 RecordConnectGATTOutcome(UMAConnectGATTOutcome::AUTH_CANCELED); | 96 BluetoothMetrics::RecordConnectGATTOutcome( |
| 97 UMAConnectGATTOutcome::AUTH_CANCELED); |
245 return WebBluetoothError::ConnectAuthCanceled; | 98 return WebBluetoothError::ConnectAuthCanceled; |
246 case device::BluetoothDevice::ERROR_AUTH_REJECTED: | 99 case device::BluetoothDevice::ERROR_AUTH_REJECTED: |
247 RecordConnectGATTOutcome(UMAConnectGATTOutcome::AUTH_REJECTED); | 100 BluetoothMetrics::RecordConnectGATTOutcome( |
| 101 UMAConnectGATTOutcome::AUTH_REJECTED); |
248 return WebBluetoothError::ConnectAuthRejected; | 102 return WebBluetoothError::ConnectAuthRejected; |
249 case device::BluetoothDevice::ERROR_AUTH_TIMEOUT: | 103 case device::BluetoothDevice::ERROR_AUTH_TIMEOUT: |
250 RecordConnectGATTOutcome(UMAConnectGATTOutcome::AUTH_TIMEOUT); | 104 BluetoothMetrics::RecordConnectGATTOutcome( |
| 105 UMAConnectGATTOutcome::AUTH_TIMEOUT); |
251 return WebBluetoothError::ConnectAuthTimeout; | 106 return WebBluetoothError::ConnectAuthTimeout; |
252 case device::BluetoothDevice::ERROR_UNSUPPORTED_DEVICE: | 107 case device::BluetoothDevice::ERROR_UNSUPPORTED_DEVICE: |
253 RecordConnectGATTOutcome(UMAConnectGATTOutcome::UNSUPPORTED_DEVICE); | 108 BluetoothMetrics::RecordConnectGATTOutcome( |
| 109 UMAConnectGATTOutcome::UNSUPPORTED_DEVICE); |
254 return WebBluetoothError::ConnectUnsupportedDevice; | 110 return WebBluetoothError::ConnectUnsupportedDevice; |
255 } | 111 } |
256 NOTREACHED(); | 112 NOTREACHED(); |
257 return WebBluetoothError::UntranslatedConnectErrorCode; | 113 return WebBluetoothError::UntranslatedConnectErrorCode; |
258 } | 114 } |
259 | 115 |
260 blink::WebBluetoothError TranslateGATTError( | 116 blink::WebBluetoothError TranslateGATTError( |
261 BluetoothGattService::GattErrorCode error_code) { | 117 BluetoothGattService::GattErrorCode error_code) { |
262 switch (error_code) { | 118 switch (error_code) { |
263 case BluetoothGattService::GATT_ERROR_UNKNOWN: | 119 case BluetoothGattService::GATT_ERROR_UNKNOWN: |
264 AddToHistogram(BluetoothGATTError::UNKNOWN); | 120 BluetoothMetrics::RecordGATTError(UMAGATTError::UNKNOWN); |
265 return blink::WebBluetoothError::GATTUnknownError; | 121 return blink::WebBluetoothError::GATTUnknownError; |
266 case BluetoothGattService::GATT_ERROR_FAILED: | 122 case BluetoothGattService::GATT_ERROR_FAILED: |
267 AddToHistogram(BluetoothGATTError::FAILED); | 123 BluetoothMetrics::RecordGATTError(UMAGATTError::FAILED); |
268 return blink::WebBluetoothError::GATTUnknownFailure; | 124 return blink::WebBluetoothError::GATTUnknownFailure; |
269 case BluetoothGattService::GATT_ERROR_IN_PROGRESS: | 125 case BluetoothGattService::GATT_ERROR_IN_PROGRESS: |
270 AddToHistogram(BluetoothGATTError::IN_PROGRESS); | 126 BluetoothMetrics::RecordGATTError(UMAGATTError::IN_PROGRESS); |
271 return blink::WebBluetoothError::GATTOperationInProgress; | 127 return blink::WebBluetoothError::GATTOperationInProgress; |
272 case BluetoothGattService::GATT_ERROR_INVALID_LENGTH: | 128 case BluetoothGattService::GATT_ERROR_INVALID_LENGTH: |
273 return blink::WebBluetoothError::GATTInvalidAttributeLength; | 129 return blink::WebBluetoothError::GATTInvalidAttributeLength; |
274 case BluetoothGattService::GATT_ERROR_NOT_PERMITTED: | 130 case BluetoothGattService::GATT_ERROR_NOT_PERMITTED: |
275 return blink::WebBluetoothError::GATTNotPermitted; | 131 return blink::WebBluetoothError::GATTNotPermitted; |
276 case BluetoothGattService::GATT_ERROR_NOT_AUTHORIZED: | 132 case BluetoothGattService::GATT_ERROR_NOT_AUTHORIZED: |
277 return blink::WebBluetoothError::GATTNotAuthorized; | 133 return blink::WebBluetoothError::GATTNotAuthorized; |
278 case BluetoothGattService::GATT_ERROR_NOT_PAIRED: | 134 case BluetoothGattService::GATT_ERROR_NOT_PAIRED: |
279 AddToHistogram(BluetoothGATTError::NOT_PAIRED); | 135 BluetoothMetrics::RecordGATTError(UMAGATTError::NOT_PAIRED); |
280 return blink::WebBluetoothError::GATTNotPaired; | 136 return blink::WebBluetoothError::GATTNotPaired; |
281 case BluetoothGattService::GATT_ERROR_NOT_SUPPORTED: | 137 case BluetoothGattService::GATT_ERROR_NOT_SUPPORTED: |
282 return blink::WebBluetoothError::GATTNotSupported; | 138 return blink::WebBluetoothError::GATTNotSupported; |
283 } | 139 } |
284 NOTREACHED(); | 140 NOTREACHED(); |
285 return blink::WebBluetoothError::GATTUntranslatedErrorCode; | 141 return blink::WebBluetoothError::GATTUntranslatedErrorCode; |
286 } | 142 } |
287 | 143 |
288 } // namespace | 144 } // namespace |
289 | 145 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 return discovery_filter.Pass(); | 233 return discovery_filter.Pass(); |
378 } | 234 } |
379 | 235 |
380 void BluetoothDispatcherHost::OnRequestDevice( | 236 void BluetoothDispatcherHost::OnRequestDevice( |
381 int thread_id, | 237 int thread_id, |
382 int request_id, | 238 int request_id, |
383 int frame_routing_id, | 239 int frame_routing_id, |
384 const std::vector<BluetoothScanFilter>& filters, | 240 const std::vector<BluetoothScanFilter>& filters, |
385 const std::vector<BluetoothUUID>& optional_services) { | 241 const std::vector<BluetoothUUID>& optional_services) { |
386 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 242 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
387 RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction::REQUEST_DEVICE); | 243 BluetoothMetrics::RecordWebBluetoothFunctionCall( |
388 RecordRequestDeviceFilters(filters); | 244 UMAWebBluetoothFunction::REQUEST_DEVICE); |
389 RecordRequestDeviceOptionalServices(optional_services); | 245 BluetoothMetrics::RecordRequestDeviceFilters(filters); |
390 RecordUnionOfServices(filters, optional_services); | 246 BluetoothMetrics::RecordRequestDeviceOptionalServices(optional_services); |
| 247 BluetoothMetrics::RecordUnionOfServices(filters, optional_services); |
391 | 248 |
392 VLOG(1) << "requestDevice called with the following filters: "; | 249 VLOG(1) << "requestDevice called with the following filters: "; |
393 for (const BluetoothScanFilter& filter : filters) { | 250 for (const BluetoothScanFilter& filter : filters) { |
394 VLOG(1) << "\t["; | 251 VLOG(1) << "\t["; |
395 for (const BluetoothUUID& service : filter.services) | 252 for (const BluetoothUUID& service : filter.services) |
396 VLOG(1) << "\t\t" << service.value(); | 253 VLOG(1) << "\t\t" << service.value(); |
397 VLOG(1) << "\t]"; | 254 VLOG(1) << "\t]"; |
398 } | 255 } |
399 | 256 |
400 VLOG(1) << "requestDevice called with the following optional services: "; | 257 VLOG(1) << "requestDevice called with the following optional services: "; |
401 for (const BluetoothUUID& service : optional_services) | 258 for (const BluetoothUUID& service : optional_services) |
402 VLOG(1) << "\t" << service.value(); | 259 VLOG(1) << "\t" << service.value(); |
403 | 260 |
404 RenderFrameHostImpl* render_frame_host = | 261 RenderFrameHostImpl* render_frame_host = |
405 RenderFrameHostImpl::FromID(render_process_id_, frame_routing_id); | 262 RenderFrameHostImpl::FromID(render_process_id_, frame_routing_id); |
406 | 263 |
407 if (!render_frame_host) { | 264 if (!render_frame_host) { |
408 DLOG(WARNING) | 265 DLOG(WARNING) |
409 << "Got a requestDevice IPC without a matching RenderFrameHost: " | 266 << "Got a requestDevice IPC without a matching RenderFrameHost: " |
410 << render_process_id_ << ", " << frame_routing_id; | 267 << render_process_id_ << ", " << frame_routing_id; |
411 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::NO_RENDER_FRAME); | 268 BluetoothMetrics::RecordRequestDeviceOutcome( |
| 269 UMARequestDeviceOutcome::NO_RENDER_FRAME); |
412 Send(new BluetoothMsg_RequestDeviceError( | 270 Send(new BluetoothMsg_RequestDeviceError( |
413 thread_id, request_id, WebBluetoothError::RequestDeviceWithoutFrame)); | 271 thread_id, request_id, WebBluetoothError::RequestDeviceWithoutFrame)); |
414 } | 272 } |
415 | 273 |
416 // TODO(scheib): Device selection UI: crbug.com/436280 | 274 // TODO(scheib): Device selection UI: crbug.com/436280 |
417 // TODO(scheib): Utilize BluetoothAdapter::Observer::DeviceAdded/Removed. | 275 // TODO(scheib): Utilize BluetoothAdapter::Observer::DeviceAdded/Removed. |
418 if (adapter_.get()) { | 276 if (adapter_.get()) { |
419 if (!request_device_sessions_ | 277 if (!request_device_sessions_ |
420 .insert(std::make_pair( | 278 .insert(std::make_pair( |
421 std::make_pair(thread_id, request_id), | 279 std::make_pair(thread_id, request_id), |
422 RequestDeviceSession(filters, optional_services))) | 280 RequestDeviceSession(filters, optional_services))) |
423 .second) { | 281 .second) { |
424 LOG(ERROR) << "2 requestDevice() calls with the same thread_id (" | 282 LOG(ERROR) << "2 requestDevice() calls with the same thread_id (" |
425 << thread_id << ") and request_id (" << request_id | 283 << thread_id << ") and request_id (" << request_id |
426 << ") shouldn't arrive at the same BluetoothDispatcherHost."; | 284 << ") shouldn't arrive at the same BluetoothDispatcherHost."; |
427 bad_message::ReceivedBadMessage( | 285 bad_message::ReceivedBadMessage( |
428 this, bad_message::BDH_DUPLICATE_REQUEST_DEVICE_ID); | 286 this, bad_message::BDH_DUPLICATE_REQUEST_DEVICE_ID); |
429 } | 287 } |
430 if (!adapter_->IsPresent()) { | 288 if (!adapter_->IsPresent()) { |
431 VLOG(1) << "Bluetooth Adapter not present. Can't serve requestDevice."; | 289 VLOG(1) << "Bluetooth Adapter not present. Can't serve requestDevice."; |
432 RecordRequestDeviceOutcome( | 290 BluetoothMetrics::RecordRequestDeviceOutcome( |
433 UMARequestDeviceOutcome::BLUETOOTH_ADAPTER_NOT_PRESENT); | 291 UMARequestDeviceOutcome::BLUETOOTH_ADAPTER_NOT_PRESENT); |
434 Send(new BluetoothMsg_RequestDeviceError( | 292 Send(new BluetoothMsg_RequestDeviceError( |
435 thread_id, request_id, WebBluetoothError::NoBluetoothAdapter)); | 293 thread_id, request_id, WebBluetoothError::NoBluetoothAdapter)); |
436 request_device_sessions_.erase(std::make_pair(thread_id, request_id)); | 294 request_device_sessions_.erase(std::make_pair(thread_id, request_id)); |
437 return; | 295 return; |
438 } | 296 } |
439 // TODO(jyasskin): Once the dialog is available, the dialog should check for | 297 // TODO(jyasskin): Once the dialog is available, the dialog should check for |
440 // the status of the adapter, i.e. check IsPowered() and | 298 // the status of the adapter, i.e. check IsPowered() and |
441 // BluetoothAdapter::Observer::PoweredChanged, and inform the user. But | 299 // BluetoothAdapter::Observer::PoweredChanged, and inform the user. But |
442 // until the dialog is available we log/histogram the status and return | 300 // until the dialog is available we log/histogram the status and return |
443 // with a message. | 301 // with a message. |
444 // https://crbug.com/517237 | 302 // https://crbug.com/517237 |
445 if (!adapter_->IsPowered()) { | 303 if (!adapter_->IsPowered()) { |
446 VLOG(1) << "Bluetooth Adapter is not powered. Can't serve requestDevice."; | 304 VLOG(1) << "Bluetooth Adapter is not powered. Can't serve requestDevice."; |
447 RecordRequestDeviceOutcome( | 305 BluetoothMetrics::RecordRequestDeviceOutcome( |
448 UMARequestDeviceOutcome::BLUETOOTH_ADAPTER_OFF); | 306 UMARequestDeviceOutcome::BLUETOOTH_ADAPTER_OFF); |
449 Send(new BluetoothMsg_RequestDeviceError( | 307 Send(new BluetoothMsg_RequestDeviceError( |
450 thread_id, request_id, WebBluetoothError::BluetoothAdapterOff)); | 308 thread_id, request_id, WebBluetoothError::BluetoothAdapterOff)); |
451 request_device_sessions_.erase(std::make_pair(thread_id, request_id)); | 309 request_device_sessions_.erase(std::make_pair(thread_id, request_id)); |
452 return; | 310 return; |
453 } | 311 } |
454 adapter_->StartDiscoverySessionWithFilter( | 312 adapter_->StartDiscoverySessionWithFilter( |
455 ComputeScanFilter(filters), | 313 ComputeScanFilter(filters), |
456 base::Bind(&BluetoothDispatcherHost::OnDiscoverySessionStarted, | 314 base::Bind(&BluetoothDispatcherHost::OnDiscoverySessionStarted, |
457 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id), | 315 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id), |
458 base::Bind(&BluetoothDispatcherHost::OnDiscoverySessionStartedError, | 316 base::Bind(&BluetoothDispatcherHost::OnDiscoverySessionStartedError, |
459 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id)); | 317 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id)); |
460 } else { | 318 } else { |
461 VLOG(1) << "No BluetoothAdapter. Can't serve requestDevice."; | 319 VLOG(1) << "No BluetoothAdapter. Can't serve requestDevice."; |
462 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::NO_BLUETOOTH_ADAPTER); | 320 BluetoothMetrics::RecordRequestDeviceOutcome( |
| 321 UMARequestDeviceOutcome::NO_BLUETOOTH_ADAPTER); |
463 Send(new BluetoothMsg_RequestDeviceError( | 322 Send(new BluetoothMsg_RequestDeviceError( |
464 thread_id, request_id, WebBluetoothError::NoBluetoothAdapter)); | 323 thread_id, request_id, WebBluetoothError::NoBluetoothAdapter)); |
465 } | 324 } |
466 return; | 325 return; |
467 } | 326 } |
468 | 327 |
469 void BluetoothDispatcherHost::OnConnectGATT( | 328 void BluetoothDispatcherHost::OnConnectGATT( |
470 int thread_id, | 329 int thread_id, |
471 int request_id, | 330 int request_id, |
472 const std::string& device_instance_id) { | 331 const std::string& device_instance_id) { |
473 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 332 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
474 RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction::CONNECT_GATT); | 333 BluetoothMetrics::RecordWebBluetoothFunctionCall( |
| 334 UMAWebBluetoothFunction::CONNECT_GATT); |
475 const base::TimeTicks start_time = base::TimeTicks::Now(); | 335 const base::TimeTicks start_time = base::TimeTicks::Now(); |
476 | 336 |
477 // TODO(ortuno): Right now it's pointless to check if the domain has access to | 337 // TODO(ortuno): Right now it's pointless to check if the domain has access to |
478 // the device, because any domain can connect to any device. But once | 338 // the device, because any domain can connect to any device. But once |
479 // permissions are implemented we should check that the domain has access to | 339 // permissions are implemented we should check that the domain has access to |
480 // the device. https://crbug.com/484745 | 340 // the device. https://crbug.com/484745 |
481 device::BluetoothDevice* device = adapter_->GetDevice(device_instance_id); | 341 device::BluetoothDevice* device = adapter_->GetDevice(device_instance_id); |
482 if (device == nullptr) { // See "NETWORK_ERROR Note" above. | 342 if (device == nullptr) { // See "NETWORK_ERROR Note" above. |
483 RecordConnectGATTOutcome(UMAConnectGATTOutcome::NO_DEVICE); | 343 BluetoothMetrics::RecordConnectGATTOutcome( |
| 344 UMAConnectGATTOutcome::NO_DEVICE); |
484 VLOG(1) << "Bluetooth Device no longer in range."; | 345 VLOG(1) << "Bluetooth Device no longer in range."; |
485 Send(new BluetoothMsg_ConnectGATTError( | 346 Send(new BluetoothMsg_ConnectGATTError( |
486 thread_id, request_id, WebBluetoothError::DeviceNoLongerInRange)); | 347 thread_id, request_id, WebBluetoothError::DeviceNoLongerInRange)); |
487 return; | 348 return; |
488 } | 349 } |
489 device->CreateGattConnection( | 350 device->CreateGattConnection( |
490 base::Bind(&BluetoothDispatcherHost::OnGATTConnectionCreated, | 351 base::Bind(&BluetoothDispatcherHost::OnGATTConnectionCreated, |
491 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id, | 352 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id, |
492 device_instance_id, start_time), | 353 device_instance_id, start_time), |
493 base::Bind(&BluetoothDispatcherHost::OnCreateGATTConnectionError, | 354 base::Bind(&BluetoothDispatcherHost::OnCreateGATTConnectionError, |
494 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id, | 355 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id, |
495 device_instance_id, start_time)); | 356 device_instance_id, start_time)); |
496 } | 357 } |
497 | 358 |
498 void BluetoothDispatcherHost::OnGetPrimaryService( | 359 void BluetoothDispatcherHost::OnGetPrimaryService( |
499 int thread_id, | 360 int thread_id, |
500 int request_id, | 361 int request_id, |
501 const std::string& device_instance_id, | 362 const std::string& device_instance_id, |
502 const std::string& service_uuid) { | 363 const std::string& service_uuid) { |
503 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 364 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
504 RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction::GET_PRIMARY_SERVICE); | 365 BluetoothMetrics::RecordWebBluetoothFunctionCall( |
505 RecordGetPrimaryServiceService(BluetoothUUID(service_uuid)); | 366 UMAWebBluetoothFunction::GET_PRIMARY_SERVICE); |
| 367 BluetoothMetrics::RecordGetPrimaryServiceService(BluetoothUUID(service_uuid)); |
506 | 368 |
507 // TODO(ortuno): Check if device_instance_id is in "allowed devices" | 369 // TODO(ortuno): Check if device_instance_id is in "allowed devices" |
508 // https://crbug.com/493459 | 370 // https://crbug.com/493459 |
509 // TODO(ortuno): Check if service_uuid is in "allowed services" | 371 // TODO(ortuno): Check if service_uuid is in "allowed services" |
510 // https://crbug.com/493460 | 372 // https://crbug.com/493460 |
511 // For now just wait a fixed time and call OnServiceDiscovered. | 373 // For now just wait a fixed time and call OnServiceDiscovered. |
512 // TODO(ortuno): Use callback once it's implemented http://crbug.com/484504 | 374 // TODO(ortuno): Use callback once it's implemented http://crbug.com/484504 |
513 BrowserThread::PostDelayedTask( | 375 BrowserThread::PostDelayedTask( |
514 BrowserThread::UI, FROM_HERE, | 376 BrowserThread::UI, FROM_HERE, |
515 base::Bind(&BluetoothDispatcherHost::OnServicesDiscovered, | 377 base::Bind(&BluetoothDispatcherHost::OnServicesDiscovered, |
516 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id, | 378 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id, |
517 device_instance_id, service_uuid), | 379 device_instance_id, service_uuid), |
518 base::TimeDelta::FromSeconds(current_delay_time_)); | 380 base::TimeDelta::FromSeconds(current_delay_time_)); |
519 } | 381 } |
520 | 382 |
521 void BluetoothDispatcherHost::OnGetCharacteristic( | 383 void BluetoothDispatcherHost::OnGetCharacteristic( |
522 int thread_id, | 384 int thread_id, |
523 int request_id, | 385 int request_id, |
524 const std::string& service_instance_id, | 386 const std::string& service_instance_id, |
525 const std::string& characteristic_uuid) { | 387 const std::string& characteristic_uuid) { |
526 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 388 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
527 RecordWebBluetoothFunctionCall(UMAWebBluetoothFunction::GET_CHARACTERISTIC); | 389 BluetoothMetrics::RecordWebBluetoothFunctionCall( |
| 390 UMAWebBluetoothFunction::GET_CHARACTERISTIC); |
528 | 391 |
529 auto device_iter = service_to_device_.find(service_instance_id); | 392 auto device_iter = service_to_device_.find(service_instance_id); |
530 // A service_instance_id not in the map implies a hostile renderer | 393 // A service_instance_id not in the map implies a hostile renderer |
531 // because a renderer obtains the service id from this class and | 394 // because a renderer obtains the service id from this class and |
532 // it will be added to the map at that time. | 395 // it will be added to the map at that time. |
533 if (device_iter == service_to_device_.end()) { | 396 if (device_iter == service_to_device_.end()) { |
534 // Kill the renderer | 397 // Kill the renderer |
535 bad_message::ReceivedBadMessage(this, bad_message::BDH_INVALID_SERVICE_ID); | 398 bad_message::ReceivedBadMessage(this, bad_message::BDH_INVALID_SERVICE_ID); |
536 return; | 399 return; |
537 } | 400 } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
579 } | 442 } |
580 Send(new BluetoothMsg_GetCharacteristicError( | 443 Send(new BluetoothMsg_GetCharacteristicError( |
581 thread_id, request_id, WebBluetoothError::CharacteristicNotFound)); | 444 thread_id, request_id, WebBluetoothError::CharacteristicNotFound)); |
582 } | 445 } |
583 | 446 |
584 void BluetoothDispatcherHost::OnReadValue( | 447 void BluetoothDispatcherHost::OnReadValue( |
585 int thread_id, | 448 int thread_id, |
586 int request_id, | 449 int request_id, |
587 const std::string& characteristic_instance_id) { | 450 const std::string& characteristic_instance_id) { |
588 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 451 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
589 RecordWebBluetoothFunctionCall( | 452 BluetoothMetrics::RecordWebBluetoothFunctionCall( |
590 UMAWebBluetoothFunction::CHARACTERISTIC_READ_VALUE); | 453 UMAWebBluetoothFunction::CHARACTERISTIC_READ_VALUE); |
591 | 454 |
592 auto characteristic_iter = | 455 auto characteristic_iter = |
593 characteristic_to_service_.find(characteristic_instance_id); | 456 characteristic_to_service_.find(characteristic_instance_id); |
594 // A characteristic_instance_id not in the map implies a hostile renderer | 457 // A characteristic_instance_id not in the map implies a hostile renderer |
595 // because a renderer obtains the characteristic id from this class and | 458 // because a renderer obtains the characteristic id from this class and |
596 // it will be added to the map at that time. | 459 // it will be added to the map at that time. |
597 if (characteristic_iter == characteristic_to_service_.end()) { | 460 if (characteristic_iter == characteristic_to_service_.end()) { |
598 // Kill the renderer | 461 // Kill the renderer |
599 bad_message::ReceivedBadMessage(this, | 462 bad_message::ReceivedBadMessage(this, |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
636 base::Bind(&BluetoothDispatcherHost::OnCharacteristicReadValueError, | 499 base::Bind(&BluetoothDispatcherHost::OnCharacteristicReadValueError, |
637 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id)); | 500 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id)); |
638 } | 501 } |
639 | 502 |
640 void BluetoothDispatcherHost::OnWriteValue( | 503 void BluetoothDispatcherHost::OnWriteValue( |
641 int thread_id, | 504 int thread_id, |
642 int request_id, | 505 int request_id, |
643 const std::string& characteristic_instance_id, | 506 const std::string& characteristic_instance_id, |
644 const std::vector<uint8_t>& value) { | 507 const std::vector<uint8_t>& value) { |
645 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 508 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
646 RecordWebBluetoothFunctionCall( | 509 BluetoothMetrics::RecordWebBluetoothFunctionCall( |
647 UMAWebBluetoothFunction::CHARACTERISTIC_WRITE_VALUE); | 510 UMAWebBluetoothFunction::CHARACTERISTIC_WRITE_VALUE); |
648 | 511 |
649 // Length check per step 3 of writeValue algorithm: | 512 // Length check per step 3 of writeValue algorithm: |
650 // https://webbluetoothchrome.github.io/web-bluetooth/#dom-bluetoothgattcharac
teristic-writevalue | 513 // https://webbluetoothchrome.github.io/web-bluetooth/#dom-bluetoothgattcharac
teristic-writevalue |
651 // We perform the length check on the renderer side. So if we | 514 // We perform the length check on the renderer side. So if we |
652 // get a value with length > 512, we can assume it's a hostile | 515 // get a value with length > 512, we can assume it's a hostile |
653 // renderer and kill it. | 516 // renderer and kill it. |
654 if (value.size() > 512) { | 517 if (value.size() > 512) { |
655 bad_message::ReceivedBadMessage( | 518 bad_message::ReceivedBadMessage( |
656 this, bad_message::BDH_INVALID_WRITE_VALUE_LENGTH); | 519 this, bad_message::BDH_INVALID_WRITE_VALUE_LENGTH); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
713 base::Bind(&BluetoothDispatcherHost::StopDiscoverySession, | 576 base::Bind(&BluetoothDispatcherHost::StopDiscoverySession, |
714 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id, | 577 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id, |
715 base::Passed(&discovery_session)), | 578 base::Passed(&discovery_session)), |
716 base::TimeDelta::FromSeconds(current_delay_time_)); | 579 base::TimeDelta::FromSeconds(current_delay_time_)); |
717 } | 580 } |
718 | 581 |
719 void BluetoothDispatcherHost::OnDiscoverySessionStartedError(int thread_id, | 582 void BluetoothDispatcherHost::OnDiscoverySessionStartedError(int thread_id, |
720 int request_id) { | 583 int request_id) { |
721 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 584 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
722 DLOG(WARNING) << "BluetoothDispatcherHost::OnDiscoverySessionStartedError"; | 585 DLOG(WARNING) << "BluetoothDispatcherHost::OnDiscoverySessionStartedError"; |
723 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::DISCOVERY_START_FAILED); | 586 BluetoothMetrics::RecordRequestDeviceOutcome( |
| 587 UMARequestDeviceOutcome::DISCOVERY_START_FAILED); |
724 Send(new BluetoothMsg_RequestDeviceError( | 588 Send(new BluetoothMsg_RequestDeviceError( |
725 thread_id, request_id, WebBluetoothError::DiscoverySessionStartFailed)); | 589 thread_id, request_id, WebBluetoothError::DiscoverySessionStartFailed)); |
726 request_device_sessions_.erase(std::make_pair(thread_id, request_id)); | 590 request_device_sessions_.erase(std::make_pair(thread_id, request_id)); |
727 } | 591 } |
728 | 592 |
729 void BluetoothDispatcherHost::StopDiscoverySession( | 593 void BluetoothDispatcherHost::StopDiscoverySession( |
730 int thread_id, | 594 int thread_id, |
731 int request_id, | 595 int request_id, |
732 scoped_ptr<device::BluetoothDiscoverySession> discovery_session) { | 596 scoped_ptr<device::BluetoothDiscoverySession> discovery_session) { |
733 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 597 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
(...skipping 22 matching lines...) Expand all Loading... |
756 device->GetAddress(), // instance_id | 620 device->GetAddress(), // instance_id |
757 device->GetName(), // name | 621 device->GetName(), // name |
758 device->GetBluetoothClass(), // device_class | 622 device->GetBluetoothClass(), // device_class |
759 device->GetVendorIDSource(), // vendor_id_source | 623 device->GetVendorIDSource(), // vendor_id_source |
760 device->GetVendorID(), // vendor_id | 624 device->GetVendorID(), // vendor_id |
761 device->GetProductID(), // product_id | 625 device->GetProductID(), // product_id |
762 device->GetDeviceID(), // product_version | 626 device->GetDeviceID(), // product_version |
763 device->IsPaired(), // paired | 627 device->IsPaired(), // paired |
764 content::BluetoothDevice::UUIDsFromBluetoothUUIDs( | 628 content::BluetoothDevice::UUIDsFromBluetoothUUIDs( |
765 device->GetUUIDs())); // uuids | 629 device->GetUUIDs())); // uuids |
766 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::SUCCESS); | 630 BluetoothMetrics::RecordRequestDeviceOutcome( |
| 631 UMARequestDeviceOutcome::SUCCESS); |
767 Send(new BluetoothMsg_RequestDeviceSuccess(thread_id, request_id, | 632 Send(new BluetoothMsg_RequestDeviceSuccess(thread_id, request_id, |
768 device_ipc)); | 633 device_ipc)); |
769 request_device_sessions_.erase(session); | 634 request_device_sessions_.erase(session); |
770 return; | 635 return; |
771 } | 636 } |
772 } | 637 } |
773 RecordRequestDeviceOutcome( | 638 BluetoothMetrics::RecordRequestDeviceOutcome( |
774 UMARequestDeviceOutcome::NO_MATCHING_DEVICES_FOUND); | 639 UMARequestDeviceOutcome::NO_MATCHING_DEVICES_FOUND); |
775 VLOG(1) << "No matching Bluetooth Devices found"; | 640 VLOG(1) << "No matching Bluetooth Devices found"; |
776 Send(new BluetoothMsg_RequestDeviceError(thread_id, request_id, | 641 Send(new BluetoothMsg_RequestDeviceError(thread_id, request_id, |
777 WebBluetoothError::NoDevicesFound)); | 642 WebBluetoothError::NoDevicesFound)); |
778 request_device_sessions_.erase(session); | 643 request_device_sessions_.erase(session); |
779 } | 644 } |
780 | 645 |
781 void BluetoothDispatcherHost::OnDiscoverySessionStoppedError(int thread_id, | 646 void BluetoothDispatcherHost::OnDiscoverySessionStoppedError(int thread_id, |
782 int request_id) { | 647 int request_id) { |
783 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 648 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
784 DLOG(WARNING) << "BluetoothDispatcherHost::OnDiscoverySessionStoppedError"; | 649 DLOG(WARNING) << "BluetoothDispatcherHost::OnDiscoverySessionStoppedError"; |
785 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::DISCOVERY_STOP_FAILED); | 650 BluetoothMetrics::RecordRequestDeviceOutcome( |
| 651 UMARequestDeviceOutcome::DISCOVERY_STOP_FAILED); |
786 Send(new BluetoothMsg_RequestDeviceError( | 652 Send(new BluetoothMsg_RequestDeviceError( |
787 thread_id, request_id, WebBluetoothError::DiscoverySessionStopFailed)); | 653 thread_id, request_id, WebBluetoothError::DiscoverySessionStopFailed)); |
788 request_device_sessions_.erase(std::make_pair(thread_id, request_id)); | 654 request_device_sessions_.erase(std::make_pair(thread_id, request_id)); |
789 } | 655 } |
790 | 656 |
791 void BluetoothDispatcherHost::OnGATTConnectionCreated( | 657 void BluetoothDispatcherHost::OnGATTConnectionCreated( |
792 int thread_id, | 658 int thread_id, |
793 int request_id, | 659 int request_id, |
794 const std::string& device_instance_id, | 660 const std::string& device_instance_id, |
795 base::TimeTicks start_time, | 661 base::TimeTicks start_time, |
796 scoped_ptr<device::BluetoothGattConnection> connection) { | 662 scoped_ptr<device::BluetoothGattConnection> connection) { |
797 // TODO(ortuno): Save the BluetoothGattConnection so we can disconnect | 663 // TODO(ortuno): Save the BluetoothGattConnection so we can disconnect |
798 // from it. | 664 // from it. |
799 RecordConnectGATTTimeSuccess(base::TimeTicks::Now() - start_time); | 665 BluetoothMetrics::RecordConnectGATTTimeSuccess(base::TimeTicks::Now() - |
800 RecordConnectGATTOutcome(UMAConnectGATTOutcome::SUCCESS); | 666 start_time); |
| 667 BluetoothMetrics::RecordConnectGATTOutcome(UMAConnectGATTOutcome::SUCCESS); |
801 Send(new BluetoothMsg_ConnectGATTSuccess(thread_id, request_id, | 668 Send(new BluetoothMsg_ConnectGATTSuccess(thread_id, request_id, |
802 device_instance_id)); | 669 device_instance_id)); |
803 } | 670 } |
804 | 671 |
805 void BluetoothDispatcherHost::OnCreateGATTConnectionError( | 672 void BluetoothDispatcherHost::OnCreateGATTConnectionError( |
806 int thread_id, | 673 int thread_id, |
807 int request_id, | 674 int request_id, |
808 const std::string& device_instance_id, | 675 const std::string& device_instance_id, |
809 base::TimeTicks start_time, | 676 base::TimeTicks start_time, |
810 device::BluetoothDevice::ConnectErrorCode error_code) { | 677 device::BluetoothDevice::ConnectErrorCode error_code) { |
811 // There was an error creating the ATT Bearer so we reject with | 678 // There was an error creating the ATT Bearer so we reject with |
812 // NetworkError. | 679 // NetworkError. |
813 // https://webbluetoothchrome.github.io/web-bluetooth/#dom-bluetoothdevice-con
nectgatt | 680 // https://webbluetoothchrome.github.io/web-bluetooth/#dom-bluetoothdevice-con
nectgatt |
814 RecordConnectGATTTimeFailed(base::TimeTicks::Now() - start_time); | 681 BluetoothMetrics::RecordConnectGATTTimeFailed(base::TimeTicks::Now() - |
815 // RecordConnectGATTOutcome is called by TranslateConnectError. | 682 start_time); |
| 683 // BluetoothMetrics::RecordConnectGATTOutcome is called by |
| 684 // TranslateConnectError. |
816 Send(new BluetoothMsg_ConnectGATTError(thread_id, request_id, | 685 Send(new BluetoothMsg_ConnectGATTError(thread_id, request_id, |
817 TranslateConnectError(error_code))); | 686 TranslateConnectError(error_code))); |
818 } | 687 } |
819 | 688 |
820 void BluetoothDispatcherHost::OnServicesDiscovered( | 689 void BluetoothDispatcherHost::OnServicesDiscovered( |
821 int thread_id, | 690 int thread_id, |
822 int request_id, | 691 int request_id, |
823 const std::string& device_instance_id, | 692 const std::string& device_instance_id, |
824 const std::string& service_uuid) { | 693 const std::string& service_uuid) { |
825 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 694 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
826 | 695 |
827 device::BluetoothDevice* device = adapter_->GetDevice(device_instance_id); | 696 device::BluetoothDevice* device = adapter_->GetDevice(device_instance_id); |
828 if (device == nullptr) { // See "NETWORK_ERROR Note" above. | 697 if (device == nullptr) { // See "NETWORK_ERROR Note" above. |
829 RecordGetPrimaryServiceOutcome(UMAGetPrimaryServiceOutcome::NO_DEVICE); | 698 BluetoothMetrics::RecordGetPrimaryServiceOutcome( |
| 699 UMAGetPrimaryServiceOutcome::NO_DEVICE); |
830 VLOG(1) << "Bluetooth Device is no longer in range."; | 700 VLOG(1) << "Bluetooth Device is no longer in range."; |
831 Send(new BluetoothMsg_GetPrimaryServiceError( | 701 Send(new BluetoothMsg_GetPrimaryServiceError( |
832 thread_id, request_id, WebBluetoothError::DeviceNoLongerInRange)); | 702 thread_id, request_id, WebBluetoothError::DeviceNoLongerInRange)); |
833 return; | 703 return; |
834 } | 704 } |
835 for (BluetoothGattService* service : device->GetGattServices()) { | 705 for (BluetoothGattService* service : device->GetGattServices()) { |
836 if (service->GetUUID().canonical_value() == service_uuid) { | 706 if (service->GetUUID().canonical_value() == service_uuid) { |
837 // TODO(ortuno): Use generated instance ID instead. | 707 // TODO(ortuno): Use generated instance ID instead. |
838 // https://crbug.com/495379 | 708 // https://crbug.com/495379 |
839 const std::string& service_identifier = service->GetIdentifier(); | 709 const std::string& service_identifier = service->GetIdentifier(); |
840 auto insert_result = service_to_device_.insert( | 710 auto insert_result = service_to_device_.insert( |
841 make_pair(service_identifier, device_instance_id)); | 711 make_pair(service_identifier, device_instance_id)); |
842 | 712 |
843 // If a value is already in map, DCHECK it's valid. | 713 // If a value is already in map, DCHECK it's valid. |
844 if (!insert_result.second) | 714 if (!insert_result.second) |
845 DCHECK(insert_result.first->second == device_instance_id); | 715 DCHECK(insert_result.first->second == device_instance_id); |
846 | 716 |
847 RecordGetPrimaryServiceOutcome(UMAGetPrimaryServiceOutcome::SUCCESS); | 717 BluetoothMetrics::RecordGetPrimaryServiceOutcome( |
| 718 UMAGetPrimaryServiceOutcome::SUCCESS); |
848 Send(new BluetoothMsg_GetPrimaryServiceSuccess(thread_id, request_id, | 719 Send(new BluetoothMsg_GetPrimaryServiceSuccess(thread_id, request_id, |
849 service_identifier)); | 720 service_identifier)); |
850 return; | 721 return; |
851 } | 722 } |
852 } | 723 } |
853 RecordGetPrimaryServiceOutcome(UMAGetPrimaryServiceOutcome::NOT_FOUND); | 724 BluetoothMetrics::RecordGetPrimaryServiceOutcome( |
| 725 UMAGetPrimaryServiceOutcome::NOT_FOUND); |
854 VLOG(1) << "No GATT services with UUID: " << service_uuid; | 726 VLOG(1) << "No GATT services with UUID: " << service_uuid; |
855 Send(new BluetoothMsg_GetPrimaryServiceError( | 727 Send(new BluetoothMsg_GetPrimaryServiceError( |
856 thread_id, request_id, WebBluetoothError::ServiceNotFound)); | 728 thread_id, request_id, WebBluetoothError::ServiceNotFound)); |
857 } | 729 } |
858 | 730 |
859 void BluetoothDispatcherHost::OnCharacteristicValueRead( | 731 void BluetoothDispatcherHost::OnCharacteristicValueRead( |
860 int thread_id, | 732 int thread_id, |
861 int request_id, | 733 int request_id, |
862 const std::vector<uint8>& value) { | 734 const std::vector<uint8>& value) { |
863 Send(new BluetoothMsg_ReadCharacteristicValueSuccess(thread_id, request_id, | 735 Send(new BluetoothMsg_ReadCharacteristicValueSuccess(thread_id, request_id, |
(...skipping 15 matching lines...) Expand all Loading... |
879 | 751 |
880 void BluetoothDispatcherHost::OnWriteValueFailed( | 752 void BluetoothDispatcherHost::OnWriteValueFailed( |
881 int thread_id, | 753 int thread_id, |
882 int request_id, | 754 int request_id, |
883 device::BluetoothGattService::GattErrorCode error_code) { | 755 device::BluetoothGattService::GattErrorCode error_code) { |
884 Send(new BluetoothMsg_WriteCharacteristicValueError( | 756 Send(new BluetoothMsg_WriteCharacteristicValueError( |
885 thread_id, request_id, TranslateGATTError(error_code))); | 757 thread_id, request_id, TranslateGATTError(error_code))); |
886 } | 758 } |
887 | 759 |
888 } // namespace content | 760 } // namespace content |
OLD | NEW |