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

Unified Diff: device/bluetooth/bluetooth_device.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 side-by-side diff with in-line comments
Download patch
Index: device/bluetooth/bluetooth_device.cc
diff --git a/device/bluetooth/bluetooth_device.cc b/device/bluetooth/bluetooth_device.cc
index c1f62d99568f249f1790b47823872e8396682840..19f3909f8360e18262f536fae3ca28ddd1323f44 100644
--- a/device/bluetooth/bluetooth_device.cc
+++ b/device/bluetooth/bluetooth_device.cc
@@ -4,11 +4,13 @@
#include "device/bluetooth/bluetooth_device.h"
+#include <limits>
#include <string>
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
+#include "device/bluetooth/bluetooth_gatt_connection.h"
#include "device/bluetooth/bluetooth_gatt_service.h"
#include "grit/device_bluetooth_strings.h"
#include "ui/base/l10n/l10n_util.h"
@@ -199,6 +201,18 @@ bool BluetoothDevice::IsTrustable() const {
return false;
}
+void BluetoothDevice::CreateGattConnection(
+ const GattConnectionCallback& callback,
+ const ConnectErrorCallback& error_callback) {
+ create_gatt_connection_success_callbacks_.push_back(callback);
+ create_gatt_connection_error_callbacks_.push_back(error_callback);
+
+ if (IsGattConnected())
+ DidConnectGatt();
+
+ CreateGattConnectionImpl();
+}
+
std::vector<BluetoothGattService*>
BluetoothDevice::GetGattServices() const {
std::vector<BluetoothGattService*> services;
@@ -272,6 +286,41 @@ BluetoothDevice::UUIDList BluetoothDevice::GetServiceDataUUIDs() const {
return uuids;
}
+void BluetoothDevice::DidConnectGatt() {
+ for (const auto& callback : create_gatt_connection_success_callbacks_) {
+ callback.Run(
+ make_scoped_ptr(new BluetoothGattConnection(adapter_, GetAddress())));
+ }
+ create_gatt_connection_success_callbacks_.clear();
+ create_gatt_connection_error_callbacks_.clear();
+}
+
+void BluetoothDevice::DidFailToConnectGatt(ConnectErrorCode error) {
+ for (const auto& error_callback : create_gatt_connection_error_callbacks_)
+ error_callback.Run(error);
+ create_gatt_connection_success_callbacks_.clear();
+ create_gatt_connection_error_callbacks_.clear();
+}
+
+void BluetoothDevice::DidDisconnectGatt() {
+ // If pending calls to connect GATT existed, flush them to ensure a consistent
+ // state.
+ DidFailToConnectGatt(ERROR_UNKNOWN);
Jeffrey Yasskin 2015/08/19 22:49:45 Don't use "UNKNOWN" here (or ever, really). If you
scheib 2015/09/13 02:40:27 Ok, though this scenario is a situation where we d
Jeffrey Yasskin 2015/09/16 00:45:39 We have places where we convert a string to an enu
+}
+
+void BluetoothDevice::IncrementGattConnectionReferenceCount() {
+ CHECK(gatt_connection_reference_count_ <
Jeffrey Yasskin 2015/08/19 22:49:45 Use base/numerics/safe_math.h instead of implement
scheib 2015/09/13 02:40:27 Done. IDMap does check: after increment and next s
+ std::numeric_limits<decltype(gatt_connection_reference_count_)>::max());
+ gatt_connection_reference_count_++;
+}
+
+void BluetoothDevice::DecrementGattConnectionReferenceCount() {
+ CHECK(gatt_connection_reference_count_ > 0);
+ gatt_connection_reference_count_--;
+ if (gatt_connection_reference_count_ == 0)
+ DisconnectGatt();
+}
+
void BluetoothDevice::ClearServiceData() { services_data_->Clear(); }
void BluetoothDevice::SetServiceData(BluetoothUUID serviceUUID,

Powered by Google App Engine
This is Rietveld 408576698