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

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

Issue 2841953002: headless: Add support for net logging (Closed)
Patch Set: Created 3 years, 7 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
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 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "base/single_thread_task_runner.h" 12 #include "base/single_thread_task_runner.h"
13 #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" 14 #include "headless/lib/browser/headless_browser_context_options.h"
15 #include "headless/lib/browser/headless_network_delegate.h" 15 #include "headless/lib/browser/headless_network_delegate.h"
16 #include "net/dns/mapped_host_resolver.h" 16 #include "net/dns/mapped_host_resolver.h"
17 #include "net/proxy/proxy_service.h" 17 #include "net/proxy/proxy_service.h"
18 #include "net/url_request/url_request_context.h" 18 #include "net/url_request/url_request_context.h"
19 #include "net/url_request/url_request_context_builder.h" 19 #include "net/url_request/url_request_context_builder.h"
20 20
21 namespace headless { 21 namespace headless {
22 22
23 HeadlessURLRequestContextGetter::HeadlessURLRequestContextGetter( 23 HeadlessURLRequestContextGetter::HeadlessURLRequestContextGetter(
24 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, 24 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner,
25 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner, 25 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner,
26 content::ProtocolHandlerMap* protocol_handlers, 26 content::ProtocolHandlerMap* protocol_handlers,
27 ProtocolHandlerMap context_protocol_handlers, 27 ProtocolHandlerMap context_protocol_handlers,
28 content::URLRequestInterceptorScopedVector request_interceptors, 28 content::URLRequestInterceptorScopedVector request_interceptors,
29 HeadlessBrowserContextOptions* options) 29 HeadlessBrowserContextOptions* options,
30 net::NetLog* net_log)
30 : io_task_runner_(std::move(io_task_runner)), 31 : io_task_runner_(std::move(io_task_runner)),
31 file_task_runner_(std::move(file_task_runner)), 32 file_task_runner_(std::move(file_task_runner)),
32 user_agent_(options->user_agent()), 33 user_agent_(options->user_agent()),
33 host_resolver_rules_(options->host_resolver_rules()), 34 host_resolver_rules_(options->host_resolver_rules()),
34 proxy_server_(options->proxy_server()), 35 proxy_server_(options->proxy_server()),
35 request_interceptors_(std::move(request_interceptors)) { 36 request_interceptors_(std::move(request_interceptors)),
37 net_log_(net_log) {
36 // Must first be created on the UI thread. 38 // Must first be created on the UI thread.
37 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 39 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
38 40
39 std::swap(protocol_handlers_, *protocol_handlers); 41 std::swap(protocol_handlers_, *protocol_handlers);
40 42
41 for (auto& pair : context_protocol_handlers) { 43 for (auto& pair : context_protocol_handlers) {
42 protocol_handlers_[pair.first] = 44 protocol_handlers_[pair.first] =
43 linked_ptr<net::URLRequestJobFactory::ProtocolHandler>( 45 linked_ptr<net::URLRequestJobFactory::ProtocolHandler>(
44 pair.second.release()); 46 pair.second.release());
45 } 47 }
(...skipping 25 matching lines...) Expand all
71 if (!proxy_server_.IsEmpty()) { 73 if (!proxy_server_.IsEmpty()) {
72 builder.set_proxy_service( 74 builder.set_proxy_service(
73 net::ProxyService::CreateFixed(proxy_server_.ToString())); 75 net::ProxyService::CreateFixed(proxy_server_.ToString()));
74 } else { 76 } else {
75 builder.set_proxy_config_service(std::move(proxy_config_service_)); 77 builder.set_proxy_config_service(std::move(proxy_config_service_));
76 } 78 }
77 builder.set_network_delegate(base::MakeUnique<HeadlessNetworkDelegate>()); 79 builder.set_network_delegate(base::MakeUnique<HeadlessNetworkDelegate>());
78 80
79 if (!host_resolver_rules_.empty()) { 81 if (!host_resolver_rules_.empty()) {
80 std::unique_ptr<net::HostResolver> host_resolver( 82 std::unique_ptr<net::HostResolver> host_resolver(
81 net::HostResolver::CreateDefaultResolver(nullptr /* net_log */)); 83 net::HostResolver::CreateDefaultResolver(net_log_));
82 std::unique_ptr<net::MappedHostResolver> mapped_host_resolver( 84 std::unique_ptr<net::MappedHostResolver> mapped_host_resolver(
83 new net::MappedHostResolver(std::move(host_resolver))); 85 new net::MappedHostResolver(std::move(host_resolver)));
84 mapped_host_resolver->SetRulesFromString(host_resolver_rules_); 86 mapped_host_resolver->SetRulesFromString(host_resolver_rules_);
85 builder.set_host_resolver(std::move(mapped_host_resolver)); 87 builder.set_host_resolver(std::move(mapped_host_resolver));
86 } 88 }
87 89
88 for (auto& pair : protocol_handlers_) { 90 for (auto& pair : protocol_handlers_) {
89 builder.SetProtocolHandler(pair.first, 91 builder.SetProtocolHandler(pair.first,
90 base::WrapUnique(pair.second.release())); 92 base::WrapUnique(pair.second.release()));
91 } 93 }
92 protocol_handlers_.clear(); 94 protocol_handlers_.clear();
93 builder.SetInterceptors(std::move(request_interceptors_)); 95 builder.SetInterceptors(std::move(request_interceptors_));
94 96
95 url_request_context_ = builder.Build(); 97 url_request_context_ = builder.Build();
98 url_request_context_->set_net_log(net_log_);
96 } 99 }
97 100
98 return url_request_context_.get(); 101 return url_request_context_.get();
99 } 102 }
100 103
101 scoped_refptr<base::SingleThreadTaskRunner> 104 scoped_refptr<base::SingleThreadTaskRunner>
102 HeadlessURLRequestContextGetter::GetNetworkTaskRunner() const { 105 HeadlessURLRequestContextGetter::GetNetworkTaskRunner() const {
103 return content::BrowserThread::GetTaskRunnerForThread( 106 return content::BrowserThread::GetTaskRunnerForThread(
104 content::BrowserThread::IO); 107 content::BrowserThread::IO);
105 } 108 }
106 109
107 net::HostResolver* HeadlessURLRequestContextGetter::host_resolver() const { 110 net::HostResolver* HeadlessURLRequestContextGetter::host_resolver() const {
108 return url_request_context_->host_resolver(); 111 return url_request_context_->host_resolver();
109 } 112 }
110 113
111 } // namespace headless 114 } // namespace headless
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698