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 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
290 } | 290 } |
291 create_gatt_connection_success_callbacks_.clear(); | 291 create_gatt_connection_success_callbacks_.clear(); |
292 create_gatt_connection_error_callbacks_.clear(); | 292 create_gatt_connection_error_callbacks_.clear(); |
293 } | 293 } |
294 | 294 |
295 void BluetoothDevice::DidFailToConnectGatt(ConnectErrorCode error) { | 295 void BluetoothDevice::DidFailToConnectGatt(ConnectErrorCode error) { |
296 for (const auto& error_callback : create_gatt_connection_error_callbacks_) | 296 for (const auto& error_callback : create_gatt_connection_error_callbacks_) |
297 error_callback.Run(error); | 297 error_callback.Run(error); |
298 create_gatt_connection_success_callbacks_.clear(); | 298 create_gatt_connection_success_callbacks_.clear(); |
299 create_gatt_connection_error_callbacks_.clear(); | 299 create_gatt_connection_error_callbacks_.clear(); |
300 | |
301 // TODO(ortuno): We shouldn't need to invalidate connections since | |
302 // DidFailToConnectGatt should only be called when a connection attempt | |
303 // fails and there are no connection objects. | |
304 // http://crbug.com/570850 | |
305 for (BluetoothGattConnection* connection : gatt_connections_) { | |
scheib
2016/01/15 01:39:45
DCHECK this instead.
ortuno
2016/01/15 21:34:41
Done.
| |
306 connection->InvalidateConnectionReference(); | |
307 } | |
308 gatt_connections_.clear(); | |
300 } | 309 } |
301 | 310 |
302 void BluetoothDevice::DidDisconnectGatt() { | 311 void BluetoothDevice::DidDisconnectGatt() { |
303 // Pending calls to connect GATT are not expected, if they were then | 312 // Pending calls to connect GATT are not expected, if they were then |
304 // DidFailToConnectGatt should be called. But in case callbacks exist | 313 // DidFailToConnectGatt should have been called. |
305 // flush them to ensure a consistent state. | 314 CHECK(!create_gatt_connection_error_callbacks_.size()); |
scheib
2016/01/15 01:39:44
If you use CHECK, please TODO and file a ship bloc
ortuno
2016/01/15 21:34:41
Done.
| |
306 if (create_gatt_connection_error_callbacks_.size() > 0) { | |
307 VLOG(1) << "Unexpected / unexplained DidDisconnectGatt call while " | |
308 "create_gatt_connection_error_callbacks_ are pending."; | |
309 } | |
310 DidFailToConnectGatt(ERROR_FAILED); | |
311 | 315 |
312 // Invalidate all BluetoothGattConnection objects. | 316 // Invalidate all BluetoothGattConnection objects. |
313 for (BluetoothGattConnection* connection : gatt_connections_) { | 317 for (BluetoothGattConnection* connection : gatt_connections_) { |
314 connection->InvalidateConnectionReference(); | 318 connection->InvalidateConnectionReference(); |
315 } | 319 } |
316 gatt_connections_.clear(); | 320 gatt_connections_.clear(); |
317 } | 321 } |
318 | 322 |
319 void BluetoothDevice::AddGattConnection(BluetoothGattConnection* connection) { | 323 void BluetoothDevice::AddGattConnection(BluetoothGattConnection* connection) { |
320 auto result = gatt_connections_.insert(connection); | 324 auto result = gatt_connections_.insert(connection); |
(...skipping 16 matching lines...) Expand all Loading... | |
337 base::BinaryValue::CreateWithCopiedBuffer(buffer, size)); | 341 base::BinaryValue::CreateWithCopiedBuffer(buffer, size)); |
338 } | 342 } |
339 | 343 |
340 void BluetoothDevice::Pair(PairingDelegate* pairing_delegate, | 344 void BluetoothDevice::Pair(PairingDelegate* pairing_delegate, |
341 const base::Closure& callback, | 345 const base::Closure& callback, |
342 const ConnectErrorCallback& error_callback) { | 346 const ConnectErrorCallback& error_callback) { |
343 NOTREACHED(); | 347 NOTREACHED(); |
344 } | 348 } |
345 | 349 |
346 } // namespace device | 350 } // namespace device |
OLD | NEW |