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

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

Issue 1347193004: Refactor DBusThreadManager to split away BT clients. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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_chromeos.h" 5 #include "device/bluetooth/bluetooth_gatt_notify_session_chromeos.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "chromeos/dbus/dbus_thread_manager.h"
10 #include "device/bluetooth/bluetooth_adapter.h" 9 #include "device/bluetooth/bluetooth_adapter.h"
11 #include "device/bluetooth/bluetooth_device.h" 10 #include "device/bluetooth/bluetooth_device.h"
12 #include "device/bluetooth/bluetooth_gatt_service.h" 11 #include "device/bluetooth/bluetooth_gatt_service.h"
13 #include "device/bluetooth/bluetooth_remote_gatt_characteristic_chromeos.h" 12 #include "device/bluetooth/bluetooth_remote_gatt_characteristic_chromeos.h"
13 #include "device/bluetooth/dbus/bluez_dbus_manager.h"
14 14
15 namespace chromeos { 15 namespace chromeos {
16 16
17 BluetoothGattNotifySessionChromeOS::BluetoothGattNotifySessionChromeOS( 17 BluetoothGattNotifySessionChromeOS::BluetoothGattNotifySessionChromeOS(
18 scoped_refptr<device::BluetoothAdapter> adapter, 18 scoped_refptr<device::BluetoothAdapter> adapter,
19 const std::string& device_address, 19 const std::string& device_address,
20 const std::string& service_identifier, 20 const std::string& service_identifier,
21 const std::string& characteristic_identifier, 21 const std::string& characteristic_identifier,
22 const dbus::ObjectPath& characteristic_path) 22 const dbus::ObjectPath& characteristic_path)
23 : active_(true), 23 : active_(true),
24 adapter_(adapter), 24 adapter_(adapter),
25 device_address_(device_address), 25 device_address_(device_address),
26 service_id_(service_identifier), 26 service_id_(service_identifier),
27 characteristic_id_(characteristic_identifier), 27 characteristic_id_(characteristic_identifier),
28 object_path_(characteristic_path) { 28 object_path_(characteristic_path) {
29 DCHECK(adapter_.get()); 29 DCHECK(adapter_.get());
30 DCHECK(!device_address_.empty()); 30 DCHECK(!device_address_.empty());
31 DCHECK(!service_id_.empty()); 31 DCHECK(!service_id_.empty());
32 DCHECK(!characteristic_id_.empty()); 32 DCHECK(!characteristic_id_.empty());
33 DCHECK(object_path_.IsValid()); 33 DCHECK(object_path_.IsValid());
34 34
35 DBusThreadManager::Get()->GetBluetoothGattCharacteristicClient()->AddObserver( 35 bluez::BluezDBusManager::Get()
36 this); 36 ->GetBluetoothGattCharacteristicClient()
37 ->AddObserver(this);
37 } 38 }
38 39
39 BluetoothGattNotifySessionChromeOS::~BluetoothGattNotifySessionChromeOS() { 40 BluetoothGattNotifySessionChromeOS::~BluetoothGattNotifySessionChromeOS() {
40 DBusThreadManager::Get() 41 bluez::BluezDBusManager::Get()
41 ->GetBluetoothGattCharacteristicClient() 42 ->GetBluetoothGattCharacteristicClient()
42 ->RemoveObserver(this); 43 ->RemoveObserver(this);
43 Stop(base::Bind(&base::DoNothing)); 44 Stop(base::Bind(&base::DoNothing));
44 } 45 }
45 46
46 std::string BluetoothGattNotifySessionChromeOS::GetCharacteristicIdentifier() 47 std::string BluetoothGattNotifySessionChromeOS::GetCharacteristicIdentifier()
47 const { 48 const {
48 return characteristic_id_; 49 return characteristic_id_;
49 } 50 }
50 51
51 bool BluetoothGattNotifySessionChromeOS::IsActive() { 52 bool BluetoothGattNotifySessionChromeOS::IsActive() {
52 // Determine if the session is active. If |active_| is false, then it's 53 // Determine if the session is active. If |active_| is false, then it's
53 // been explicitly marked, so return false. 54 // been explicitly marked, so return false.
54 if (!active_) 55 if (!active_)
55 return false; 56 return false;
56 57
57 // The fact that |active_| is true doesn't mean that the session is 58 // The fact that |active_| is true doesn't mean that the session is
58 // actually active, since the characteristic might have stopped sending 59 // actually active, since the characteristic might have stopped sending
59 // notifications yet this method was called before we processed the 60 // notifications yet this method was called before we processed the
60 // observer event (e.g. because somebody else called this method in their 61 // observer event (e.g. because somebody else called this method in their
61 // BluetoothGattCharacteristicClient::Observer implementation, which was 62 // bluez::BluetoothGattCharacteristicClient::Observer implementation, which
63 // was
62 // called before ours). Check the client to see if notifications are still 64 // called before ours). Check the client to see if notifications are still
63 // being sent. 65 // being sent.
64 BluetoothGattCharacteristicClient::Properties* properties = 66 bluez::BluetoothGattCharacteristicClient::Properties* properties =
65 DBusThreadManager::Get() 67 bluez::BluezDBusManager::Get()
66 ->GetBluetoothGattCharacteristicClient() 68 ->GetBluetoothGattCharacteristicClient()
67 ->GetProperties(object_path_); 69 ->GetProperties(object_path_);
68 if (!properties || !properties->notifying.value()) 70 if (!properties || !properties->notifying.value())
69 active_ = false; 71 active_ = false;
70 72
71 return active_; 73 return active_;
72 } 74 }
73 75
74 void BluetoothGattNotifySessionChromeOS::Stop(const base::Closure& callback) { 76 void BluetoothGattNotifySessionChromeOS::Stop(const base::Closure& callback) {
75 if (!active_) { 77 if (!active_) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 110
109 void BluetoothGattNotifySessionChromeOS::GattCharacteristicPropertyChanged( 111 void BluetoothGattNotifySessionChromeOS::GattCharacteristicPropertyChanged(
110 const dbus::ObjectPath& object_path, 112 const dbus::ObjectPath& object_path,
111 const std::string& property_name) { 113 const std::string& property_name) {
112 if (object_path != object_path_) 114 if (object_path != object_path_)
113 return; 115 return;
114 116
115 if (!active_) 117 if (!active_)
116 return; 118 return;
117 119
118 BluetoothGattCharacteristicClient::Properties* properties = 120 bluez::BluetoothGattCharacteristicClient::Properties* properties =
119 DBusThreadManager::Get() 121 bluez::BluezDBusManager::Get()
120 ->GetBluetoothGattCharacteristicClient() 122 ->GetBluetoothGattCharacteristicClient()
121 ->GetProperties(object_path_); 123 ->GetProperties(object_path_);
122 if (!properties) { 124 if (!properties) {
123 active_ = false; 125 active_ = false;
124 return; 126 return;
125 } 127 }
126 128
127 if (property_name == properties->notifying.name() && 129 if (property_name == properties->notifying.name() &&
128 !properties->notifying.value()) 130 !properties->notifying.value())
129 active_ = false; 131 active_ = false;
130 } 132 }
131 133
132 } // namespace chromeos 134 } // namespace chromeos
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_gatt_notify_session_chromeos.h ('k') | device/bluetooth/bluetooth_pairing_chromeos.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698