Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1374)

Unified Diff: chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_event_router.cc

Issue 1341103004: Handle change of BLE address after pairing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: ***ADDED BY MISTAKE, OMMIT *** Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_event_router.cc
diff --git a/chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_event_router.cc b/chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_event_router.cc
index eaa0564f3733e9848cddea5f78d9de9496e43919..8318cc63e423e6ec7194d177713fb77d1d055c48 100644
--- a/chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_event_router.cc
+++ b/chrome/browser/extensions/api/bluetooth_low_energy/bluetooth_low_energy_event_router.cc
@@ -247,16 +247,15 @@ void BluetoothLowEnergyEventRouter::Connect(
}
const std::string extension_id = extension->id();
- const std::string connect_id = extension_id + device_address;
- if (connecting_devices_.count(connect_id) != 0) {
- error_callback.Run(kStatusErrorInProgress);
- return;
- }
+ auto conn = FindConnection(extension_id, device_address);
- BluetoothLowEnergyConnection* conn =
- FindConnection(extension_id, device_address);
if (conn) {
+ if (conn->GetConnection()->InProgress()) {
+ error_callback.Run(kStatusErrorInProgress);
+ return;
+ }
+
if (conn->GetConnection()->IsConnected()) {
VLOG(1) << "Application already connected to device: " << device_address;
error_callback.Run(kStatusErrorAlreadyConnected);
@@ -274,19 +273,19 @@ void BluetoothLowEnergyEventRouter::Connect(
return;
}
- connecting_devices_.insert(connect_id);
- device->CreateGattConnection(
+ auto connection = device->CreateGattConnection(
base::Bind(&BluetoothLowEnergyEventRouter::OnCreateGattConnection,
- weak_ptr_factory_.GetWeakPtr(),
- persistent,
- extension_id,
- device_address,
- callback),
+ weak_ptr_factory_.GetWeakPtr(), persistent, extension_id,
+ device_address, callback),
base::Bind(&BluetoothLowEnergyEventRouter::OnConnectError,
- weak_ptr_factory_.GetWeakPtr(),
- extension_id,
- device_address,
+ weak_ptr_factory_.GetWeakPtr(), extension_id, device_address,
error_callback));
+
+ conn = new BluetoothLowEnergyConnection(persistent, extension_id,
+ connection.Pass());
+ ConnectionResourceManager* manager =
+ GetConnectionResourceManager(browser_context_);
+ manager->Add(conn);
}
void BluetoothLowEnergyEventRouter::Disconnect(
@@ -302,18 +301,18 @@ void BluetoothLowEnergyEventRouter::Disconnect(
}
const std::string extension_id = extension->id();
+ const std::string connect_id = extension_id + device_address;
BluetoothLowEnergyConnection* conn =
FindConnection(extension_id, device_address);
- if (!conn || !conn->GetConnection()->IsConnected()) {
+
+ if (!conn || (!conn->GetConnection()->IsConnected() &&
+ !conn->GetConnection()->InProgress())) {
VLOG(1) << "Application not connected to device: " << device_address;
error_callback.Run(kStatusErrorNotConnected);
return;
}
- conn->GetConnection()->Disconnect();
- VLOG(2) << "GATT connection terminated.";
-
if (!RemoveConnection(extension_id, device_address)) {
VLOG(1) << "The connection was removed before disconnect completed, id: "
<< extension_id << ", device: " << device_address;
@@ -1267,23 +1266,10 @@ void BluetoothLowEnergyEventRouter::OnCreateGattConnection(
bool persistent,
const std::string& extension_id,
const std::string& device_address,
- const base::Closure& callback,
- scoped_ptr<BluetoothGattConnection> connection) {
+ const base::Closure& callback) {
VLOG(2) << "GATT connection created.";
- DCHECK(connection.get());
- DCHECK(!FindConnection(extension_id, device_address));
- DCHECK_EQ(device_address, connection->GetDeviceAddress());
+ DCHECK(FindConnection(extension_id, device_address));
- const std::string connect_id = extension_id + device_address;
- DCHECK_NE(0U, connecting_devices_.count(connect_id));
-
- BluetoothLowEnergyConnection* conn = new BluetoothLowEnergyConnection(
- persistent, extension_id, connection.Pass());
- ConnectionResourceManager* manager =
- GetConnectionResourceManager(browser_context_);
- manager->Add(conn);
-
- connecting_devices_.erase(connect_id);
callback.Run();
}
@@ -1302,10 +1288,8 @@ void BluetoothLowEnergyEventRouter::OnConnectError(
BluetoothDevice::ConnectErrorCode error_code) {
VLOG(2) << "Failed to create GATT connection: " << error_code;
- const std::string connect_id = extension_id + device_address;
- DCHECK_NE(0U, connecting_devices_.count(connect_id));
+ RemoveConnection(extension_id, device_address);
- connecting_devices_.erase(connect_id);
Status error_status = kStatusErrorFailed;
if (error_code == BluetoothDevice::ERROR_INPROGRESS) {
error_status = kStatusErrorInProgress;

Powered by Google App Engine
This is Rietveld 408576698