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

Side by Side Diff: device/bluetooth/bluetooth_gatt_connection_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_connection_chromeos.h" 5 #include "device/bluetooth/bluetooth_gatt_connection_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"
11 #include "device/bluetooth/dbus/bluez_dbus_manager.h"
12 12
13 namespace chromeos { 13 namespace chromeos {
14 14
15 BluetoothGattConnectionChromeOS::BluetoothGattConnectionChromeOS( 15 BluetoothGattConnectionChromeOS::BluetoothGattConnectionChromeOS(
16 scoped_refptr<device::BluetoothAdapter> adapter, 16 scoped_refptr<device::BluetoothAdapter> adapter,
17 const std::string& device_address, 17 const std::string& device_address,
18 const dbus::ObjectPath& object_path) 18 const dbus::ObjectPath& object_path)
19 : BluetoothGattConnection(adapter.get(), device_address), 19 : BluetoothGattConnection(adapter.get(), device_address),
20 connected_(true), 20 connected_(true),
21 object_path_(object_path) { 21 object_path_(object_path) {
22 DCHECK(adapter_.get()); 22 DCHECK(adapter_.get());
23 DCHECK(!device_address_.empty()); 23 DCHECK(!device_address_.empty());
24 DCHECK(object_path_.IsValid()); 24 DCHECK(object_path_.IsValid());
25 25
26 DBusThreadManager::Get()->GetBluetoothDeviceClient()->AddObserver(this); 26 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->AddObserver(this);
27 } 27 }
28 28
29 BluetoothGattConnectionChromeOS::~BluetoothGattConnectionChromeOS() { 29 BluetoothGattConnectionChromeOS::~BluetoothGattConnectionChromeOS() {
30 DBusThreadManager::Get()->GetBluetoothDeviceClient()->RemoveObserver(this); 30 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->RemoveObserver(
31 this);
31 Disconnect(); 32 Disconnect();
32 } 33 }
33 34
34 bool BluetoothGattConnectionChromeOS::IsConnected() { 35 bool BluetoothGattConnectionChromeOS::IsConnected() {
35 // Lazily determine the activity state of the connection. If already 36 // Lazily determine the activity state of the connection. If already
36 // marked as inactive, then return false. Otherwise, explicitly mark 37 // marked as inactive, then return false. Otherwise, explicitly mark
37 // |connected_| as false if the device is removed or disconnected. We do this, 38 // |connected_| as false if the device is removed or disconnected. We do this,
38 // so that if this method is called during a call to DeviceRemoved or 39 // so that if this method is called during a call to DeviceRemoved or
39 // DeviceChanged somewhere else, it returns the correct status. 40 // DeviceChanged somewhere else, it returns the correct status.
40 if (!connected_) 41 if (!connected_)
41 return false; 42 return false;
42 43
43 BluetoothDeviceClient::Properties* properties = 44 bluez::BluetoothDeviceClient::Properties* properties =
44 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> 45 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties(
45 GetProperties(object_path_); 46 object_path_);
46 if (!properties || !properties->connected.value()) 47 if (!properties || !properties->connected.value())
47 connected_ = false; 48 connected_ = false;
48 49
49 return connected_; 50 return connected_;
50 } 51 }
51 52
52 void BluetoothGattConnectionChromeOS::Disconnect() { 53 void BluetoothGattConnectionChromeOS::Disconnect() {
53 if (!connected_) { 54 if (!connected_) {
54 VLOG(1) << "Connection already inactive."; 55 VLOG(1) << "Connection already inactive.";
55 return; 56 return;
(...skipping 19 matching lines...) Expand all
75 76
76 void BluetoothGattConnectionChromeOS::DevicePropertyChanged( 77 void BluetoothGattConnectionChromeOS::DevicePropertyChanged(
77 const dbus::ObjectPath& object_path, 78 const dbus::ObjectPath& object_path,
78 const std::string& property_name) { 79 const std::string& property_name) {
79 if (object_path != object_path_) 80 if (object_path != object_path_)
80 return; 81 return;
81 82
82 if (!connected_) 83 if (!connected_)
83 return; 84 return;
84 85
85 BluetoothDeviceClient::Properties* properties = 86 bluez::BluetoothDeviceClient::Properties* properties =
86 DBusThreadManager::Get()->GetBluetoothDeviceClient()-> 87 bluez::BluezDBusManager::Get()->GetBluetoothDeviceClient()->GetProperties(
87 GetProperties(object_path_); 88 object_path_);
88 89
89 if (!properties) { 90 if (!properties) {
90 connected_ = false; 91 connected_ = false;
91 return; 92 return;
92 } 93 }
93 94
94 if (property_name == properties->connected.name() && 95 if (property_name == properties->connected.name() &&
95 !properties->connected.value()) 96 !properties->connected.value())
96 connected_ = false; 97 connected_ = false;
97 98
98 // The remote device's bluetooth address may change if it is paired while 99 // The remote device's bluetooth address may change if it is paired while
99 // connected. 100 // connected.
100 if (property_name == properties->address.name()) 101 if (property_name == properties->address.name())
101 device_address_ = properties->address.value(); 102 device_address_ = properties->address.value();
102 } 103 }
103 104
104 } // namespace chromeos 105 } // namespace chromeos
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_gatt_connection_chromeos.h ('k') | device/bluetooth/bluetooth_gatt_notify_session_chromeos.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698