Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_gatt_notify_session.h" | 5 #include "device/bluetooth/bluetooth_gatt_notify_session.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | |
| 8 #include "base/logging.h" | |
| 9 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h" | |
| 10 | |
| 7 namespace device { | 11 namespace device { |
| 8 | 12 |
| 9 BluetoothGattNotifySession::BluetoothGattNotifySession() { | 13 BluetoothGattNotifySession::BluetoothGattNotifySession( |
| 14 base::WeakPtr<BluetoothRemoteGattCharacteristic> characteristic) | |
| 15 : characteristic_(characteristic), | |
| 16 characteristic_id_(characteristic.get() ? characteristic->GetIdentifier() | |
| 17 : std::string()), | |
| 18 active_(true) {} | |
| 19 | |
| 20 BluetoothGattNotifySession::~BluetoothGattNotifySession() { | |
| 21 if (active_) { | |
| 22 Stop(base::Bind(&base::DoNothing)); | |
| 23 } | |
| 10 } | 24 } |
| 11 | 25 |
| 12 BluetoothGattNotifySession::~BluetoothGattNotifySession() { | 26 std::string BluetoothGattNotifySession::GetCharacteristicIdentifier() const { |
| 27 return characteristic_id_; | |
| 28 } | |
| 29 | |
| 30 BluetoothRemoteGattCharacteristic* | |
| 31 BluetoothGattNotifySession::GetCharacteristic() const { | |
| 32 return characteristic_.get(); | |
| 33 } | |
| 34 | |
| 35 bool BluetoothGattNotifySession::IsActive() { | |
| 36 return active_ && characteristic_ != nullptr && | |
| 37 characteristic_->IsNotifying(); | |
| 38 } | |
| 39 | |
| 40 void BluetoothGattNotifySession::Stop(const base::Closure& callback) { | |
| 41 active_ = false; | |
| 42 if (characteristic_ != nullptr) { | |
| 43 characteristic_->StopNotifySession(this, callback); | |
| 44 } else { | |
| 45 callback.Run(); | |
|
ortuno
2016/08/09 21:57:55
nit: post a task. Could you also add a test to che
tommyt
2016/08/10 12:07:18
Done. I've added the StopNotifySession_AfterDelete
| |
| 46 } | |
| 13 } | 47 } |
| 14 | 48 |
| 15 } // namespace device | 49 } // namespace device |
| OLD | NEW |