Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(32)

Side by Side Diff: headless/lib/browser/headless_url_request_context_getter.cc

Issue 1912673002: headless: Add support for host resolver mapping (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased again Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « headless/app/headless_shell.cc ('k') | headless/lib/headless_browser_browsertest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "headless/lib/browser/headless_url_request_context_getter.h" 5 #include "headless/lib/browser/headless_url_request_context_getter.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/command_line.h"
10 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
11 #include "base/single_thread_task_runner.h" 10 #include "base/single_thread_task_runner.h"
12 #include "base/threading/worker_pool.h" 11 #include "base/threading/worker_pool.h"
13 #include "content/public/browser/browser_thread.h" 12 #include "content/public/browser/browser_thread.h"
14 #include "content/public/browser/cookie_store_factory.h" 13 #include "content/public/browser/cookie_store_factory.h"
15 #include "content/public/common/content_switches.h" 14 #include "content/public/common/content_switches.h"
16 #include "net/cert/cert_verifier.h" 15 #include "net/cert/cert_verifier.h"
17 #include "net/cookies/cookie_store.h" 16 #include "net/cookies/cookie_store.h"
18 #include "net/dns/host_resolver.h" 17 #include "net/dns/host_resolver.h"
19 #include "net/dns/mapped_host_resolver.h" 18 #include "net/dns/mapped_host_resolver.h"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 return net::ProxyService::CreateFixed(options_.proxy_server.ToString()); 97 return net::ProxyService::CreateFixed(options_.proxy_server.ToString());
99 return net::ProxyService::CreateUsingSystemProxyResolver( 98 return net::ProxyService::CreateUsingSystemProxyResolver(
100 std::move(proxy_config_service_), 0, url_request_context_->net_log()); 99 std::move(proxy_config_service_), 0, url_request_context_->net_log());
101 } 100 }
102 101
103 net::URLRequestContext* 102 net::URLRequestContext*
104 HeadlessURLRequestContextGetter::GetURLRequestContext() { 103 HeadlessURLRequestContextGetter::GetURLRequestContext() {
105 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 104 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
106 105
107 if (!url_request_context_) { 106 if (!url_request_context_) {
108 const base::CommandLine& command_line =
109 *base::CommandLine::ForCurrentProcess();
110
111 url_request_context_.reset(new net::URLRequestContext()); 107 url_request_context_.reset(new net::URLRequestContext());
112 url_request_context_->set_net_log(net_log_); 108 url_request_context_->set_net_log(net_log_);
113 network_delegate_ = CreateNetworkDelegate(); 109 network_delegate_ = CreateNetworkDelegate();
114 url_request_context_->set_network_delegate(network_delegate_.get()); 110 url_request_context_->set_network_delegate(network_delegate_.get());
115 storage_.reset( 111 storage_.reset(
116 new net::URLRequestContextStorage(url_request_context_.get())); 112 new net::URLRequestContextStorage(url_request_context_.get()));
117 storage_->set_cookie_store( 113 storage_->set_cookie_store(
118 content::CreateCookieStore(content::CookieStoreConfig())); 114 content::CreateCookieStore(content::CookieStoreConfig()));
119 storage_->set_channel_id_service(base::WrapUnique( 115 storage_->set_channel_id_service(base::WrapUnique(
120 new net::ChannelIDService(new net::DefaultChannelIDStore(nullptr), 116 new net::ChannelIDService(new net::DefaultChannelIDStore(nullptr),
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 url_request_context_->proxy_service(); 151 url_request_context_->proxy_service();
156 network_session_params.ssl_config_service = 152 network_session_params.ssl_config_service =
157 url_request_context_->ssl_config_service(); 153 url_request_context_->ssl_config_service();
158 network_session_params.http_auth_handler_factory = 154 network_session_params.http_auth_handler_factory =
159 url_request_context_->http_auth_handler_factory(); 155 url_request_context_->http_auth_handler_factory();
160 network_session_params.http_server_properties = 156 network_session_params.http_server_properties =
161 url_request_context_->http_server_properties(); 157 url_request_context_->http_server_properties();
162 network_session_params.net_log = url_request_context_->net_log(); 158 network_session_params.net_log = url_request_context_->net_log();
163 network_session_params.ignore_certificate_errors = 159 network_session_params.ignore_certificate_errors =
164 ignore_certificate_errors_; 160 ignore_certificate_errors_;
165 if (command_line.HasSwitch(switches::kHostResolverRules)) { 161 if (!options_.host_resolver_rules.empty()) {
166 std::unique_ptr<net::MappedHostResolver> mapped_host_resolver( 162 std::unique_ptr<net::MappedHostResolver> mapped_host_resolver(
167 new net::MappedHostResolver(std::move(host_resolver))); 163 new net::MappedHostResolver(std::move(host_resolver)));
168 mapped_host_resolver->SetRulesFromString( 164 mapped_host_resolver->SetRulesFromString(options_.host_resolver_rules);
169 command_line.GetSwitchValueASCII(switches::kHostResolverRules));
170 host_resolver = std::move(mapped_host_resolver); 165 host_resolver = std::move(mapped_host_resolver);
171 } 166 }
172 167
173 // Give |storage_| ownership at the end in case it's |mapped_host_resolver|. 168 // Give |storage_| ownership at the end in case it's |mapped_host_resolver|.
174 storage_->set_host_resolver(std::move(host_resolver)); 169 storage_->set_host_resolver(std::move(host_resolver));
175 network_session_params.host_resolver = 170 network_session_params.host_resolver =
176 url_request_context_->host_resolver(); 171 url_request_context_->host_resolver();
177 172
178 storage_->set_http_network_session( 173 storage_->set_http_network_session(
179 base::WrapUnique(new net::HttpNetworkSession(network_session_params))); 174 base::WrapUnique(new net::HttpNetworkSession(network_session_params)));
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 HeadlessURLRequestContextGetter::GetNetworkTaskRunner() const { 212 HeadlessURLRequestContextGetter::GetNetworkTaskRunner() const {
218 return content::BrowserThread::GetMessageLoopProxyForThread( 213 return content::BrowserThread::GetMessageLoopProxyForThread(
219 content::BrowserThread::IO); 214 content::BrowserThread::IO);
220 } 215 }
221 216
222 net::HostResolver* HeadlessURLRequestContextGetter::host_resolver() const { 217 net::HostResolver* HeadlessURLRequestContextGetter::host_resolver() const {
223 return url_request_context_->host_resolver(); 218 return url_request_context_->host_resolver();
224 } 219 }
225 220
226 } // namespace headless 221 } // namespace headless
OLDNEW
« no previous file with comments | « headless/app/headless_shell.cc ('k') | headless/lib/headless_browser_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698