| 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 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 // how common they are and if we need to investigate more. | 35 // how common they are and if we need to investigate more. |
| 36 enum class BluetoothGATTError { | 36 enum class BluetoothGATTError { |
| 37 UNKNOWN, | 37 UNKNOWN, |
| 38 FAILED, | 38 FAILED, |
| 39 IN_PROGRESS, | 39 IN_PROGRESS, |
| 40 NOT_PAIRED, | 40 NOT_PAIRED, |
| 41 // Add errors above this line and update corresponding histograms.xml enum. | 41 // Add errors above this line and update corresponding histograms.xml enum. |
| 42 MAX_ERROR, | 42 MAX_ERROR, |
| 43 }; | 43 }; |
| 44 | 44 |
| 45 enum class UMARequestDeviceOutcome { |
| 46 SUCCESS = 0, |
| 47 NO_BLUETOOTH_ADAPTER = 1, |
| 48 NO_RENDER_FRAME = 2, |
| 49 DISCOVERY_START_FAILED = 3, |
| 50 DISCOVERY_STOP_FAILED = 4, |
| 51 NO_MATCHING_DEVICES_FOUND = 5, |
| 52 // NOTE: Add new requestDevice() outcomes immediately above this line. Make |
| 53 // sure to update the enum list in tools/histogram/histograms.xml accordingly. |
| 54 COUNT |
| 55 }; |
| 56 |
| 57 void RecordRequestDeviceOutcome(UMARequestDeviceOutcome outcome) { |
| 58 UMA_HISTOGRAM_ENUMERATION("Bluetooth.RequestDevice.Outcome", |
| 59 static_cast<int>(outcome), |
| 60 static_cast<int>(UMARequestDeviceOutcome::COUNT)); |
| 61 } |
| 62 |
| 45 // TODO(ortuno): Once we have a chooser for scanning and the right | 63 // TODO(ortuno): Once we have a chooser for scanning and the right |
| 46 // callback for discovered services we should delete these constants. | 64 // callback for discovered services we should delete these constants. |
| 47 // https://crbug.com/436280 and https://crbug.com/484504 | 65 // https://crbug.com/436280 and https://crbug.com/484504 |
| 48 const int kDelayTime = 5; // 5 seconds for scanning and discovering | 66 const int kDelayTime = 5; // 5 seconds for scanning and discovering |
| 49 const int kTestingDelayTime = 0; // No need to wait during tests | 67 const int kTestingDelayTime = 0; // No need to wait during tests |
| 50 | 68 |
| 51 // Defined at | 69 // Defined at |
| 52 // https://webbluetoothchrome.github.io/web-bluetooth/#dfn-matches-a-filter | 70 // https://webbluetoothchrome.github.io/web-bluetooth/#dfn-matches-a-filter |
| 53 bool MatchesFilter(const std::set<BluetoothUUID>& device_uuids, | 71 bool MatchesFilter(const std::set<BluetoothUUID>& device_uuids, |
| 54 const content::BluetoothScanFilter& filter) { | 72 const content::BluetoothScanFilter& filter) { |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 const std::vector<BluetoothUUID>& optional_services) { | 250 const std::vector<BluetoothUUID>& optional_services) { |
| 233 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 251 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 234 | 252 |
| 235 RenderFrameHostImpl* render_frame_host = | 253 RenderFrameHostImpl* render_frame_host = |
| 236 RenderFrameHostImpl::FromID(render_process_id_, frame_routing_id); | 254 RenderFrameHostImpl::FromID(render_process_id_, frame_routing_id); |
| 237 | 255 |
| 238 if (!render_frame_host) { | 256 if (!render_frame_host) { |
| 239 DLOG(WARNING) | 257 DLOG(WARNING) |
| 240 << "Got a requestDevice IPC without a matching RenderFrameHost: " | 258 << "Got a requestDevice IPC without a matching RenderFrameHost: " |
| 241 << render_process_id_ << ", " << frame_routing_id; | 259 << render_process_id_ << ", " << frame_routing_id; |
| 260 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::NO_RENDER_FRAME); |
| 242 Send(new BluetoothMsg_RequestDeviceError( | 261 Send(new BluetoothMsg_RequestDeviceError( |
| 243 thread_id, request_id, WebBluetoothError::RequestDeviceWithoutFrame)); | 262 thread_id, request_id, WebBluetoothError::RequestDeviceWithoutFrame)); |
| 244 } | 263 } |
| 245 | 264 |
| 246 // TODO(scheib): Device selection UI: crbug.com/436280 | 265 // TODO(scheib): Device selection UI: crbug.com/436280 |
| 247 // TODO(scheib): Utilize BluetoothAdapter::Observer::DeviceAdded/Removed. | 266 // TODO(scheib): Utilize BluetoothAdapter::Observer::DeviceAdded/Removed. |
| 248 if (adapter_.get()) { | 267 if (adapter_.get()) { |
| 249 if (!request_device_sessions_ | 268 if (!request_device_sessions_ |
| 250 .insert(std::make_pair( | 269 .insert(std::make_pair( |
| 251 std::make_pair(thread_id, request_id), | 270 std::make_pair(thread_id, request_id), |
| 252 RequestDeviceSession(filters, optional_services))) | 271 RequestDeviceSession(filters, optional_services))) |
| 253 .second) { | 272 .second) { |
| 254 LOG(ERROR) << "2 requestDevice() calls with the same thread_id (" | 273 LOG(ERROR) << "2 requestDevice() calls with the same thread_id (" |
| 255 << thread_id << ") and request_id (" << request_id | 274 << thread_id << ") and request_id (" << request_id |
| 256 << ") shouldn't arrive at the same BluetoothDispatcherHost."; | 275 << ") shouldn't arrive at the same BluetoothDispatcherHost."; |
| 257 bad_message::ReceivedBadMessage( | 276 bad_message::ReceivedBadMessage( |
| 258 this, bad_message::BDH_DUPLICATE_REQUEST_DEVICE_ID); | 277 this, bad_message::BDH_DUPLICATE_REQUEST_DEVICE_ID); |
| 259 } | 278 } |
| 260 adapter_->StartDiscoverySessionWithFilter( | 279 adapter_->StartDiscoverySessionWithFilter( |
| 261 ComputeScanFilter(filters), | 280 ComputeScanFilter(filters), |
| 262 base::Bind(&BluetoothDispatcherHost::OnDiscoverySessionStarted, | 281 base::Bind(&BluetoothDispatcherHost::OnDiscoverySessionStarted, |
| 263 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id), | 282 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id), |
| 264 base::Bind(&BluetoothDispatcherHost::OnDiscoverySessionStartedError, | 283 base::Bind(&BluetoothDispatcherHost::OnDiscoverySessionStartedError, |
| 265 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id)); | 284 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id)); |
| 266 } else { | 285 } else { |
| 267 DLOG(WARNING) << "No BluetoothAdapter. Can't serve requestDevice."; | 286 DLOG(WARNING) << "No BluetoothAdapter. Can't serve requestDevice."; |
| 287 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::NO_BLUETOOTH_ADAPTER); |
| 268 Send(new BluetoothMsg_RequestDeviceError( | 288 Send(new BluetoothMsg_RequestDeviceError( |
| 269 thread_id, request_id, WebBluetoothError::NoBluetoothAdapter)); | 289 thread_id, request_id, WebBluetoothError::NoBluetoothAdapter)); |
| 270 } | 290 } |
| 271 return; | 291 return; |
| 272 } | 292 } |
| 273 | 293 |
| 274 void BluetoothDispatcherHost::OnConnectGATT( | 294 void BluetoothDispatcherHost::OnConnectGATT( |
| 275 int thread_id, | 295 int thread_id, |
| 276 int request_id, | 296 int request_id, |
| 277 const std::string& device_instance_id) { | 297 const std::string& device_instance_id) { |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 base::Bind(&BluetoothDispatcherHost::StopDiscoverySession, | 525 base::Bind(&BluetoothDispatcherHost::StopDiscoverySession, |
| 506 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id, | 526 weak_ptr_factory_.GetWeakPtr(), thread_id, request_id, |
| 507 base::Passed(&discovery_session)), | 527 base::Passed(&discovery_session)), |
| 508 base::TimeDelta::FromSeconds(current_delay_time_)); | 528 base::TimeDelta::FromSeconds(current_delay_time_)); |
| 509 } | 529 } |
| 510 | 530 |
| 511 void BluetoothDispatcherHost::OnDiscoverySessionStartedError(int thread_id, | 531 void BluetoothDispatcherHost::OnDiscoverySessionStartedError(int thread_id, |
| 512 int request_id) { | 532 int request_id) { |
| 513 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 533 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 514 DLOG(WARNING) << "BluetoothDispatcherHost::OnDiscoverySessionStartedError"; | 534 DLOG(WARNING) << "BluetoothDispatcherHost::OnDiscoverySessionStartedError"; |
| 535 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::DISCOVERY_START_FAILED); |
| 515 Send(new BluetoothMsg_RequestDeviceError( | 536 Send(new BluetoothMsg_RequestDeviceError( |
| 516 thread_id, request_id, WebBluetoothError::DiscoverySessionStartFailed)); | 537 thread_id, request_id, WebBluetoothError::DiscoverySessionStartFailed)); |
| 517 request_device_sessions_.erase(std::make_pair(thread_id, request_id)); | 538 request_device_sessions_.erase(std::make_pair(thread_id, request_id)); |
| 518 } | 539 } |
| 519 | 540 |
| 520 void BluetoothDispatcherHost::StopDiscoverySession( | 541 void BluetoothDispatcherHost::StopDiscoverySession( |
| 521 int thread_id, | 542 int thread_id, |
| 522 int request_id, | 543 int request_id, |
| 523 scoped_ptr<device::BluetoothDiscoverySession> discovery_session) { | 544 scoped_ptr<device::BluetoothDiscoverySession> discovery_session) { |
| 524 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 545 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 542 device->GetAddress(), // instance_id | 563 device->GetAddress(), // instance_id |
| 543 device->GetName(), // name | 564 device->GetName(), // name |
| 544 device->GetBluetoothClass(), // device_class | 565 device->GetBluetoothClass(), // device_class |
| 545 device->GetVendorIDSource(), // vendor_id_source | 566 device->GetVendorIDSource(), // vendor_id_source |
| 546 device->GetVendorID(), // vendor_id | 567 device->GetVendorID(), // vendor_id |
| 547 device->GetProductID(), // product_id | 568 device->GetProductID(), // product_id |
| 548 device->GetDeviceID(), // product_version | 569 device->GetDeviceID(), // product_version |
| 549 device->IsPaired(), // paired | 570 device->IsPaired(), // paired |
| 550 content::BluetoothDevice::UUIDsFromBluetoothUUIDs( | 571 content::BluetoothDevice::UUIDsFromBluetoothUUIDs( |
| 551 device->GetUUIDs())); // uuids | 572 device->GetUUIDs())); // uuids |
| 573 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::SUCCESS); |
| 552 Send(new BluetoothMsg_RequestDeviceSuccess(thread_id, request_id, | 574 Send(new BluetoothMsg_RequestDeviceSuccess(thread_id, request_id, |
| 553 device_ipc)); | 575 device_ipc)); |
| 554 request_device_sessions_.erase(session); | 576 request_device_sessions_.erase(session); |
| 555 return; | 577 return; |
| 556 } | 578 } |
| 557 } | 579 } |
| 580 RecordRequestDeviceOutcome( |
| 581 UMARequestDeviceOutcome::NO_MATCHING_DEVICES_FOUND); |
| 558 Send(new BluetoothMsg_RequestDeviceError(thread_id, request_id, | 582 Send(new BluetoothMsg_RequestDeviceError(thread_id, request_id, |
| 559 WebBluetoothError::NoDevicesFound)); | 583 WebBluetoothError::NoDevicesFound)); |
| 560 request_device_sessions_.erase(session); | 584 request_device_sessions_.erase(session); |
| 561 } | 585 } |
| 562 | 586 |
| 563 void BluetoothDispatcherHost::OnDiscoverySessionStoppedError(int thread_id, | 587 void BluetoothDispatcherHost::OnDiscoverySessionStoppedError(int thread_id, |
| 564 int request_id) { | 588 int request_id) { |
| 565 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 589 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 566 DLOG(WARNING) << "BluetoothDispatcherHost::OnDiscoverySessionStoppedError"; | 590 DLOG(WARNING) << "BluetoothDispatcherHost::OnDiscoverySessionStoppedError"; |
| 591 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::DISCOVERY_STOP_FAILED); |
| 567 Send(new BluetoothMsg_RequestDeviceError( | 592 Send(new BluetoothMsg_RequestDeviceError( |
| 568 thread_id, request_id, WebBluetoothError::DiscoverySessionStopFailed)); | 593 thread_id, request_id, WebBluetoothError::DiscoverySessionStopFailed)); |
| 569 request_device_sessions_.erase(std::make_pair(thread_id, request_id)); | 594 request_device_sessions_.erase(std::make_pair(thread_id, request_id)); |
| 570 } | 595 } |
| 571 | 596 |
| 572 void BluetoothDispatcherHost::OnGATTConnectionCreated( | 597 void BluetoothDispatcherHost::OnGATTConnectionCreated( |
| 573 int thread_id, | 598 int thread_id, |
| 574 int request_id, | 599 int request_id, |
| 575 const std::string& device_instance_id, | 600 const std::string& device_instance_id, |
| 576 scoped_ptr<device::BluetoothGattConnection> connection) { | 601 scoped_ptr<device::BluetoothGattConnection> connection) { |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 649 | 674 |
| 650 void BluetoothDispatcherHost::OnWriteValueFailed( | 675 void BluetoothDispatcherHost::OnWriteValueFailed( |
| 651 int thread_id, | 676 int thread_id, |
| 652 int request_id, | 677 int request_id, |
| 653 device::BluetoothGattService::GattErrorCode error_code) { | 678 device::BluetoothGattService::GattErrorCode error_code) { |
| 654 Send(new BluetoothMsg_WriteCharacteristicValueError( | 679 Send(new BluetoothMsg_WriteCharacteristicValueError( |
| 655 thread_id, request_id, TranslateGATTError(error_code))); | 680 thread_id, request_id, TranslateGATTError(error_code))); |
| 656 } | 681 } |
| 657 | 682 |
| 658 } // namespace content | 683 } // namespace content |
| OLD | NEW |