refactor: Enable network service (Part 1) (#17431)

* Convert InspectableWebContentsImpl::LoadNetworkResource to SimpleURLLoader

https://bugs.chromium.org/p/chromium/issues/detail?id=721408

* Plumb creation of network context with the service
This commit is contained in:
Robo 2019-03-26 06:40:48 +05:30 committed by Cheng Zhao
parent 4ec2f8b67b
commit 6c20c6e668
18 changed files with 469 additions and 172 deletions

View file

@ -11,7 +11,6 @@
#include "atom/common/application_info.h"
#include "atom/common/options_switches.h"
#include "base/command_line.h"
#include "base/lazy_instance.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/net/chrome_mojo_proxy_resolver_factory.h"
#include "components/net_log/net_export_file_writer.h"
@ -27,11 +26,11 @@
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "url/gurl.h"
base::LazyInstance<SystemNetworkContextManager>::Leaky
g_system_network_context_manager = LAZY_INSTANCE_INITIALIZER;
namespace {
// The global instance of the SystemNetworkContextmanager.
SystemNetworkContextManager* g_system_network_context_manager = nullptr;
network::mojom::HttpAuthStaticParamsPtr CreateHttpAuthStaticParams() {
network::mojom::HttpAuthStaticParamsPtr auth_static_params =
network::mojom::HttpAuthStaticParams::New();
@ -63,10 +62,11 @@ class SystemNetworkContextManager::URLLoaderFactoryForSystem
: public network::SharedURLLoaderFactory {
public:
explicit URLLoaderFactoryForSystem(SystemNetworkContextManager* manager)
: manager_(manager) {}
: manager_(manager) {
DETACH_FROM_SEQUENCE(sequence_checker_);
}
// mojom::URLLoaderFactory implementation:
void CreateLoaderAndStart(network::mojom::URLLoaderRequest request,
int32_t routing_id,
int32_t request_id,
@ -75,7 +75,7 @@ class SystemNetworkContextManager::URLLoaderFactoryForSystem
network::mojom::URLLoaderClientPtr client,
const net::MutableNetworkTrafficAnnotationTag&
traffic_annotation) override {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (!manager_)
return;
manager_->GetURLLoaderFactory()->CreateLoaderAndStart(
@ -91,6 +91,7 @@ class SystemNetworkContextManager::URLLoaderFactoryForSystem
// SharedURLLoaderFactory implementation:
std::unique_ptr<network::SharedURLLoaderFactoryInfo> Clone() override {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
return std::make_unique<network::CrossThreadSharedURLLoaderFactoryInfo>(
this);
@ -102,6 +103,7 @@ class SystemNetworkContextManager::URLLoaderFactoryForSystem
friend class base::RefCounted<URLLoaderFactoryForSystem>;
~URLLoaderFactoryForSystem() override {}
SEQUENCE_CHECKER(sequence_checker_);
SystemNetworkContextManager* manager_;
DISALLOW_COPY_AND_ASSIGN(URLLoaderFactoryForSystem);
@ -157,7 +159,6 @@ SystemNetworkContextManager::GetNetExportFileWriter() {
return net_export_file_writer_.get();
}
// static
network::mojom::NetworkContextParamsPtr
SystemNetworkContextManager::CreateDefaultNetworkContextParams() {
network::mojom::NetworkContextParamsPtr network_context_params =
@ -191,8 +192,29 @@ void SystemNetworkContextManager::SetUp(
*http_auth_dynamic_params = CreateHttpAuthDynamicParams();
}
SystemNetworkContextManager::SystemNetworkContextManager()
: proxy_config_monitor_(g_browser_process->local_state()) {
// static
SystemNetworkContextManager* SystemNetworkContextManager::CreateInstance(
PrefService* pref_service) {
DCHECK(!g_system_network_context_manager);
g_system_network_context_manager =
new SystemNetworkContextManager(pref_service);
return g_system_network_context_manager;
}
// static
SystemNetworkContextManager* SystemNetworkContextManager::GetInstance() {
return g_system_network_context_manager;
}
// static
void SystemNetworkContextManager::DeleteInstance() {
DCHECK(g_system_network_context_manager);
delete g_system_network_context_manager;
}
SystemNetworkContextManager::SystemNetworkContextManager(
PrefService* pref_service)
: proxy_config_monitor_(pref_service) {
shared_url_loader_factory_ = new URLLoaderFactoryForSystem(this);
}