0

Apply WrapUnique and make_unique to misc files

Split out from crrev.com/c/2826514 to make review easier.

This is a large-scale change: go/chromium-modernize-make-unique

Bug: 1194272
Change-Id: Ic288c491480a48d47e462555c657f5fbf266921d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2827036
Commit-Queue: Peter Boström <pbos@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Owners-Override: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#872717}
This commit is contained in:
Peter Boström
2021-04-15 05:03:20 +00:00
committed by Chromium LUCI CQ
parent 6f02ad3149
commit f47f505dba
15 changed files with 89 additions and 60 deletions

@ -7,6 +7,7 @@
#include <stddef.h>
#include <cstddef>
#include <memory>
#include <set>
#include <utility>
#include <vector>
@ -23,6 +24,7 @@
#include "base/format_macros.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/metrics/histogram_macros.h"
#include "base/single_thread_task_runner.h"
#include "base/strings/string_number_conversions.h"
@ -366,8 +368,8 @@ ChromeUserManagerImpl::ChromeUserManagerImpl()
kAccountsPrefDeviceLocalAccounts,
base::BindRepeating(&ChromeUserManagerImpl::RetrieveTrustedDevicePolicies,
weak_factory_.GetWeakPtr()));
multi_profile_user_controller_.reset(
new MultiProfileUserController(this, GetLocalState()));
multi_profile_user_controller_ =
std::make_unique<MultiProfileUserController>(this, GetLocalState());
policy::DeviceLocalAccountPolicyService* device_local_account_policy_service =
g_browser_process->platform_part()
@ -708,8 +710,8 @@ void ChromeUserManagerImpl::PerformPostUserLoggedInActions(
bool browser_restart) {
// Initialize the session length limiter and start it only if
// session limit is defined by the policy.
session_length_limiter_.reset(
new SessionLengthLimiter(NULL, browser_restart));
session_length_limiter_ =
base::WrapUnique(new SessionLengthLimiter(nullptr, browser_restart));
}
bool ChromeUserManagerImpl::IsDeviceLocalAccountMarkedForRemoval(
@ -1173,7 +1175,7 @@ bool ChromeUserManagerImpl::IsUserAllowed(
UserFlow* ChromeUserManagerImpl::GetDefaultUserFlow() const {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
if (!default_flow_.get())
default_flow_.reset(new DefaultUserFlow());
default_flow_ = std::make_unique<DefaultUserFlow>();
return default_flow_.get();
}

@ -5,6 +5,8 @@
#include "chrome/browser/extensions/external_install_error.h"
#include <stddef.h>
#include <memory>
#include <utility>
#include "base/bind.h"
@ -326,11 +328,11 @@ ExternalInstallError::ExternalInstallError(
manager_(manager),
error_service_(GlobalErrorServiceFactory::GetForProfile(
Profile::FromBrowserContext(browser_context_))) {
prompt_.reset(new ExtensionInstallPrompt::Prompt(
ExtensionInstallPrompt::EXTERNAL_INSTALL_PROMPT));
prompt_ = std::make_unique<ExtensionInstallPrompt::Prompt>(
ExtensionInstallPrompt::EXTERNAL_INSTALL_PROMPT);
webstore_data_fetcher_.reset(
new WebstoreDataFetcher(this, GURL(), extension_id_));
webstore_data_fetcher_ =
std::make_unique<WebstoreDataFetcher>(this, GURL(), extension_id_);
webstore_data_fetcher_->Start(
content::BrowserContext::GetDefaultStoragePartition(browser_context_)
->GetURLLoaderFactoryForBrowserProcess()
@ -398,8 +400,8 @@ void ExternalInstallError::ShowDialog(Browser* browser) {
DCHECK(browser);
content::WebContents* web_contents = NULL;
web_contents = browser->tab_strip_model()->GetActiveWebContents();
install_ui_show_params_.reset(
new ExtensionInstallPromptShowParams(web_contents));
install_ui_show_params_ =
std::make_unique<ExtensionInstallPromptShowParams>(web_contents);
manager_->DidChangeInstallAlertVisibility(this, true);
ExtensionInstallPrompt::GetDefaultShowDialogCallback().Run(
install_ui_show_params_.get(),
@ -453,9 +455,9 @@ void ExternalInstallError::OnFetchComplete() {
// Create a new ExtensionInstallPrompt. We pass in NULL for the UI
// components because we display at a later point, and don't want
// to pass ones which may be invalidated.
install_ui_.reset(
install_ui_ = base::WrapUnique(
new ExtensionInstallPrompt(Profile::FromBrowserContext(browser_context_),
NULL)); // NULL native window.
/*native_window=*/nullptr));
install_ui_->ShowDialog(
base::BindOnce(&ExternalInstallError::OnInstallPromptDone,
@ -474,7 +476,8 @@ void ExternalInstallError::OnDialogReady(
prompt_ = std::move(prompt);
if (alert_type_ == BUBBLE_ALERT) {
global_error_.reset(new ExternalInstallBubbleAlert(this, prompt_.get()));
global_error_ =
std::make_unique<ExternalInstallBubbleAlert>(this, prompt_.get());
error_service_->AddUnownedGlobalError(global_error_.get());
if (!manager_->has_currently_visible_install_alert()) {
@ -489,7 +492,7 @@ void ExternalInstallError::OnDialogReady(
}
} else {
DCHECK(alert_type_ == MENU_ALERT);
global_error_.reset(new ExternalInstallMenuAlert(this));
global_error_ = std::make_unique<ExternalInstallMenuAlert>(this);
error_service_->AddUnownedGlobalError(global_error_.get());
}
}

@ -4,7 +4,10 @@
#include "chrome/browser/extensions/install_tracker.h"
#include <memory>
#include "base/files/file_path.h"
#include "base/memory/ptr_util.h"
#include "chrome/browser/extensions/active_install_data.h"
#include "chrome/browser/extensions/scoped_active_install.h"
#include "chrome/test/base/testing_profile.h"
@ -41,8 +44,8 @@ scoped_refptr<const Extension> CreateDummyExtension(const std::string& id) {
class InstallTrackerTest : public testing::Test {
public:
InstallTrackerTest() {
profile_.reset(new TestingProfile());
tracker_.reset(new InstallTracker(profile_.get(), NULL));
profile_ = std::make_unique<TestingProfile>();
tracker_ = base::WrapUnique(new InstallTracker(profile_.get(), nullptr));
}
~InstallTrackerTest() override {}
@ -110,8 +113,8 @@ TEST_F(InstallTrackerTest, ScopedActiveInstallDeregister) {
EXPECT_FALSE(tracker_->GetActiveInstall(kExtensionId1));
// Verify the constructor that doesn't register the install.
scoped_active_install.reset(
new ScopedActiveInstall(tracker(), kExtensionId1));
scoped_active_install =
std::make_unique<ScopedActiveInstall>(tracker(), kExtensionId1);
EXPECT_FALSE(tracker_->GetActiveInstall(kExtensionId1));
tracker_->AddActiveInstall(install_data);

@ -6,11 +6,13 @@
#include <stddef.h>
#include <memory>
#include <string>
#include <utility>
#include "base/bind.h"
#include "base/files/file_util.h"
#include "base/memory/ptr_util.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
@ -230,7 +232,7 @@ void FileSelectHelper::FileSelectionCanceled(void* params) {
void FileSelectHelper::StartNewEnumeration(const base::FilePath& path) {
base_dir_ = path;
auto entry = std::make_unique<ActiveDirectoryEnumeration>(path);
entry->lister_.reset(new net::DirectoryLister(
entry->lister_ = base::WrapUnique(new net::DirectoryLister(
path, net::DirectoryLister::NO_SORT_RECURSIVE, this));
entry->lister_->Start();
directory_enumeration_ = std::move(entry);

@ -349,8 +349,8 @@ TEST_F(BookmarkContextMenuControllerTest, CutCopyPasteNode) {
// Copy the URL.
controller->ExecuteCommand(IDC_COPY, 0);
controller.reset(new BookmarkContextMenuController(
NULL, NULL, NULL, profile_.get(), NullNavigatorGetter(),
controller = base::WrapUnique(new BookmarkContextMenuController(
nullptr, nullptr, nullptr, profile_.get(), NullNavigatorGetter(),
BOOKMARK_LAUNCH_LOCATION_NONE, nodes[0]->parent(), nodes));
size_t old_count = bb_node->children().size();
controller->ExecuteCommand(IDC_PASTE, 0);
@ -359,8 +359,8 @@ TEST_F(BookmarkContextMenuControllerTest, CutCopyPasteNode) {
ASSERT_EQ(old_count + 1, bb_node->children().size());
ASSERT_EQ(bb_node->children()[0]->url(), bb_node->children()[1]->url());
controller.reset(new BookmarkContextMenuController(
NULL, NULL, NULL, profile_.get(), NullNavigatorGetter(),
controller = base::WrapUnique(new BookmarkContextMenuController(
nullptr, nullptr, nullptr, profile_.get(), NullNavigatorGetter(),
BOOKMARK_LAUNCH_LOCATION_NONE, nodes[0]->parent(), nodes));
// Cut the URL.
controller->ExecuteCommand(IDC_CUT, 0);

@ -12,6 +12,7 @@
#include "base/callback.h"
#include "base/files/file_path.h"
#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "base/memory/ref_counted.h"
#include "base/sequenced_task_runner.h"
#include "base/strings/pattern.h"
@ -163,7 +164,7 @@ class DragAndDropSimulator {
gfx::PointF event_location;
gfx::PointF event_root_location;
CalculateEventLocations(location, &event_location, &event_root_location);
active_drag_event_.reset(new ui::DropTargetEvent(
active_drag_event_ = base::WrapUnique(new ui::DropTargetEvent(
data, event_location, event_root_location, kDefaultSourceOperations));
delegate->OnDragEntered(*active_drag_event_);
@ -580,7 +581,7 @@ class DragAndDropBrowserTest : public InProcessBrowserTest,
host_resolver()->AddRule("*", "127.0.0.1");
content::SetupCrossSiteRedirector(embedded_test_server());
ASSERT_TRUE(embedded_test_server()->Start());
drag_simulator_.reset(new DragAndDropSimulator(web_contents()));
drag_simulator_ = std::make_unique<DragAndDropSimulator>(web_contents());
}
void TearDownOnMainThread() override {
@ -1068,9 +1069,10 @@ IN_PROC_BROWSER_TEST_P(DragAndDropBrowserTest, MAYBE_DragImageBetweenFrames) {
// Setup test expectations.
DragAndDropBrowserTest::DragImageBetweenFrames_TestState state;
state.left_frame_events_counter.reset(new DOMDragEventCounter(left_frame()));
state.right_frame_events_counter.reset(
new DOMDragEventCounter(right_frame()));
state.left_frame_events_counter =
std::make_unique<DOMDragEventCounter>(left_frame());
state.right_frame_events_counter =
std::make_unique<DOMDragEventCounter>(right_frame());
state.expected_dom_event_data.set_expected_client_position("(55, 50)");
state.expected_dom_event_data.set_expected_drop_effect("none");
// (dragstart event handler in image_source.html is asking for "copy" only).
@ -1194,9 +1196,10 @@ void DragAndDropBrowserTest::DragImageBetweenFrames_Step2(
{"dragstart", "dragleave", "drop", "dragend"}));
// Release the mouse button to end the drag.
state->drop_event_waiter.reset(new DOMDragEventWaiter("drop", right_frame()));
state->dragend_event_waiter.reset(
new DOMDragEventWaiter("dragend", left_frame()));
state->drop_event_waiter =
std::make_unique<DOMDragEventWaiter>("drop", right_frame());
state->dragend_event_waiter =
std::make_unique<DOMDragEventWaiter>("dragend", left_frame());
state->left_frame_events_counter->Reset();
state->right_frame_events_counter->Reset();
SimulateMouseUp();
@ -1353,7 +1356,8 @@ void DragAndDropBrowserTest::DragImageFromDisappearingFrame_Step2(
}
// Release the mouse button to end the drag.
state->drop_event_waiter.reset(new DOMDragEventWaiter("drop", right_frame()));
state->drop_event_waiter =
std::make_unique<DOMDragEventWaiter>("drop", right_frame());
SimulateMouseUp();
// The test will continue in DragImageFromDisappearingFrame_Step3.
}
@ -1401,9 +1405,10 @@ IN_PROC_BROWSER_TEST_P(DragAndDropBrowserTest, MAYBE_CrossSiteDrag) {
// Setup test expectations.
DragAndDropBrowserTest::CrossSiteDrag_TestState state;
state.left_frame_events_counter.reset(new DOMDragEventCounter(left_frame()));
state.right_frame_events_counter.reset(
new DOMDragEventCounter(right_frame()));
state.left_frame_events_counter =
std::make_unique<DOMDragEventCounter>(left_frame());
state.right_frame_events_counter =
std::make_unique<DOMDragEventCounter>(right_frame());
// Start the drag in the left frame.
DragStartWaiter drag_start_waiter(web_contents());
@ -1450,8 +1455,8 @@ void DragAndDropBrowserTest::CrossSiteDrag_Step2(
}
// Release the mouse button to end the drag.
state->dragend_event_waiter.reset(
new DOMDragEventWaiter("dragend", left_frame()));
state->dragend_event_waiter =
std::make_unique<DOMDragEventWaiter>("dragend", left_frame());
SimulateMouseUp();
// The test will continue in DragImageBetweenFrames_Step3.
}

@ -4,6 +4,7 @@
#include "chromeos/services/device_sync/cryptauth_client_impl.h"
#include <memory>
#include <string>
#include <utility>
#include <vector>
@ -185,10 +186,10 @@ class DeviceSyncCryptAuthClientTest : public testing::Test {
identity_test_environment_.MakeUnconsentedPrimaryAccountAvailable(kEmail);
client_.reset(
new CryptAuthClientImpl(base::WrapUnique(api_call_flow_),
identity_test_environment_.identity_manager(),
shared_factory_, device_classifier));
client_ = std::make_unique<CryptAuthClientImpl>(
base::WrapUnique(api_call_flow_),
identity_test_environment_.identity_manager(), shared_factory_,
device_classifier);
}
// Sets up an expectation and captures a CryptAuth API POST request to

@ -14,6 +14,7 @@
#include "base/cpu.h"
#include "base/json/json_writer.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/memory/unsafe_shared_memory_region.h"
#include "base/metrics/histogram_macros.h"
#include "base/no_destructor.h"
@ -548,8 +549,9 @@ void Session::CreateVideoEncodeAccelerator(
vea_provider_->CreateVideoEncodeAccelerator(
vea.InitWithNewPipeAndPassReceiver());
// std::make_unique doesn't work to create a unique pointer of the subclass.
mojo_vea.reset(new media::MojoVideoEncodeAccelerator(std::move(vea),
supported_profiles_));
mojo_vea = base::WrapUnique<media::VideoEncodeAccelerator>(
new media::MojoVideoEncodeAccelerator(std::move(vea),
supported_profiles_));
}
std::move(callback).Run(base::ThreadTaskRunnerHandle::Get(),
std::move(mojo_vea));

@ -592,13 +592,13 @@ LegacyCacheStorage::LegacyCacheStorage(
owner_(owner),
cache_storage_manager_(cache_storage_manager) {
if (memory_only) {
cache_loader_.reset(new MemoryLoader(
cache_loader_ = base::WrapUnique<CacheLoader>(new MemoryLoader(
cache_task_runner_.get(), std::move(scheduler_task_runner),
quota_manager_proxy, blob_storage_context_, this, origin, owner));
return;
}
cache_loader_.reset(new SimpleCacheLoader(
cache_loader_ = base::WrapUnique<CacheLoader>(new SimpleCacheLoader(
origin_path_, cache_task_runner_.get(), std::move(scheduler_task_runner),
quota_manager_proxy, blob_storage_context_, this, origin, owner));

@ -24,6 +24,7 @@
#include "base/logging.h"
#include "base/macros.h"
#include "base/memory/memory_pressure_listener.h"
#include "base/memory/ptr_util.h"
#include "base/message_loop/timer_slack.h"
#include "base/metrics/field_trial.h"
#include "base/metrics/histogram_macros.h"
@ -702,8 +703,8 @@ void ChildThreadImpl::Init(const Options& options) {
// In single-process mode, there is no need to synchronize trials to the
// browser process (because it's the same process).
if (!IsInBrowserProcess()) {
field_trial_syncer_.reset(
new variations::ChildProcessFieldTrialSyncer(this));
field_trial_syncer_ =
base::WrapUnique(new variations::ChildProcessFieldTrialSyncer(this));
field_trial_syncer_->InitFieldTrialObserving(
*base::CommandLine::ForCurrentProcess());
}

@ -7,6 +7,7 @@
#include <stddef.h>
#include "base/bind.h"
#include "base/memory/ptr_util.h"
#include "base/memory/unsafe_shared_memory_region.h"
#include "build/build_config.h"
#include "content/common/pepper_file_util.h"
@ -160,7 +161,8 @@ int32_t PepperVideoDecoderHost::OnHostMsgInitialize(
// This is not synchronous, but subsequent IPC messages will be buffered, so
// it is okay to immediately send IPC messages.
if (command_buffer->channel()) {
decoder_.reset(new media::GpuVideoDecodeAcceleratorHost(command_buffer));
decoder_ = base::WrapUnique<media::VideoDecodeAccelerator>(
new media::GpuVideoDecodeAcceleratorHost(command_buffer));
media::VideoDecodeAccelerator::Config vda_config(profile_);
vda_config.supported_output_formats.assign(
{media::PIXEL_FORMAT_XRGB, media::PIXEL_FORMAT_ARGB});

@ -7,6 +7,7 @@
#include <string>
#include "base/check_op.h"
#include "base/memory/ptr_util.h"
#include "base/metrics/histogram_macros.h"
#include "base/notreached.h"
#include "content/renderer/pepper/host_globals.h"
@ -130,7 +131,8 @@ bool PPB_VideoDecoder_Impl::Init(PP_Resource graphics_context,
// This is not synchronous, but subsequent IPC messages will be buffered, so
// it is okay to immediately send IPC messages.
if (command_buffer->channel()) {
decoder_.reset(new media::GpuVideoDecodeAcceleratorHost(command_buffer));
decoder_ = base::WrapUnique<media::VideoDecodeAccelerator>(
new media::GpuVideoDecodeAcceleratorHost(command_buffer));
media::VideoDecodeAccelerator::Config config(PPToMediaProfile(profile));
config.supported_output_formats.assign(
{media::PIXEL_FORMAT_XRGB, media::PIXEL_FORMAT_ARGB});

@ -16,6 +16,7 @@
#include "base/bind.h"
#include "base/compiler_specific.h"
#include "base/memory/ptr_util.h"
#include "base/stl_util.h"
#include "cc/paint/raw_memory_transfer_cache_entry.h"
#include "cc/paint/transfer_cache_serialize_helper.h"
@ -97,17 +98,17 @@ class RasterImplementationTest : public testing::Test {
bool transfer_buffer_initialize_fail,
bool sync_query) {
SharedMemoryLimits limits = SharedMemoryLimitsForTesting();
command_buffer_.reset(new StrictMock<MockClientCommandBuffer>());
command_buffer_ = std::make_unique<StrictMock<MockClientCommandBuffer>>();
transfer_buffer_.reset(new MockTransferBuffer(
transfer_buffer_ = base::WrapUnique(new MockTransferBuffer(
command_buffer_.get(), kTransferBufferSize,
RasterImplementation::kStartingOffset,
RasterImplementation::kAlignment, transfer_buffer_initialize_fail));
helper_.reset(new RasterCmdHelper(command_buffer()));
helper_ = std::make_unique<RasterCmdHelper>(command_buffer());
helper_->Initialize(limits.command_buffer_size);
gpu_control_.reset(new StrictMock<MockClientGpuControl>());
gpu_control_ = std::make_unique<StrictMock<MockClientGpuControl>>();
capabilities_.max_combined_texture_image_units =
kMaxCombinedTextureImageUnits;
capabilities_.max_texture_image_units = kMaxTextureImageUnits;
@ -123,10 +124,10 @@ class RasterImplementationTest : public testing::Test {
{
InSequence sequence;
gl_.reset(new RasterImplementation(
gl_ = std::make_unique<RasterImplementation>(
helper_.get(), transfer_buffer_.get(),
bind_generates_resource_client, lose_context_when_out_of_memory,
gpu_control_.get(), nullptr /* image_decode_accelerator */));
gpu_control_.get(), nullptr /* image_decode_accelerator */);
}
// The client should be set to something non-null.

@ -4,6 +4,9 @@
#include <stddef.h>
#include <memory>
#include "base/memory/ptr_util.h"
#include "base/run_loop.h"
#include "base/test/task_environment.h"
#include "gpu/config/gpu_info.h"
@ -146,9 +149,10 @@ class MojoVideoEncodeAcceleratorTest : public ::testing::Test {
std::make_unique<MockMojoVideoEncodeAccelerator>(),
mojo_vea.InitWithNewPipeAndPassReceiver());
mojo_vea_.reset(new MojoVideoEncodeAccelerator(
std::move(mojo_vea),
media::VideoEncodeAccelerator::SupportedProfiles()));
mojo_vea_ =
base::WrapUnique<VideoEncodeAccelerator>(new MojoVideoEncodeAccelerator(
std::move(mojo_vea),
media::VideoEncodeAccelerator::SupportedProfiles()));
}
void TearDown() override {

@ -6,6 +6,7 @@
#include <memory>
#include "base/memory/ptr_util.h"
#include "base/metrics/field_trial_params.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
@ -203,7 +204,7 @@ FrameSchedulerImpl::FrameSchedulerImpl(
loading_power_mode_voter_(
power_scheduler::PowerModeArbiter::GetInstance()->NewVoter(
"PowerModeVoter.Loading")) {
frame_task_queue_controller_.reset(
frame_task_queue_controller_ = base::WrapUnique(
new FrameTaskQueueController(main_thread_scheduler_, this, this));
}