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 <memory> | 7 #include <memory> |
| 8 #include <utility> |
| 9 #include <vector> |
8 | 10 |
9 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
10 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
11 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
| 14 #include "headless/lib/browser/headless_browser_context_options.h" |
12 #include "net/dns/mapped_host_resolver.h" | 15 #include "net/dns/mapped_host_resolver.h" |
13 #include "net/proxy/proxy_service.h" | 16 #include "net/proxy/proxy_service.h" |
14 #include "net/url_request/url_request_context.h" | 17 #include "net/url_request/url_request_context.h" |
15 #include "net/url_request/url_request_context_builder.h" | 18 #include "net/url_request/url_request_context_builder.h" |
16 | 19 |
17 namespace headless { | 20 namespace headless { |
18 | 21 |
19 HeadlessURLRequestContextGetter::HeadlessURLRequestContextGetter( | 22 HeadlessURLRequestContextGetter::HeadlessURLRequestContextGetter( |
20 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, | 23 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, |
21 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner, | 24 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner, |
22 content::ProtocolHandlerMap* protocol_handlers, | 25 content::ProtocolHandlerMap* protocol_handlers, |
23 ProtocolHandlerMap context_protocol_handlers, | 26 ProtocolHandlerMap context_protocol_handlers, |
24 content::URLRequestInterceptorScopedVector request_interceptors, | 27 content::URLRequestInterceptorScopedVector request_interceptors, |
25 HeadlessBrowser::Options* options) | 28 HeadlessBrowserContextOptions* options) |
26 : io_task_runner_(std::move(io_task_runner)), | 29 : io_task_runner_(std::move(io_task_runner)), |
27 file_task_runner_(std::move(file_task_runner)), | 30 file_task_runner_(std::move(file_task_runner)), |
28 user_agent_(options->user_agent), | 31 user_agent_(options->user_agent()), |
29 host_resolver_rules_(options->host_resolver_rules), | 32 host_resolver_rules_(options->host_resolver_rules()), |
30 proxy_server_(options->proxy_server), | 33 proxy_server_(options->proxy_server()), |
31 request_interceptors_(std::move(request_interceptors)) { | 34 request_interceptors_(std::move(request_interceptors)) { |
32 // Must first be created on the UI thread. | 35 // Must first be created on the UI thread. |
33 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 36 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
34 | 37 |
35 std::swap(protocol_handlers_, *protocol_handlers); | |
36 for (auto& pair : options->protocol_handlers) { | |
37 protocol_handlers_[pair.first] = | |
38 linked_ptr<net::URLRequestJobFactory::ProtocolHandler>( | |
39 pair.second.release()); | |
40 } | |
41 options->protocol_handlers.clear(); | |
42 for (auto& pair : context_protocol_handlers) { | 38 for (auto& pair : context_protocol_handlers) { |
43 protocol_handlers_[pair.first] = | 39 protocol_handlers_[pair.first] = |
44 linked_ptr<net::URLRequestJobFactory::ProtocolHandler>( | 40 linked_ptr<net::URLRequestJobFactory::ProtocolHandler>( |
45 pair.second.release()); | 41 pair.second.release()); |
46 } | 42 } |
47 context_protocol_handlers.clear(); | 43 context_protocol_handlers.clear(); |
48 | 44 |
49 // We must create the proxy config service on the UI loop on Linux because it | 45 // We must create the proxy config service on the UI loop on Linux because it |
50 // must synchronously run on the glib message loop. This will be passed to | 46 // must synchronously run on the glib message loop. This will be passed to |
51 // the URLRequestContextStorage on the IO thread in GetURLRequestContext(). | 47 // the URLRequestContextStorage on the IO thread in GetURLRequestContext(). |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 HeadlessURLRequestContextGetter::GetNetworkTaskRunner() const { | 105 HeadlessURLRequestContextGetter::GetNetworkTaskRunner() const { |
110 return content::BrowserThread::GetTaskRunnerForThread( | 106 return content::BrowserThread::GetTaskRunnerForThread( |
111 content::BrowserThread::IO); | 107 content::BrowserThread::IO); |
112 } | 108 } |
113 | 109 |
114 net::HostResolver* HeadlessURLRequestContextGetter::host_resolver() const { | 110 net::HostResolver* HeadlessURLRequestContextGetter::host_resolver() const { |
115 return url_request_context_->host_resolver(); | 111 return url_request_context_->host_resolver(); |
116 } | 112 } |
117 | 113 |
118 } // namespace headless | 114 } // namespace headless |
OLD | NEW |