From 7353fa88cd15038368aa757de327705ee57cde5f Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Mon, 8 Jul 2024 13:49:23 -0400 Subject: [PATCH] refactor: minor electron browser context cleanup (#42815) * refactor: make DevicePermissionMap private to electron::ElectronBrowserContext refactor: make PartitionPath private to electron::ElectronBrowserContext Co-authored-by: Charles Kerr * refactor: remove unused forward declarations of v8 classes Co-authored-by: Charles Kerr * chore: forward declare gin::Arguments Co-authored-by: Charles Kerr * refactor: use unique_ptr operator bool Co-authored-by: Charles Kerr --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Charles Kerr --- shell/browser/electron_browser_context.cc | 11 ++++----- shell/browser/electron_browser_context.h | 28 ++++++++++------------- 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/shell/browser/electron_browser_context.cc b/shell/browser/electron_browser_context.cc index ec3462b21515..de61fb1e2198 100644 --- a/shell/browser/electron_browser_context.cc +++ b/shell/browser/electron_browser_context.cc @@ -401,7 +401,7 @@ bool ElectronBrowserContext::IsOffTheRecord() { } std::string ElectronBrowserContext::GetMediaDeviceIDSalt() { - if (!media_device_id_salt_.get()) + if (!media_device_id_salt_) media_device_id_salt_ = std::make_unique(prefs_.get()); return media_device_id_salt_->GetSalt(); } @@ -417,10 +417,9 @@ ElectronBrowserContext::CreateZoomLevelDelegate( content::DownloadManagerDelegate* ElectronBrowserContext::GetDownloadManagerDelegate() { - if (!download_manager_delegate_.get()) { - auto* download_manager = this->GetDownloadManager(); + if (!download_manager_delegate_) { download_manager_delegate_ = - std::make_unique(download_manager); + std::make_unique(GetDownloadManager()); } return download_manager_delegate_.get(); } @@ -438,7 +437,7 @@ ElectronBrowserContext::GetPlatformNotificationService() { content::PermissionControllerDelegate* ElectronBrowserContext::GetPermissionControllerDelegate() { - if (!permission_manager_.get()) + if (!permission_manager_) permission_manager_ = std::make_unique(); return permission_manager_.get(); } @@ -453,7 +452,7 @@ std::string ElectronBrowserContext::GetUserAgent() const { } predictors::PreconnectManager* ElectronBrowserContext::GetPreconnectManager() { - if (!preconnect_manager_.get()) { + if (!preconnect_manager_) { preconnect_manager_ = std::make_unique(nullptr, this); } diff --git a/shell/browser/electron_browser_context.h b/shell/browser/electron_browser_context.h index 09e9c7ce7228..149851967a85 100644 --- a/shell/browser/electron_browser_context.h +++ b/shell/browser/electron_browser_context.h @@ -21,7 +21,6 @@ #include "content/public/browser/resource_context.h" #include "electron/buildflags/buildflags.h" #include "electron/shell/browser/media/media_device_id_salt.h" -#include "gin/arguments.h" #include "mojo/public/cpp/bindings/remote.h" #include "services/network/public/mojom/network_context.mojom.h" #include "services/network/public/mojom/url_loader_factory.mojom.h" @@ -30,6 +29,10 @@ class PrefService; class ValueMapPrefStore; +namespace gin { +class Arguments; +} + namespace network { class SharedURLLoaderFactory; } @@ -44,19 +47,8 @@ class ElectronExtensionSystem; } #endif -namespace v8 { -template -class Local; -class Isolate; -class Value; -} // namespace v8 - namespace electron { -using DevicePermissionMap = - std::map>>>; - class ElectronDownloadManagerDelegate; class ElectronPermissionManager; class CookieChangeNotifier; @@ -69,10 +61,6 @@ using DisplayMediaResponseCallbackJs = using DisplayMediaRequestHandler = base::RepeatingCallback; -using PartitionOrPath = - std::variant, - std::reference_wrapper>; - class ElectronBrowserContext : public content::BrowserContext { public: // disable copy @@ -207,6 +195,14 @@ class ElectronBrowserContext : public content::BrowserContext { blink::PermissionType permissionType); private: + using DevicePermissionMap = std::map< + blink::PermissionType, + std::map>>>; + + using PartitionOrPath = + std::variant, + std::reference_wrapper>; + ElectronBrowserContext(const PartitionOrPath partition_location, bool in_memory, base::Value::Dict options);