Commit 922ae26b authored by jdoerrie's avatar jdoerrie Committed by Commit Bot

Reland "[Bluetooth] Make BluetoothDevice::UUIDSet a base::flat_set"

This is a reland of 9a6c55fc

In order to address the CFI failures [1,2] causing the revert of the
initial CL, this change also de-virtualizes BluetoothUUID. BluetoothUUID
has no subclasses and is meant to use as a value type, which is why a virtual
destructor does not make sense.

[1] https://ci.chromium.org/p/chromium/builders/luci.chromium.ci/Linux%20CFI/9368
[2] https://ci.chromium.org/p/chromium/builders/luci.chromium.ci/Android%20CFI/2352

Original change's description:
> [Bluetooth] Make BluetoothDevice::UUIDSet a base::flat_set
>
> BluetoothDevice::DeviceUUIDs::UpdateDeviceUUIDs() makes use of
> std::set_union in order to merge advertised uuids and service uuids.
> However, std::set_union requires sorted ranges as input, which wasn't
> necessarily guaranteed before this change. When using a
> std::unordered_set the order of elements is not specified and
> std::set_union is not guaranteed to work correctly. Using a
> base::flat_set for UUIDSet instead fixes this issue. In order to prevent
> future regressions this change also replaces the usage of std::set_union
> with base::STLSetUnion performing an explicit IsSorted() check in Debug
> builds.
>
> Bug: 821766, 870208
> Change-Id: Id25711e6acf77ded9eebb6c80db5bcb2ed8a63e0
> Reviewed-on: https://chromium-review.googlesource.com/1159374
> Reviewed-by: Giovanni Ortuño Urquidi <ortuno@chromium.org>
> Commit-Queue: Jan Wilken Dörrie <jdoerrie@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#580198}

TBR=ortuno@chromium.org

Bug: 821766, 870208
Change-Id: I3fc55939ff5b8b136db0d45978c5b19083adb1d9
Reviewed-on: https://chromium-review.googlesource.com/1161883Reviewed-by: default avatarJan Wilken Dörrie <jdoerrie@chromium.org>
Commit-Queue: Jan Wilken Dörrie <jdoerrie@chromium.org>
Cr-Commit-Position: refs/heads/master@{#580530}
parent dbea7821
......@@ -10,6 +10,7 @@
#include <utility>
#include "base/memory/ptr_util.h"
#include "base/stl_util.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
......@@ -66,10 +67,8 @@ const BluetoothDevice::UUIDSet& BluetoothDevice::DeviceUUIDs::GetUUIDs() const {
}
void BluetoothDevice::DeviceUUIDs::UpdateDeviceUUIDs() {
device_uuids_.clear();
std::set_union(advertised_uuids_.begin(), advertised_uuids_.end(),
service_uuids_.begin(), service_uuids_.end(),
std::inserter(device_uuids_, device_uuids_.begin()));
device_uuids_ = base::STLSetUnion<BluetoothDevice::UUIDSet>(advertised_uuids_,
service_uuids_);
}
BluetoothDevice::BluetoothDevice(BluetoothAdapter* adapter)
......
......@@ -16,6 +16,7 @@
#include <vector>
#include "base/callback.h"
#include "base/containers/flat_set.h"
#include "base/gtest_prod_util.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
......@@ -95,7 +96,7 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothDevice {
};
typedef std::vector<BluetoothUUID> UUIDList;
typedef std::unordered_set<BluetoothUUID, BluetoothUUIDHash> UUIDSet;
typedef base::flat_set<BluetoothUUID> UUIDSet;
typedef std::unordered_map<BluetoothUUID,
std::vector<uint8_t>,
BluetoothUUIDHash>
......
......@@ -60,7 +60,7 @@ class DEVICE_BLUETOOTH_EXPORT BluetoothUUID {
// value to them later. The default constructor will initialize an invalid
// UUID by definition and the string accessors will return an empty string.
BluetoothUUID();
virtual ~BluetoothUUID();
~BluetoothUUID();
#if defined(OS_WIN)
// The canonical UUID string format is device::BluetoothUUID.value().
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment