refactor: Add ElectronBrowserContext::BrowserContexts() (35-x-y backport) (#46161)

refactor: Add `ElectronBrowserContext::BrowserContexts()`

* 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-21 10:50:16 -05:00 committed by GitHub
parent e3d95bb8a4
commit 998de7aa6c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 58 additions and 51 deletions

View file

@ -554,11 +554,9 @@ void ElectronBrowserMainParts::PostMainMessageLoopRun() {
// Shutdown the DownloadManager before destroying Node to prevent
// DownloadItem callbacks from crashing.
for (auto& iter : ElectronBrowserContext::browser_context_map()) {
auto* download_manager = iter.second.get()->GetDownloadManager();
if (download_manager) {
for (auto* browser_context : ElectronBrowserContext::BrowserContexts()) {
if (auto* download_manager = browser_context->GetDownloadManager())
download_manager->Shutdown();
}
}
// Shutdown utility process created with Electron API before
@ -598,11 +596,7 @@ void ElectronBrowserMainParts::PostMainMessageLoopRun() {
node_bindings_->set_uv_env(nullptr);
node_env_.reset();
auto default_context_key = ElectronBrowserContext::PartitionKey("", false);
std::unique_ptr<ElectronBrowserContext> default_context = std::move(
ElectronBrowserContext::browser_context_map()[default_context_key]);
ElectronBrowserContext::browser_context_map().clear();
default_context.reset();
ElectronBrowserContext::DestroyAllContexts();
fake_browser_process_->PostMainMessageLoopRun();
content::DevToolsAgentHost::StopRemoteDebuggingPipeHandler();