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

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: fix ProximityAuthBluetoothLowEnergyConnectionTest Created 5 years, 3 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 scoped_refptr<device::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 device_ = adapter_->GetDevice(device_address_);
19 DCHECK(device_);
20 owns_reference_for_connection_ = true;
21 device_->AddGattConnection(this);
10 } 22 }
11 23
12 BluetoothGattConnection::~BluetoothGattConnection() { 24 BluetoothGattConnection::~BluetoothGattConnection() {
25 Disconnect();
26 }
27
28 const std::string& BluetoothGattConnection::GetDeviceAddress() const {
29 return device_address_;
30 }
31
32 bool BluetoothGattConnection::IsConnected() {
33 if (!owns_reference_for_connection_)
34 return false;
35 DCHECK(adapter_->GetDevice(device_address_));
36 DCHECK(device_->IsGattConnected());
37 return true;
38 }
39
40 void BluetoothGattConnection::Disconnect() {
41 if (!owns_reference_for_connection_)
42 return;
43
44 owns_reference_for_connection_ = false;
45 device_->RemoveGattConnection(this);
46 }
47
48 void BluetoothGattConnection::InvalidateConnectionReference() {
49 owns_reference_for_connection_ = false;
13 } 50 }
14 51
15 } // namespace device 52 } // namespace device
OLDNEW
« no previous file with comments | « device/bluetooth/bluetooth_gatt_connection.h ('k') | device/bluetooth/bluetooth_gatt_connection_chromeos.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698