Commit 0c937aa6 authored by ricea's avatar ricea Committed by Commit bot

Re-write many calls to WrapUnique() with MakeUnique()

A mostly-automated change to convert instances of WrapUnique(new Foo(...)) to
MakeUnique<Foo>(...). See the thread at
https://groups.google.com/a/chromium.org/forum/#!topic/chromium-dev/iQgMedVA8-k
for background.

To avoid requiring too many manual fixups, the change skips some cases that are
frequently problematic. In particular, in methods named Foo::Method() it will
not try to change WrapUnique(new Foo()) to MakeUnique<Foo>(). This is because
Foo::Method() may be accessing an internal constructor of Foo.

Cases where MakeUnique<NestedClass>(...) is called within a method of
OuterClass are common but hard to detect automatically, so have been fixed-up
manually.

The only types of manual fix ups applied are:
1) Revert MakeUnique back to WrapUnique
2) Change NULL to nullptr in argument list (MakeUnique cannot forward NULL
   correctly)
3) Add base:: namespace qualifier where missing.

WrapUnique(new Foo) has not been converted to MakeUnique<Foo>() as this might
change behaviour if Foo does not have a user-defined constructor. For example,
WrapUnique(new int) creates an unitialised integer, but MakeUnique<int>()
creates an integer initialised to 0.

git cl format has been been run over the CL. Spot-checking has uncovered no
cases of mis-formatting.

  BUG=637812

