OLD | NEW |
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 "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
10 #include "base/threading/worker_pool.h" | 10 #include "base/threading/worker_pool.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 options_(options), | 66 options_(options), |
67 request_interceptors_(std::move(request_interceptors)) { | 67 request_interceptors_(std::move(request_interceptors)) { |
68 // Must first be created on the UI thread. | 68 // Must first be created on the UI thread. |
69 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 69 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
70 | 70 |
71 std::swap(protocol_handlers_, *protocol_handlers); | 71 std::swap(protocol_handlers_, *protocol_handlers); |
72 | 72 |
73 // We must create the proxy config service on the UI loop on Linux because it | 73 // We must create the proxy config service on the UI loop on Linux because it |
74 // must synchronously run on the glib message loop. This will be passed to | 74 // must synchronously run on the glib message loop. This will be passed to |
75 // the URLRequestContextStorage on the IO thread in GetURLRequestContext(). | 75 // the URLRequestContextStorage on the IO thread in GetURLRequestContext(). |
76 proxy_config_service_ = GetProxyConfigService(); | 76 if (options_.proxy_server.IsEmpty()) |
| 77 proxy_config_service_ = GetProxyConfigService(); |
77 } | 78 } |
78 | 79 |
79 HeadlessURLRequestContextGetter::~HeadlessURLRequestContextGetter() {} | 80 HeadlessURLRequestContextGetter::~HeadlessURLRequestContextGetter() {} |
80 | 81 |
81 scoped_ptr<net::NetworkDelegate> | 82 scoped_ptr<net::NetworkDelegate> |
82 HeadlessURLRequestContextGetter::CreateNetworkDelegate() { | 83 HeadlessURLRequestContextGetter::CreateNetworkDelegate() { |
83 return nullptr; | 84 return nullptr; |
84 } | 85 } |
85 | 86 |
86 scoped_ptr<net::ProxyConfigService> | 87 scoped_ptr<net::ProxyConfigService> |
87 HeadlessURLRequestContextGetter::GetProxyConfigService() { | 88 HeadlessURLRequestContextGetter::GetProxyConfigService() { |
88 return net::ProxyService::CreateSystemProxyConfigService(io_task_runner_, | 89 return net::ProxyService::CreateSystemProxyConfigService(io_task_runner_, |
89 file_task_runner_); | 90 file_task_runner_); |
90 } | 91 } |
91 | 92 |
92 scoped_ptr<net::ProxyService> | 93 scoped_ptr<net::ProxyService> |
93 HeadlessURLRequestContextGetter::GetProxyService() { | 94 HeadlessURLRequestContextGetter::GetProxyService() { |
| 95 if (!options_.proxy_server.IsEmpty()) |
| 96 return net::ProxyService::CreateFixed(options_.proxy_server.ToString()); |
94 return net::ProxyService::CreateUsingSystemProxyResolver( | 97 return net::ProxyService::CreateUsingSystemProxyResolver( |
95 std::move(proxy_config_service_), 0, url_request_context_->net_log()); | 98 std::move(proxy_config_service_), 0, url_request_context_->net_log()); |
96 } | 99 } |
97 | 100 |
98 net::URLRequestContext* | 101 net::URLRequestContext* |
99 HeadlessURLRequestContextGetter::GetURLRequestContext() { | 102 HeadlessURLRequestContextGetter::GetURLRequestContext() { |
100 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); | 103 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
101 | 104 |
102 if (!url_request_context_) { | 105 if (!url_request_context_) { |
103 const base::CommandLine& command_line = | 106 const base::CommandLine& command_line = |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 HeadlessURLRequestContextGetter::GetNetworkTaskRunner() const { | 216 HeadlessURLRequestContextGetter::GetNetworkTaskRunner() const { |
214 return content::BrowserThread::GetMessageLoopProxyForThread( | 217 return content::BrowserThread::GetMessageLoopProxyForThread( |
215 content::BrowserThread::IO); | 218 content::BrowserThread::IO); |
216 } | 219 } |
217 | 220 |
218 net::HostResolver* HeadlessURLRequestContextGetter::host_resolver() const { | 221 net::HostResolver* HeadlessURLRequestContextGetter::host_resolver() const { |
219 return url_request_context_->host_resolver(); | 222 return url_request_context_->host_resolver(); |
220 } | 223 } |
221 | 224 |
222 } // namespace headless | 225 } // namespace headless |
OLD | NEW |