| 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.h" | 5 #include "device/bluetooth/bluetooth_device.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 | 236 |
| 237 bool BluetoothDevice::IsTrustable() const { | 237 bool BluetoothDevice::IsTrustable() const { |
| 238 // Sony PlayStation Dualshock3 | 238 // Sony PlayStation Dualshock3 |
| 239 if ((GetVendorID() == 0x054c && GetProductID() == 0x0268 && | 239 if ((GetVendorID() == 0x054c && GetProductID() == 0x0268 && |
| 240 GetName() == std::string("PLAYSTATION(R)3 Controller"))) | 240 GetName() == std::string("PLAYSTATION(R)3 Controller"))) |
| 241 return true; | 241 return true; |
| 242 | 242 |
| 243 return false; | 243 return false; |
| 244 } | 244 } |
| 245 | 245 |
| 246 BluetoothDevice::UUIDList BluetoothDevice::GetUUIDs() const { |
| 247 if (!IsGattConnected()) { |
| 248 return BluetoothDevice::UUIDList(advertised_uuids_.begin(), |
| 249 advertised_uuids_.end()); |
| 250 } |
| 251 |
| 252 if (IsGattServicesDiscoveryComplete()) { |
| 253 std::unordered_set<BluetoothUUID, BluetoothUUIDHash> local_uuids; |
| 254 for (const auto& gatt_service_pair : gatt_services_) { |
| 255 local_uuids.insert(gatt_service_pair.second->GetUUID()); |
| 256 } |
| 257 return BluetoothDevice::UUIDList(local_uuids.begin(), local_uuids.end()); |
| 258 } |
| 259 |
| 260 return BluetoothDevice::UUIDList(); |
| 261 } |
| 262 |
| 246 void BluetoothDevice::CreateGattConnection( | 263 void BluetoothDevice::CreateGattConnection( |
| 247 const GattConnectionCallback& callback, | 264 const GattConnectionCallback& callback, |
| 248 const ConnectErrorCallback& error_callback) { | 265 const ConnectErrorCallback& error_callback) { |
| 249 create_gatt_connection_success_callbacks_.push_back(callback); | 266 create_gatt_connection_success_callbacks_.push_back(callback); |
| 250 create_gatt_connection_error_callbacks_.push_back(error_callback); | 267 create_gatt_connection_error_callbacks_.push_back(error_callback); |
| 251 | 268 |
| 252 if (IsGattConnected()) | 269 if (IsGattConnected()) |
| 253 return DidConnectGatt(); | 270 return DidConnectGatt(); |
| 254 | 271 |
| 255 CreateGattConnectionImpl(); | 272 CreateGattConnectionImpl(); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 base::DictionaryValue::Iterator iter(*services_data_); | 343 base::DictionaryValue::Iterator iter(*services_data_); |
| 327 while (!iter.IsAtEnd()) { | 344 while (!iter.IsAtEnd()) { |
| 328 BluetoothUUID uuid(iter.key()); | 345 BluetoothUUID uuid(iter.key()); |
| 329 uuids.push_back(uuid); | 346 uuids.push_back(uuid); |
| 330 iter.Advance(); | 347 iter.Advance(); |
| 331 } | 348 } |
| 332 return uuids; | 349 return uuids; |
| 333 } | 350 } |
| 334 | 351 |
| 335 void BluetoothDevice::DidConnectGatt() { | 352 void BluetoothDevice::DidConnectGatt() { |
| 353 advertised_uuids_.clear(); |
| 336 for (const auto& callback : create_gatt_connection_success_callbacks_) { | 354 for (const auto& callback : create_gatt_connection_success_callbacks_) { |
| 337 callback.Run( | 355 callback.Run( |
| 338 base::WrapUnique(new BluetoothGattConnection(adapter_, GetAddress()))); | 356 base::WrapUnique(new BluetoothGattConnection(adapter_, GetAddress()))); |
| 339 } | 357 } |
| 340 create_gatt_connection_success_callbacks_.clear(); | 358 create_gatt_connection_success_callbacks_.clear(); |
| 341 create_gatt_connection_error_callbacks_.clear(); | 359 create_gatt_connection_error_callbacks_.clear(); |
| 342 GetAdapter()->NotifyDeviceChanged(this); | 360 GetAdapter()->NotifyDeviceChanged(this); |
| 343 } | 361 } |
| 344 | 362 |
| 345 void BluetoothDevice::DidFailToConnectGatt(ConnectErrorCode error) { | 363 void BluetoothDevice::DidFailToConnectGatt(ConnectErrorCode error) { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 const base::Closure& callback, | 415 const base::Closure& callback, |
| 398 const ConnectErrorCallback& error_callback) { | 416 const ConnectErrorCallback& error_callback) { |
| 399 NOTREACHED(); | 417 NOTREACHED(); |
| 400 } | 418 } |
| 401 | 419 |
| 402 void BluetoothDevice::UpdateTimestamp() { | 420 void BluetoothDevice::UpdateTimestamp() { |
| 403 last_update_time_ = base::Time::NowFromSystemTime(); | 421 last_update_time_ = base::Time::NowFromSystemTime(); |
| 404 } | 422 } |
| 405 | 423 |
| 406 } // namespace device | 424 } // namespace device |
| OLD | NEW |