| 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 DCHECK(service_uuids_.empty()); |
| 249 return advertised_uuids_; |
| 250 } |
| 251 |
| 252 if (IsGattServicesDiscoveryComplete()) { |
| 253 DCHECK(advertised_uuids_.empty()); |
| 254 return service_uuids_; |
| 255 } |
| 256 |
| 257 DCHECK(service_uuids_.empty()); |
| 258 DCHECK(advertised_uuids_.empty()); |
| 259 return BluetoothDevice::UUIDList(); |
| 260 } |
| 261 |
| 246 void BluetoothDevice::CreateGattConnection( | 262 void BluetoothDevice::CreateGattConnection( |
| 247 const GattConnectionCallback& callback, | 263 const GattConnectionCallback& callback, |
| 248 const ConnectErrorCallback& error_callback) { | 264 const ConnectErrorCallback& error_callback) { |
| 249 create_gatt_connection_success_callbacks_.push_back(callback); | 265 create_gatt_connection_success_callbacks_.push_back(callback); |
| 250 create_gatt_connection_error_callbacks_.push_back(error_callback); | 266 create_gatt_connection_error_callbacks_.push_back(error_callback); |
| 251 | 267 |
| 252 if (IsGattConnected()) | 268 if (IsGattConnected()) |
| 253 return DidConnectGatt(); | 269 return DidConnectGatt(); |
| 254 | 270 |
| 255 CreateGattConnectionImpl(); | 271 CreateGattConnectionImpl(); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 base::DictionaryValue::Iterator iter(*services_data_); | 342 base::DictionaryValue::Iterator iter(*services_data_); |
| 327 while (!iter.IsAtEnd()) { | 343 while (!iter.IsAtEnd()) { |
| 328 BluetoothUUID uuid(iter.key()); | 344 BluetoothUUID uuid(iter.key()); |
| 329 uuids.push_back(uuid); | 345 uuids.push_back(uuid); |
| 330 iter.Advance(); | 346 iter.Advance(); |
| 331 } | 347 } |
| 332 return uuids; | 348 return uuids; |
| 333 } | 349 } |
| 334 | 350 |
| 335 void BluetoothDevice::DidConnectGatt() { | 351 void BluetoothDevice::DidConnectGatt() { |
| 352 advertised_uuids_.clear(); |
| 336 for (const auto& callback : create_gatt_connection_success_callbacks_) { | 353 for (const auto& callback : create_gatt_connection_success_callbacks_) { |
| 337 callback.Run( | 354 callback.Run( |
| 338 base::WrapUnique(new BluetoothGattConnection(adapter_, GetAddress()))); | 355 base::WrapUnique(new BluetoothGattConnection(adapter_, GetAddress()))); |
| 339 } | 356 } |
| 340 create_gatt_connection_success_callbacks_.clear(); | 357 create_gatt_connection_success_callbacks_.clear(); |
| 341 create_gatt_connection_error_callbacks_.clear(); | 358 create_gatt_connection_error_callbacks_.clear(); |
| 342 GetAdapter()->NotifyDeviceChanged(this); | 359 GetAdapter()->NotifyDeviceChanged(this); |
| 343 } | 360 } |
| 344 | 361 |
| 345 void BluetoothDevice::DidFailToConnectGatt(ConnectErrorCode error) { | 362 void BluetoothDevice::DidFailToConnectGatt(ConnectErrorCode error) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 372 } | 389 } |
| 373 | 390 |
| 374 void BluetoothDevice::RemoveGattConnection( | 391 void BluetoothDevice::RemoveGattConnection( |
| 375 BluetoothGattConnection* connection) { | 392 BluetoothGattConnection* connection) { |
| 376 size_t erased_count = gatt_connections_.erase(connection); | 393 size_t erased_count = gatt_connections_.erase(connection); |
| 377 DCHECK(erased_count); | 394 DCHECK(erased_count); |
| 378 if (gatt_connections_.size() == 0) | 395 if (gatt_connections_.size() == 0) |
| 379 DisconnectGatt(); | 396 DisconnectGatt(); |
| 380 } | 397 } |
| 381 | 398 |
| 399 void BluetoothDevice::UpdateServiceUUIDs() { |
| 400 std::unordered_set<BluetoothUUID, BluetoothUUIDHash> uuid_set; |
| 401 for (const auto& gatt_service_pair : gatt_services_) { |
| 402 uuid_set.insert(gatt_service_pair.second->GetUUID()); |
| 403 } |
| 404 service_uuids_ = UUIDList(uuid_set.begin(), uuid_set.end()); |
| 405 } |
| 406 |
| 382 void BluetoothDevice::ClearServiceData() { services_data_->Clear(); } | 407 void BluetoothDevice::ClearServiceData() { services_data_->Clear(); } |
| 383 | 408 |
| 384 void BluetoothDevice::SetServiceData(BluetoothUUID serviceUUID, | 409 void BluetoothDevice::SetServiceData(BluetoothUUID serviceUUID, |
| 385 const char* buffer, size_t size) { | 410 const char* buffer, size_t size) { |
| 386 services_data_->Set(serviceUUID.value(), | 411 services_data_->Set(serviceUUID.value(), |
| 387 base::BinaryValue::CreateWithCopiedBuffer(buffer, size)); | 412 base::BinaryValue::CreateWithCopiedBuffer(buffer, size)); |
| 388 } | 413 } |
| 389 | 414 |
| 390 void BluetoothDevice::SetAsExpiredForTesting() { | 415 void BluetoothDevice::SetAsExpiredForTesting() { |
| 391 last_update_time_ = | 416 last_update_time_ = |
| 392 base::Time::NowFromSystemTime() - | 417 base::Time::NowFromSystemTime() - |
| 393 (BluetoothAdapter::timeoutSec + base::TimeDelta::FromSeconds(1)); | 418 (BluetoothAdapter::timeoutSec + base::TimeDelta::FromSeconds(1)); |
| 394 } | 419 } |
| 395 | 420 |
| 396 void BluetoothDevice::Pair(PairingDelegate* pairing_delegate, | 421 void BluetoothDevice::Pair(PairingDelegate* pairing_delegate, |
| 397 const base::Closure& callback, | 422 const base::Closure& callback, |
| 398 const ConnectErrorCallback& error_callback) { | 423 const ConnectErrorCallback& error_callback) { |
| 399 NOTREACHED(); | 424 NOTREACHED(); |
| 400 } | 425 } |
| 401 | 426 |
| 402 void BluetoothDevice::UpdateTimestamp() { | 427 void BluetoothDevice::UpdateTimestamp() { |
| 403 last_update_time_ = base::Time::NowFromSystemTime(); | 428 last_update_time_ = base::Time::NowFromSystemTime(); |
| 404 } | 429 } |
| 405 | 430 |
| 406 } // namespace device | 431 } // namespace device |
| OLD | NEW |