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

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

Issue 1292263002: bluetooth: Create base class BluetoothDevice::CreateGattConnection impl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bt-adapter-
Patch Set: Updated patchset dependency Created 5 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_connection.h" 5 #include "device/bluetooth/bluetooth_gatt_connection.h"
6 6
7 #include "device/bluetooth/bluetooth_adapter.h"
8
7 namespace device { 9 namespace device {
8 10
9 BluetoothGattConnection::BluetoothGattConnection() { 11 BluetoothGattConnection::BluetoothGattConnection(
12 BluetoothAdapter* adapter,
13 const std::string& device_address)
14 : adapter_(adapter), device_address_(device_address) {
15 DCHECK(adapter_.get());
16 DCHECK(!device_address_.empty());
17
18 BluetoothDevice* device = adapter_->GetDevice(device_address_);
19 if (device)
Jeffrey Yasskin 2015/08/19 22:49:45 If !device, IsConnected() should probably return f
scheib 2015/09/13 02:40:28 Done.
20 device->IncrementGattConnectionReferenceCount();
10 } 21 }
11 22
12 BluetoothGattConnection::~BluetoothGattConnection() { 23 BluetoothGattConnection::~BluetoothGattConnection() {
24 Disconnect();
25 }
26
27 std::string BluetoothGattConnection::GetDeviceAddress() const {
Jeffrey Yasskin 2015/08/19 22:49:46 Return a const std::string&?
scheib 2015/09/13 02:40:28 Done.
28 return device_address_;
29 }
30
31 bool BluetoothGattConnection::IsConnected() {
32 return !already_decremented_connection_reference_on_device_ &&
33 adapter_->GetDevice(device_address_)->IsGattConnected();
Jeffrey Yasskin 2015/08/19 22:49:46 This leads to an interesting situation where: 1) w
Jeffrey Yasskin 2015/08/19 22:49:46 Do you need to check for adapter_->GetDevice() ret
scheib 2015/09/13 02:40:28 Done - refactored reference counting to have point
scheib 2015/09/13 02:40:28 Done.
34 }
35
36 void BluetoothGattConnection::Disconnect() {
37 if (already_decremented_connection_reference_on_device_)
38 return;
39
40 already_decremented_connection_reference_on_device_ = true;
41 BluetoothDevice* device = adapter_->GetDevice(device_address_);
42 if (device)
43 device->DecrementGattConnectionReferenceCount();
13 } 44 }
14 45
15 } // namespace device 46 } // namespace device
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698