Commit 3711eb12 authored by Joshua Bell's avatar Joshua Bell Committed by Commit Bot

Make BluetoothAllowedDevicesMap non-refcounted

The type was refcounted, but only ever had a single owner
(StoragePartitionImpl). Change the ownership to unique_ptr and
slightly simplify the class.

Change-Id: Idaed9b5b0443982731b6a78c0027a959014d354c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2028731
Commit-Queue: Joshua Bell <jsbell@chromium.org>
Auto-Submit: Joshua Bell <jsbell@chromium.org>
Reviewed-by: default avatarOvidio de Jesús Ruiz-Henríquez <odejesush@chromium.org>
Cr-Commit-Position: refs/heads/master@{#737010}
parent 1841cc77
......@@ -10,9 +10,9 @@
namespace content {
BluetoothAllowedDevicesMap::BluetoothAllowedDevicesMap() {}
BluetoothAllowedDevicesMap::BluetoothAllowedDevicesMap() = default;
BluetoothAllowedDevicesMap::~BluetoothAllowedDevicesMap() {}
BluetoothAllowedDevicesMap::~BluetoothAllowedDevicesMap() = default;
content::BluetoothAllowedDevices&
BluetoothAllowedDevicesMap::GetOrCreateAllowedDevices(
......
......@@ -8,7 +8,6 @@
#include <map>
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "content/common/content_export.h"
#include "url/origin.h"
......@@ -18,10 +17,10 @@ class BluetoothAllowedDevices;
// Class for keeping track of which origins are allowed to access which
// Bluetooth devices and their services.
class CONTENT_EXPORT BluetoothAllowedDevicesMap
: public base::RefCountedThreadSafe<BluetoothAllowedDevicesMap> {
class CONTENT_EXPORT BluetoothAllowedDevicesMap {
public:
BluetoothAllowedDevicesMap();
~BluetoothAllowedDevicesMap();
// Gets a BluetoothAllowedDevices for each origin; creates one if it doesn't
// exist.
......@@ -32,8 +31,6 @@ class CONTENT_EXPORT BluetoothAllowedDevicesMap
void Clear();
private:
friend class base::RefCountedThreadSafe<BluetoothAllowedDevicesMap>;
~BluetoothAllowedDevicesMap();
std::map<url::Origin, content::BluetoothAllowedDevices>
origin_to_allowed_devices_map_;
......@@ -42,4 +39,4 @@ class CONTENT_EXPORT BluetoothAllowedDevicesMap
} // namespace content
#endif // CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_ALLOWED_DEVICES_MAP_H_
\ No newline at end of file
#endif // CONTENT_BROWSER_BLUETOOTH_BLUETOOTH_ALLOWED_DEVICES_MAP_H_
......@@ -53,8 +53,7 @@ class BluetoothAllowedDevicesTest : public testing::Test {
} // namespace
TEST_F(BluetoothAllowedDevicesTest, UniqueOriginNotSupported) {
scoped_refptr<BluetoothAllowedDevicesMap> allowed_devices_map =
new BluetoothAllowedDevicesMap();
auto allowed_devices_map = std::make_unique<BluetoothAllowedDevicesMap>();
EXPECT_DEATH_IF_SUPPORTED(
allowed_devices_map->GetOrCreateAllowedDevices(url::Origin()), "");
}
......@@ -102,8 +101,7 @@ TEST_F(BluetoothAllowedDevicesTest, AddTwoDevices) {
}
TEST_F(BluetoothAllowedDevicesTest, AddTwoDevicesFromTwoOriginsToMap) {
scoped_refptr<BluetoothAllowedDevicesMap> allowed_devices_map =
new BluetoothAllowedDevicesMap();
auto allowed_devices_map = std::make_unique<BluetoothAllowedDevicesMap>();
content::BluetoothAllowedDevices& allowed_devices1 =
allowed_devices_map->GetOrCreateAllowedDevices(TestOrigin1());
content::BluetoothAllowedDevices& allowed_devices2 =
......@@ -132,8 +130,7 @@ TEST_F(BluetoothAllowedDevicesTest, AddTwoDevicesFromTwoOriginsToMap) {
}
TEST_F(BluetoothAllowedDevicesTest, AddDeviceFromTwoOriginsToMap) {
scoped_refptr<BluetoothAllowedDevicesMap> allowed_devices_map =
new BluetoothAllowedDevicesMap();
auto allowed_devices_map = std::make_unique<BluetoothAllowedDevicesMap>();
content::BluetoothAllowedDevices& allowed_devices1 =
allowed_devices_map->GetOrCreateAllowedDevices(TestOrigin1());
content::BluetoothAllowedDevices& allowed_devices2 =
......@@ -346,8 +343,7 @@ TEST_F(BluetoothAllowedDevicesTest, AllowedServices_TwoDevices) {
}
TEST_F(BluetoothAllowedDevicesTest, AllowedServices_TwoOriginsOneDevice) {
scoped_refptr<BluetoothAllowedDevicesMap> allowed_devices_map =
new BluetoothAllowedDevicesMap();
auto allowed_devices_map = std::make_unique<BluetoothAllowedDevicesMap>();
content::BluetoothAllowedDevices& allowed_devices1 =
allowed_devices_map->GetOrCreateAllowedDevices(TestOrigin1());
content::BluetoothAllowedDevices& allowed_devices2 =
......
......@@ -1778,9 +1778,8 @@ BluetoothAllowedDevices& WebBluetoothServiceImpl::allowed_devices() {
StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>(
BrowserContext::GetDefaultStoragePartition(
web_contents()->GetBrowserContext()));
scoped_refptr<BluetoothAllowedDevicesMap> allowed_devices_map =
partition->GetBluetoothAllowedDevicesMap();
return allowed_devices_map->GetOrCreateAllowedDevices(GetOrigin());
return partition->GetBluetoothAllowedDevicesMap()->GetOrCreateAllowedDevices(
GetOrigin());
}
void WebBluetoothServiceImpl::StoreAllowedScanOptions(
......
......@@ -1375,7 +1375,8 @@ void StoragePartitionImpl::Initialize() {
broadcast_channel_provider_ = std::make_unique<BroadcastChannelProvider>();
bluetooth_allowed_devices_map_ = new BluetoothAllowedDevicesMap();
bluetooth_allowed_devices_map_ =
std::make_unique<BluetoothAllowedDevicesMap>();
scoped_refptr<ChromeBlobStorageContext> blob_context =
ChromeBlobStorageContext::GetFor(browser_context_);
......
......@@ -453,7 +453,7 @@ class CONTENT_EXPORT StoragePartitionImpl
scoped_refptr<BackgroundSyncContextImpl> background_sync_context_;
scoped_refptr<PaymentAppContextImpl> payment_app_context_;
std::unique_ptr<BroadcastChannelProvider> broadcast_channel_provider_;
scoped_refptr<BluetoothAllowedDevicesMap> bluetooth_allowed_devices_map_;
std::unique_ptr<BluetoothAllowedDevicesMap> bluetooth_allowed_devices_map_;
scoped_refptr<BlobRegistryWrapper> blob_registry_;
scoped_refptr<PrefetchURLLoaderService> prefetch_url_loader_service_;
scoped_refptr<CookieStoreContext> cookie_store_context_;
......
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