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 <string> | 7 #include <string> |
8 | 8 |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 void BluetoothDevice::DidConnectGatt() { | 296 void BluetoothDevice::DidConnectGatt() { |
297 for (const auto& callback : create_gatt_connection_success_callbacks_) { | 297 for (const auto& callback : create_gatt_connection_success_callbacks_) { |
298 callback.Run( | 298 callback.Run( |
299 make_scoped_ptr(new BluetoothGattConnection(adapter_, GetAddress()))); | 299 make_scoped_ptr(new BluetoothGattConnection(adapter_, GetAddress()))); |
300 } | 300 } |
301 create_gatt_connection_success_callbacks_.clear(); | 301 create_gatt_connection_success_callbacks_.clear(); |
302 create_gatt_connection_error_callbacks_.clear(); | 302 create_gatt_connection_error_callbacks_.clear(); |
303 } | 303 } |
304 | 304 |
305 void BluetoothDevice::DidFailToConnectGatt(ConnectErrorCode error) { | 305 void BluetoothDevice::DidFailToConnectGatt(ConnectErrorCode error) { |
| 306 // Connection request should only be made if there are no active |
| 307 // connections. |
| 308 DCHECK(gatt_connections_.empty()); |
| 309 |
306 for (const auto& error_callback : create_gatt_connection_error_callbacks_) | 310 for (const auto& error_callback : create_gatt_connection_error_callbacks_) |
307 error_callback.Run(error); | 311 error_callback.Run(error); |
308 create_gatt_connection_success_callbacks_.clear(); | 312 create_gatt_connection_success_callbacks_.clear(); |
309 create_gatt_connection_error_callbacks_.clear(); | 313 create_gatt_connection_error_callbacks_.clear(); |
310 } | 314 } |
311 | 315 |
312 void BluetoothDevice::DidDisconnectGatt() { | 316 void BluetoothDevice::DidDisconnectGatt() { |
313 // Pending calls to connect GATT are not expected, if they were then | 317 // Pending calls to connect GATT are not expected, if they were then |
314 // DidFailToConnectGatt should be called. But in case callbacks exist | 318 // DidFailToConnectGatt should have been called. |
315 // flush them to ensure a consistent state. | 319 DCHECK(create_gatt_connection_error_callbacks_.empty()); |
316 if (create_gatt_connection_error_callbacks_.size() > 0) { | |
317 VLOG(1) << "Unexpected / unexplained DidDisconnectGatt call while " | |
318 "create_gatt_connection_error_callbacks_ are pending."; | |
319 } | |
320 DidFailToConnectGatt(ERROR_FAILED); | |
321 | 320 |
322 // Invalidate all BluetoothGattConnection objects. | 321 // Invalidate all BluetoothGattConnection objects. |
323 for (BluetoothGattConnection* connection : gatt_connections_) { | 322 for (BluetoothGattConnection* connection : gatt_connections_) { |
324 connection->InvalidateConnectionReference(); | 323 connection->InvalidateConnectionReference(); |
325 } | 324 } |
326 gatt_connections_.clear(); | 325 gatt_connections_.clear(); |
327 } | 326 } |
328 | 327 |
329 void BluetoothDevice::AddGattConnection(BluetoothGattConnection* connection) { | 328 void BluetoothDevice::AddGattConnection(BluetoothGattConnection* connection) { |
330 auto result = gatt_connections_.insert(connection); | 329 auto result = gatt_connections_.insert(connection); |
(...skipping 16 matching lines...) Expand all Loading... |
347 base::BinaryValue::CreateWithCopiedBuffer(buffer, size)); | 346 base::BinaryValue::CreateWithCopiedBuffer(buffer, size)); |
348 } | 347 } |
349 | 348 |
350 void BluetoothDevice::Pair(PairingDelegate* pairing_delegate, | 349 void BluetoothDevice::Pair(PairingDelegate* pairing_delegate, |
351 const base::Closure& callback, | 350 const base::Closure& callback, |
352 const ConnectErrorCallback& error_callback) { | 351 const ConnectErrorCallback& error_callback) { |
353 NOTREACHED(); | 352 NOTREACHED(); |
354 } | 353 } |
355 | 354 |
356 } // namespace device | 355 } // namespace device |
OLD | NEW |