ChildAccountService[Java] delegates everything to native side.
[chromium-blink-merge.git] / device / bluetooth / bluetooth_gatt_connection.cc
blob233476c6d466a6002d0bee249b23119df3b97da6
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
3 // found in the LICENSE file.
5 #include "device/bluetooth/bluetooth_gatt_connection.h"
7 #include "device/bluetooth/bluetooth_adapter.h"
9 namespace device {
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());
18 device_ = adapter_->GetDevice(device_address_);
19 DCHECK(device_);
20 owns_reference_for_connection_ = true;
21 device_->AddGattConnection(this);
24 BluetoothGattConnection::~BluetoothGattConnection() {
25 Disconnect();
28 const std::string& BluetoothGattConnection::GetDeviceAddress() const {
29 return device_address_;
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;
40 void BluetoothGattConnection::Disconnect() {
41 if (!owns_reference_for_connection_)
42 return;
44 owns_reference_for_connection_ = false;
45 device_->RemoveGattConnection(this);
48 void BluetoothGattConnection::InvalidateConnectionReference() {
49 owns_reference_for_connection_ = false;
52 } // namespace device