OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 // ID Not In Map Note: | 5 // ID Not In Map Note: |
6 // A service, characteristic, or descriptor ID not in the corresponding | 6 // A service, characteristic, or descriptor ID not in the corresponding |
7 // WebBluetoothServiceImpl map [service_id_to_device_address_, | 7 // WebBluetoothServiceImpl map [service_id_to_device_address_, |
8 // characteristic_id_to_service_id_, descriptor_to_characteristic_] implies a | 8 // characteristic_id_to_service_id_, descriptor_to_characteristic_] implies a |
9 // hostile renderer because a renderer obtains the corresponding ID from this | 9 // hostile renderer because a renderer obtains the corresponding ID from this |
10 // class and it will be added to the map at that time. | 10 // class and it will be added to the map at that time. |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 | 238 |
239 void WebBluetoothServiceImpl::GattServicesDiscovered( | 239 void WebBluetoothServiceImpl::GattServicesDiscovered( |
240 device::BluetoothAdapter* adapter, | 240 device::BluetoothAdapter* adapter, |
241 device::BluetoothDevice* device) { | 241 device::BluetoothDevice* device) { |
242 if (device_chooser_controller_.get()) { | 242 if (device_chooser_controller_.get()) { |
243 device_chooser_controller_->AddFilteredDevice(*device); | 243 device_chooser_controller_->AddFilteredDevice(*device); |
244 } | 244 } |
245 | 245 |
246 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 246 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
247 const std::string& device_address = device->GetAddress(); | 247 const std::string& device_address = device->GetAddress(); |
248 VLOG(1) << "Services discovered for device: " << device_address; | 248 DVLOG(1) << "Services discovered for device: " << device_address; |
249 | 249 |
250 auto iter = pending_primary_services_requests_.find(device_address); | 250 auto iter = pending_primary_services_requests_.find(device_address); |
251 if (iter == pending_primary_services_requests_.end()) { | 251 if (iter == pending_primary_services_requests_.end()) { |
252 return; | 252 return; |
253 } | 253 } |
254 std::vector<PrimaryServicesRequestCallback> requests = | 254 std::vector<PrimaryServicesRequestCallback> requests = |
255 std::move(iter->second); | 255 std::move(iter->second); |
256 pending_primary_services_requests_.erase(iter); | 256 pending_primary_services_requests_.erase(iter); |
257 | 257 |
258 for (const PrimaryServicesRequestCallback& request : requests) { | 258 for (const PrimaryServicesRequestCallback& request : requests) { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 | 333 |
334 const CacheQueryResult query_result = QueryCacheForDevice(device_id); | 334 const CacheQueryResult query_result = QueryCacheForDevice(device_id); |
335 | 335 |
336 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { | 336 if (query_result.outcome != CacheQueryOutcome::SUCCESS) { |
337 RecordConnectGATTOutcome(query_result.outcome); | 337 RecordConnectGATTOutcome(query_result.outcome); |
338 callback.Run(query_result.GetWebResult()); | 338 callback.Run(query_result.GetWebResult()); |
339 return; | 339 return; |
340 } | 340 } |
341 | 341 |
342 if (connected_devices_->IsConnectedToDeviceWithId(device_id)) { | 342 if (connected_devices_->IsConnectedToDeviceWithId(device_id)) { |
343 VLOG(1) << "Already connected."; | 343 DVLOG(1) << "Already connected."; |
344 callback.Run(blink::mojom::WebBluetoothResult::SUCCESS); | 344 callback.Run(blink::mojom::WebBluetoothResult::SUCCESS); |
345 return; | 345 return; |
346 } | 346 } |
347 | 347 |
348 // It's possible for WebBluetoothServiceImpl to issue two successive | 348 // It's possible for WebBluetoothServiceImpl to issue two successive |
349 // connection requests for which it would get two successive responses | 349 // connection requests for which it would get two successive responses |
350 // and consequently try to insert two BluetoothGattConnections for the | 350 // and consequently try to insert two BluetoothGattConnections for the |
351 // same device. WebBluetoothServiceImpl should reject or queue connection | 351 // same device. WebBluetoothServiceImpl should reject or queue connection |
352 // requests if there is a pending connection already, but the platform | 352 // requests if there is a pending connection already, but the platform |
353 // abstraction doesn't currently support checking for pending connections. | 353 // abstraction doesn't currently support checking for pending connections. |
354 // TODO(ortuno): CHECK that this never happens once the platform | 354 // TODO(ortuno): CHECK that this never happens once the platform |
355 // abstraction allows to check for pending connections. | 355 // abstraction allows to check for pending connections. |
356 // http://crbug.com/583544 | 356 // http://crbug.com/583544 |
357 const base::TimeTicks start_time = base::TimeTicks::Now(); | 357 const base::TimeTicks start_time = base::TimeTicks::Now(); |
358 query_result.device->CreateGattConnection( | 358 query_result.device->CreateGattConnection( |
359 base::Bind(&WebBluetoothServiceImpl::OnCreateGATTConnectionSuccess, | 359 base::Bind(&WebBluetoothServiceImpl::OnCreateGATTConnectionSuccess, |
360 weak_ptr_factory_.GetWeakPtr(), device_id, start_time, | 360 weak_ptr_factory_.GetWeakPtr(), device_id, start_time, |
361 callback), | 361 callback), |
362 base::Bind(&WebBluetoothServiceImpl::OnCreateGATTConnectionFailed, | 362 base::Bind(&WebBluetoothServiceImpl::OnCreateGATTConnectionFailed, |
363 weak_ptr_factory_.GetWeakPtr(), start_time, callback)); | 363 weak_ptr_factory_.GetWeakPtr(), start_time, callback)); |
364 } | 364 } |
365 | 365 |
366 void WebBluetoothServiceImpl::RemoteServerDisconnect( | 366 void WebBluetoothServiceImpl::RemoteServerDisconnect( |
367 const WebBluetoothDeviceId& device_id) { | 367 const WebBluetoothDeviceId& device_id) { |
368 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 368 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
369 RecordWebBluetoothFunctionCall( | 369 RecordWebBluetoothFunctionCall( |
370 UMAWebBluetoothFunction::REMOTE_GATT_SERVER_DISCONNECT); | 370 UMAWebBluetoothFunction::REMOTE_GATT_SERVER_DISCONNECT); |
371 | 371 |
372 if (connected_devices_->IsConnectedToDeviceWithId(device_id)) { | 372 if (connected_devices_->IsConnectedToDeviceWithId(device_id)) { |
373 VLOG(1) << "Disconnecting device: " << device_id.str(); | 373 DVLOG(1) << "Disconnecting device: " << device_id.str(); |
374 connected_devices_->CloseConnectionToDeviceWithId(device_id); | 374 connected_devices_->CloseConnectionToDeviceWithId(device_id); |
375 } | 375 } |
376 } | 376 } |
377 | 377 |
378 void WebBluetoothServiceImpl::RemoteServerGetPrimaryServices( | 378 void WebBluetoothServiceImpl::RemoteServerGetPrimaryServices( |
379 const WebBluetoothDeviceId& device_id, | 379 const WebBluetoothDeviceId& device_id, |
380 blink::mojom::WebBluetoothGATTQueryQuantity quantity, | 380 blink::mojom::WebBluetoothGATTQueryQuantity quantity, |
381 const base::Optional<BluetoothUUID>& services_uuid, | 381 const base::Optional<BluetoothUUID>& services_uuid, |
382 const RemoteServerGetPrimaryServicesCallback& callback) { | 382 const RemoteServerGetPrimaryServicesCallback& callback) { |
383 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 383 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 const std::string& device_address = query_result.device->GetAddress(); | 419 const std::string& device_address = query_result.device->GetAddress(); |
420 | 420 |
421 // We can't know if a service is present or not until GATT service discovery | 421 // We can't know if a service is present or not until GATT service discovery |
422 // is complete for the device. | 422 // is complete for the device. |
423 if (query_result.device->IsGattServicesDiscoveryComplete()) { | 423 if (query_result.device->IsGattServicesDiscoveryComplete()) { |
424 RemoteServerGetPrimaryServicesImpl(device_id, quantity, services_uuid, | 424 RemoteServerGetPrimaryServicesImpl(device_id, quantity, services_uuid, |
425 callback, query_result.device); | 425 callback, query_result.device); |
426 return; | 426 return; |
427 } | 427 } |
428 | 428 |
429 VLOG(1) << "Services not yet discovered."; | 429 DVLOG(1) << "Services not yet discovered."; |
430 pending_primary_services_requests_[device_address].push_back(base::Bind( | 430 pending_primary_services_requests_[device_address].push_back(base::Bind( |
431 &WebBluetoothServiceImpl::RemoteServerGetPrimaryServicesImpl, | 431 &WebBluetoothServiceImpl::RemoteServerGetPrimaryServicesImpl, |
432 base::Unretained(this), device_id, quantity, services_uuid, callback)); | 432 base::Unretained(this), device_id, quantity, services_uuid, callback)); |
433 } | 433 } |
434 | 434 |
435 void WebBluetoothServiceImpl::RemoteServiceGetCharacteristics( | 435 void WebBluetoothServiceImpl::RemoteServiceGetCharacteristics( |
436 const std::string& service_instance_id, | 436 const std::string& service_instance_id, |
437 blink::mojom::WebBluetoothGATTQueryQuantity quantity, | 437 blink::mojom::WebBluetoothGATTQueryQuantity quantity, |
438 const base::Optional<BluetoothUUID>& characteristics_uuid, | 438 const base::Optional<BluetoothUUID>& characteristics_uuid, |
439 const RemoteServiceGetCharacteristicsCallback& callback) { | 439 const RemoteServiceGetCharacteristicsCallback& callback) { |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
725 service_ptr->instance_id = service_instance_id; | 725 service_ptr->instance_id = service_instance_id; |
726 service_ptr->uuid = service->GetUUID().canonical_value(); | 726 service_ptr->uuid = service->GetUUID().canonical_value(); |
727 response_services.push_back(std::move(service_ptr)); | 727 response_services.push_back(std::move(service_ptr)); |
728 | 728 |
729 if (quantity == blink::mojom::WebBluetoothGATTQueryQuantity::SINGLE) { | 729 if (quantity == blink::mojom::WebBluetoothGATTQueryQuantity::SINGLE) { |
730 break; | 730 break; |
731 } | 731 } |
732 } | 732 } |
733 | 733 |
734 if (!response_services.empty()) { | 734 if (!response_services.empty()) { |
735 VLOG(1) << "Services found in device."; | 735 DVLOG(1) << "Services found in device."; |
736 RecordGetPrimaryServicesOutcome(quantity, | 736 RecordGetPrimaryServicesOutcome(quantity, |
737 UMAGetPrimaryServiceOutcome::SUCCESS); | 737 UMAGetPrimaryServiceOutcome::SUCCESS); |
738 callback.Run(blink::mojom::WebBluetoothResult::SUCCESS, | 738 callback.Run(blink::mojom::WebBluetoothResult::SUCCESS, |
739 std::move(response_services)); | 739 std::move(response_services)); |
740 return; | 740 return; |
741 } | 741 } |
742 | 742 |
743 VLOG(1) << "Services not found in device."; | 743 DVLOG(1) << "Services not found in device."; |
744 RecordGetPrimaryServicesOutcome( | 744 RecordGetPrimaryServicesOutcome( |
745 quantity, services_uuid ? UMAGetPrimaryServiceOutcome::NOT_FOUND | 745 quantity, services_uuid ? UMAGetPrimaryServiceOutcome::NOT_FOUND |
746 : UMAGetPrimaryServiceOutcome::NO_SERVICES); | 746 : UMAGetPrimaryServiceOutcome::NO_SERVICES); |
747 callback.Run(services_uuid | 747 callback.Run(services_uuid |
748 ? blink::mojom::WebBluetoothResult::SERVICE_NOT_FOUND | 748 ? blink::mojom::WebBluetoothResult::SERVICE_NOT_FOUND |
749 : blink::mojom::WebBluetoothResult::NO_SERVICES_FOUND, | 749 : blink::mojom::WebBluetoothResult::NO_SERVICES_FOUND, |
750 base::nullopt /* services */); | 750 base::nullopt /* services */); |
751 } | 751 } |
752 | 752 |
753 void WebBluetoothServiceImpl::OnGetDeviceSuccess( | 753 void WebBluetoothServiceImpl::OnGetDeviceSuccess( |
754 const RequestDeviceCallback& callback, | 754 const RequestDeviceCallback& callback, |
755 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options, | 755 blink::mojom::WebBluetoothRequestDeviceOptionsPtr options, |
756 const std::string& device_address) { | 756 const std::string& device_address) { |
757 device_chooser_controller_.reset(); | 757 device_chooser_controller_.reset(); |
758 | 758 |
759 const device::BluetoothDevice* const device = | 759 const device::BluetoothDevice* const device = |
760 GetAdapter()->GetDevice(device_address); | 760 GetAdapter()->GetDevice(device_address); |
761 if (device == nullptr) { | 761 if (device == nullptr) { |
762 VLOG(1) << "Device " << device_address << " no longer in adapter"; | 762 DVLOG(1) << "Device " << device_address << " no longer in adapter"; |
763 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::CHOSEN_DEVICE_VANISHED); | 763 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::CHOSEN_DEVICE_VANISHED); |
764 callback.Run(blink::mojom::WebBluetoothResult::CHOSEN_DEVICE_VANISHED, | 764 callback.Run(blink::mojom::WebBluetoothResult::CHOSEN_DEVICE_VANISHED, |
765 nullptr /* device */); | 765 nullptr /* device */); |
766 return; | 766 return; |
767 } | 767 } |
768 | 768 |
769 const WebBluetoothDeviceId device_id_for_origin = | 769 const WebBluetoothDeviceId device_id_for_origin = |
770 allowed_devices_map_.AddDevice(GetOrigin(), device_address, options); | 770 allowed_devices_map_.AddDevice(GetOrigin(), device_address, options); |
771 | 771 |
772 VLOG(1) << "Device: " << device->GetNameForDisplay(); | 772 DVLOG(1) << "Device: " << device->GetNameForDisplay(); |
773 | 773 |
774 blink::mojom::WebBluetoothDevicePtr device_ptr = | 774 blink::mojom::WebBluetoothDevicePtr device_ptr = |
775 blink::mojom::WebBluetoothDevice::New(); | 775 blink::mojom::WebBluetoothDevice::New(); |
776 device_ptr->id = device_id_for_origin; | 776 device_ptr->id = device_id_for_origin; |
777 device_ptr->name = device->GetName(); | 777 device_ptr->name = device->GetName(); |
778 | 778 |
779 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::SUCCESS); | 779 RecordRequestDeviceOutcome(UMARequestDeviceOutcome::SUCCESS); |
780 callback.Run(blink::mojom::WebBluetoothResult::SUCCESS, | 780 callback.Run(blink::mojom::WebBluetoothResult::SUCCESS, |
781 std::move(device_ptr)); | 781 std::move(device_ptr)); |
782 } | 782 } |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
978 characteristic_id_to_service_id_.clear(); | 978 characteristic_id_to_service_id_.clear(); |
979 service_id_to_device_address_.clear(); | 979 service_id_to_device_address_.clear(); |
980 connected_devices_.reset( | 980 connected_devices_.reset( |
981 new FrameConnectedBluetoothDevices(render_frame_host_)); | 981 new FrameConnectedBluetoothDevices(render_frame_host_)); |
982 allowed_devices_map_ = BluetoothAllowedDevicesMap(); | 982 allowed_devices_map_ = BluetoothAllowedDevicesMap(); |
983 device_chooser_controller_.reset(); | 983 device_chooser_controller_.reset(); |
984 BluetoothAdapterFactoryWrapper::Get().ReleaseAdapter(this); | 984 BluetoothAdapterFactoryWrapper::Get().ReleaseAdapter(this); |
985 } | 985 } |
986 | 986 |
987 } // namespace content | 987 } // namespace content |
OLD | NEW |