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

Unified Diff: device/bluetooth/bluetooth_task_manager_win.cc

Issue 2567903004: Replace ScopedVector/ScopedPtrHashMap with std::vector and std::unordered_map (Closed)
Patch Set: Replace ScopedVector/ScopedPtrHashMap with std::vector and std::unordered_map 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..137936a58db7ebfe29cb8d42876219463bc34cea 100644
--- a/device/bluetooth/bluetooth_task_manager_win.cc
+++ b/device/bluetooth/bluetooth_task_manager_win.cc
@@ -378,7 +378,8 @@ void BluetoothTaskManagerWin::OnDiscoveryStopped() {
}
void BluetoothTaskManagerWin::OnDevicesPolled(
- const ScopedVector<DeviceState>* devices) {
+ const std::vector<std::unique_ptr<DeviceState>>* devices) {
+ DCHECK(devices);
DCHECK(ui_task_runner_->RunsTasksOnCurrentThread());
for (auto& observer : observers_)
observer.DevicesPolled(*devices);
@@ -476,14 +477,12 @@ void BluetoothTaskManagerWin::DiscoverDevices(int timeout_multiplier) {
return;
}
- std::unique_ptr<ScopedVector<DeviceState>> device_list(
- new ScopedVector<DeviceState>());
- if (SearchDevices(timeout_multiplier, false, device_list.get())) {
+ auto device_list(new std::vector<std::unique_ptr<DeviceState>>());
Reilly Grant (use Gerrit) 2016/12/21 22:25:15 auto device_list = base::MakeUnique<std::vector<st
dougt 2016/12/22 01:18:03 Done.
+
+ if (SearchDevices(timeout_multiplier, false, device_list)) {
ui_task_runner_->PostTask(
- FROM_HERE,
- base::Bind(&BluetoothTaskManagerWin::OnDevicesPolled,
- this,
- base::Owned(device_list.release())));
+ FROM_HERE, base::Bind(&BluetoothTaskManagerWin::OnDevicesPolled, this,
+ base::Passed(&device_list)));
}
if (timeout_multiplier < kMaxDeviceDiscoveryTimeoutMultiplier)
@@ -495,21 +494,18 @@ void BluetoothTaskManagerWin::DiscoverDevices(int timeout_multiplier) {
}
void BluetoothTaskManagerWin::GetKnownDevices() {
- std::unique_ptr<ScopedVector<DeviceState>> device_list(
- new ScopedVector<DeviceState>());
- if (SearchDevices(1, true, device_list.get())) {
+ auto device_list(new std::vector<std::unique_ptr<DeviceState>>());
+ if (SearchDevices(1, true, device_list)) {
ui_task_runner_->PostTask(
- FROM_HERE,
- base::Bind(&BluetoothTaskManagerWin::OnDevicesPolled,
- this,
- base::Owned(device_list.release())));
+ FROM_HERE, base::Bind(&BluetoothTaskManagerWin::OnDevicesPolled, this,
+ base::Passed(&device_list)));
Reilly Grant (use Gerrit) 2016/12/21 22:25:15 std::vector<std::unique_ptr<DeviceState>> device_l
dougt 2016/12/22 01:18:03 Done.
}
}
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 +515,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));
@@ -547,9 +543,9 @@ bool BluetoothTaskManagerWin::SearchClassicDevices(
}
while (true) {
- DeviceState* device_state = new DeviceState();
- GetDeviceState(device_info, device_state);
- device_list->push_back(device_state);
+ std::unique_ptr<DeviceState> device_state(new DeviceState());
+ GetDeviceState(device_info, device_state.get());
+ device_list->push_back(std::move(device_state));
// Reset device info before next call (as a safety precaution).
ZeroMemory(&device_info, sizeof(device_info));
@@ -575,13 +571,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,12 +587,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);
- DeviceState* device_state = new DeviceState();
+ for (auto& device_info : btle_devices) {
+ std::unique_ptr<DeviceState> device_state(new DeviceState());
Reilly Grant (use Gerrit) 2016/12/21 22:25:15 auto device_state = base::MakeUnique<DeviceState>(
dougt 2016/12/22 01:18:03 Done.
device_state->name = device_info->friendly_name;
device_state->address =
BluetoothAddressToCanonicalString(device_info->address);
@@ -604,37 +596,29 @@ bool BluetoothTaskManagerWin::SearchLowEnergyDevices(
device_state->authenticated = device_info->authenticated;
device_state->connected = device_info->connected;
device_state->path = device_info->path;
- device_list->push_back(device_state);
+ device_list->push_back(std::move(device_state));
}
return true;
}
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;
-
- if ((*iter)->is_bluetooth_classic()) {
- if (!DiscoverClassicDeviceServices(device->address,
- L2CAP_PROTOCOL_UUID,
- search_cached_services_only,
- service_record_states)) {
+ for (auto& device : *device_list) {
+ auto& state = device->service_record_states;
+
+ if (device->is_bluetooth_classic()) {
+ if (!DiscoverClassicDeviceServices(device->address, L2CAP_PROTOCOL_UUID,
+ search_cached_services_only, &state)) {
return false;
}
} else {
- if (!DiscoverLowEnergyDeviceServices(device->path,
- service_record_states)) {
+ if (!DiscoverLowEnergyDeviceServices(device->path, &state)) {
return false;
}
- if (!SearchForGattServiceDevicePaths(device->address,
- service_record_states)) {
+ if (!SearchForGattServiceDevicePaths(device->address, &state)) {
return false;
}
}
@@ -646,7 +630,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 +652,7 @@ int BluetoothTaskManagerWin::DiscoverClassicDeviceServicesWorker(
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) {
// Bluetooth and WSAQUERYSET for Service Inquiry. See http://goo.gl/2v9pyt.
WSAQUERYSET sdp_query;
ZeroMemory(&sdp_query, sizeof(sdp_query));
@@ -719,14 +703,15 @@ int BluetoothTaskManagerWin::DiscoverClassicDeviceServicesWorker(
WSALookupServiceEnd(sdp_handle);
return last_error;
}
- ServiceRecordState* service_record_state = new ServiceRecordState();
+ std::unique_ptr<ServiceRecordState> service_record_state(
+ new ServiceRecordState());
Reilly Grant (use Gerrit) 2016/12/21 22:25:15 base::MakeUnique.
dougt 2016/12/22 01:18:03 Done.
service_record_state->name =
base::SysWideToUTF8(sdp_result_data->lpszServiceInstanceName);
for (uint64_t i = 0; i < sdp_result_data->lpBlob->cbSize; i++) {
service_record_state->sdp_bytes.push_back(
sdp_result_data->lpBlob->pBlobData[i]);
}
- service_record_states->push_back(service_record_state);
+ service_record_states->push_back(std::move(service_record_state));
}
if (ERROR_SUCCESS != WSALookupServiceEnd(sdp_handle)) {
int last_error = WSAGetLastError();
@@ -739,14 +724,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,15 +740,12 @@ bool BluetoothTaskManagerWin::DiscoverLowEnergyDeviceServices(
return false;
}
- for (ScopedVector<win::BluetoothLowEnergyServiceInfo>::iterator iter2 =
- services.begin();
- iter2 != services.end();
- ++iter2) {
- ServiceRecordState* service_state = new ServiceRecordState();
+ for (auto& service : services) {
+ std::unique_ptr<ServiceRecordState> service_state(new ServiceRecordState());
Reilly Grant (use Gerrit) 2016/12/21 22:25:15 base::MakeUnique
dougt 2016/12/22 01:18:03 Done.
service_state->gatt_uuid =
- BluetoothLowEnergyUuidToBluetoothUuid((*iter2)->uuid);
- service_state->attribute_handle = (*iter2)->attribute_handle;
- service_record_states->push_back(service_state);
+ BluetoothLowEnergyUuidToBluetoothUuid(service->uuid);
+ service_state->attribute_handle = service->attribute_handle;
+ service_record_states->push_back(std::move(service_state));
}
return true;
}
@@ -775,11 +757,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::unique_ptr<win::BluetoothLowEnergyDeviceInfo>>
+ gatt_service_devices;
bool success = win::BluetoothLowEnergyWrapper::GetInstance()
->EnumerateKnownBluetoothLowEnergyGattServiceDevices(
&gatt_service_devices, &error);
@@ -788,7 +771,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 +779,8 @@ bool BluetoothTaskManagerWin::SearchForGattServiceDevicePaths(
}
// Discover this service device's contained services.
- ScopedVector<win::BluetoothLowEnergyServiceInfo> gatt_services;
+ std::vector<std::unique_ptr<win::BluetoothLowEnergyServiceInfo>>
+ gatt_services;
if (!win::BluetoothLowEnergyWrapper::GetInstance()
->EnumerateKnownBluetoothLowEnergyServices(
gatt_service_device->path, &gatt_services, &error)) {
@@ -812,8 +796,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