fix: UtilityProcess.fork before app ready

This commit is contained in:
Shelley Vohr
2024-02-27 20:53:24 +01:00
parent 707b9a58cc
commit 63411ec513
6 changed files with 29 additions and 7 deletions

View File

@@ -93,7 +93,7 @@ BuildState* BrowserProcessImpl::GetBuildState() {
return nullptr;
}
void BrowserProcessImpl::PostEarlyInitialization() {
void BrowserProcessImpl::PreEarlyInitialization() {
PrefServiceFactory prefs_factory;
auto pref_registry = base::MakeRefCounted<PrefRegistrySimple>();
PrefProxyConfigTrackerImpl::RegisterPrefs(pref_registry.get());
@@ -126,7 +126,7 @@ void BrowserProcessImpl::PreCreateThreads() {
// Must be created before the IOThread.
// Once IOThread class is no longer needed,
// this can be created on first use.
if (!SystemNetworkContextManager::GetInstance())
if (!SystemNetworkContextManager::HasInstance())
SystemNetworkContextManager::CreateInstance(local_state_.get());
}

View File

@@ -52,7 +52,7 @@ class BrowserProcessImpl : public BrowserProcess {
static void ApplyProxyModeFromCommandLine(ValueMapPrefStore* pref_store);
BuildState* GetBuildState() override;
void PostEarlyInitialization();
void PreEarlyInitialization();
void PreCreateThreads();
void PreMainMessageLoopRun();
void PostDestroyThreads() {}

View File

@@ -999,6 +999,10 @@ void ElectronBrowserClient::OnNetworkServiceCreated(
if (!g_browser_process)
return;
if (!SystemNetworkContextManager::HasInstance())
SystemNetworkContextManager::CreateInstance(
g_browser_process->local_state());
g_browser_process->system_network_context_manager()->OnNetworkServiceCreated(
network_service);
}

View File

@@ -223,6 +223,9 @@ int ElectronBrowserMainParts::PreEarlyInitialization() {
ui::ColorProviderManager::Get().AppendColorProviderInitializer(
base::BindRepeating(AddChromeColorMixers));
// Initialize after user script environment creation.
fake_browser_process_->PreEarlyInitialization();
return GetExitCode();
}
@@ -276,9 +279,6 @@ void ElectronBrowserMainParts::PostEarlyInitialization() {
// and/or user data directory.
logging::InitElectronLogging(*base::CommandLine::ForCurrentProcess(),
/* is_preinit = */ false);
// Initialize after user script environment creation.
fake_browser_process_->PostEarlyInitialization();
}
int ElectronBrowserMainParts::PreCreateThreads() {

View File

@@ -214,8 +214,20 @@ SystemNetworkContextManager* SystemNetworkContextManager::CreateInstance(
return g_system_network_context_manager;
}
// static
bool SystemNetworkContextManager::HasInstance() {
return !!g_system_network_context_manager;
}
// static
SystemNetworkContextManager* SystemNetworkContextManager::GetInstance() {
if (!g_system_network_context_manager) {
// Initialize the network service, which will trigger
// ElectronBrowserClient::OnNetworkServiceCreated(), which calls
// CreateInstance() to initialize |g_system_network_context_manager|.
content::GetNetworkService();
}
return g_system_network_context_manager;
}
@@ -223,6 +235,7 @@ SystemNetworkContextManager* SystemNetworkContextManager::GetInstance() {
void SystemNetworkContextManager::DeleteInstance() {
DCHECK(g_system_network_context_manager);
delete g_system_network_context_manager;
g_system_network_context_manager = nullptr;
}
// c.f.

View File

@@ -41,11 +41,16 @@ class SystemNetworkContextManager {
SystemNetworkContextManager& operator=(const SystemNetworkContextManager&) =
delete;
// Checks if the global SystemNetworkContextManager has been created.
static bool HasInstance();
// Creates the global instance of SystemNetworkContextManager. If an
// instance already exists, this will cause a DCHECK failure.
static SystemNetworkContextManager* CreateInstance(PrefService* pref_service);
// Gets the global SystemNetworkContextManager instance.
// Gets the global SystemNetworkContextManager instance. If it has not been
// created yet, NetworkService is called, which will cause the
// SystemNetworkContextManager to be created.
static SystemNetworkContextManager* GetInstance();
// Destroys the global SystemNetworkContextManager instance.