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

Unified Diff: device/bluetooth/bluetooth_device_win.cc

Issue 424093004: Improve processing of Bluetooth device discovery on Windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address code review feedback (nits and memory leak). Created 6 years, 5 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 db79c6aaf3ac3cc831d63fdd302658326d0e6522..67c2aec154c2aaaad1b89c6b3293f4f1c834572a 100644
--- a/device/bluetooth/bluetooth_device_win.cc
+++ b/device/bluetooth/bluetooth_device_win.cc
@@ -7,6 +7,7 @@
#include <string>
#include "base/basictypes.h"
+#include "base/containers/scoped_ptr_hash_map.h"
#include "base/logging.h"
#include "base/memory/scoped_vector.h"
#include "base/sequenced_task_runner.h"
@@ -26,9 +27,9 @@ const int kSdpBytesBufferSize = 1024;
namespace device {
BluetoothDeviceWin::BluetoothDeviceWin(
- const BluetoothTaskManagerWin::DeviceState& state,
- scoped_refptr<base::SequencedTaskRunner> ui_task_runner,
- scoped_refptr<BluetoothSocketThread> socket_thread,
+ const BluetoothTaskManagerWin::DeviceState& device_state,
+ const scoped_refptr<base::SequencedTaskRunner>& ui_task_runner,
+ const scoped_refptr<BluetoothSocketThread>& socket_thread,
net::NetLog* net_log,
const net::NetLog::Source& net_log_source)
: BluetoothDevice(),
@@ -36,25 +37,100 @@ BluetoothDeviceWin::BluetoothDeviceWin(
socket_thread_(socket_thread),
net_log_(net_log),
net_log_source_(net_log_source) {
- name_ = state.name;
- address_ = CanonicalizeAddress(state.address);
- bluetooth_class_ = state.bluetooth_class;
- visible_ = state.visible;
- connected_ = state.connected;
- paired_ = state.authenticated;
+ Update(device_state);
+}
+
+BluetoothDeviceWin::~BluetoothDeviceWin() {
+}
+
+void BluetoothDeviceWin::Update(
+ const BluetoothTaskManagerWin::DeviceState& device_state) {
+ address_ = device_state.address;
+ // Note: Callers are responsible for providing a canonicalized address.
+ DCHECK_EQ(address_, BluetoothDevice::CanonicalizeAddress(address_));
+ name_ = device_state.name;
+ bluetooth_class_ = device_state.bluetooth_class;
+ visible_ = device_state.visible;
+ connected_ = device_state.connected;
+ paired_ = device_state.authenticated;
+ UpdateServices(device_state);
+}
+
+void BluetoothDeviceWin::UpdateServices(
+ const BluetoothTaskManagerWin::DeviceState& device_state) {
+ uuids_.clear();
+ service_record_list_.clear();
for (ScopedVector<BluetoothTaskManagerWin::ServiceRecordState>::const_iterator
- iter = state.service_record_states.begin();
- iter != state.service_record_states.end();
+ iter = device_state.service_record_states.begin();
+ iter != device_state.service_record_states.end();
++iter) {
- BluetoothServiceRecordWin* service_record = new BluetoothServiceRecordWin(
- state.address, (*iter)->name, (*iter)->sdp_bytes, (*iter)->gatt_uuid);
+ BluetoothServiceRecordWin* service_record =
+ new BluetoothServiceRecordWin(device_state.address,
+ (*iter)->name,
+ (*iter)->sdp_bytes,
+ (*iter)->gatt_uuid);
service_record_list_.push_back(service_record);
uuids_.push_back(service_record->uuid());
}
}
-BluetoothDeviceWin::~BluetoothDeviceWin() {
+bool BluetoothDeviceWin::IsEqual(
+ const BluetoothTaskManagerWin::DeviceState& device_state) {
+ if (address_ != device_state.address || name_ != device_state.name ||
+ bluetooth_class_ != device_state.bluetooth_class ||
+ visible_ != device_state.visible ||
+ connected_ != device_state.connected ||
+ paired_ != device_state.authenticated) {
+ return false;
+ }
+
+ // Checks service collection
+ typedef std::set<BluetoothUUID> UUIDSet;
+ typedef base::ScopedPtrHashMap<std::string, BluetoothServiceRecordWin>
+ ServiceRecordMap;
+
+ UUIDSet known_services;
+ for (UUIDList::const_iterator iter = uuids_.begin(); iter != uuids_.end();
+ ++iter) {
+ known_services.insert((*iter));
+ }
+
+ UUIDSet new_services;
+ ServiceRecordMap new_service_records;
+ for (ScopedVector<BluetoothTaskManagerWin::ServiceRecordState>::const_iterator
+ iter = device_state.service_record_states.begin();
+ iter != device_state.service_record_states.end();
+ ++iter) {
+ BluetoothServiceRecordWin* service_record = new BluetoothServiceRecordWin(
+ address_, (*iter)->name, (*iter)->sdp_bytes, (*iter)->gatt_uuid);
+ new_services.insert(service_record->uuid());
+ new_service_records.set(
+ service_record->uuid().canonical_value(),
+ scoped_ptr<BluetoothServiceRecordWin>(service_record));
+ }
+
+ UUIDSet removed_services =
+ base::STLSetDifference<UUIDSet>(known_services, new_services);
+ if (!removed_services.empty()) {
+ return false;
+ }
+ UUIDSet added_devices =
+ base::STLSetDifference<UUIDSet>(new_services, known_services);
+ if (!added_devices.empty()) {
+ return false;
+ }
+
+ for (ServiceRecordList::const_iterator iter = service_record_list_.begin();
+ iter != service_record_list_.end();
+ ++iter) {
+ BluetoothServiceRecordWin* service_record = (*iter);
+ BluetoothServiceRecordWin* new_service_record =
+ new_service_records.get((*iter)->uuid().canonical_value());
+ if (!service_record->IsEqual(*new_service_record))
+ return false;
+ }
+ return true;
}
void BluetoothDeviceWin::SetVisible(bool visible) {
« 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