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

Unified Diff: device/bluetooth/bluetooth_task_manager_win.cc

Issue 2567903004: Replace ScopedVector/ScopedPtrHashMap with std::vector and std::unordered_map (Closed)
Patch Set: Created 4 years 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_task_manager_win.cc
diff --git a/device/bluetooth/bluetooth_task_manager_win.cc b/device/bluetooth/bluetooth_task_manager_win.cc
index 4573fb9ffbd65237437a8040b90e87c1b6d10eb0..0a6a372b76cc74301d5f481bd60869ae587aee26 100644
--- a/device/bluetooth/bluetooth_task_manager_win.cc
+++ b/device/bluetooth/bluetooth_task_manager_win.cc
@@ -378,7 +378,7 @@ void BluetoothTaskManagerWin::OnDiscoveryStopped() {
}
void BluetoothTaskManagerWin::OnDevicesPolled(
- const ScopedVector<DeviceState>* devices) {
+ const std::vector<std::unique_ptr<DeviceState>>& devices) {
DCHECK(ui_task_runner_->RunsTasksOnCurrentThread());
for (auto& observer : observers_)
observer.DevicesPolled(*devices);
@@ -476,8 +476,8 @@ void BluetoothTaskManagerWin::DiscoverDevices(int timeout_multiplier) {
return;
}
- std::unique_ptr<ScopedVector<DeviceState>> device_list(
- new ScopedVector<DeviceState>());
+ std::unique_ptr<std::vector<std::unique_ptr<DeviceState>>> device_list(
+ new std::vector<std::unique_ptr<DeviceState>>());
if (SearchDevices(timeout_multiplier, false, device_list.get())) {
ui_task_runner_->PostTask(
FROM_HERE,
@@ -495,8 +495,8 @@ void BluetoothTaskManagerWin::DiscoverDevices(int timeout_multiplier) {
}
void BluetoothTaskManagerWin::GetKnownDevices() {
- std::unique_ptr<ScopedVector<DeviceState>> device_list(
- new ScopedVector<DeviceState>());
+ std::unique_ptr<std::vector<std::unique_ptr<DeviceState>>> device_list(
+ new std::vector<std::unique_ptr<DeviceState>>());
if (SearchDevices(1, true, device_list.get())) {
ui_task_runner_->PostTask(
FROM_HERE,
@@ -509,7 +509,7 @@ void BluetoothTaskManagerWin::GetKnownDevices() {
bool BluetoothTaskManagerWin::SearchDevices(
int timeout_multiplier,
bool search_cached_devices_only,
- ScopedVector<DeviceState>* device_list) {
+ std::vector<std::unique_ptr<DeviceState>>& device_list) {
return SearchClassicDevices(
timeout_multiplier, search_cached_devices_only, device_list) &&
SearchLowEnergyDevices(device_list) &&
@@ -519,7 +519,7 @@ bool BluetoothTaskManagerWin::SearchDevices(
bool BluetoothTaskManagerWin::SearchClassicDevices(
int timeout_multiplier,
bool search_cached_devices_only,
- ScopedVector<DeviceState>* device_list) {
+ std::vector<std::unique_ptr<DeviceState>>& device_list) {
// Issues a device inquiry and waits for |timeout_multiplier| * 1.28 seconds.
BLUETOOTH_DEVICE_SEARCH_PARAMS device_search_params;
ZeroMemory(&device_search_params, sizeof(device_search_params));
@@ -575,13 +575,13 @@ bool BluetoothTaskManagerWin::SearchClassicDevices(
}
bool BluetoothTaskManagerWin::SearchLowEnergyDevices(
- ScopedVector<DeviceState>* device_list) {
+ std::vector<std::unique_ptr<DeviceState>>& device_list) {
if (!win::BluetoothLowEnergyWrapper::GetInstance()
->IsBluetoothLowEnergySupported()) {
return true; // Bluetooth LE not supported is not an error.
}
- ScopedVector<win::BluetoothLowEnergyDeviceInfo> btle_devices;
+ std::vector<std::unique_ptr<win::BluetoothLowEnergyDeviceInfo>> btle_devices;
std::string error;
bool success =
win::BluetoothLowEnergyWrapper::GetInstance()
@@ -591,11 +591,8 @@ bool BluetoothTaskManagerWin::SearchLowEnergyDevices(
return false;
}
- for (ScopedVector<win::BluetoothLowEnergyDeviceInfo>::iterator iter =
- btle_devices.begin();
- iter != btle_devices.end();
- ++iter) {
- win::BluetoothLowEnergyDeviceInfo* device_info = (*iter);
+ for (auto& device : btle_devices) {
+ win::BluetoothLowEnergyDeviceInfo* device_info = device;
DeviceState* device_state = new DeviceState();
device_state->name = device_info->friendly_name;
device_state->address =
@@ -610,16 +607,13 @@ bool BluetoothTaskManagerWin::SearchLowEnergyDevices(
}
bool BluetoothTaskManagerWin::DiscoverServices(
- ScopedVector<DeviceState>* device_list,
+ std::vector<std::unique_ptr<DeviceState>>& device_list,
bool search_cached_services_only) {
DCHECK(bluetooth_task_runner_->RunsTasksOnCurrentThread());
net::EnsureWinsockInit();
- for (ScopedVector<DeviceState>::iterator iter = device_list->begin();
- iter != device_list->end();
- ++iter) {
- DeviceState* device = (*iter);
- ScopedVector<ServiceRecordState>* service_record_states =
- &(*iter)->service_record_states;
+ for (auto& device : device_list) {
+ std::vector<std::unique_ptr<ServiceRecordState>>& service_record_states =
+ &device->service_record_states;
if ((*iter)->is_bluetooth_classic()) {
if (!DiscoverClassicDeviceServices(device->address,
@@ -646,7 +640,7 @@ bool BluetoothTaskManagerWin::DiscoverClassicDeviceServices(
const std::string& device_address,
const GUID& protocol_uuid,
bool search_cached_services_only,
- ScopedVector<ServiceRecordState>* service_record_states) {
+ std::vector<std::unique_ptr<ServiceRecordState>>& service_record_states) {
int error_code =
DiscoverClassicDeviceServicesWorker(device_address,
protocol_uuid,
@@ -668,7 +662,7 @@ int BluetoothTaskManagerWin::DiscoverClassicDeviceServicesWorker(
const std::string& device_address,
const GUID& protocol_uuid,
bool search_cached_services_only,
- ScopedVector<ServiceRecordState>* service_record_states) {
+ Sstd::vector<std::unique_ptr<ServiceRecordState>>& service_record_states) {
// Bluetooth and WSAQUERYSET for Service Inquiry. See http://goo.gl/2v9pyt.
WSAQUERYSET sdp_query;
ZeroMemory(&sdp_query, sizeof(sdp_query));
@@ -739,14 +733,14 @@ int BluetoothTaskManagerWin::DiscoverClassicDeviceServicesWorker(
bool BluetoothTaskManagerWin::DiscoverLowEnergyDeviceServices(
const base::FilePath& device_path,
- ScopedVector<ServiceRecordState>* service_record_states) {
+ std::vector<std::unique_ptr<ServiceRecordState>>& service_record_states) {
if (!win::BluetoothLowEnergyWrapper::GetInstance()
->IsBluetoothLowEnergySupported()) {
return true; // Bluetooth LE not supported is not an error.
}
std::string error;
- ScopedVector<win::BluetoothLowEnergyServiceInfo> services;
+ std::vector<std::unique_ptr<win::BluetoothLowEnergyServiceInfo>> services;
bool success = win::BluetoothLowEnergyWrapper::GetInstance()
->EnumerateKnownBluetoothLowEnergyServices(
device_path, &services, &error);
@@ -755,14 +749,11 @@ bool BluetoothTaskManagerWin::DiscoverLowEnergyDeviceServices(
return false;
}
- for (ScopedVector<win::BluetoothLowEnergyServiceInfo>::iterator iter2 =
- services.begin();
- iter2 != services.end();
- ++iter2) {
+ for (auto& service : services) {
ServiceRecordState* service_state = new ServiceRecordState();
service_state->gatt_uuid =
- BluetoothLowEnergyUuidToBluetoothUuid((*iter2)->uuid);
- service_state->attribute_handle = (*iter2)->attribute_handle;
+ BluetoothLowEnergyUuidToBluetoothUuid(service->uuid);
+ service_state->attribute_handle = service->attribute_handle;
service_record_states->push_back(service_state);
}
return true;
@@ -775,11 +766,12 @@ bool BluetoothTaskManagerWin::DiscoverLowEnergyDeviceServices(
// attribute handles, as we did not find a more neat way to bond them.
bool BluetoothTaskManagerWin::SearchForGattServiceDevicePaths(
const std::string device_address,
- ScopedVector<ServiceRecordState>* service_record_states) {
+ std::vector<std::unique_ptr<ServiceRecordState>>& service_record_states) {
std::string error;
// List all known GATT service devices on the machine.
- ScopedVector<win::BluetoothLowEnergyDeviceInfo> gatt_service_devices;
+ std::vector<std::unqiue_ptr<win::BluetoothLowEnergyDeviceInfo>>
+ gatt_service_devices;
bool success = win::BluetoothLowEnergyWrapper::GetInstance()
->EnumerateKnownBluetoothLowEnergyGattServiceDevices(
&gatt_service_devices, &error);
@@ -788,7 +780,7 @@ bool BluetoothTaskManagerWin::SearchForGattServiceDevicePaths(
return false;
}
- for (auto* gatt_service_device : gatt_service_devices) {
+ for (auto& gatt_service_device : gatt_service_devices) {
// Only care about the service devices with |device_address|.
if (BluetoothAddressToCanonicalString(gatt_service_device->address) !=
device_address) {
@@ -796,7 +788,8 @@ bool BluetoothTaskManagerWin::SearchForGattServiceDevicePaths(
}
// Discover this service device's contained services.
- ScopedVector<win::BluetoothLowEnergyServiceInfo> gatt_services;
+ std::vector<std::unqiue_ptr<win::BluetoothLowEnergyServiceInfo>>
+ gatt_services;
if (!win::BluetoothLowEnergyWrapper::GetInstance()
->EnumerateKnownBluetoothLowEnergyServices(
gatt_service_device->path, &gatt_services, &error)) {
@@ -812,8 +805,8 @@ bool BluetoothTaskManagerWin::SearchForGattServiceDevicePaths(
// Associate service device to corresponding service record. Attribute
// handle is unique on one device.
- for (auto* gatt_service : gatt_services) {
- for (auto* service_record_state : *service_record_states) {
+ for (auto& gatt_service : gatt_services) {
+ for (auto& service_record_state : service_record_states) {
if (service_record_state->attribute_handle ==
gatt_service->attribute_handle) {
service_record_state->path = gatt_service_device->path;

Powered by Google App Engine
This is Rietveld 408576698