refactor: minor electron browser context cleanup (#42816)

* refactor: make DevicePermissionMap private to electron::ElectronBrowserContext

refactor: make PartitionPath private to electron::ElectronBrowserContext

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* refactor: remove unused forward declarations of v8 classes

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* chore: forward declare gin::Arguments

Co-authored-by: Charles Kerr <charles@charleskerr.com>

* refactor: use unique_ptr operator bool

Co-authored-by: Charles Kerr <charles@charleskerr.com>

---------

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Charles Kerr <charles@charleskerr.com>
This commit is contained in:
trop[bot] 2024-07-08 12:50:24 -04:00 committed by GitHub
parent f21c2f3837
commit 8ed47c429b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 17 additions and 22 deletions

View file

@ -467,7 +467,7 @@ bool ElectronBrowserContext::IsOffTheRecord() {
} }
std::string ElectronBrowserContext::GetMediaDeviceIDSalt() { std::string ElectronBrowserContext::GetMediaDeviceIDSalt() {
if (!media_device_id_salt_.get()) if (!media_device_id_salt_)
media_device_id_salt_ = std::make_unique<MediaDeviceIDSalt>(prefs_.get()); media_device_id_salt_ = std::make_unique<MediaDeviceIDSalt>(prefs_.get());
return media_device_id_salt_->GetSalt(); return media_device_id_salt_->GetSalt();
} }
@ -483,10 +483,9 @@ ElectronBrowserContext::CreateZoomLevelDelegate(
content::DownloadManagerDelegate* content::DownloadManagerDelegate*
ElectronBrowserContext::GetDownloadManagerDelegate() { ElectronBrowserContext::GetDownloadManagerDelegate() {
if (!download_manager_delegate_.get()) { if (!download_manager_delegate_) {
auto* download_manager = this->GetDownloadManager();
download_manager_delegate_ = download_manager_delegate_ =
std::make_unique<ElectronDownloadManagerDelegate>(download_manager); std::make_unique<ElectronDownloadManagerDelegate>(GetDownloadManager());
} }
return download_manager_delegate_.get(); return download_manager_delegate_.get();
} }
@ -504,7 +503,7 @@ ElectronBrowserContext::GetPlatformNotificationService() {
content::PermissionControllerDelegate* content::PermissionControllerDelegate*
ElectronBrowserContext::GetPermissionControllerDelegate() { ElectronBrowserContext::GetPermissionControllerDelegate() {
if (!permission_manager_.get()) if (!permission_manager_)
permission_manager_ = std::make_unique<ElectronPermissionManager>(); permission_manager_ = std::make_unique<ElectronPermissionManager>();
return permission_manager_.get(); return permission_manager_.get();
} }
@ -519,7 +518,7 @@ std::string ElectronBrowserContext::GetUserAgent() const {
} }
predictors::PreconnectManager* ElectronBrowserContext::GetPreconnectManager() { predictors::PreconnectManager* ElectronBrowserContext::GetPreconnectManager() {
if (!preconnect_manager_.get()) { if (!preconnect_manager_) {
preconnect_manager_ = preconnect_manager_ =
std::make_unique<predictors::PreconnectManager>(nullptr, this); std::make_unique<predictors::PreconnectManager>(nullptr, this);
} }

View file

@ -21,7 +21,6 @@
#include "content/public/browser/resource_context.h" #include "content/public/browser/resource_context.h"
#include "electron/buildflags/buildflags.h" #include "electron/buildflags/buildflags.h"
#include "electron/shell/browser/media/media_device_id_salt.h" #include "electron/shell/browser/media/media_device_id_salt.h"
#include "gin/arguments.h"
#include "mojo/public/cpp/bindings/remote.h" #include "mojo/public/cpp/bindings/remote.h"
#include "services/network/public/mojom/network_context.mojom.h" #include "services/network/public/mojom/network_context.mojom.h"
#include "services/network/public/mojom/url_loader_factory.mojom.h" #include "services/network/public/mojom/url_loader_factory.mojom.h"
@ -30,6 +29,10 @@
class PrefService; class PrefService;
class ValueMapPrefStore; class ValueMapPrefStore;
namespace gin {
class Arguments;
}
namespace network { namespace network {
class SharedURLLoaderFactory; class SharedURLLoaderFactory;
} }
@ -44,19 +47,8 @@ class ElectronExtensionSystem;
} }
#endif #endif
namespace v8 {
template <typename T>
class Local;
class Isolate;
class Value;
} // namespace v8
namespace electron { namespace electron {
using DevicePermissionMap =
std::map<blink::PermissionType,
std::map<url::Origin, std::vector<std::unique_ptr<base::Value>>>>;
class ElectronDownloadManagerDelegate; class ElectronDownloadManagerDelegate;
class ElectronPermissionManager; class ElectronPermissionManager;
class CookieChangeNotifier; class CookieChangeNotifier;
@ -69,10 +61,6 @@ using DisplayMediaResponseCallbackJs =
using DisplayMediaRequestHandler = using DisplayMediaRequestHandler =
base::RepeatingCallback<void(const content::MediaStreamRequest&, base::RepeatingCallback<void(const content::MediaStreamRequest&,
DisplayMediaResponseCallbackJs)>; DisplayMediaResponseCallbackJs)>;
using PartitionOrPath =
std::variant<std::reference_wrapper<const std::string>,
std::reference_wrapper<const base::FilePath>>;
class ElectronBrowserContext : public content::BrowserContext { class ElectronBrowserContext : public content::BrowserContext {
public: public:
// disable copy // disable copy
@ -207,6 +195,14 @@ class ElectronBrowserContext : public content::BrowserContext {
blink::PermissionType permissionType); blink::PermissionType permissionType);
private: private:
using DevicePermissionMap = std::map<
blink::PermissionType,
std::map<url::Origin, std::vector<std::unique_ptr<base::Value>>>>;
using PartitionOrPath =
std::variant<std::reference_wrapper<const std::string>,
std::reference_wrapper<const base::FilePath>>;
ElectronBrowserContext(const PartitionOrPath partition_location, ElectronBrowserContext(const PartitionOrPath partition_location,
bool in_memory, bool in_memory,
base::Value::Dict options); base::Value::Dict options);