refactor: Add ElectronBrowserContext::BrowserContexts() (#46089)

* refactor: add ElectronBrowserContext::BrowserContexts()

* refactor: use ElectronBrowserContext::BrowserContexts() in ElectronBrowserMainParts::PostMainMessageLoopRun()

* refactor: use ElectronBrowserContext::BrowserContexts() in ElectronExtensionsBrowserClient::IsValidContext()

* refactor: use ElectronBrowserContext::BrowserContexts() in ElectronExtensionsBrowserClient::BroadcastEventToRenderers()

* refactor: move PartitionKey, BrowserContextMap private

* refactor: add ElectronBrowserContext::IsValidContext()

decouple ElectronExtensionsBrowserClient from the internals of ElectronBrowserContext
This commit is contained in:
Charles Kerr 2025-03-20 11:17:26 -05:00 committed by GitHub
parent 273baf4ec2
commit 46967ca9c9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 49 additions and 48 deletions

View file

@ -61,28 +61,9 @@ class ElectronBrowserContext : public content::BrowserContext {
ElectronBrowserContext(const ElectronBrowserContext&) = delete;
ElectronBrowserContext& operator=(const ElectronBrowserContext&) = delete;
// partition_id => browser_context
struct PartitionKey {
PartitionKey(const std::string_view partition, bool in_memory)
: type_{Type::Partition}, location_{partition}, in_memory_{in_memory} {}
[[nodiscard]] static std::vector<ElectronBrowserContext*> BrowserContexts();
explicit PartitionKey(const base::FilePath& file_path)
: type_{Type::Path},
location_{file_path.AsUTF8Unsafe()},
in_memory_{false} {}
friend auto operator<=>(const PartitionKey&, const PartitionKey&) = default;
private:
enum class Type { Partition, Path };
Type type_;
std::string location_;
bool in_memory_;
};
using BrowserContextMap =
std::map<PartitionKey, std::unique_ptr<ElectronBrowserContext>>;
[[nodiscard]] static bool IsValidContext(const void* context);
// Get or create the default BrowserContext.
static ElectronBrowserContext* GetDefaultBrowserContext(
@ -101,8 +82,6 @@ class ElectronBrowserContext : public content::BrowserContext {
static ElectronBrowserContext* FromPath(const base::FilePath& path,
base::Value::Dict options = {});
static BrowserContextMap& browser_context_map();
static void DestroyAllContexts();
void SetUserAgent(const std::string& user_agent);