Commit dd436299 authored by David Benjamin's avatar David Benjamin Committed by Commit Bot

Replace easy WrapUnique uses in //base.

WrapUnique(new ...) should be std::make_unique.

Bug: none
Change-Id: Ic2687b75ab5ef5884d2857d05defb37908a9e1ee
Reviewed-on: https://chromium-review.googlesource.com/c/1234961
Commit-Queue: David Benjamin <davidben@chromium.org>
Reviewed-by: default avatarAlbert J. Wong <ajwong@chromium.org>
Cr-Commit-Position: refs/heads/master@{#598795}
parent 442ccdda
......@@ -1073,7 +1073,7 @@ TEST_F(BindTest, BindMoveOnlyVector) {
using MoveOnlyVector = std::vector<std::unique_ptr<int>>;
MoveOnlyVector v;
v.push_back(WrapUnique(new int(12345)));
v.push_back(std::make_unique<int>(12345));
// Early binding should work:
base::Callback<MoveOnlyVector()> bound_cb =
......
......@@ -9,7 +9,6 @@
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/location.h"
#include "base/memory/ptr_util.h"
#include "base/memory/ref_counted.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
......@@ -198,7 +197,7 @@ TEST(CancelableCallbackTest, MoveOnlyType) {
int result = 0;
CancelableCallback<void(std::unique_ptr<int>)> cb(
base::Bind(&OnMoveOnlyReceived, base::Unretained(&result)));
cb.callback().Run(base::WrapUnique(new int(kExpectedResult)));
cb.callback().Run(std::make_unique<int>(kExpectedResult));
EXPECT_EQ(kExpectedResult, result);
}
......
......@@ -7,7 +7,6 @@
#include <cstddef>
#include <memory>
#include "base/memory/ptr_util.h"
#include "base/trace_event/memory_usage_estimator.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -200,8 +199,8 @@ TEST(MRUCacheTest, Owning) {
// First insert and item and then overwrite it.
static const int kItem1Key = 1;
cache.Put(kItem1Key, WrapUnique(new CachedItem(20)));
cache.Put(kItem1Key, WrapUnique(new CachedItem(22)));
cache.Put(kItem1Key, std::make_unique<CachedItem>(20));
cache.Put(kItem1Key, std::make_unique<CachedItem>(22));
// There should still be one item, and one extra live item.
auto iter = cache.Get(kItem1Key);
......@@ -217,8 +216,8 @@ TEST(MRUCacheTest, Owning) {
// go away.
{
Cache cache2(Cache::NO_AUTO_EVICT);
cache2.Put(1, WrapUnique(new CachedItem(20)));
cache2.Put(2, WrapUnique(new CachedItem(20)));
cache2.Put(1, std::make_unique<CachedItem>(20));
cache2.Put(2, std::make_unique<CachedItem>(20));
}
// There should be no objects leaked.
......@@ -227,8 +226,8 @@ TEST(MRUCacheTest, Owning) {
// Check that Clear() also frees things correctly.
{
Cache cache2(Cache::NO_AUTO_EVICT);
cache2.Put(1, WrapUnique(new CachedItem(20)));
cache2.Put(2, WrapUnique(new CachedItem(20)));
cache2.Put(1, std::make_unique<CachedItem>(20));
cache2.Put(2, std::make_unique<CachedItem>(20));
EXPECT_EQ(initial_count + 2, cached_item_live_count);
cache2.Clear();
EXPECT_EQ(initial_count, cached_item_live_count);
......
......@@ -12,7 +12,6 @@
#include "base/files/memory_mapped_file.h"
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/metrics/histogram_macros.h"
#include "base/stl_util.h"
#include "base/strings/string_util.h"
......@@ -108,7 +107,7 @@ GlobalActivityAnalyzer::CreateWithAllocator(
return nullptr;
}
return WrapUnique(new GlobalActivityAnalyzer(std::move(allocator)));
return std::make_unique<GlobalActivityAnalyzer>(std::move(allocator));
}
#if !defined(OS_NACL)
......
......@@ -11,7 +11,6 @@
#include "base/format_macros.h"
#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "base/metrics/field_trial.h"
#include "base/metrics/persistent_memory_allocator.h"
#include "base/strings/string_piece.h"
......@@ -45,7 +44,7 @@ std::string SortFeatureListString(const std::string& feature_list) {
class FeatureListTest : public testing::Test {
public:
FeatureListTest() : feature_list_(nullptr) {
RegisterFeatureListInstance(WrapUnique(new FeatureList));
RegisterFeatureListInstance(std::make_unique<FeatureList>());
}
~FeatureListTest() override { ClearFeatureListInstance(); }
......
......@@ -5,7 +5,6 @@
#include "base/metrics/persistent_sample_map.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/metrics/histogram_macros.h"
#include "base/metrics/persistent_histogram_allocator.h"
#include "base/numerics/safe_conversions.h"
......@@ -154,7 +153,7 @@ std::unique_ptr<SampleCountIterator> PersistentSampleMap::Iterator() const {
// Have to override "const" in order to make sure all samples have been
// loaded before trying to iterate over the map.
const_cast<PersistentSampleMap*>(this)->ImportSamples(-1, true);
return WrapUnique(new PersistentSampleMapIterator(sample_counts_));
return std::make_unique<PersistentSampleMapIterator>(sample_counts_);
}
// static
......
......@@ -5,7 +5,6 @@
#include "base/metrics/sample_map.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/numerics/safe_conversions.h"
#include "base/stl_util.h"
......@@ -106,7 +105,7 @@ Count SampleMap::TotalCount() const {
}
std::unique_ptr<SampleCountIterator> SampleMap::Iterator() const {
return WrapUnique(new SampleMapIterator(sample_counts_));
return std::make_unique<SampleMapIterator>(sample_counts_);
}
bool SampleMap::AddSubtractImpl(SampleCountIterator* iter, Operator op) {
......
......@@ -4,7 +4,6 @@
#include "base/metrics/single_sample_metrics.h"
#include "base/memory/ptr_util.h"
#include "base/metrics/dummy_histogram.h"
#include "base/test/gtest_util.h"
#include "base/test/metrics/histogram_tester.h"
......@@ -42,14 +41,14 @@ TEST_F(SingleSampleMetricsTest, DefaultFactoryGetSet) {
EXPECT_EQ(factory, SingleSampleMetricsFactory::Get());
// Setting a factory after the default has been instantiated should fail.
EXPECT_DCHECK_DEATH(SingleSampleMetricsFactory::SetFactory(
WrapUnique<SingleSampleMetricsFactory>(nullptr)));
EXPECT_DCHECK_DEATH(SingleSampleMetricsFactory::SetFactory(nullptr));
}
TEST_F(SingleSampleMetricsTest, CustomFactoryGetSet) {
SingleSampleMetricsFactory* factory = new DefaultSingleSampleMetricsFactory();
SingleSampleMetricsFactory::SetFactory(WrapUnique(factory));
EXPECT_EQ(factory, SingleSampleMetricsFactory::Get());
auto factory = std::make_unique<DefaultSingleSampleMetricsFactory>();
SingleSampleMetricsFactory* factory_raw = factory.get();
SingleSampleMetricsFactory::SetFactory(std::move(factory));
EXPECT_EQ(factory_raw, SingleSampleMetricsFactory::Get());
}
TEST_F(SingleSampleMetricsTest, DefaultSingleSampleMetricNoValue) {
......
......@@ -9,7 +9,6 @@
#include <utility>
#include "base/macros.h"
#include "base/memory/ptr_util.h"
namespace base {
......@@ -112,7 +111,7 @@ Win32StackFrameUnwinder::UnwindFunctions::~UnwindFunctions() {}
Win32StackFrameUnwinder::UnwindFunctions::UnwindFunctions() {}
Win32StackFrameUnwinder::Win32StackFrameUnwinder()
: Win32StackFrameUnwinder(WrapUnique(new Win32UnwindFunctions)) {}
: Win32StackFrameUnwinder(std::make_unique<Win32UnwindFunctions>()) {}
Win32StackFrameUnwinder::~Win32StackFrameUnwinder() {}
......
......@@ -5,7 +5,6 @@
#include "base/task/task_scheduler/scheduler_worker_stack.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/memory/ref_counted.h"
#include "base/task/task_scheduler/scheduler_worker.h"
#include "base/task/task_scheduler/sequence.h"
......@@ -45,15 +44,15 @@ class TaskSchedulerWorkerStackTest : public testing::Test {
protected:
void SetUp() override {
worker_a_ = MakeRefCounted<SchedulerWorker>(
ThreadPriority::NORMAL, WrapUnique(new MockSchedulerWorkerDelegate),
ThreadPriority::NORMAL, std::make_unique<MockSchedulerWorkerDelegate>(),
task_tracker_.GetTrackedRef());
ASSERT_TRUE(worker_a_);
worker_b_ = MakeRefCounted<SchedulerWorker>(
ThreadPriority::NORMAL, WrapUnique(new MockSchedulerWorkerDelegate),
ThreadPriority::NORMAL, std::make_unique<MockSchedulerWorkerDelegate>(),
task_tracker_.GetTrackedRef());
ASSERT_TRUE(worker_b_);
worker_c_ = MakeRefCounted<SchedulerWorker>(
ThreadPriority::NORMAL, WrapUnique(new MockSchedulerWorkerDelegate),
ThreadPriority::NORMAL, std::make_unique<MockSchedulerWorkerDelegate>(),
task_tracker_.GetTrackedRef());
ASSERT_TRUE(worker_c_);
}
......
......@@ -16,7 +16,6 @@
#include "base/cfi_buildflags.h"
#include "base/debug/stack_trace.h"
#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "base/metrics/field_trial.h"
#include "base/metrics/field_trial_params.h"
#include "base/synchronization/waitable_event.h"
......@@ -451,9 +450,9 @@ TEST_F(TaskSchedulerImplTest, MultipleTraitsExecutionModePairs) {
StartTaskScheduler();
std::vector<std::unique_ptr<ThreadPostingTasks>> threads_posting_tasks;
for (const auto& traits_execution_mode_pair : GetTraitsExecutionModePairs()) {
threads_posting_tasks.push_back(WrapUnique(
new ThreadPostingTasks(&scheduler_, traits_execution_mode_pair.traits,
traits_execution_mode_pair.execution_mode)));
threads_posting_tasks.push_back(std::make_unique<ThreadPostingTasks>(
&scheduler_, traits_execution_mode_pair.traits,
traits_execution_mode_pair.execution_mode));
threads_posting_tasks.back()->Start();
}
......
......@@ -8,7 +8,6 @@
#include <stdint.h>
#include "base/bind.h"
#include "base/memory/ptr_util.h"
#include "base/memory/ref_counted_memory.h"
#include "base/synchronization/waitable_event.h"
#include "base/threading/platform_thread.h"
......@@ -103,7 +102,7 @@ TEST_F(TraceEventAnalyzerTest, TraceEvent) {
event.arg_numbers["int"] = static_cast<double>(int_num);
event.arg_numbers["double"] = double_num;
event.arg_strings["string"] = str;
event.arg_values["dict"] = WrapUnique(new base::DictionaryValue());
event.arg_values["dict"] = std::make_unique<base::DictionaryValue>();
ASSERT_TRUE(event.HasNumberArg("false"));
ASSERT_TRUE(event.HasNumberArg("true"));
......
......@@ -16,7 +16,6 @@
#include "base/command_line.h"
#include "base/debug/thread_heap_usage_tracker.h"
#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "base/run_loop.h"
#include "base/single_thread_task_runner.h"
#include "base/synchronization/waitable_event.h"
......@@ -425,11 +424,11 @@ TEST_F(MemoryDumpManagerTest, RespectTaskRunnerAffinity) {
// we will pop out one thread/MemoryDumpProvider, each MDP is supposed to be
// invoked a number of times equal to its index.
for (uint32_t i = kNumInitialThreads; i > 0; --i) {
threads.push_back(WrapUnique(new Thread("test thread")));
threads.push_back(std::make_unique<Thread>("test thread"));
auto* thread = threads.back().get();
thread->Start();
scoped_refptr<SingleThreadTaskRunner> task_runner = thread->task_runner();
mdps.push_back(WrapUnique(new MockMemoryDumpProvider()));
mdps.push_back(std::make_unique<MockMemoryDumpProvider>());
auto* mdp = mdps.back().get();
RegisterDumpProvider(mdp, task_runner, kDefaultOptions);
EXPECT_CALL(*mdp, OnMemoryDump(_, _))
......@@ -602,9 +601,8 @@ TEST_F(MemoryDumpManagerTest, UnregisterDumperFromThreadWhileDumping) {
std::vector<std::unique_ptr<MockMemoryDumpProvider>> mdps;
for (int i = 0; i < 2; i++) {
threads.push_back(
WrapUnique(new TestIOThread(TestIOThread::kAutoStart)));
mdps.push_back(WrapUnique(new MockMemoryDumpProvider()));
threads.push_back(std::make_unique<TestIOThread>(TestIOThread::kAutoStart));
mdps.push_back(std::make_unique<MockMemoryDumpProvider>());
RegisterDumpProvider(mdps.back().get(), threads.back()->task_runner(),
kDefaultOptions);
}
......@@ -651,9 +649,8 @@ TEST_F(MemoryDumpManagerTest, TearDownThreadWhileDumping) {
std::vector<std::unique_ptr<MockMemoryDumpProvider>> mdps;
for (int i = 0; i < 2; i++) {
threads.push_back(
WrapUnique(new TestIOThread(TestIOThread::kAutoStart)));
mdps.push_back(WrapUnique(new MockMemoryDumpProvider()));
threads.push_back(std::make_unique<TestIOThread>(TestIOThread::kAutoStart));
mdps.push_back(std::make_unique<MockMemoryDumpProvider>());
RegisterDumpProvider(mdps.back().get(), threads.back()->task_runner(),
kDefaultOptions);
}
......
......@@ -8,7 +8,6 @@
#include <utility>
#include "base/memory/ptr_util.h"
#include "base/values.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -101,14 +100,14 @@ TEST(TraceEventArgumentTest, PassBaseValue) {
Value bool_value(true);
Value double_value(42.0f);
auto dict_value = WrapUnique(new DictionaryValue);
auto dict_value = std::make_unique<DictionaryValue>();
dict_value->SetBoolean("bool", true);
dict_value->SetInteger("int", 42);
dict_value->SetDouble("double", 42.0f);
dict_value->SetString("string", std::string("a") + "b");
dict_value->SetString("string", std::string("a") + "b");
auto list_value = WrapUnique(new ListValue);
auto list_value = std::make_unique<ListValue>();
list_value->AppendBoolean(false);
list_value->AppendInteger(1);
list_value->AppendString("in_list");
......
......@@ -15,7 +15,6 @@
#include <vector>
#include "base/containers/adapters.h"
#include "base/memory/ptr_util.h"
#include "base/strings/string16.h"
#include "base/strings/string_piece.h"
#include "base/strings/utf_string_conversions.h"
......@@ -1208,7 +1207,7 @@ TEST(ValuesTest, Equals) {
std::unique_ptr<ListValue> list(new ListValue);
list->Append(std::make_unique<Value>());
list->Append(WrapUnique(new DictionaryValue));
list->Append(std::make_unique<DictionaryValue>());
auto list_copy = std::make_unique<Value>(list->Clone());
ListValue* list_weak = dv.SetList("f", std::move(list));
......
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