| 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 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 return uuids; | 328 return uuids; |
| 329 } | 329 } |
| 330 | 330 |
| 331 void BluetoothDevice::DidConnectGatt() { | 331 void BluetoothDevice::DidConnectGatt() { |
| 332 for (const auto& callback : create_gatt_connection_success_callbacks_) { | 332 for (const auto& callback : create_gatt_connection_success_callbacks_) { |
| 333 callback.Run( | 333 callback.Run( |
| 334 base::WrapUnique(new BluetoothGattConnection(adapter_, GetAddress()))); | 334 base::WrapUnique(new BluetoothGattConnection(adapter_, GetAddress()))); |
| 335 } | 335 } |
| 336 create_gatt_connection_success_callbacks_.clear(); | 336 create_gatt_connection_success_callbacks_.clear(); |
| 337 create_gatt_connection_error_callbacks_.clear(); | 337 create_gatt_connection_error_callbacks_.clear(); |
| 338 GetAdapter()->NotifyDeviceChanged(this); |
| 338 } | 339 } |
| 339 | 340 |
| 340 void BluetoothDevice::DidFailToConnectGatt(ConnectErrorCode error) { | 341 void BluetoothDevice::DidFailToConnectGatt(ConnectErrorCode error) { |
| 341 // Connection request should only be made if there are no active | 342 // Connection request should only be made if there are no active |
| 342 // connections. | 343 // connections. |
| 343 DCHECK(gatt_connections_.empty()); | 344 DCHECK(gatt_connections_.empty()); |
| 344 | 345 |
| 345 for (const auto& error_callback : create_gatt_connection_error_callbacks_) | 346 for (const auto& error_callback : create_gatt_connection_error_callbacks_) |
| 346 error_callback.Run(error); | 347 error_callback.Run(error); |
| 347 create_gatt_connection_success_callbacks_.clear(); | 348 create_gatt_connection_success_callbacks_.clear(); |
| 348 create_gatt_connection_error_callbacks_.clear(); | 349 create_gatt_connection_error_callbacks_.clear(); |
| 349 } | 350 } |
| 350 | 351 |
| 351 void BluetoothDevice::DidDisconnectGatt() { | 352 void BluetoothDevice::DidDisconnectGatt() { |
| 352 // Pending calls to connect GATT are not expected, if they were then | 353 // Pending calls to connect GATT are not expected, if they were then |
| 353 // DidFailToConnectGatt should have been called. | 354 // DidFailToConnectGatt should have been called. |
| 354 DCHECK(create_gatt_connection_error_callbacks_.empty()); | 355 DCHECK(create_gatt_connection_error_callbacks_.empty()); |
| 355 | 356 |
| 356 // Invalidate all BluetoothGattConnection objects. | 357 // Invalidate all BluetoothGattConnection objects. |
| 357 for (BluetoothGattConnection* connection : gatt_connections_) { | 358 for (BluetoothGattConnection* connection : gatt_connections_) { |
| 358 connection->InvalidateConnectionReference(); | 359 connection->InvalidateConnectionReference(); |
| 359 } | 360 } |
| 360 gatt_connections_.clear(); | 361 gatt_connections_.clear(); |
| 362 GetAdapter()->NotifyDeviceChanged(this); |
| 361 } | 363 } |
| 362 | 364 |
| 363 void BluetoothDevice::AddGattConnection(BluetoothGattConnection* connection) { | 365 void BluetoothDevice::AddGattConnection(BluetoothGattConnection* connection) { |
| 364 auto result = gatt_connections_.insert(connection); | 366 auto result = gatt_connections_.insert(connection); |
| 365 DCHECK(result.second); // Check insert happened; there was no duplicate. | 367 DCHECK(result.second); // Check insert happened; there was no duplicate. |
| 366 } | 368 } |
| 367 | 369 |
| 368 void BluetoothDevice::RemoveGattConnection( | 370 void BluetoothDevice::RemoveGattConnection( |
| 369 BluetoothGattConnection* connection) { | 371 BluetoothGattConnection* connection) { |
| 370 size_t erased_count = gatt_connections_.erase(connection); | 372 size_t erased_count = gatt_connections_.erase(connection); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 381 base::BinaryValue::CreateWithCopiedBuffer(buffer, size)); | 383 base::BinaryValue::CreateWithCopiedBuffer(buffer, size)); |
| 382 } | 384 } |
| 383 | 385 |
| 384 void BluetoothDevice::Pair(PairingDelegate* pairing_delegate, | 386 void BluetoothDevice::Pair(PairingDelegate* pairing_delegate, |
| 385 const base::Closure& callback, | 387 const base::Closure& callback, |
| 386 const ConnectErrorCallback& error_callback) { | 388 const ConnectErrorCallback& error_callback) { |
| 387 NOTREACHED(); | 389 NOTREACHED(); |
| 388 } | 390 } |
| 389 | 391 |
| 390 } // namespace device | 392 } // namespace device |
| OLD | NEW |