OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/network/network_context.h" | 5 #include "content/network/network_context.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "components/network_session_configurator/common/network_switches.h" | 10 #include "components/network_session_configurator/common/network_switches.h" |
11 #include "content/network/cache_url_loader.h" | 11 #include "content/network/cache_url_loader.h" |
12 #include "content/network/network_service.h" | 12 #include "content/network/network_service_impl.h" |
13 #include "content/network/network_service_url_loader_factory_impl.h" | 13 #include "content/network/network_service_url_loader_factory_impl.h" |
14 #include "content/network/url_loader_impl.h" | 14 #include "content/network/url_loader_impl.h" |
15 #include "content/public/common/content_client.h" | 15 #include "content/public/common/content_client.h" |
16 #include "content/public/common/content_switches.h" | 16 #include "content/public/common/content_switches.h" |
17 #include "net/dns/host_resolver.h" | 17 #include "net/dns/host_resolver.h" |
18 #include "net/dns/mapped_host_resolver.h" | 18 #include "net/dns/mapped_host_resolver.h" |
19 #include "net/http/http_network_session.h" | 19 #include "net/http/http_network_session.h" |
20 #include "net/proxy/proxy_config.h" | 20 #include "net/proxy/proxy_config.h" |
21 #include "net/proxy/proxy_config_service_fixed.h" | 21 #include "net/proxy/proxy_config_service_fixed.h" |
22 #include "net/url_request/url_request_context.h" | 22 #include "net/url_request/url_request_context.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 builder.set_proxy_config_service(std::move(fixed_config_service)); | 80 builder.set_proxy_config_service(std::move(fixed_config_service)); |
81 } else { | 81 } else { |
82 builder.set_proxy_service(net::ProxyService::CreateDirect()); | 82 builder.set_proxy_service(net::ProxyService::CreateDirect()); |
83 } | 83 } |
84 | 84 |
85 return builder.Build(); | 85 return builder.Build(); |
86 } | 86 } |
87 | 87 |
88 } // namespace | 88 } // namespace |
89 | 89 |
90 NetworkContext::NetworkContext(NetworkService* network_service, | 90 NetworkContext::NetworkContext(NetworkServiceImpl* network_service, |
91 mojom::NetworkContextRequest request, | 91 mojom::NetworkContextRequest request, |
92 mojom::NetworkContextParamsPtr params) | 92 mojom::NetworkContextParamsPtr params) |
93 : network_service_(network_service), | 93 : network_service_(network_service), |
94 url_request_context_(MakeURLRequestContext()), | 94 url_request_context_(MakeURLRequestContext()), |
95 params_(std::move(params)), | 95 params_(std::move(params)), |
96 binding_(this, std::move(request)) { | 96 binding_(this, std::move(request)) { |
97 network_service_->RegisterNetworkContext(this); | 97 network_service_->RegisterNetworkContext(this); |
98 binding_.set_connection_error_handler( | 98 binding_.set_connection_error_handler( |
99 base::Bind(&NetworkContext::OnConnectionError, base::Unretained(this))); | 99 base::Bind(&NetworkContext::OnConnectionError, base::Unretained(this))); |
100 } | 100 } |
101 | 101 |
| 102 // TODO(mmenke): Share URLRequestContextBulder configuration between two |
| 103 // constructors. Can only share them once consumer code is ready for its |
| 104 // corresponding options to be overwritten. |
| 105 NetworkContext::NetworkContext( |
| 106 mojom::NetworkContextRequest request, |
| 107 mojom::NetworkContextParamsPtr params, |
| 108 std::unique_ptr<net::URLRequestContextBuilder> builder) |
| 109 : network_service_(nullptr), |
| 110 url_request_context_(builder->Build()), |
| 111 params_(std::move(params)), |
| 112 binding_(this, std::move(request)) {} |
| 113 |
102 NetworkContext::~NetworkContext() { | 114 NetworkContext::~NetworkContext() { |
103 // Call each URLLoaderImpl and ask it to release its net::URLRequest, as the | 115 // Call each URLLoaderImpl and ask it to release its net::URLRequest, as the |
104 // corresponding net::URLRequestContext is going away with this | 116 // corresponding net::URLRequestContext is going away with this |
105 // NetworkContext. The loaders can be deregistering themselves in Cleanup(), | 117 // NetworkContext. The loaders can be deregistering themselves in Cleanup(), |
106 // so have to be careful. | 118 // so have to be careful. |
107 while (!url_loaders_.empty()) | 119 while (!url_loaders_.empty()) |
108 (*url_loaders_.begin())->Cleanup(); | 120 (*url_loaders_.begin())->Cleanup(); |
109 | 121 |
110 // May be nullptr in tests. | 122 // May be nullptr in tests. |
111 if (network_service_) | 123 if (network_service_) |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 binding_(this) {} | 163 binding_(this) {} |
152 | 164 |
153 void NetworkContext::OnConnectionError() { | 165 void NetworkContext::OnConnectionError() { |
154 // Don't delete |this| in response to connection errors when it was created by | 166 // Don't delete |this| in response to connection errors when it was created by |
155 // CreateForTesting. | 167 // CreateForTesting. |
156 if (network_service_) | 168 if (network_service_) |
157 delete this; | 169 delete this; |
158 } | 170 } |
159 | 171 |
160 } // namespace content | 172 } // namespace content |
OLD | NEW |