forked from sanyaade-mobiledev/chromium.src
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
device/bluetooth: Implement BluetoothGattConnection on Chrome OS.
This patch adds BluetoothGattConnectionChromeOS and implements BluetoothDeviceChromeOS::CreateGattConnection. At this point, creating a connection simply calls org.bluez.Device1.Connect without pairing. BluetoothGattConnectionChromeOS::Disconnect currently doesn't do anything, at least until there is a system in bluetoothd for managing GATT connections properly between Chrome and its profiles and plugins. BUG=384620,381305 TEST=device_unittests Review URL: https://codereview.chromium.org/333983003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@278595 0039d316-1c4b-4281-b951-d872f2087c98
- Loading branch information
armansito@chromium.org
committed
Jun 20, 2014
1 parent
05adc15
commit aa2ec2a
Showing
9 changed files
with
328 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
// Copyright 2014 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "device/bluetooth/bluetooth_gatt_connection_chromeos.h" | ||
|
||
#include "base/bind.h" | ||
#include "base/logging.h" | ||
#include "chromeos/dbus/dbus_thread_manager.h" | ||
#include "device/bluetooth/bluetooth_adapter.h" | ||
#include "device/bluetooth/bluetooth_device.h" | ||
|
||
namespace chromeos { | ||
|
||
BluetoothGattConnectionChromeOS::BluetoothGattConnectionChromeOS( | ||
scoped_refptr<device::BluetoothAdapter> adapter, | ||
const std::string& device_address, | ||
const dbus::ObjectPath& object_path) | ||
: connected_(true), | ||
adapter_(adapter), | ||
device_address_(device_address), | ||
object_path_(object_path) { | ||
DCHECK(adapter_.get()); | ||
DCHECK(!device_address_.empty()); | ||
DCHECK(object_path_.IsValid()); | ||
|
||
DBusThreadManager::Get()->GetBluetoothDeviceClient()->AddObserver(this); | ||
} | ||
|
||
BluetoothGattConnectionChromeOS::~BluetoothGattConnectionChromeOS() { | ||
DBusThreadManager::Get()->GetBluetoothDeviceClient()->RemoveObserver(this); | ||
Disconnect(base::Bind(&base::DoNothing)); | ||
} | ||
|
||
std::string BluetoothGattConnectionChromeOS::GetDeviceAddress() const { | ||
return device_address_; | ||
} | ||
|
||
bool BluetoothGattConnectionChromeOS::IsConnected() { | ||
// Lazily determine the activity state of the connection. If already | ||
// marked as inactive, then return false. Otherwise, explicitly mark | ||
// |connected_| as false if the device is removed or disconnected. We do this, | ||
// so that if this method is called during a call to DeviceRemoved or | ||
// DeviceChanged somewhere else, it returns the correct status. | ||
if (!connected_) | ||
return false; | ||
|
||
BluetoothDeviceClient::Properties* properties = | ||
DBusThreadManager::Get()->GetBluetoothDeviceClient()-> | ||
GetProperties(object_path_); | ||
if (!properties || !properties->connected.value()) | ||
connected_ = false; | ||
|
||
return connected_; | ||
} | ||
|
||
void BluetoothGattConnectionChromeOS::Disconnect( | ||
const base::Closure& callback) { | ||
if (!connected_) { | ||
VLOG(1) << "Connection already inactive."; | ||
callback.Run(); | ||
return; | ||
} | ||
|
||
// TODO(armansito): There isn't currently a good way to manage the ownership | ||
// of a connection between Chrome and bluetoothd plugins/profiles. Until | ||
// a proper reference count is kept by bluetoothd, we might unwittingly kill | ||
// a connection that is managed by the daemon (e.g. HoG). For now, just return | ||
// success to indicate that this BluetoothGattConnection is no longer active, | ||
// even though the underlying connection won't actually be disconnected. This | ||
// technically doesn't violate the contract put forth by this API. | ||
connected_ = false; | ||
callback.Run(); | ||
} | ||
|
||
void BluetoothGattConnectionChromeOS::DeviceRemoved( | ||
const dbus::ObjectPath& object_path) { | ||
if (object_path != object_path_) | ||
return; | ||
|
||
connected_ = false; | ||
} | ||
|
||
void BluetoothGattConnectionChromeOS::DevicePropertyChanged( | ||
const dbus::ObjectPath& object_path, | ||
const std::string& property_name) { | ||
if (object_path != object_path_) | ||
return; | ||
|
||
if (!connected_) | ||
return; | ||
|
||
BluetoothDeviceClient::Properties* properties = | ||
DBusThreadManager::Get()->GetBluetoothDeviceClient()-> | ||
GetProperties(object_path_); | ||
|
||
if (!properties) { | ||
connected_ = false; | ||
return; | ||
} | ||
|
||
if (property_name == properties->connected.name() && | ||
!properties->connected.value()) | ||
connected_ = false; | ||
} | ||
|
||
} // namespace chromeos |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Copyright 2014 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef DEVICE_BLUETOOTH_BLUETOOTH_GATT_CONNECTION_CHROMEOS_H_ | ||
#define DEVICE_BLUETOOTH_BLUETOOTH_GATT_CONNECTION_CHROMEOS_H_ | ||
|
||
#include <string> | ||
|
||
#include "base/callback.h" | ||
#include "base/memory/weak_ptr.h" | ||
#include "chromeos/dbus/bluetooth_device_client.h" | ||
#include "dbus/object_path.h" | ||
#include "device/bluetooth/bluetooth_gatt_connection.h" | ||
|
||
namespace device { | ||
|
||
class BluetoothAdapter; | ||
|
||
} // namespace device | ||
|
||
namespace chromeos { | ||
|
||
// BluetoothGattConnectionChromeOS implements BluetoothGattConnection for the | ||
// Chrome OS platform. | ||
class BluetoothGattConnectionChromeOS | ||
: public device::BluetoothGattConnection, | ||
public BluetoothDeviceClient::Observer { | ||
public: | ||
explicit BluetoothGattConnectionChromeOS( | ||
scoped_refptr<device::BluetoothAdapter> adapter, | ||
const std::string& device_address, | ||
const dbus::ObjectPath& object_path); | ||
virtual ~BluetoothGattConnectionChromeOS(); | ||
|
||
// BluetoothGattConnection overrides. | ||
virtual std::string GetDeviceAddress() const OVERRIDE; | ||
virtual bool IsConnected() OVERRIDE; | ||
virtual void Disconnect(const base::Closure& callback) OVERRIDE; | ||
|
||
private: | ||
|
||
// chromeos::BluetoothDeviceClient::Observer overrides. | ||
virtual void DeviceRemoved(const dbus::ObjectPath& object_path) OVERRIDE; | ||
virtual void DevicePropertyChanged(const dbus::ObjectPath& object_path, | ||
const std::string& property_name) OVERRIDE; | ||
|
||
// True, if the connection is currently active. | ||
bool connected_; | ||
|
||
// The Bluetooth adapter that this connection is associated with. | ||
scoped_refptr<device::BluetoothAdapter> adapter_; | ||
|
||
// Bluetooth address of the underlying device. | ||
std::string device_address_; | ||
|
||
// D-Bus object path of the underlying device. This is used to filter observer | ||
// events. | ||
dbus::ObjectPath object_path_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(BluetoothGattConnectionChromeOS); | ||
}; | ||
|
||
} // namespace chromeos | ||
|
||
#endif // DEVICE_BLUETOOTH_BLUETOOTH_GATT_CONNECTION_CHROMEOS_H_ |
Oops, something went wrong.