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/2257793002
Cr-Commit-Position: refs/heads/master@{#415593}
diff --git a/components/prefs/json_pref_store_unittest.cc b/components/prefs/json_pref_store_unittest.cc
index 18299e2..32e30ea4 100644
--- a/components/prefs/json_pref_store_unittest.cc
+++ b/components/prefs/json_pref_store_unittest.cc
@@ -213,7 +213,7 @@
base::FilePath some_path(FILE_PATH_LITERAL("/usr/sbin/"));
pref_store->SetValue(kSomeDirectory,
- base::WrapUnique(new StringValue(some_path.value())),
+ base::MakeUnique<StringValue>(some_path.value()),
WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
EXPECT_TRUE(pref_store->GetValue(kSomeDirectory, &actual));
EXPECT_TRUE(actual->GetAsString(&path));
@@ -226,7 +226,7 @@
EXPECT_TRUE(boolean);
pref_store->SetValue(kNewWindowsInTabs,
- base::WrapUnique(new FundamentalValue(false)),
+ base::MakeUnique<FundamentalValue>(false),
WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
EXPECT_TRUE(pref_store->GetValue(kNewWindowsInTabs, &actual));
EXPECT_TRUE(actual->GetAsBoolean(&boolean));
@@ -236,16 +236,15 @@
int integer = 0;
EXPECT_TRUE(actual->GetAsInteger(&integer));
EXPECT_EQ(20, integer);
- pref_store->SetValue(kMaxTabs, base::WrapUnique(new FundamentalValue(10)),
+ pref_store->SetValue(kMaxTabs, base::MakeUnique<FundamentalValue>(10),
WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
EXPECT_TRUE(pref_store->GetValue(kMaxTabs, &actual));
EXPECT_TRUE(actual->GetAsInteger(&integer));
EXPECT_EQ(10, integer);
- pref_store->SetValue(
- kLongIntPref,
- base::WrapUnique(new StringValue(base::Int64ToString(214748364842LL))),
- WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
+ pref_store->SetValue(kLongIntPref, base::MakeUnique<StringValue>(
+ base::Int64ToString(214748364842LL)),
+ WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
EXPECT_TRUE(pref_store->GetValue(kLongIntPref, &actual));
EXPECT_TRUE(actual->GetAsString(&string_value));
int64_t value;
@@ -855,8 +854,7 @@
// Set a normal pref and check that it gets scheduled to be written.
ASSERT_FALSE(file_writer->HasPendingWrite());
- pref_store->SetValue("normal",
- base::WrapUnique(new base::StringValue("normal")),
+ pref_store->SetValue("normal", base::MakeUnique<base::StringValue>("normal"),
WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
ASSERT_TRUE(file_writer->HasPendingWrite());
file_writer->DoScheduledWrite();
@@ -865,8 +863,7 @@
// Set a lossy pref and check that it is not scheduled to be written.
// SetValue/RemoveValue.
- pref_store->SetValue("lossy",
- base::WrapUnique(new base::StringValue("lossy")),
+ pref_store->SetValue("lossy", base::MakeUnique<base::StringValue>("lossy"),
WriteablePrefStore::LOSSY_PREF_WRITE_FLAG);
ASSERT_FALSE(file_writer->HasPendingWrite());
pref_store->RemoveValue("lossy", WriteablePrefStore::LOSSY_PREF_WRITE_FLAG);
@@ -874,7 +871,7 @@
// SetValueSilently/RemoveValueSilently.
pref_store->SetValueSilently("lossy",
- base::WrapUnique(new base::StringValue("lossy")),
+ base::MakeUnique<base::StringValue>("lossy"),
WriteablePrefStore::LOSSY_PREF_WRITE_FLAG);
ASSERT_FALSE(file_writer->HasPendingWrite());
pref_store->RemoveValueSilently("lossy",
@@ -882,8 +879,7 @@
ASSERT_FALSE(file_writer->HasPendingWrite());
// ReportValueChanged.
- pref_store->SetValue("lossy",
- base::WrapUnique(new base::StringValue("lossy")),
+ pref_store->SetValue("lossy", base::MakeUnique<base::StringValue>("lossy"),
WriteablePrefStore::LOSSY_PREF_WRITE_FLAG);
ASSERT_FALSE(file_writer->HasPendingWrite());
pref_store->ReportValueChanged("lossy",
@@ -904,14 +900,12 @@
// Set a lossy pref and check that it is not scheduled to be written.
ASSERT_FALSE(file_writer->HasPendingWrite());
- pref_store->SetValue("lossy",
- base::WrapUnique(new base::StringValue("lossy")),
+ pref_store->SetValue("lossy", base::MakeUnique<base::StringValue>("lossy"),
WriteablePrefStore::LOSSY_PREF_WRITE_FLAG);
ASSERT_FALSE(file_writer->HasPendingWrite());
// Set a normal pref and check that it is scheduled to be written.
- pref_store->SetValue("normal",
- base::WrapUnique(new base::StringValue("normal")),
+ pref_store->SetValue("normal", base::MakeUnique<base::StringValue>("normal"),
WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
ASSERT_TRUE(file_writer->HasPendingWrite());
@@ -928,14 +922,12 @@
// Set a normal pref and check that it is scheduled to be written.
ASSERT_FALSE(file_writer->HasPendingWrite());
- pref_store->SetValue("normal",
- base::WrapUnique(new base::StringValue("normal")),
+ pref_store->SetValue("normal", base::MakeUnique<base::StringValue>("normal"),
WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
ASSERT_TRUE(file_writer->HasPendingWrite());
// Set a lossy pref and check that the write is still scheduled.
- pref_store->SetValue("lossy",
- base::WrapUnique(new base::StringValue("lossy")),
+ pref_store->SetValue("lossy", base::MakeUnique<base::StringValue>("lossy"),
WriteablePrefStore::LOSSY_PREF_WRITE_FLAG);
ASSERT_TRUE(file_writer->HasPendingWrite());
@@ -951,8 +943,7 @@
ImportantFileWriter* file_writer = GetImportantFileWriter(pref_store);
// Set a lossy pref and check that it is not scheduled to be written.
- pref_store->SetValue("lossy",
- base::WrapUnique(new base::StringValue("lossy")),
+ pref_store->SetValue("lossy", base::MakeUnique<base::StringValue>("lossy"),
WriteablePrefStore::LOSSY_PREF_WRITE_FLAG);
ASSERT_FALSE(file_writer->HasPendingWrite());