fix: create system network context for global requests
Global requests currently includes DNS over HTTPS requests, certain cert validation requests (OCSP, AIA, etc) on some platforms and geolocation requests.
This commit is contained in:
parent
787dbbe610
commit
414dcfcd07
8 changed files with 448 additions and 86 deletions
|
@ -4,6 +4,23 @@
|
|||
|
||||
#include "atom/browser/browser_process_impl.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "chrome/browser/printing/print_job_manager.h"
|
||||
#include "chrome/common/chrome_switches.h"
|
||||
#include "components/prefs/in_memory_pref_store.h"
|
||||
#include "components/prefs/overlay_user_pref_store.h"
|
||||
#include "components/prefs/pref_registry.h"
|
||||
#include "components/prefs/pref_registry_simple.h"
|
||||
#include "components/prefs/pref_service_factory.h"
|
||||
#include "components/proxy_config/pref_proxy_config_tracker_impl.h"
|
||||
#include "components/proxy_config/proxy_config_dictionary.h"
|
||||
#include "components/proxy_config/proxy_config_pref_names.h"
|
||||
#include "content/public/common/content_switches.h"
|
||||
#include "net/proxy_resolution/proxy_config.h"
|
||||
#include "net/proxy_resolution/proxy_config_service.h"
|
||||
#include "net/proxy_resolution/proxy_config_with_annotation.h"
|
||||
#include "net/proxy_resolution/proxy_resolution_service.h"
|
||||
#include "ui/base/l10n/l10n_util.h"
|
||||
|
||||
#if BUILDFLAG(ENABLE_PRINTING)
|
||||
|
@ -18,6 +35,68 @@ BrowserProcessImpl::~BrowserProcessImpl() {
|
|||
g_browser_process = nullptr;
|
||||
}
|
||||
|
||||
// static
|
||||
void BrowserProcessImpl::ApplyProxyModeFromCommandLine(
|
||||
ValueMapPrefStore* pref_store) {
|
||||
if (!pref_store)
|
||||
return;
|
||||
|
||||
auto* command_line = base::CommandLine::ForCurrentProcess();
|
||||
|
||||
if (command_line->HasSwitch(switches::kNoProxyServer)) {
|
||||
pref_store->SetValue(proxy_config::prefs::kProxy,
|
||||
ProxyConfigDictionary::CreateDirect(),
|
||||
WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
|
||||
} else if (command_line->HasSwitch(switches::kProxyPacUrl)) {
|
||||
std::string pac_script_url =
|
||||
command_line->GetSwitchValueASCII(switches::kProxyPacUrl);
|
||||
pref_store->SetValue(proxy_config::prefs::kProxy,
|
||||
ProxyConfigDictionary::CreatePacScript(
|
||||
pac_script_url, false /* pac_mandatory */),
|
||||
WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
|
||||
} else if (command_line->HasSwitch(switches::kProxyAutoDetect)) {
|
||||
pref_store->SetValue(proxy_config::prefs::kProxy,
|
||||
ProxyConfigDictionary::CreateAutoDetect(),
|
||||
WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
|
||||
} else if (command_line->HasSwitch(switches::kProxyServer)) {
|
||||
std::string proxy_server =
|
||||
command_line->GetSwitchValueASCII(switches::kProxyServer);
|
||||
std::string bypass_list =
|
||||
command_line->GetSwitchValueASCII(switches::kProxyBypassList);
|
||||
pref_store->SetValue(
|
||||
proxy_config::prefs::kProxy,
|
||||
ProxyConfigDictionary::CreateFixedServers(proxy_server, bypass_list),
|
||||
WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
|
||||
}
|
||||
}
|
||||
|
||||
void BrowserProcessImpl::PostEarlyInitialization() {
|
||||
// Mock user prefs, as we only need to track changes for a
|
||||
// in memory pref store. There are no persistent preferences
|
||||
PrefServiceFactory prefs_factory;
|
||||
auto pref_registry = base::MakeRefCounted<PrefRegistrySimple>();
|
||||
PrefProxyConfigTrackerImpl::RegisterPrefs(pref_registry.get());
|
||||
auto pref_store = base::MakeRefCounted<ValueMapPrefStore>();
|
||||
ApplyProxyModeFromCommandLine(pref_store.get());
|
||||
prefs_factory.set_command_line_prefs(std::move(pref_store));
|
||||
prefs_factory.set_user_prefs(new OverlayUserPrefStore(new InMemoryPrefStore));
|
||||
local_state_ = prefs_factory.Create(std::move(pref_registry));
|
||||
}
|
||||
|
||||
void BrowserProcessImpl::PreCreateThreads(
|
||||
const base::CommandLine& command_line) {
|
||||
// Must be created before the IOThread.
|
||||
// Once IOThread class is no longer needed,
|
||||
// this can be created on first use.
|
||||
system_network_context_manager_ =
|
||||
std::make_unique<SystemNetworkContextManager>();
|
||||
}
|
||||
|
||||
void BrowserProcessImpl::PostMainMessageLoopRun() {
|
||||
// This expects to be destroyed before the task scheduler is torn down.
|
||||
system_network_context_manager_.reset();
|
||||
}
|
||||
|
||||
bool BrowserProcessImpl::IsShuttingDown() {
|
||||
return false;
|
||||
}
|
||||
|
@ -40,7 +119,8 @@ ProfileManager* BrowserProcessImpl::profile_manager() {
|
|||
}
|
||||
|
||||
PrefService* BrowserProcessImpl::local_state() {
|
||||
return nullptr;
|
||||
DCHECK(local_state_.get());
|
||||
return local_state_.get();
|
||||
}
|
||||
|
||||
net::URLRequestContextGetter* BrowserProcessImpl::system_request_context() {
|
||||
|
@ -79,7 +159,8 @@ IOThread* BrowserProcessImpl::io_thread() {
|
|||
|
||||
SystemNetworkContextManager*
|
||||
BrowserProcessImpl::system_network_context_manager() {
|
||||
return nullptr;
|
||||
DCHECK(system_network_context_manager_.get());
|
||||
return system_network_context_manager_.get();
|
||||
}
|
||||
|
||||
network::NetworkQualityTracker* BrowserProcessImpl::network_quality_tracker() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue