From 79cb5144ae7773efc49a543d68ca2826d40be6c9 Mon Sep 17 00:00:00 2001 From: David Sanders Date: Mon, 7 Jun 2021 19:00:05 -0700 Subject: [PATCH] chore: use std::make_unique/base::MakeRefCounted when possible (#29510) --- .../chrome/browser/process_singleton_posix.cc | 2 +- shell/app/electron_main.cc | 2 +- shell/app/node_main.cc | 2 +- .../browser/api/electron_api_crash_reporter.cc | 4 ++-- shell/browser/api/electron_api_menu.cc | 3 ++- .../api/electron_api_system_preferences_win.cc | 6 ++++-- shell/browser/api/electron_api_web_contents.cc | 18 ++++++++++-------- shell/browser/browser_process_impl.cc | 5 +++-- shell/browser/electron_browser_client.cc | 2 +- shell/browser/electron_browser_context.cc | 6 +++--- shell/browser/electron_browser_main_parts.cc | 11 ++++++----- .../electron_management_api_delegate.cc | 10 ++++------ .../api/streams_private/streams_private_api.cc | 7 +++---- shell/browser/extensions/api/tabs/tabs_api.cc | 9 ++++----- .../extensions/electron_extension_system.cc | 4 ++-- .../electron_extensions_browser_client.cc | 15 ++++++++------- shell/browser/native_window.cc | 2 +- shell/browser/native_window_views.cc | 9 +++++---- .../browser/net/electron_url_loader_factory.cc | 10 ++++++---- .../browser/net/proxying_url_loader_factory.cc | 5 +++-- .../net/system_network_context_manager.cc | 3 ++- .../win/notification_presenter_win.cc | 3 +-- .../browser/osr/osr_render_widget_host_view.cc | 4 ++-- shell/browser/ui/certificate_trust_mac.mm | 2 +- shell/browser/ui/devtools_manager_delegate.cc | 7 +++---- shell/browser/ui/gtk/status_icon.cc | 7 +++---- shell/browser/ui/inspectable_web_contents.cc | 3 +-- shell/browser/ui/webui/accessibility_ui.cc | 12 +++++------- shell/browser/ui/win/notify_icon.cc | 6 +++--- shell/browser/ui/x/x_window_utils.cc | 2 +- .../browser/web_contents_permission_helper.cc | 2 +- shell/common/gin_converters/net_converter.cc | 2 +- shell/common/v8_value_converter.cc | 2 +- .../api/electron_api_context_bridge.cc | 6 +++--- shell/renderer/electron_renderer_client.cc | 3 ++- .../electron_extensions_dispatcher_delegate.cc | 3 +-- shell/renderer/renderer_client_base.cc | 5 +++-- shell/renderer/web_worker_observer.cc | 3 ++- 38 files changed, 106 insertions(+), 101 deletions(-) diff --git a/chromium_src/chrome/browser/process_singleton_posix.cc b/chromium_src/chrome/browser/process_singleton_posix.cc index 6933d51e33ab..4c009f9311b7 100644 --- a/chromium_src/chrome/browser/process_singleton_posix.cc +++ b/chromium_src/chrome/browser/process_singleton_posix.cc @@ -878,7 +878,7 @@ ProcessSingleton::NotifyResult ProcessSingleton::NotifyOtherProcessOrCreate() { } void ProcessSingleton::StartListeningOnSocket() { - watcher_ = new LinuxWatcher(this); + watcher_ = base::MakeRefCounted(this); base::PostTask(FROM_HERE, {BrowserThread::IO}, base::BindOnce(&ProcessSingleton::LinuxWatcher::StartListening, watcher_, sock_)); diff --git a/shell/app/electron_main.cc b/shell/app/electron_main.cc index 0d360903eaf6..d8cb6300f591 100644 --- a/shell/app/electron_main.cc +++ b/shell/app/electron_main.cc @@ -252,7 +252,7 @@ int main(int argc, char* argv[]) { abort(); } - std::unique_ptr exec_path(new char[exec_path_size]); + auto exec_path = std::make_unique(exec_path_size); rv = _NSGetExecutablePath(exec_path.get(), &exec_path_size); if (rv != 0) { fprintf(stderr, "_NSGetExecutablePath: get path failed\n"); diff --git a/shell/app/node_main.cc b/shell/app/node_main.cc index ff9c7c373d2e..0fb50ec3ca2c 100644 --- a/shell/app/node_main.cc +++ b/shell/app/node_main.cc @@ -158,7 +158,7 @@ int NodeMain(int argc, char* argv[]) { // Feed gin::PerIsolateData with a task runner. argv = uv_setup_args(argc, argv); uv_loop_t* loop = uv_default_loop(); - scoped_refptr uv_task_runner(new UvTaskRunner(loop)); + auto uv_task_runner = base::MakeRefCounted(loop); base::ThreadTaskRunnerHandle handle(uv_task_runner); // Initialize feature list. diff --git a/shell/browser/api/electron_api_crash_reporter.cc b/shell/browser/api/electron_api_crash_reporter.cc index 5e56f9603379..f24aaffff7d7 100644 --- a/shell/browser/api/electron_api_crash_reporter.cc +++ b/shell/browser/api/electron_api_crash_reporter.cc @@ -197,13 +197,13 @@ void GetUploadedReports( #else scoped_refptr CreateCrashUploadList() { #if defined(OS_MAC) || defined(OS_WIN) - return new CrashUploadListCrashpad(); + return base::MakeRefCounted(); #else base::FilePath crash_dir_path; base::PathService::Get(electron::DIR_CRASH_DUMPS, &crash_dir_path); base::FilePath upload_log_path = crash_dir_path.AppendASCII(CrashUploadList::kReporterLogFilename); - return new TextLogUploadList(upload_log_path); + return base::MakeRefCounted(upload_log_path); #endif // defined(OS_MAC) || defined(OS_WIN) } diff --git a/shell/browser/api/electron_api_menu.cc b/shell/browser/api/electron_api_menu.cc index 7c0a505b417c..2630463d4863 100644 --- a/shell/browser/api/electron_api_menu.cc +++ b/shell/browser/api/electron_api_menu.cc @@ -50,7 +50,8 @@ namespace api { gin::WrapperInfo Menu::kWrapperInfo = {gin::kEmbedderNativeGin}; -Menu::Menu(gin::Arguments* args) : model_(new ElectronMenuModel(this)) { +Menu::Menu(gin::Arguments* args) + : model_(std::make_unique(this)) { model_->AddObserver(this); #if defined(OS_MAC) diff --git a/shell/browser/api/electron_api_system_preferences_win.cc b/shell/browser/api/electron_api_system_preferences_win.cc index 5b62866c5d08..00e9a2728bd4 100644 --- a/shell/browser/api/electron_api_system_preferences_win.cc +++ b/shell/browser/api/electron_api_system_preferences_win.cc @@ -192,7 +192,8 @@ void SystemPreferences::InitializeWindow() { // Creating this listener before the app is ready causes global shortcuts // to not fire if (Browser::Get()->is_ready()) - color_change_listener_.reset(new gfx::ScopedSysColorChangeListener(this)); + color_change_listener_ = + std::make_unique(this); else Browser::Get()->AddObserver(this); @@ -259,7 +260,8 @@ void SystemPreferences::OnSysColorChange() { void SystemPreferences::OnFinishLaunching( const base::DictionaryValue& launch_info) { - color_change_listener_.reset(new gfx::ScopedSysColorChangeListener(this)); + color_change_listener_ = + std::make_unique(this); } } // namespace api diff --git a/shell/browser/api/electron_api_web_contents.cc b/shell/browser/api/electron_api_web_contents.cc index 1c192f038021..7471a3a54d7c 100644 --- a/shell/browser/api/electron_api_web_contents.cc +++ b/shell/browser/api/electron_api_web_contents.cc @@ -537,8 +537,7 @@ FileSystem CreateFileSystemStruct(content::WebContents* web_contents, std::unique_ptr CreateFileSystemValue( const FileSystem& file_system) { - std::unique_ptr file_system_value( - new base::DictionaryValue()); + auto file_system_value = std::make_unique(); file_system_value->SetString("type", file_system.type); file_system_value->SetString("fileSystemName", file_system.file_system_name); file_system_value->SetString("rootURL", file_system.root_url); @@ -618,7 +617,8 @@ WebContents::WebContents(v8::Isolate* isolate, : content::WebContentsObserver(web_contents), type_(Type::kRemote), id_(GetAllWebContents().Add(this)), - devtools_file_system_indexer_(new DevToolsFileSystemIndexer), + devtools_file_system_indexer_( + base::MakeRefCounted()), file_task_runner_( base::ThreadPool::CreateSequencedTaskRunner({base::MayBlock()})) #if BUILDFLAG(ENABLE_PRINTING) @@ -635,7 +635,7 @@ WebContents::WebContents(v8::Isolate* isolate, extensions::ElectronExtensionWebContentsObserver::CreateForWebContents( web_contents); - script_executor_.reset(new extensions::ScriptExecutor(web_contents)); + script_executor_ = std::make_unique(web_contents); #endif auto session = Session::CreateFrom(isolate, GetBrowserContext()); @@ -674,7 +674,8 @@ WebContents::WebContents(v8::Isolate* isolate, WebContents::WebContents(v8::Isolate* isolate, const gin_helper::Dictionary& options) : id_(GetAllWebContents().Add(this)), - devtools_file_system_indexer_(new DevToolsFileSystemIndexer), + devtools_file_system_indexer_( + base::MakeRefCounted()), file_task_runner_( base::ThreadPool::CreateSequencedTaskRunner({base::MayBlock()})) #if BUILDFLAG(ENABLE_PRINTING) @@ -838,7 +839,8 @@ void WebContents::InitWithSessionAndOptions( #if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS) extensions::ElectronExtensionWebContentsObserver::CreateForWebContents( web_contents()); - script_executor_.reset(new extensions::ScriptExecutor(web_contents())); + script_executor_ = + std::make_unique(web_contents()); #endif AutofillDriverFactory::CreateForWebContents(web_contents()); @@ -904,8 +906,8 @@ void WebContents::InitWithWebContents(content::WebContents* web_contents, web_preferences && web_preferences->IsEnabled(options::kOffscreen); // Create InspectableWebContents. - inspectable_web_contents_.reset(new InspectableWebContents( - web_contents, browser_context->prefs(), is_guest)); + inspectable_web_contents_ = std::make_unique( + web_contents, browser_context->prefs(), is_guest); inspectable_web_contents_->SetDelegate(this); } diff --git a/shell/browser/browser_process_impl.cc b/shell/browser/browser_process_impl.cc index cf1ac7a3893b..91badf042138 100644 --- a/shell/browser/browser_process_impl.cc +++ b/shell/browser/browser_process_impl.cc @@ -112,8 +112,9 @@ void BrowserProcessImpl::PostEarlyInitialization() { user_pref_store->ReadPrefs(); prefs_factory.set_user_prefs(user_pref_store); } else { - prefs_factory.set_user_prefs( - new OverlayUserPrefStore(new InMemoryPrefStore)); + auto user_pref_store = + base::MakeRefCounted(new InMemoryPrefStore); + prefs_factory.set_user_prefs(user_pref_store); } local_state_ = prefs_factory.Create(std::move(pref_registry)); } diff --git a/shell/browser/electron_browser_client.cc b/shell/browser/electron_browser_client.cc index 8ae3760e54c4..0d6feee0c8fa 100644 --- a/shell/browser/electron_browser_client.cc +++ b/shell/browser/electron_browser_client.cc @@ -611,7 +611,7 @@ std::string ElectronBrowserClient::GetGeolocationApiKey() { scoped_refptr ElectronBrowserClient::CreateQuotaPermissionContext() { - return new ElectronQuotaPermissionContext; + return base::MakeRefCounted(); } content::GeneratedCodeCacheSettings diff --git a/shell/browser/electron_browser_context.cc b/shell/browser/electron_browser_context.cc index e7dfaad07c36..2b831d1c5e6c 100644 --- a/shell/browser/electron_browser_context.cc +++ b/shell/browser/electron_browser_context.cc @@ -103,7 +103,7 @@ ElectronBrowserContext::browser_context_map() { ElectronBrowserContext::ElectronBrowserContext(const std::string& partition, bool in_memory, base::DictionaryValue options) - : storage_policy_(new SpecialStoragePolicy), + : storage_policy_(base::MakeRefCounted()), protocol_registry_(new ProtocolRegistry), in_memory_(in_memory), ssl_config_(network::mojom::SSLConfig::New()) { @@ -184,9 +184,9 @@ void ElectronBrowserContext::InitPrefs() { #if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS) || \ BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER) - auto registry = WrapRefCounted(new user_prefs::PrefRegistrySyncable); + auto registry = base::MakeRefCounted(); #else - auto registry = WrapRefCounted(new PrefRegistrySimple); + auto registry = base::MakeRefCounted(); #endif registry->RegisterFilePathPref(prefs::kSelectFileLastDirectory, diff --git a/shell/browser/electron_browser_main_parts.cc b/shell/browser/electron_browser_main_parts.cc index 0b0dcf8a0ee6..d97f24fe631a 100644 --- a/shell/browser/electron_browser_main_parts.cc +++ b/shell/browser/electron_browser_main_parts.cc @@ -199,11 +199,12 @@ ElectronBrowserMainParts* ElectronBrowserMainParts::self_ = nullptr; ElectronBrowserMainParts::ElectronBrowserMainParts( const content::MainFunctionParams& params) - : fake_browser_process_(new BrowserProcessImpl), - browser_(new Browser), + : fake_browser_process_(std::make_unique()), + browser_(std::make_unique()), node_bindings_( NodeBindings::Create(NodeBindings::BrowserEnvironment::kBrowser)), - electron_bindings_(new ElectronBindings(node_bindings_->uv_loop())) { + electron_bindings_( + std::make_unique(node_bindings_->uv_loop())) { DCHECK(!self_) << "Cannot have two ElectronBrowserMainParts"; self_ = this; } @@ -386,7 +387,7 @@ void ElectronBrowserMainParts::ToolkitInitialized() { UpdateDarkThemeSetting(); // Update the native theme when GTK theme changes. The GetNativeTheme // here returns a NativeThemeGtk, which monitors GTK settings. - dark_theme_observer_.reset(new DarkThemeObserver); + dark_theme_observer_ = std::make_unique(); linux_ui->GetNativeTheme(nullptr)->AddObserver(dark_theme_observer_.get()); views::LinuxUI::SetInstance(std::move(linux_ui)); #endif @@ -401,7 +402,7 @@ void ElectronBrowserMainParts::ToolkitInitialized() { #endif #if defined(OS_MAC) - views_delegate_.reset(new ViewsDelegateMac); + views_delegate_ = std::make_unique(); #else views_delegate_ = std::make_unique(); #endif diff --git a/shell/browser/extensions/api/management/electron_management_api_delegate.cc b/shell/browser/extensions/api/management/electron_management_api_delegate.cc index 17669e9bad48..e81b273de5d9 100644 --- a/shell/browser/extensions/api/management/electron_management_api_delegate.cc +++ b/shell/browser/extensions/api/management/electron_management_api_delegate.cc @@ -111,9 +111,8 @@ ElectronManagementAPIDelegate::SetEnabledFunctionDelegate( content::BrowserContext* browser_context, const extensions::Extension* extension, base::OnceCallback callback) const { - return std::unique_ptr( - new ManagementSetEnabledFunctionInstallPromptDelegate( - web_contents, browser_context, extension, std::move(callback))); + return std::make_unique( + web_contents, browser_context, extension, std::move(callback)); } std::unique_ptr @@ -121,9 +120,8 @@ ElectronManagementAPIDelegate::UninstallFunctionDelegate( extensions::ManagementUninstallFunctionBase* function, const extensions::Extension* target_extension, bool show_programmatic_uninstall_ui) const { - return std::unique_ptr( - new ManagementUninstallFunctionUninstallDialogDelegate( - function, target_extension, show_programmatic_uninstall_ui)); + return std::make_unique( + function, target_extension, show_programmatic_uninstall_ui); } bool ElectronManagementAPIDelegate::CreateAppShortcutFunctionDelegate( diff --git a/shell/browser/extensions/api/streams_private/streams_private_api.cc b/shell/browser/extensions/api/streams_private/streams_private_api.cc index ab5dc0032006..4b0ef5df249b 100644 --- a/shell/browser/extensions/api/streams_private/streams_private_api.cc +++ b/shell/browser/extensions/api/streams_private/streams_private_api.cc @@ -62,10 +62,9 @@ void StreamsPrivateAPI::SendExecuteMimeTypeHandlerEvent( auto* api_contents = electron::api::WebContents::From(web_contents); if (api_contents) tab_id = api_contents->ID(); - std::unique_ptr stream_container( - new extensions::StreamContainer( - tab_id, embedded, handler_url, extension_id, - std::move(transferrable_loader), original_url)); + auto stream_container = std::make_unique( + tab_id, embedded, handler_url, extension_id, + std::move(transferrable_loader), original_url); extensions::MimeHandlerStreamManager::Get(browser_context) ->AddStream(view_id, std::move(stream_container), frame_tree_node_id, render_process_id, render_frame_id); diff --git a/shell/browser/extensions/api/tabs/tabs_api.cc b/shell/browser/extensions/api/tabs/tabs_api.cc index 3625ac3238a6..60838cd88917 100644 --- a/shell/browser/extensions/api/tabs/tabs_api.cc +++ b/shell/browser/extensions/api/tabs/tabs_api.cc @@ -72,7 +72,7 @@ ExecuteCodeFunction::InitResult ExecuteCodeInTabFunction::Init() { base::DictionaryValue* details_value = NULL; if (!args_->GetDictionary(1, &details_value)) return set_init_result(VALIDATION_FAILURE); - std::unique_ptr details(new InjectDetails()); + auto details = std::make_unique(); if (!InjectDetails::Populate(*details_value, details.get())) return set_init_result(VALIDATION_FAILURE); @@ -180,7 +180,7 @@ ExtensionFunction::ResponseAction TabsGetFunction::Run() { tabs::Tab tab; - tab.id.reset(new int(tab_id)); + tab.id = std::make_unique(tab_id); // TODO(nornagon): in Chrome, the tab URL is only available to extensions // that have the "tabs" (or "activeTab") permission. We should do the same // permission check here. @@ -249,9 +249,8 @@ ExtensionFunction::ResponseAction TabsGetZoomSettingsFunction::Run() { contents->GetZoomController()->zoom_mode(); api::tabs::ZoomSettings zoom_settings; ZoomModeToZoomSettings(zoom_mode, &zoom_settings); - zoom_settings.default_zoom_factor.reset( - new double(blink::PageZoomLevelToZoomFactor( - zoom_controller->GetDefaultZoomLevel()))); + zoom_settings.default_zoom_factor = std::make_unique( + blink::PageZoomLevelToZoomFactor(zoom_controller->GetDefaultZoomLevel())); return RespondNow( ArgumentList(api::tabs::GetZoomSettings::Results::Create(zoom_settings))); diff --git a/shell/browser/extensions/electron_extension_system.cc b/shell/browser/extensions/electron_extension_system.cc index 66ed510bd8fe..dfa0d8b85b03 100644 --- a/shell/browser/extensions/electron_extension_system.cc +++ b/shell/browser/extensions/electron_extension_system.cc @@ -92,7 +92,7 @@ void ElectronExtensionSystem::InitForRegularProfile(bool extensions_enabled) { if (!browser_context_->IsOffTheRecord()) LoadComponentExtensions(); - management_policy_.reset(new ManagementPolicy); + management_policy_ = std::make_unique(); } std::unique_ptr ParseManifest( @@ -160,7 +160,7 @@ scoped_refptr ElectronExtensionSystem::store_factory() { InfoMap* ElectronExtensionSystem::info_map() { if (!info_map_.get()) - info_map_ = new InfoMap; + info_map_ = base::MakeRefCounted(); return info_map_.get(); } diff --git a/shell/browser/extensions/electron_extensions_browser_client.cc b/shell/browser/extensions/electron_extensions_browser_client.cc index 5de1aa938ae5..a6678e3bf39b 100644 --- a/shell/browser/extensions/electron_extensions_browser_client.cc +++ b/shell/browser/extensions/electron_extensions_browser_client.cc @@ -57,14 +57,15 @@ using extensions::ExtensionsBrowserClient; namespace electron { ElectronExtensionsBrowserClient::ElectronExtensionsBrowserClient() - : api_client_(new extensions::ElectronExtensionsAPIClient), - process_manager_delegate_(new extensions::ElectronProcessManagerDelegate), - extension_cache_(new extensions::NullExtensionCache()) { + : api_client_(std::make_unique()), + process_manager_delegate_( + std::make_unique()), + extension_cache_(std::make_unique()) { // Electron does not have a concept of channel, so leave UNKNOWN to // enable all channel-dependent extension APIs. extensions::SetCurrentChannel(version_info::Channel::UNKNOWN); - resource_manager_.reset( - new extensions::ElectronComponentExtensionResourceManager()); + resource_manager_ = + std::make_unique(); AddAPIProvider( std::make_unique()); @@ -245,7 +246,7 @@ ElectronExtensionsBrowserClient::GetProcessManagerDelegate() const { std::unique_ptr ElectronExtensionsBrowserClient:: CreateExtensionHostDelegate() { // TODO(samuelmaddock): - return base::WrapUnique(new extensions::ElectronExtensionHostDelegate); + return std::make_unique(); } bool ElectronExtensionsBrowserClient::DidVersionUpdate( @@ -348,7 +349,7 @@ ElectronExtensionsBrowserClient::GetExtensionWebContentsObserver( extensions::KioskDelegate* ElectronExtensionsBrowserClient::GetKioskDelegate() { if (!kiosk_delegate_) - kiosk_delegate_.reset(new ElectronKioskDelegate()); + kiosk_delegate_ = std::make_unique(); return kiosk_delegate_.get(); } diff --git a/shell/browser/native_window.cc b/shell/browser/native_window.cc index 47346d3d13b4..9bfd5a36f7dd 100644 --- a/shell/browser/native_window.cc +++ b/shell/browser/native_window.cc @@ -47,7 +47,7 @@ gfx::Size GetExpandedWindowSize(const NativeWindow* window, gfx::Size size) { NativeWindow::NativeWindow(const gin_helper::Dictionary& options, NativeWindow* parent) - : widget_(new views::Widget), parent_(parent) { + : widget_(std::make_unique()), parent_(parent) { ++next_id_; options.Get(options::kFrame, &has_frame_); diff --git a/shell/browser/native_window_views.cc b/shell/browser/native_window_views.cc index a57af998a4d0..3d8253601260 100644 --- a/shell/browser/native_window_views.cc +++ b/shell/browser/native_window_views.cc @@ -145,8 +145,9 @@ class NativeWindowClientView : public views::ClientView { NativeWindowViews::NativeWindowViews(const gin_helper::Dictionary& options, NativeWindow* parent) : NativeWindow(options, parent), - root_view_(new RootView(this)), - keyboard_event_handler_(new views::UnhandledKeyboardEventHandler) { + root_view_(std::make_unique(this)), + keyboard_event_handler_( + std::make_unique()) { options.Get(options::kTitle, &title_); bool menu_bar_autohide; @@ -747,8 +748,8 @@ bool NativeWindowViews::MoveAbove(const std::string& sourceId) { } void NativeWindowViews::MoveTop() { - // TODO(julien.isorce): fix chromium in order to use existing - // widget()->StackAtTop(). +// TODO(julien.isorce): fix chromium in order to use existing +// widget()->StackAtTop(). #if defined(OS_WIN) gfx::Point pos = GetPosition(); gfx::Size size = GetSize(); diff --git a/shell/browser/net/electron_url_loader_factory.cc b/shell/browser/net/electron_url_loader_factory.cc index 5b922f185d09..21435fdfed18 100644 --- a/shell/browser/net/electron_url_loader_factory.cc +++ b/shell/browser/net/electron_url_loader_factory.cc @@ -97,15 +97,17 @@ network::mojom::URLResponseHeadPtr ToResponseHead( head->mime_type = "text/html"; head->charset = "utf-8"; if (dict.IsEmpty()) { - head->headers = new net::HttpResponseHeaders("HTTP/1.1 200 OK"); + head->headers = + base::MakeRefCounted("HTTP/1.1 200 OK"); return head; } int status_code = net::HTTP_OK; dict.Get("statusCode", &status_code); - head->headers = new net::HttpResponseHeaders(base::StringPrintf( - "HTTP/1.1 %d %s", status_code, - net::GetHttpReasonPhrase(static_cast(status_code)))); + head->headers = base::MakeRefCounted( + base::StringPrintf("HTTP/1.1 %d %s", status_code, + net::GetHttpReasonPhrase( + static_cast(status_code)))); dict.Get("charset", &head->charset); bool has_mime_type = dict.Get("mimeType", &head->mime_type); diff --git a/shell/browser/net/proxying_url_loader_factory.cc b/shell/browser/net/proxying_url_loader_factory.cc index 45f3c9f7adf1..30eb0d77a1e2 100644 --- a/shell/browser/net/proxying_url_loader_factory.cc +++ b/shell/browser/net/proxying_url_loader_factory.cc @@ -820,8 +820,9 @@ void ProxyingURLLoaderFactory::CreateLoaderAndStart( // make ServiceWorker work with file:// URLs, we have to intercept its // requests here. if (IsForServiceWorkerScript() && request.url.SchemeIsFile()) { - asar::CreateAsarURLLoader(request, std::move(loader), std::move(client), - new net::HttpResponseHeaders("")); + asar::CreateAsarURLLoader( + request, std::move(loader), std::move(client), + base::MakeRefCounted("")); return; } diff --git a/shell/browser/net/system_network_context_manager.cc b/shell/browser/net/system_network_context_manager.cc index dd8724a1f61f..94daa0a06724 100644 --- a/shell/browser/net/system_network_context_manager.cc +++ b/shell/browser/net/system_network_context_manager.cc @@ -214,7 +214,8 @@ void SystemNetworkContextManager::DeleteInstance() { SystemNetworkContextManager::SystemNetworkContextManager( PrefService* pref_service) : proxy_config_monitor_(pref_service) { - shared_url_loader_factory_ = new URLLoaderFactoryForSystem(this); + shared_url_loader_factory_ = + base::MakeRefCounted(this); } SystemNetworkContextManager::~SystemNetworkContextManager() { diff --git a/shell/browser/notifications/win/notification_presenter_win.cc b/shell/browser/notifications/win/notification_presenter_win.cc index 0ba3a7ce7ec2..ca268714878a 100644 --- a/shell/browser/notifications/win/notification_presenter_win.cc +++ b/shell/browser/notifications/win/notification_presenter_win.cc @@ -52,8 +52,7 @@ NotificationPresenter* NotificationPresenter::Create() { return new NotificationPresenterWin7; if (!WindowsToastNotification::Initialize()) return nullptr; - std::unique_ptr presenter( - new NotificationPresenterWin); + auto presenter = std::make_unique(); if (!presenter->Init()) return nullptr; diff --git a/shell/browser/osr/osr_render_widget_host_view.cc b/shell/browser/osr/osr_render_widget_host_view.cc index 679d878cfb12..e1892f01add9 100644 --- a/shell/browser/osr/osr_render_widget_host_view.cc +++ b/shell/browser/osr/osr_render_widget_host_view.cc @@ -183,9 +183,9 @@ OffScreenRenderWidgetHostView::OffScreenRenderWidgetHostView( frame_rate_(frame_rate), size_(initial_size), painting_(painting), - cursor_manager_(new content::CursorManager(this)), + cursor_manager_(std::make_unique(this)), mouse_wheel_phase_handler_(this), - backing_(new SkBitmap) { + backing_(std::make_unique()) { DCHECK(render_widget_host_); DCHECK(!render_widget_host_->GetView()); diff --git a/shell/browser/ui/certificate_trust_mac.mm b/shell/browser/ui/certificate_trust_mac.mm index 62c3a7c50ea9..ae234d6fccf7 100644 --- a/shell/browser/ui/certificate_trust_mac.mm +++ b/shell/browser/ui/certificate_trust_mac.mm @@ -58,7 +58,7 @@ certChain:(CFArrayRef)certChain secPolicy:(SecPolicyRef)secPolicy { if ((self = [super init])) { - promise_.reset(new gin_helper::Promise(std::move(promise))); + promise_ = std::make_unique>(std::move(promise)); panel_ = panel; cert_ = cert; trust_ = trust; diff --git a/shell/browser/ui/devtools_manager_delegate.cc b/shell/browser/ui/devtools_manager_delegate.cc index 0f8bd1252bff..d09cf6f5cc42 100644 --- a/shell/browser/ui/devtools_manager_delegate.cc +++ b/shell/browser/ui/devtools_manager_delegate.cc @@ -43,8 +43,8 @@ class TCPServerSocketFactory : public content::DevToolsSocketFactory { private: // content::ServerSocketFactory. std::unique_ptr CreateForHttpServer() override { - std::unique_ptr socket( - new net::TCPServerSocket(nullptr, net::NetLogSource())); + auto socket = + std::make_unique(nullptr, net::NetLogSource()); if (socket->ListenWithAddressAndPort(address_, port_, 10) != net::OK) return std::unique_ptr(); @@ -77,8 +77,7 @@ std::unique_ptr CreateSocketFactory() { DLOG(WARNING) << "Invalid http debugger port number " << temp_port; } } - return std::unique_ptr( - new TCPServerSocketFactory("127.0.0.1", port)); + return std::make_unique("127.0.0.1", port); } const char kBrowserCloseMethod[] = "Browser.close"; diff --git a/shell/browser/ui/gtk/status_icon.cc b/shell/browser/ui/gtk/status_icon.cc index 6a78f82d0c10..b14b71de64e5 100644 --- a/shell/browser/ui/gtk/status_icon.cc +++ b/shell/browser/ui/gtk/status_icon.cc @@ -46,12 +46,11 @@ std::unique_ptr CreateLinuxStatusIcon( if (AppIndicatorIcon::CouldOpen()) { ++indicators_count; - return std::unique_ptr(new AppIndicatorIcon( + return std::make_unique( base::StringPrintf("%s%d", id_prefix, indicators_count), image, - tool_tip)); + tool_tip); } else { - return std::unique_ptr( - new GtkStatusIcon(image, tool_tip)); + return std::make_unique(image, tool_tip); } return nullptr; #endif diff --git a/shell/browser/ui/inspectable_web_contents.cc b/shell/browser/ui/inspectable_web_contents.cc index ea14e88bfd61..7b422da122ca 100644 --- a/shell/browser/ui/inspectable_web_contents.cc +++ b/shell/browser/ui/inspectable_web_contents.cc @@ -614,8 +614,7 @@ void InspectableWebContents::AddDevToolsExtensionsToClient() { web_contents_->GetMainFrame()->GetProcess()->GetID(), url::Origin::Create(extension->url())); - std::unique_ptr extension_info( - new base::DictionaryValue()); + auto extension_info = std::make_unique(); extension_info->SetString("startPage", devtools_page_url.spec()); extension_info->SetString("name", extension->name()); extension_info->SetBoolean( diff --git a/shell/browser/ui/webui/accessibility_ui.cc b/shell/browser/ui/webui/accessibility_ui.cc index e1a1b8d5f71e..55dda5e70eee 100644 --- a/shell/browser/ui/webui/accessibility_ui.cc +++ b/shell/browser/ui/webui/accessibility_ui.cc @@ -91,8 +91,7 @@ std::unique_ptr BuildTargetDescriptor( int routing_id, ui::AXMode accessibility_mode, base::ProcessHandle handle = base::kNullProcessHandle) { - std::unique_ptr target_data( - new base::DictionaryValue()); + auto target_data = std::make_unique(); target_data->SetInteger(kProcessIdField, process_id); target_data->SetInteger(kRoutingIdField, routing_id); target_data->SetString(kUrlField, url.spec()); @@ -135,8 +134,7 @@ std::unique_ptr BuildTargetDescriptor( std::unique_ptr BuildTargetDescriptor( electron::NativeWindow* window) { - std::unique_ptr target_data( - new base::DictionaryValue()); + auto target_data = std::make_unique(); target_data->SetInteger(kSessionIdField, window->window_id()); target_data->SetString(kNameField, window->GetTitle()); target_data->SetString(kTypeField, kBrowser); @@ -259,7 +257,7 @@ void HandleAccessibilityRequestCallback( // Always dump the Accessibility tree. data.SetString(kInternal, kOn); - std::unique_ptr rvh_list(new base::ListValue()); + auto rvh_list = std::make_unique(); std::unique_ptr widgets( content::RenderWidgetHost::GetRenderWidgetHosts()); @@ -293,7 +291,7 @@ void HandleAccessibilityRequestCallback( data.Set(kPagesField, std::move(rvh_list)); - std::unique_ptr window_list(new base::ListValue()); + auto window_list = std::make_unique(); for (auto* window : electron::WindowList::GetWindows()) { window_list->Append(BuildTargetDescriptor(window)); } @@ -383,7 +381,7 @@ void ElectronAccessibilityUIMessageHandler::RequestNativeUITree( } // No browser with the specified |id| was found. - std::unique_ptr result(new base::DictionaryValue()); + auto result = std::make_unique(); result->SetInteger(kSessionIdField, window_id); result->SetString(kTypeField, kBrowser); result->SetString(kErrorField, "Window no longer exists."); diff --git a/shell/browser/ui/win/notify_icon.cc b/shell/browser/ui/win/notify_icon.cc index 06f3a6086a4c..fa65ce0f3f18 100644 --- a/shell/browser/ui/win/notify_icon.cc +++ b/shell/browser/ui/win/notify_icon.cc @@ -210,9 +210,9 @@ void NotifyIcon::PopUpContextMenu(const gfx::Point& pos, if (pos.IsOrigin()) rect.set_origin(display::Screen::GetScreen()->GetCursorScreenPoint()); - menu_runner_.reset( - new views::MenuRunner(menu_model != nullptr ? menu_model : menu_model_, - views::MenuRunner::HAS_MNEMONICS)); + menu_runner_ = std::make_unique( + menu_model != nullptr ? menu_model : menu_model_, + views::MenuRunner::HAS_MNEMONICS); menu_runner_->RunMenuAt(nullptr, nullptr, rect, views::MenuAnchorPosition::kTopLeft, ui::MENU_SOURCE_MOUSE); diff --git a/shell/browser/ui/x/x_window_utils.cc b/shell/browser/ui/x/x_window_utils.cc index e1511c65f502..ae174d60187c 100644 --- a/shell/browser/ui/x/x_window_utils.cc +++ b/shell/browser/ui/x/x_window_utils.cc @@ -40,7 +40,7 @@ bool ShouldUseGlobalMenuBar() { return false; dbus::Bus::Options options; - scoped_refptr bus(new dbus::Bus(options)); + auto bus = base::MakeRefCounted(options); dbus::ObjectProxy* object_proxy = bus->GetObjectProxy(DBUS_SERVICE_DBUS, dbus::ObjectPath(DBUS_PATH_DBUS)); diff --git a/shell/browser/web_contents_permission_helper.cc b/shell/browser/web_contents_permission_helper.cc index 82273f6adc73..87980a22ac9b 100644 --- a/shell/browser/web_contents_permission_helper.cc +++ b/shell/browser/web_contents_permission_helper.cc @@ -108,7 +108,7 @@ void WebContentsPermissionHelper::RequestMediaAccessPermission( &MediaAccessAllowed, request, std::move(response_callback))); base::DictionaryValue details; - std::unique_ptr media_types(new base::ListValue); + auto media_types = std::make_unique(); if (request.audio_type == blink::mojom::MediaStreamType::DEVICE_AUDIO_CAPTURE) { media_types->AppendString("audio"); diff --git a/shell/common/gin_converters/net_converter.cc b/shell/common/gin_converters/net_converter.cc index b5f776d40642..8612df21b640 100644 --- a/shell/common/gin_converters/net_converter.cc +++ b/shell/common/gin_converters/net_converter.cc @@ -315,7 +315,7 @@ bool Converter>::FromV8( auto list = std::make_unique(); if (!ConvertFromV8(isolate, val, list.get())) return false; - *out = new network::ResourceRequestBody(); + *out = base::MakeRefCounted(); for (size_t i = 0; i < list->GetSize(); ++i) { base::DictionaryValue* dict = nullptr; std::string type; diff --git a/shell/common/v8_value_converter.cc b/shell/common/v8_value_converter.cc index 43a7ddc2013b..a5d81a894a93 100644 --- a/shell/common/v8_value_converter.cc +++ b/shell/common/v8_value_converter.cc @@ -391,7 +391,7 @@ std::unique_ptr V8ValueConverter::FromV8Array( val->CreationContext() != isolate->GetCurrentContext()) scope = std::make_unique(val->CreationContext()); - std::unique_ptr result(new base::ListValue()); + auto result = std::make_unique(); // Only fields with integer keys are carried over to the ListValue. for (uint32_t i = 0; i < val->Length(); ++i) { diff --git a/shell/renderer/api/electron_api_context_bridge.cc b/shell/renderer/api/electron_api_context_bridge.cc index 1f5df6cea9ad..342aeca3963f 100644 --- a/shell/renderer/api/electron_api_context_bridge.cc +++ b/shell/renderer/api/electron_api_context_bridge.cc @@ -220,9 +220,9 @@ v8::MaybeLocal PassValueToOtherContext( // Make the promise a shared_ptr so that when the original promise is // freed the proxy promise is correctly freed as well instead of being // left dangling - std::shared_ptr>> proxied_promise( - new gin_helper::Promise>( - destination_context->GetIsolate())); + auto proxied_promise = + std::make_shared>>( + destination_context->GetIsolate()); v8::Local proxied_promise_handle = proxied_promise->GetHandle(); diff --git a/shell/renderer/electron_renderer_client.cc b/shell/renderer/electron_renderer_client.cc index ff2f2ec0c6e7..b37860eedbdd 100644 --- a/shell/renderer/electron_renderer_client.cc +++ b/shell/renderer/electron_renderer_client.cc @@ -35,7 +35,8 @@ bool IsDevToolsExtension(content::RenderFrame* render_frame) { ElectronRendererClient::ElectronRendererClient() : node_bindings_( NodeBindings::Create(NodeBindings::BrowserEnvironment::kRenderer)), - electron_bindings_(new ElectronBindings(node_bindings_->uv_loop())) {} + electron_bindings_( + std::make_unique(node_bindings_->uv_loop())) {} ElectronRendererClient::~ElectronRendererClient() = default; diff --git a/shell/renderer/extensions/electron_extensions_dispatcher_delegate.cc b/shell/renderer/extensions/electron_extensions_dispatcher_delegate.cc index 4e3e510e919e..3c1b8664d722 100644 --- a/shell/renderer/extensions/electron_extensions_dispatcher_delegate.cc +++ b/shell/renderer/extensions/electron_extensions_dispatcher_delegate.cc @@ -31,8 +31,7 @@ void ElectronExtensionsDispatcherDelegate::RegisterNativeHandlers( extensions::ScriptContext* context) { module_system->RegisterNativeHandler( "lazy_background_page", - std::unique_ptr( - new extensions::LazyBackgroundPageNativeHandler(context))); + std::make_unique(context)); } void ElectronExtensionsDispatcherDelegate::PopulateSourceMap( diff --git a/shell/renderer/renderer_client_base.cc b/shell/renderer/renderer_client_base.cc index eab9f352035e..d7b270fe1b08 100644 --- a/shell/renderer/renderer_client_base.cc +++ b/shell/renderer/renderer_client_base.cc @@ -179,7 +179,8 @@ void RendererClientBase::RenderThreadStarted() { extensions_client_.reset(CreateExtensionsClient()); extensions::ExtensionsClient::Set(extensions_client_.get()); - extensions_renderer_client_.reset(new ElectronExtensionsRendererClient); + extensions_renderer_client_ = + std::make_unique(); extensions::ExtensionsRendererClient::Set(extensions_renderer_client_.get()); thread->AddObserver(extensions_renderer_client_->GetDispatcher()); @@ -187,7 +188,7 @@ void RendererClientBase::RenderThreadStarted() { #if BUILDFLAG(ENABLE_PDF_VIEWER) // Enables printing from Chrome PDF viewer. - pdf_print_client_.reset(new ChromePDFPrintClient()); + pdf_print_client_ = std::make_unique(); pdf::PepperPDFHost::SetPrintClient(pdf_print_client_.get()); #endif diff --git a/shell/renderer/web_worker_observer.cc b/shell/renderer/web_worker_observer.cc index 7bd69ebc3114..e2ae116cdd7f 100644 --- a/shell/renderer/web_worker_observer.cc +++ b/shell/renderer/web_worker_observer.cc @@ -30,7 +30,8 @@ WebWorkerObserver* WebWorkerObserver::GetCurrent() { WebWorkerObserver::WebWorkerObserver() : node_bindings_( NodeBindings::Create(NodeBindings::BrowserEnvironment::kWorker)), - electron_bindings_(new ElectronBindings(node_bindings_->uv_loop())) { + electron_bindings_( + std::make_unique(node_bindings_->uv_loop())) { lazy_tls.Pointer()->Set(this); }