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

Side by Side Diff: device/bluetooth/bluetooth_gatt_notify_session.cc

Issue 2051333004: Implement BluetoothGattNotifySession::Stop on Android, 2nd attempt (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase onto latest master Created 4 years, 4 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 unified diff | Download patch
OLDNEW
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"
rkc 2016/08/15 22:54:44 nit: #include "base/bind_helpers.h"?
tommyt 2016/08/16 07:46:49 I could certainly include that file, but may I ask
rkc 2016/08/16 07:48:08 base::DoNothing
tommyt 2016/08/16 07:54:08 Aha, that does make sense. I will add this line in
8 #include "base/logging.h"
9 #include "base/threading/thread_task_runner_handle.h"
10 #include "device/bluetooth/bluetooth_remote_gatt_characteristic.h"
11
7 namespace device { 12 namespace device {
8 13
9 BluetoothGattNotifySession::BluetoothGattNotifySession() { 14 BluetoothGattNotifySession::BluetoothGattNotifySession(
15 base::WeakPtr<BluetoothRemoteGattCharacteristic> characteristic)
16 : characteristic_(characteristic),
17 characteristic_id_(characteristic.get() ? characteristic->GetIdentifier()
18 : std::string()),
19 active_(true) {}
20
21 BluetoothGattNotifySession::~BluetoothGattNotifySession() {
22 if (active_) {
23 Stop(base::Bind(&base::DoNothing));
24 }
10 } 25 }
11 26
12 BluetoothGattNotifySession::~BluetoothGattNotifySession() { 27 std::string BluetoothGattNotifySession::GetCharacteristicIdentifier() const {
28 return characteristic_id_;
29 }
30
31 BluetoothRemoteGattCharacteristic*
32 BluetoothGattNotifySession::GetCharacteristic() const {
33 return characteristic_.get();
34 }
35
36 bool BluetoothGattNotifySession::IsActive() {
37 return active_ && characteristic_ != nullptr &&
38 characteristic_->IsNotifying();
39 }
40
41 void BluetoothGattNotifySession::Stop(const base::Closure& callback) {
42 active_ = false;
43 if (characteristic_ != nullptr) {
44 characteristic_->StopNotifySession(this, callback);
45 } else {
46 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, callback);
47 }
13 } 48 }
14 49
15 } // namespace device 50 } // namespace device
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_gatt_notify_session.h ('k') | device/bluetooth/bluetooth_gatt_notify_session_android.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698