diff options
author | sacomoto <sacomoto@chromium.org> | 2015-07-13 03:25:13 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-07-13 10:25:54 +0000 |
commit | 1115d224320f206cefc6cdaa660b0c811215575f (patch) | |
tree | 0c9952006933449e6358960ab955c16e032dc840 /components/proximity_auth | |
parent | 758d51959316cdbf4d4e5232b4fdc9d8c52adc98 (diff) | |
download | chromium_src-1115d224320f206cefc6cdaa660b0c811215575f.zip chromium_src-1115d224320f206cefc6cdaa660b0c811215575f.tar.gz chromium_src-1115d224320f206cefc6cdaa660b0c811215575f.tar.bz2 |
Cleaning up some log messages and adding new ones.
- Only call |BluetoothAdapter| observers if not disconnected (this was
polluting the log messages);
- Adding new log messages;
- Reseting the |authenticated_| flag after the connection is dropped;
- Removing some unused methods in BluetoothLowEnergyConnection.
BUG=
Review URL: https://codereview.chromium.org/1226203005
Cr-Commit-Position: refs/heads/master@{#338490}
Diffstat (limited to 'components/proximity_auth')
4 files changed, 28 insertions, 22 deletions
diff --git a/components/proximity_auth/ble/bluetooth_low_energy_connection.cc b/components/proximity_auth/ble/bluetooth_low_energy_connection.cc index e4959e8..a788fa2 100644 --- a/components/proximity_auth/ble/bluetooth_low_energy_connection.cc +++ b/components/proximity_auth/ble/bluetooth_low_energy_connection.cc @@ -104,6 +104,7 @@ void BluetoothLowEnergyConnection::Disconnect() { // Destroying BluetoothGattConnection also disconnects it. gatt_connection_.reset(); } + // Only transition to the DISCONNECTED state after perfoming all necessary // operations. Otherwise, it'll trigger observers that can pontentially // destroy the current instance (causing a crash). @@ -111,14 +112,6 @@ void BluetoothLowEnergyConnection::Disconnect() { } } -void BluetoothLowEnergyConnection::OnDisconnected() { - PA_LOG(INFO) << "Disconnected."; -} - -void BluetoothLowEnergyConnection::OnDisconnectError() { - PA_LOG(WARNING) << "Disconnection failed."; -} - void BluetoothLowEnergyConnection::SetSubStatus(SubStatus new_sub_status) { sub_status_ = new_sub_status; @@ -171,15 +164,25 @@ void BluetoothLowEnergyConnection::SendMessageImpl( // so the object can notify its observers put itself in the right state. void BluetoothLowEnergyConnection::DeviceChanged(BluetoothAdapter* adapter, BluetoothDevice* device) { + if (sub_status_ == SubStatus::DISCONNECTED) + return; + if (device && device->GetAddress() == GetRemoteDeviceAddress() && !device->IsConnected()) { - PA_LOG(INFO) << "GATT connection dropped " << GetRemoteDeviceAddress(); + PA_LOG(INFO) << "GATT connection dropped " << GetRemoteDeviceAddress() + << "\ndevice connected: " << device->IsConnected() + << "\ngatt connection: " + << (gatt_connection_ ? gatt_connection_->IsConnected() + : false); Disconnect(); } } void BluetoothLowEnergyConnection::DeviceRemoved(BluetoothAdapter* adapter, BluetoothDevice* device) { + if (sub_status_ == SubStatus::DISCONNECTED) + return; + if (device && device->GetAddress() == GetRemoteDeviceAddress()) { PA_LOG(INFO) << "Device removed " << GetRemoteDeviceAddress(); Disconnect(); @@ -190,6 +193,9 @@ void BluetoothLowEnergyConnection::GattCharacteristicValueChanged( BluetoothAdapter* adapter, BluetoothGattCharacteristic* characteristic, const std::vector<uint8>& value) { + if (sub_status_ == SubStatus::DISCONNECTED) + return; + DCHECK_EQ(adapter, adapter_.get()); PA_LOG(INFO) << "Characteristic value changed: " diff --git a/components/proximity_auth/ble/bluetooth_low_energy_connection.h b/components/proximity_auth/ble/bluetooth_low_energy_connection.h index 9a57608..a03ad65 100644 --- a/components/proximity_auth/ble/bluetooth_low_energy_connection.h +++ b/components/proximity_auth/ble/bluetooth_low_energy_connection.h @@ -137,12 +137,6 @@ class BluetoothLowEnergyConnection : public Connection, int number_of_failed_attempts; }; - // Called when the remote device is successfully disconnected. - void OnDisconnected(); - - // Called when there is an error disconnecting the remote device. - void OnDisconnectError(); - // Called when a GATT connection is created or received by the constructor. void OnGattConnectionCreated( scoped_ptr<device::BluetoothGattConnection> gatt_connection); diff --git a/components/proximity_auth/ble/bluetooth_low_energy_connection_finder.cc b/components/proximity_auth/ble/bluetooth_low_energy_connection_finder.cc index be966d0..5f9a59e 100644 --- a/components/proximity_auth/ble/bluetooth_low_energy_connection_finder.cc +++ b/components/proximity_auth/ble/bluetooth_low_energy_connection_finder.cc @@ -278,7 +278,8 @@ void BluetoothLowEnergyConnectionFinder::OnGattConnectionCreated( return; } - PA_LOG(INFO) << "GATT connection created"; + PA_LOG(INFO) << "GATT connection with " << gatt_connection->GetDeviceAddress() + << " created."; connected_ = true; pending_connections_.clear(); @@ -304,10 +305,8 @@ void BluetoothLowEnergyConnectionFinder::CompleteConnection() { void BluetoothLowEnergyConnectionFinder::CreateGattConnection( device::BluetoothDevice* remote_device) { - PA_LOG(INFO) << "SmartLock service found (" - << remote_service_uuid_.canonical_value() << ")\n" - << "device = " << remote_device->GetAddress() - << ", name = " << remote_device->GetName(); + PA_LOG(INFO) << "Creating GATT connection with " + << remote_device->GetAddress(); remote_device->CreateGattConnection( base::Bind(&BluetoothLowEnergyConnectionFinder::OnGattConnectionCreated, weak_ptr_factory_.GetWeakPtr()), @@ -319,6 +318,8 @@ void BluetoothLowEnergyConnectionFinder::CreateGattConnection( void BluetoothLowEnergyConnectionFinder::CloseGattConnection( scoped_ptr<device::BluetoothGattConnection> gatt_connection) { DCHECK(gatt_connection); + PA_LOG(INFO) << "Closing GATT connection with " + << gatt_connection->GetDeviceAddress(); // Destroying the BluetoothGattConnection also disconnects it. gatt_connection.reset(); @@ -358,6 +359,8 @@ void BluetoothLowEnergyConnectionFinder::OnConnectionStatusChanged( } void BluetoothLowEnergyConnectionFinder::RestartDiscoverySessionWhenReady() { + PA_LOG(INFO) << "Trying to restart discovery."; + // To restart scanning for devices, it's necessary to ensure that: // (i) the GATT connection to |remove_device_| is closed; // (ii) there is no pending call to @@ -366,6 +369,7 @@ void BluetoothLowEnergyConnectionFinder::RestartDiscoverySessionWhenReady() { // |discovery_session_| is reset. if ((!gatt_connection_ || !gatt_connection_->IsConnected()) && !discovery_session_) { + PA_LOG(INFO) << "Ready to start discovery."; connection_.reset(); connected_ = false; StartDiscoverySession(); diff --git a/components/proximity_auth/ble/proximity_auth_ble_system.cc b/components/proximity_auth/ble/proximity_auth_ble_system.cc index 0ff9653..790824a 100644 --- a/components/proximity_auth/ble/proximity_auth_ble_system.cc +++ b/components/proximity_auth/ble/proximity_auth_ble_system.cc @@ -296,6 +296,7 @@ void ProximityAuthBleSystem::OnConnectionStatusChanged( << new_status; if (old_status == Connection::CONNECTED && new_status == Connection::DISCONNECTED) { + device_authenticated_ = false; StopPollingScreenState(); // Note: it's not necessary to destroy the |connection_| here, as it's @@ -312,14 +313,13 @@ void ProximityAuthBleSystem::OnConnectionStatusChanged( } void ProximityAuthBleSystem::StartPollingScreenState() { - PA_LOG(INFO) << "Start polling."; + PA_LOG(INFO) << "Polling screen state."; if (is_polling_screen_state_) { if (!connection_ || !connection_->IsConnected()) { PA_LOG(INFO) << "Polling stopped."; is_polling_screen_state_ = false; return; } - // Sends message requesting screen state. connection_->SendMessage( make_scoped_ptr(new FakeWireMessage(kPollScreenState))); @@ -329,6 +329,8 @@ void ProximityAuthBleSystem::StartPollingScreenState() { FROM_HERE, base::Bind(&ProximityAuthBleSystem::StartPollingScreenState, weak_ptr_factory_.GetWeakPtr()), base::TimeDelta::FromSeconds(kPollingIntervalSeconds)); + + PA_LOG(INFO) << "Next poll iteration posted."; } } |