Review-Url: https://codereview.chromium.org/2254833003
Cr-Commit-Position: refs/heads/master@{#414312}
parent c0a685cd
...@@ -34,7 +34,7 @@ TEST(BluetoothAdvertisementTest, DataMembersAreAssignedCorrectly) { ...@@ -34,7 +34,7 @@ TEST(BluetoothAdvertisementTest, DataMembersAreAssignedCorrectly) {
ASSERT_FALSE(data.service_uuids().get()); ASSERT_FALSE(data.service_uuids().get());
// Assign Service UUID. // Assign Service UUID.
data.set_service_uuids( data.set_service_uuids(
base::WrapUnique(new BluetoothAdvertisement::UUIDList(uuids))); base::MakeUnique<BluetoothAdvertisement::UUIDList>(uuids));
// Retrieve Service UUID. // Retrieve Service UUID.
ASSERT_EQ(*data.service_uuids(), uuids); ASSERT_EQ(*data.service_uuids(), uuids);
// Retrieve again. // Retrieve again.
...@@ -43,8 +43,9 @@ TEST(BluetoothAdvertisementTest, DataMembersAreAssignedCorrectly) { ...@@ -43,8 +43,9 @@ TEST(BluetoothAdvertisementTest, DataMembersAreAssignedCorrectly) {
// Try without assigning Manufacturer Data. // Try without assigning Manufacturer Data.
ASSERT_FALSE(data.manufacturer_data().get()); ASSERT_FALSE(data.manufacturer_data().get());
// Assign Manufacturer Data. // Assign Manufacturer Data.
data.set_manufacturer_data(base::WrapUnique( data.set_manufacturer_data(
new BluetoothAdvertisement::ManufacturerData(manufacturer_data))); base::MakeUnique<BluetoothAdvertisement::ManufacturerData>(
manufacturer_data));
// Retrieve Manufacturer Data. // Retrieve Manufacturer Data.
ASSERT_EQ(*data.manufacturer_data(), manufacturer_data); ASSERT_EQ(*data.manufacturer_data(), manufacturer_data);
// Retrieve again. // Retrieve again.
...@@ -54,7 +55,7 @@ TEST(BluetoothAdvertisementTest, DataMembersAreAssignedCorrectly) { ...@@ -54,7 +55,7 @@ TEST(BluetoothAdvertisementTest, DataMembersAreAssignedCorrectly) {
ASSERT_FALSE(data.solicit_uuids().get()); ASSERT_FALSE(data.solicit_uuids().get());
// Assign Solicit UUIDs. // Assign Solicit UUIDs.
data.set_solicit_uuids( data.set_solicit_uuids(
base::WrapUnique(new BluetoothAdvertisement::UUIDList(uuids))); base::MakeUnique<BluetoothAdvertisement::UUIDList>(uuids));
// Retrieve Solicit UUIDs. // Retrieve Solicit UUIDs.
ASSERT_EQ(*data.solicit_uuids(), uuids); ASSERT_EQ(*data.solicit_uuids(), uuids);
// Retieve again. // Retieve again.
...@@ -64,7 +65,7 @@ TEST(BluetoothAdvertisementTest, DataMembersAreAssignedCorrectly) { ...@@ -64,7 +65,7 @@ TEST(BluetoothAdvertisementTest, DataMembersAreAssignedCorrectly) {
ASSERT_FALSE(data.service_data().get()); ASSERT_FALSE(data.service_data().get());
// Assign Service Data. // Assign Service Data.
data.set_service_data( data.set_service_data(
base::WrapUnique(new BluetoothAdvertisement::ServiceData(service_data))); base::MakeUnique<BluetoothAdvertisement::ServiceData>(service_data));
// Retrieve Service Data. // Retrieve Service Data.
ASSERT_EQ(*data.service_data(), service_data); ASSERT_EQ(*data.service_data(), service_data);
// Retrieve again. // Retrieve again.
......
...@@ -397,7 +397,7 @@ void BluetoothDevice::ClearAdvertisementData() { ...@@ -397,7 +397,7 @@ void BluetoothDevice::ClearAdvertisementData() {
void BluetoothDevice::DidConnectGatt() { void BluetoothDevice::DidConnectGatt() {
for (const auto& callback : create_gatt_connection_success_callbacks_) { for (const auto& callback : create_gatt_connection_success_callbacks_) {
callback.Run( callback.Run(
base::WrapUnique(new BluetoothGattConnection(adapter_, GetAddress()))); base::MakeUnique<BluetoothGattConnection>(adapter_, GetAddress()));
} }
create_gatt_connection_success_callbacks_.clear(); create_gatt_connection_success_callbacks_.clear();
create_gatt_connection_error_callbacks_.clear(); create_gatt_connection_error_callbacks_.clear();
......
...@@ -447,8 +447,8 @@ void BluetoothRemoteGattCharacteristicWin::GattEventRegistrationCallback( ...@@ -447,8 +447,8 @@ void BluetoothRemoteGattCharacteristicWin::GattEventRegistrationCallback(
if (SUCCEEDED(hr)) { if (SUCCEEDED(hr)) {
gatt_event_handle_ = event_handle; gatt_event_handle_ = event_handle;
for (const auto& callback : callbacks) { for (const auto& callback : callbacks) {
callback.first.Run(base::WrapUnique( callback.first.Run(base::MakeUnique<BluetoothGattNotifySession>(
new BluetoothGattNotifySession(weak_ptr_factory_.GetWeakPtr()))); weak_ptr_factory_.GetWeakPtr()));
} }
} else { } else {
for (const auto& callback : callbacks) for (const auto& callback : callbacks)
......
...@@ -98,16 +98,16 @@ class BluetoothAdvertisementBlueZTest : public testing::Test { ...@@ -98,16 +98,16 @@ class BluetoothAdvertisementBlueZTest : public testing::Test {
std::unique_ptr<BluetoothAdvertisement::Data> CreateAdvertisementData() { std::unique_ptr<BluetoothAdvertisement::Data> CreateAdvertisementData() {
std::unique_ptr<BluetoothAdvertisement::Data> data = std::unique_ptr<BluetoothAdvertisement::Data> data =
base::WrapUnique(new BluetoothAdvertisement::Data( base::MakeUnique<BluetoothAdvertisement::Data>(
BluetoothAdvertisement::ADVERTISEMENT_TYPE_BROADCAST)); BluetoothAdvertisement::ADVERTISEMENT_TYPE_BROADCAST);
data->set_service_uuids( data->set_service_uuids(
base::WrapUnique(new BluetoothAdvertisement::UUIDList())); base::MakeUnique<BluetoothAdvertisement::UUIDList>());
data->set_manufacturer_data( data->set_manufacturer_data(
base::WrapUnique(new BluetoothAdvertisement::ManufacturerData())); base::MakeUnique<BluetoothAdvertisement::ManufacturerData>());
data->set_solicit_uuids( data->set_solicit_uuids(
base::WrapUnique(new BluetoothAdvertisement::UUIDList())); base::MakeUnique<BluetoothAdvertisement::UUIDList>());
data->set_service_data( data->set_service_data(
base::WrapUnique(new BluetoothAdvertisement::ServiceData())); base::MakeUnique<BluetoothAdvertisement::ServiceData>());
return data; return data;
} }
......
...@@ -116,8 +116,8 @@ void BluetoothGattApplicationServiceProvider::CreateAttributeServiceProviders( ...@@ -116,8 +116,8 @@ void BluetoothGattApplicationServiceProvider::CreateAttributeServiceProviders(
characteristic_providers_.push_back( characteristic_providers_.push_back(
base::WrapUnique(BluetoothGattCharacteristicServiceProvider::Create( base::WrapUnique(BluetoothGattCharacteristicServiceProvider::Create(
bus, characteristic.second->object_path(), bus, characteristic.second->object_path(),
base::WrapUnique(new BluetoothGattCharacteristicDelegateWrapper( base::MakeUnique<BluetoothGattCharacteristicDelegateWrapper>(
service.second, characteristic.second.get())), service.second, characteristic.second.get()),
characteristic.second->GetUUID().value(), characteristic.second->GetUUID().value(),
FlagsFromProperties(characteristic.second->GetProperties()), FlagsFromProperties(characteristic.second->GetProperties()),
service.second->object_path()))); service.second->object_path())));
...@@ -125,8 +125,8 @@ void BluetoothGattApplicationServiceProvider::CreateAttributeServiceProviders( ...@@ -125,8 +125,8 @@ void BluetoothGattApplicationServiceProvider::CreateAttributeServiceProviders(
descriptor_providers_.push_back( descriptor_providers_.push_back(
base::WrapUnique(BluetoothGattDescriptorServiceProvider::Create( base::WrapUnique(BluetoothGattDescriptorServiceProvider::Create(
bus, descriptor->object_path(), bus, descriptor->object_path(),
base::WrapUnique(new BluetoothGattDescriptorDelegateWrapper( base::MakeUnique<BluetoothGattDescriptorDelegateWrapper>(
service.second, descriptor.get())), service.second, descriptor.get()),
descriptor->GetUUID().value(), descriptor->GetUUID().value(),
FlagsFromPermissions(descriptor->GetPermissions()), FlagsFromPermissions(descriptor->GetPermissions()),
characteristic.second->object_path()))); characteristic.second->object_path())));
...@@ -161,8 +161,8 @@ BluetoothGattApplicationServiceProvider::Create( ...@@ -161,8 +161,8 @@ BluetoothGattApplicationServiceProvider::Create(
return base::WrapUnique(new BluetoothGattApplicationServiceProviderImpl( return base::WrapUnique(new BluetoothGattApplicationServiceProviderImpl(
bus, object_path, services)); bus, object_path, services));
} }
return base::WrapUnique( return base::MakeUnique<FakeBluetoothGattApplicationServiceProvider>(
new FakeBluetoothGattApplicationServiceProvider(object_path, services)); object_path, services);
} }
} // namespace bluez } // namespace bluez
...@@ -293,9 +293,9 @@ class BluetoothGattApplicationServiceProviderTest : public testing::Test { ...@@ -293,9 +293,9 @@ class BluetoothGattApplicationServiceProviderTest : public testing::Test {
const std::string& full_service_path = const std::string& full_service_path =
std::string(kAppObjectPath) + "/" + service_path; std::string(kAppObjectPath) + "/" + service_path;
app_provider->service_providers_.push_back( app_provider->service_providers_.push_back(
base::WrapUnique(new BluetoothGattServiceServiceProviderImpl( base::MakeUnique<BluetoothGattServiceServiceProviderImpl>(
nullptr, dbus::ObjectPath(full_service_path), kFakeServiceUuid, nullptr, dbus::ObjectPath(full_service_path), kFakeServiceUuid,
true, std::vector<dbus::ObjectPath>()))); true, std::vector<dbus::ObjectPath>()));
return full_service_path; return full_service_path;
} }
...@@ -350,9 +350,9 @@ class BluetoothGattApplicationServiceProviderTest : public testing::Test { ...@@ -350,9 +350,9 @@ class BluetoothGattApplicationServiceProviderTest : public testing::Test {
TEST_F(BluetoothGattApplicationServiceProviderTest, GetManagedObjects) { TEST_F(BluetoothGattApplicationServiceProviderTest, GetManagedObjects) {
std::unique_ptr<BluetoothGattApplicationServiceProviderImpl> app_provider = std::unique_ptr<BluetoothGattApplicationServiceProviderImpl> app_provider =
base::WrapUnique(new BluetoothGattApplicationServiceProviderImpl( base::MakeUnique<BluetoothGattApplicationServiceProviderImpl>(
nullptr, dbus::ObjectPath(kAppObjectPath), nullptr, dbus::ObjectPath(kAppObjectPath),
std::map<dbus::ObjectPath, BluetoothLocalGattServiceBlueZ*>())); std::map<dbus::ObjectPath, BluetoothLocalGattServiceBlueZ*>());
CreateFakeAttributes(app_provider.get()); CreateFakeAttributes(app_provider.get());
dbus::MethodCall method_call("com.example.Interface", "SomeMethod"); dbus::MethodCall method_call("com.example.Interface", "SomeMethod");
...@@ -364,9 +364,9 @@ TEST_F(BluetoothGattApplicationServiceProviderTest, GetManagedObjects) { ...@@ -364,9 +364,9 @@ TEST_F(BluetoothGattApplicationServiceProviderTest, GetManagedObjects) {
TEST_F(BluetoothGattApplicationServiceProviderTest, SendValueChanged) { TEST_F(BluetoothGattApplicationServiceProviderTest, SendValueChanged) {
std::unique_ptr<BluetoothGattApplicationServiceProviderImpl> app_provider = std::unique_ptr<BluetoothGattApplicationServiceProviderImpl> app_provider =
base::WrapUnique(new BluetoothGattApplicationServiceProviderImpl( base::MakeUnique<BluetoothGattApplicationServiceProviderImpl>(
nullptr, dbus::ObjectPath(kAppObjectPath), nullptr, dbus::ObjectPath(kAppObjectPath),
std::map<dbus::ObjectPath, BluetoothLocalGattServiceBlueZ*>())); std::map<dbus::ObjectPath, BluetoothLocalGattServiceBlueZ*>());
const std::string& kServicePath = const std::string& kServicePath =
CreateFakeService(app_provider.get(), "service0"); CreateFakeService(app_provider.get(), "service0");
const std::string& kCharacteristicPath = CreateFakeCharacteristic( const std::string& kCharacteristicPath = CreateFakeCharacteristic(
......
...@@ -416,13 +416,13 @@ BluetoothLEAdvertisementServiceProvider::Create( ...@@ -416,13 +416,13 @@ BluetoothLEAdvertisementServiceProvider::Create(
std::unique_ptr<UUIDList> solicit_uuids, std::unique_ptr<UUIDList> solicit_uuids,
std::unique_ptr<ServiceData> service_data) { std::unique_ptr<ServiceData> service_data) {
if (!bluez::BluezDBusManager::Get()->IsUsingFakes()) { if (!bluez::BluezDBusManager::Get()->IsUsingFakes()) {
return base::WrapUnique(new BluetoothAdvertisementServiceProviderImpl( return base::MakeUnique<BluetoothAdvertisementServiceProviderImpl>(
bus, object_path, delegate, type, std::move(service_uuids), bus, object_path, delegate, type, std::move(service_uuids),
std::move(manufacturer_data), std::move(solicit_uuids), std::move(manufacturer_data), std::move(solicit_uuids),
std::move(service_data))); std::move(service_data));
} }
return base::WrapUnique( return base::MakeUnique<FakeBluetoothLEAdvertisementServiceProvider>(
new FakeBluetoothLEAdvertisementServiceProvider(object_path, delegate)); object_path, delegate);
} }
} // namespace bluez } // namespace bluez
...@@ -32,7 +32,7 @@ void BluetoothGattServerTest::SetUp() { ...@@ -32,7 +32,7 @@ void BluetoothGattServerTest::SetUp() {
BluetoothTest::SetUp(); BluetoothTest::SetUp();
last_read_value_ = std::vector<uint8_t>(); last_read_value_ = std::vector<uint8_t>();
InitWithFakeAdapter(); InitWithFakeAdapter();
delegate_ = base::WrapUnique(new TestBluetoothLocalGattServiceDelegate()); delegate_ = base::MakeUnique<TestBluetoothLocalGattServiceDelegate>();
} }
void BluetoothGattServerTest::TearDown() { void BluetoothGattServerTest::TearDown() {
......
...@@ -38,7 +38,7 @@ BluetoothTestBase::~BluetoothTestBase() { ...@@ -38,7 +38,7 @@ BluetoothTestBase::~BluetoothTestBase() {
void BluetoothTestBase::StartLowEnergyDiscoverySession() { void BluetoothTestBase::StartLowEnergyDiscoverySession() {
adapter_->StartDiscoverySessionWithFilter( adapter_->StartDiscoverySessionWithFilter(
base::WrapUnique(new BluetoothDiscoveryFilter(BLUETOOTH_TRANSPORT_LE)), base::MakeUnique<BluetoothDiscoveryFilter>(BLUETOOTH_TRANSPORT_LE),
GetDiscoverySessionCallback(Call::EXPECTED), GetDiscoverySessionCallback(Call::EXPECTED),
GetErrorCallback(Call::NOT_EXPECTED)); GetErrorCallback(Call::NOT_EXPECTED));
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
...@@ -46,7 +46,7 @@ void BluetoothTestBase::StartLowEnergyDiscoverySession() { ...@@ -46,7 +46,7 @@ void BluetoothTestBase::StartLowEnergyDiscoverySession() {
void BluetoothTestBase::StartLowEnergyDiscoverySessionExpectedToFail() { void BluetoothTestBase::StartLowEnergyDiscoverySessionExpectedToFail() {
adapter_->StartDiscoverySessionWithFilter( adapter_->StartDiscoverySessionWithFilter(
base::WrapUnique(new BluetoothDiscoveryFilter(BLUETOOTH_TRANSPORT_LE)), base::MakeUnique<BluetoothDiscoveryFilter>(BLUETOOTH_TRANSPORT_LE),
GetDiscoverySessionCallback(Call::NOT_EXPECTED), GetDiscoverySessionCallback(Call::NOT_EXPECTED),
GetErrorCallback(Call::EXPECTED)); GetErrorCallback(Call::EXPECTED));
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
......
...@@ -191,8 +191,8 @@ GeolocationProviderImpl::CreateArbitrator() { ...@@ -191,8 +191,8 @@ GeolocationProviderImpl::CreateArbitrator() {
if (!g_delegate.Get()) if (!g_delegate.Get())
g_delegate.Get().reset(new GeolocationDelegate); g_delegate.Get().reset(new GeolocationDelegate);
return base::WrapUnique( return base::MakeUnique<LocationArbitratorImpl>(callback,
new LocationArbitratorImpl(callback, g_delegate.Get().get())); g_delegate.Get().get());
} }
} // namespace device } // namespace device
...@@ -160,8 +160,8 @@ LocationArbitratorImpl::NewNetworkLocationProvider( ...@@ -160,8 +160,8 @@ LocationArbitratorImpl::NewNetworkLocationProvider(
// Android uses its own SystemLocationProvider. // Android uses its own SystemLocationProvider.
return nullptr; return nullptr;
#else #else
return base::WrapUnique(new NetworkLocationProvider( return base::MakeUnique<NetworkLocationProvider>(access_token_store, context,
access_token_store, context, url, access_token)); url, access_token);
#endif #endif
} }
......
...@@ -218,8 +218,8 @@ class UsbGadgetFactory : public UsbService::Observer, ...@@ -218,8 +218,8 @@ class UsbGadgetFactory : public UsbService::Observer,
std::unique_ptr<UsbTestGadget> WaitForDevice() { std::unique_ptr<UsbTestGadget> WaitForDevice() {
EnumerateDevices(); EnumerateDevices();
run_loop_.Run(); run_loop_.Run();
return base::WrapUnique( return base::MakeUnique<UsbTestGadgetImpl>(request_context_getter_,
new UsbTestGadgetImpl(request_context_getter_, usb_service_, device_)); usb_service_, device_);
} }
private: private:
......
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