| OLD | NEW | 
|---|
| 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" | 9 #include "chromeos/dbus/dbus_thread_manager.h" | 
| 10 #include "device/bluetooth/bluetooth_adapter.h" | 10 #include "device/bluetooth/bluetooth_adapter.h" | 
| (...skipping 11 matching lines...) Expand all  Loading... | 
| 22       object_path_(object_path) { | 22       object_path_(object_path) { | 
| 23   DCHECK(adapter_.get()); | 23   DCHECK(adapter_.get()); | 
| 24   DCHECK(!device_address_.empty()); | 24   DCHECK(!device_address_.empty()); | 
| 25   DCHECK(object_path_.IsValid()); | 25   DCHECK(object_path_.IsValid()); | 
| 26 | 26 | 
| 27   DBusThreadManager::Get()->GetBluetoothDeviceClient()->AddObserver(this); | 27   DBusThreadManager::Get()->GetBluetoothDeviceClient()->AddObserver(this); | 
| 28 } | 28 } | 
| 29 | 29 | 
| 30 BluetoothGattConnectionChromeOS::~BluetoothGattConnectionChromeOS() { | 30 BluetoothGattConnectionChromeOS::~BluetoothGattConnectionChromeOS() { | 
| 31   DBusThreadManager::Get()->GetBluetoothDeviceClient()->RemoveObserver(this); | 31   DBusThreadManager::Get()->GetBluetoothDeviceClient()->RemoveObserver(this); | 
| 32   Disconnect(base::Bind(&base::DoNothing)); | 32   Disconnect(); | 
| 33 } | 33 } | 
| 34 | 34 | 
| 35 std::string BluetoothGattConnectionChromeOS::GetDeviceAddress() const { | 35 std::string BluetoothGattConnectionChromeOS::GetDeviceAddress() const { | 
| 36   return device_address_; | 36   return device_address_; | 
| 37 } | 37 } | 
| 38 | 38 | 
| 39 bool BluetoothGattConnectionChromeOS::IsConnected() { | 39 bool BluetoothGattConnectionChromeOS::IsConnected() { | 
| 40   // Lazily determine the activity state of the connection. If already | 40   // Lazily determine the activity state of the connection. If already | 
| 41   // marked as inactive, then return false. Otherwise, explicitly mark | 41   // marked as inactive, then return false. Otherwise, explicitly mark | 
| 42   // |connected_| as false if the device is removed or disconnected. We do this, | 42   // |connected_| as false if the device is removed or disconnected. We do this, | 
| 43   // so that if this method is called during a call to DeviceRemoved or | 43   // so that if this method is called during a call to DeviceRemoved or | 
| 44   // DeviceChanged somewhere else, it returns the correct status. | 44   // DeviceChanged somewhere else, it returns the correct status. | 
| 45   if (!connected_) | 45   if (!connected_) | 
| 46     return false; | 46     return false; | 
| 47 | 47 | 
| 48   BluetoothDeviceClient::Properties* properties = | 48   BluetoothDeviceClient::Properties* properties = | 
| 49       DBusThreadManager::Get()->GetBluetoothDeviceClient()-> | 49       DBusThreadManager::Get()->GetBluetoothDeviceClient()-> | 
| 50           GetProperties(object_path_); | 50           GetProperties(object_path_); | 
| 51   if (!properties || !properties->connected.value()) | 51   if (!properties || !properties->connected.value()) | 
| 52     connected_ = false; | 52     connected_ = false; | 
| 53 | 53 | 
| 54   return connected_; | 54   return connected_; | 
| 55 } | 55 } | 
| 56 | 56 | 
| 57 void BluetoothGattConnectionChromeOS::Disconnect( | 57 void BluetoothGattConnectionChromeOS::Disconnect() { | 
| 58     const base::Closure& callback) { |  | 
| 59   if (!connected_) { | 58   if (!connected_) { | 
| 60     VLOG(1) << "Connection already inactive."; | 59     VLOG(1) << "Connection already inactive."; | 
| 61     callback.Run(); |  | 
| 62     return; | 60     return; | 
| 63   } | 61   } | 
| 64 | 62 | 
| 65   // TODO(armansito): There isn't currently a good way to manage the ownership | 63   // TODO(armansito): There isn't currently a good way to manage the ownership | 
| 66   // of a connection between Chrome and bluetoothd plugins/profiles. Until | 64   // of a connection between Chrome and bluetoothd plugins/profiles. Until | 
| 67   // a proper reference count is kept by bluetoothd, we might unwittingly kill | 65   // a proper reference count is kept by bluetoothd, we might unwittingly kill | 
| 68   // a connection that is managed by the daemon (e.g. HoG). For now, just return | 66   // a connection that is managed by the daemon (e.g. HoG). For now, just return | 
| 69   // success to indicate that this BluetoothGattConnection is no longer active, | 67   // success to indicate that this BluetoothGattConnection is no longer active, | 
| 70   // even though the underlying connection won't actually be disconnected. This | 68   // even though the underlying connection won't actually be disconnected. This | 
| 71   // technically doesn't violate the contract put forth by this API. | 69   // technically doesn't violate the contract put forth by this API. | 
| 72   connected_ = false; | 70   connected_ = false; | 
| 73   callback.Run(); |  | 
| 74 } | 71 } | 
| 75 | 72 | 
| 76 void BluetoothGattConnectionChromeOS::DeviceRemoved( | 73 void BluetoothGattConnectionChromeOS::DeviceRemoved( | 
| 77     const dbus::ObjectPath& object_path) { | 74     const dbus::ObjectPath& object_path) { | 
| 78   if (object_path != object_path_) | 75   if (object_path != object_path_) | 
| 79     return; | 76     return; | 
| 80 | 77 | 
| 81   connected_ = false; | 78   connected_ = false; | 
| 82 } | 79 } | 
| 83 | 80 | 
| (...skipping 14 matching lines...) Expand all  Loading... | 
| 98     connected_ = false; | 95     connected_ = false; | 
| 99     return; | 96     return; | 
| 100   } | 97   } | 
| 101 | 98 | 
| 102   if (property_name == properties->connected.name() && | 99   if (property_name == properties->connected.name() && | 
| 103       !properties->connected.value()) | 100       !properties->connected.value()) | 
| 104     connected_ = false; | 101     connected_ = false; | 
| 105 } | 102 } | 
| 106 | 103 | 
| 107 }  // namespace chromeos | 104 }  // namespace chromeos | 
| OLD | NEW | 
|---|