OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "device/bluetooth/bluetooth_device_chromeos.h" | 5 #include "device/bluetooth/bluetooth_device_chromeos.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 // empty and we had something before. Some devices only answer this | 450 // empty and we had something before. Some devices only answer this |
451 // information while paired, and this callback could be called in any order if | 451 // information while paired, and this callback could be called in any order if |
452 // several calls to GetServiceRecords are made while initial pairing with the | 452 // several calls to GetServiceRecords are made while initial pairing with the |
453 // device. This requires more investigation. | 453 // device. This requires more investigation. |
454 for (BluetoothDeviceClient::ServiceMap::const_iterator i = | 454 for (BluetoothDeviceClient::ServiceMap::const_iterator i = |
455 service_map.begin(); i != service_map.end(); ++i) { | 455 service_map.begin(); i != service_map.end(); ++i) { |
456 service_records_.push_back( | 456 service_records_.push_back( |
457 new BluetoothServiceRecordChromeOS(address(), i->second)); | 457 new BluetoothServiceRecordChromeOS(address(), i->second)); |
458 } | 458 } |
459 service_records_loaded_ = true; | 459 service_records_loaded_ = true; |
460 OnServiceRecordsChanged(); | |
461 | 460 |
462 callback.Run(service_records_); | 461 callback.Run(service_records_); |
463 } | 462 } |
464 | 463 |
465 void BluetoothDeviceChromeOS::OnServiceRecordsChanged(void) { | |
466 // Update the BluetoothDevice::connectable_ property. | |
467 bool hid_normally_connectable = true; | |
468 bool hid_reconnect_initiate = true; | |
469 for (ServiceRecordList::const_iterator it = service_records_.begin(); | |
470 it != service_records_.end(); ++it) { | |
471 if ((*it)->SupportsHid()) { | |
472 // If there are several HID profiles, we assume the device is connectable | |
473 // if all them are connectable. | |
474 hid_normally_connectable = | |
475 hid_normally_connectable && (*it)->hid_normally_connectable(); | |
476 hid_reconnect_initiate = | |
477 hid_reconnect_initiate && (*it)->hid_reconnect_initiate(); | |
478 } | |
479 } | |
480 // The Bluetooth HID spec states that if HIDNormallyConnectable or | |
481 // HIDReconnectInitiate are not present in a HID profile, the value is false. | |
482 // Nevertheless, a device with both properties in false can't reconnect to the | |
483 // adapter and can't be reconnected from the adapter. To avoid problems with | |
484 // devices that don't export this properties we asume they are connectable. | |
485 connectable_ = hid_normally_connectable || !hid_reconnect_initiate; | |
486 VLOG(1) << "ServiceRecordsChanged for " << address_ | |
487 << ": connectable = " << connectable_; | |
488 } | |
489 | |
490 void BluetoothDeviceChromeOS::OnSetTrusted(bool success) { | 464 void BluetoothDeviceChromeOS::OnSetTrusted(bool success) { |
491 LOG_IF(WARNING, !success) << "Failed to set device as trusted: " << address_; | 465 LOG_IF(WARNING, !success) << "Failed to set device as trusted: " << address_; |
492 } | 466 } |
493 | 467 |
494 void BluetoothDeviceChromeOS::OnInitialGetServiceRecords( | 468 void BluetoothDeviceChromeOS::OnInitialGetServiceRecords( |
495 const base::Closure& callback, | 469 const base::Closure& callback, |
496 const ConnectErrorCallback& error_callback, | 470 const ConnectErrorCallback& error_callback, |
497 const ServiceRecordList& list) { | 471 const ServiceRecordList& list) { |
498 // Connect application-layer protocols. | 472 // Connect application-layer protocols. |
499 ConnectApplications(callback, error_callback); | 473 ConnectApplications(callback, error_callback); |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
847 } | 821 } |
848 | 822 |
849 | 823 |
850 // static | 824 // static |
851 BluetoothDeviceChromeOS* BluetoothDeviceChromeOS::Create( | 825 BluetoothDeviceChromeOS* BluetoothDeviceChromeOS::Create( |
852 BluetoothAdapterChromeOS* adapter) { | 826 BluetoothAdapterChromeOS* adapter) { |
853 return new BluetoothDeviceChromeOS(adapter); | 827 return new BluetoothDeviceChromeOS(adapter); |
854 } | 828 } |
855 | 829 |
856 } // namespace chromeos | 830 } // namespace chromeos |
OLD | NEW |