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

Unified Diff: device/bluetooth/bluetooth_device_win.cc

Issue 1606013002: BLE GATT service implementation in Chrome for Windows 8 and later (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update Build.gn Created 4 years, 11 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
« no previous file with comments | « device/bluetooth/bluetooth_device_win.h ('k') | device/bluetooth/bluetooth_device_win_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: device/bluetooth/bluetooth_device_win.cc
diff --git a/device/bluetooth/bluetooth_device_win.cc b/device/bluetooth/bluetooth_device_win.cc
index 8678576feeb91dfb76a3ecc70396962cae082ece..4a4fd904982d5281d27ba9f02a6402a91f31ef07 100644
--- a/device/bluetooth/bluetooth_device_win.cc
+++ b/device/bluetooth/bluetooth_device_win.cc
@@ -12,6 +12,7 @@
#include "base/sequenced_task_runner.h"
#include "base/strings/stringprintf.h"
#include "device/bluetooth/bluetooth_adapter_win.h"
+#include "device/bluetooth/bluetooth_remote_gatt_service_win.h"
#include "device/bluetooth/bluetooth_service_record_win.h"
#include "device/bluetooth/bluetooth_socket_thread.h"
#include "device/bluetooth/bluetooth_socket_win.h"
@@ -300,6 +301,65 @@ void BluetoothDeviceWin::UpdateServices(
service_record_list_.push_back(service_record);
uuids_.push_back(service_record->uuid());
}
+
+ if (!device_state.is_bluetooth_classic())
+ UpdateGattServices(device_state);
+}
+
+void BluetoothDeviceWin::UpdateGattServices(
+ const BluetoothTaskManagerWin::DeviceState& device_state) {
+ // Remove no longer exist gatt services first.
+ if (gatt_services_.size() != 0) {
+ std::vector<std::string> removed_services;
+ for (auto gatt_service : gatt_services_) {
+ BluetoothUUID uuid = gatt_service.second->GetUUID();
+ ScopedVector<BluetoothTaskManagerWin::ServiceRecordState>::const_iterator
+ iter = device_state.service_record_states.begin();
+ for (; iter != device_state.service_record_states.end(); ++iter) {
+ if (uuid == (*iter)->gatt_uuid)
+ break;
+ }
+ if (iter == device_state.service_record_states.end()) {
+ removed_services.push_back(gatt_service.first);
+ }
+ }
+ for (auto key : removed_services) {
+ gatt_services_.erase(key);
+ }
+ // Update previously discovered services.
+ for (auto gatt_service : gatt_services_) {
+ static_cast<BluetoothRemoteGattServiceWin*>(gatt_service.second)
+ ->Update();
+ }
+ }
+
+ // Return if no new services have been added.
+ if (gatt_services_.size() == device_state.service_record_states.size())
+ return;
+
+ // Add new services.
+ for (ScopedVector<BluetoothTaskManagerWin::ServiceRecordState>::const_iterator
+ iter = device_state.service_record_states.begin();
+ iter != device_state.service_record_states.end(); ++iter) {
+ GattServiceMap::iterator it = gatt_services_.begin();
+ for (; it != gatt_services_.end(); it++) {
+ if ((*iter)->gatt_uuid == it->second->GetUUID())
+ break;
+ }
+ if (it == gatt_services_.end()) {
+ BluetoothRemoteGattServiceWin* primary_service =
+ new BluetoothRemoteGattServiceWin(
+ this, (*iter)->path, (*iter)->gatt_uuid,
+ (*iter)->gatt_attribute_handle, true, nullptr, ui_task_runner_);
+ gatt_services_.add(primary_service->GetIdentifier(),
+ scoped_ptr<BluetoothGattService>(primary_service));
+ static_cast<BluetoothAdapterWin*>(adapter_)
+ ->NotifyGattServiceAdded(this, primary_service);
+ }
+ }
+
+ static_cast<BluetoothAdapterWin*>(adapter_)
+ ->NotifyGattServicesDiscovered(this);
}
} // namespace device
« no previous file with comments | « device/bluetooth/bluetooth_device_win.h ('k') | device/bluetooth/bluetooth_device_win_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698