OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/shell/browser/shell_url_request_context_getter.h" | 5 #include "content/shell/browser/shell_url_request_context_getter.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/memory/scoped_ptr.h" | |
9 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
10 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
11 #include "base/strings/string_split.h" | 12 #include "base/strings/string_split.h" |
12 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
13 #include "base/threading/sequenced_worker_pool.h" | 14 #include "base/threading/sequenced_worker_pool.h" |
14 #include "base/threading/worker_pool.h" | 15 #include "base/threading/worker_pool.h" |
15 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
16 #include "content/public/browser/cookie_store_factory.h" | 17 #include "content/public/browser/cookie_store_factory.h" |
17 #include "content/public/common/content_switches.h" | 18 #include "content/public/common/content_switches.h" |
18 #include "content/shell/browser/shell_network_delegate.h" | 19 #include "content/shell/browser/shell_network_delegate.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
75 net_log_(net_log), | 76 net_log_(net_log), |
76 request_interceptors_(request_interceptors.Pass()) { | 77 request_interceptors_(request_interceptors.Pass()) { |
77 // Must first be created on the UI thread. | 78 // Must first be created on the UI thread. |
78 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 79 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
79 | 80 |
80 std::swap(protocol_handlers_, *protocol_handlers); | 81 std::swap(protocol_handlers_, *protocol_handlers); |
81 | 82 |
82 // We must create the proxy config service on the UI loop on Linux because it | 83 // We must create the proxy config service on the UI loop on Linux because it |
83 // must synchronously run on the glib message loop. This will be passed to | 84 // must synchronously run on the glib message loop. This will be passed to |
84 // the URLRequestContextStorage on the IO thread in GetURLRequestContext(). | 85 // the URLRequestContextStorage on the IO thread in GetURLRequestContext(). |
85 proxy_config_service_.reset(GetProxyConfigService()); | 86 proxy_config_service_ = GetProxyConfigService(); |
86 } | 87 } |
87 | 88 |
88 ShellURLRequestContextGetter::~ShellURLRequestContextGetter() { | 89 ShellURLRequestContextGetter::~ShellURLRequestContextGetter() { |
89 } | 90 } |
90 | 91 |
91 net::NetworkDelegate* ShellURLRequestContextGetter::CreateNetworkDelegate() { | 92 scoped_ptr<net::NetworkDelegate> |
92 return new ShellNetworkDelegate; | 93 ShellURLRequestContextGetter::CreateNetworkDelegate() { |
94 return make_scoped_ptr(new ShellNetworkDelegate).Pass(); | |
davidben
2015/09/08 17:02:45
Does it not work without the Pass?
| |
93 } | 95 } |
94 | 96 |
95 net::ProxyConfigService* ShellURLRequestContextGetter::GetProxyConfigService() { | 97 scoped_ptr<net::ProxyConfigService> |
96 return net::ProxyService::CreateSystemProxyConfigService( | 98 ShellURLRequestContextGetter::GetProxyConfigService() { |
97 io_loop_->task_runner(), file_loop_->task_runner()); | 99 return make_scoped_ptr(net::ProxyService::CreateSystemProxyConfigService( |
100 io_loop_->task_runner(), file_loop_->task_runner())); | |
98 } | 101 } |
99 | 102 |
100 net::ProxyService* ShellURLRequestContextGetter::GetProxyService() { | 103 scoped_ptr<net::ProxyService> ShellURLRequestContextGetter::GetProxyService() { |
101 // TODO(jam): use v8 if possible, look at chrome code. | 104 // TODO(jam): use v8 if possible, look at chrome code. |
102 return net::ProxyService::CreateUsingSystemProxyResolver( | 105 return net::ProxyService::CreateUsingSystemProxyResolver( |
103 proxy_config_service_.release(), 0, url_request_context_->net_log()); | 106 proxy_config_service_.release(), 0, url_request_context_->net_log()); |
104 } | 107 } |
105 | 108 |
106 net::URLRequestContext* ShellURLRequestContextGetter::GetURLRequestContext() { | 109 net::URLRequestContext* ShellURLRequestContextGetter::GetURLRequestContext() { |
107 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 110 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
108 | 111 |
109 if (!url_request_context_) { | 112 if (!url_request_context_) { |
110 const base::CommandLine& command_line = | 113 const base::CommandLine& command_line = |
111 *base::CommandLine::ForCurrentProcess(); | 114 *base::CommandLine::ForCurrentProcess(); |
112 | 115 |
113 url_request_context_.reset(new net::URLRequestContext()); | 116 url_request_context_.reset(new net::URLRequestContext()); |
114 url_request_context_->set_net_log(net_log_); | 117 url_request_context_->set_net_log(net_log_); |
115 network_delegate_.reset(CreateNetworkDelegate()); | 118 network_delegate_ = CreateNetworkDelegate(); |
116 url_request_context_->set_network_delegate(network_delegate_.get()); | 119 url_request_context_->set_network_delegate(network_delegate_.get()); |
117 storage_.reset( | 120 storage_.reset( |
118 new net::URLRequestContextStorage(url_request_context_.get())); | 121 new net::URLRequestContextStorage(url_request_context_.get())); |
119 storage_->set_cookie_store(CreateCookieStore(CookieStoreConfig())); | 122 storage_->set_cookie_store(CreateCookieStore(CookieStoreConfig())); |
120 storage_->set_channel_id_service(make_scoped_ptr( | 123 storage_->set_channel_id_service(make_scoped_ptr( |
121 new net::ChannelIDService(new net::DefaultChannelIDStore(NULL), | 124 new net::ChannelIDService(new net::DefaultChannelIDStore(NULL), |
122 base::WorkerPool::GetTaskRunner(true)))); | 125 base::WorkerPool::GetTaskRunner(true)))); |
123 storage_->set_http_user_agent_settings( | 126 storage_->set_http_user_agent_settings(make_scoped_ptr( |
124 new net::StaticHttpUserAgentSettings( | 127 new net::StaticHttpUserAgentSettings("en-us,en", GetShellUserAgent()))); |
125 "en-us,en", GetShellUserAgent())); | |
126 | 128 |
127 scoped_ptr<net::HostResolver> host_resolver( | 129 scoped_ptr<net::HostResolver> host_resolver( |
128 net::HostResolver::CreateDefaultResolver( | 130 net::HostResolver::CreateDefaultResolver( |
129 url_request_context_->net_log())); | 131 url_request_context_->net_log())); |
130 | 132 |
131 storage_->set_cert_verifier(net::CertVerifier::CreateDefault()); | 133 storage_->set_cert_verifier(net::CertVerifier::CreateDefault()); |
132 storage_->set_transport_security_state(new net::TransportSecurityState); | 134 storage_->set_transport_security_state( |
135 make_scoped_ptr(new net::TransportSecurityState)); | |
133 storage_->set_proxy_service(GetProxyService()); | 136 storage_->set_proxy_service(GetProxyService()); |
134 storage_->set_ssl_config_service(new net::SSLConfigServiceDefaults); | 137 storage_->set_ssl_config_service(new net::SSLConfigServiceDefaults); |
135 storage_->set_http_auth_handler_factory( | 138 storage_->set_http_auth_handler_factory( |
136 net::HttpAuthHandlerFactory::CreateDefault(host_resolver.get())); | 139 net::HttpAuthHandlerFactory::CreateDefault(host_resolver.get())); |
137 storage_->set_http_server_properties( | 140 storage_->set_http_server_properties( |
138 scoped_ptr<net::HttpServerProperties>( | 141 make_scoped_ptr(new net::HttpServerPropertiesImpl())); |
139 new net::HttpServerPropertiesImpl())); | |
140 | 142 |
141 base::FilePath cache_path = base_path_.Append(FILE_PATH_LITERAL("Cache")); | 143 base::FilePath cache_path = base_path_.Append(FILE_PATH_LITERAL("Cache")); |
142 net::HttpCache::DefaultBackend* main_backend = | 144 net::HttpCache::DefaultBackend* main_backend = |
143 new net::HttpCache::DefaultBackend( | 145 new net::HttpCache::DefaultBackend( |
144 net::DISK_CACHE, | 146 net::DISK_CACHE, |
145 #if defined(OS_ANDROID) | 147 #if defined(OS_ANDROID) |
146 // TODO(rdsmith): Remove when default backend for Android is | 148 // TODO(rdsmith): Remove when default backend for Android is |
147 // changed to simple cache. | 149 // changed to simple cache. |
148 net::CACHE_BACKEND_SIMPLE, | 150 net::CACHE_BACKEND_SIMPLE, |
149 #else | 151 #else |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
192 mapped_host_resolver->SetRulesFromString( | 194 mapped_host_resolver->SetRulesFromString( |
193 command_line.GetSwitchValueASCII(switches::kHostResolverRules)); | 195 command_line.GetSwitchValueASCII(switches::kHostResolverRules)); |
194 host_resolver = mapped_host_resolver.Pass(); | 196 host_resolver = mapped_host_resolver.Pass(); |
195 } | 197 } |
196 | 198 |
197 // Give |storage_| ownership at the end in case it's |mapped_host_resolver|. | 199 // Give |storage_| ownership at the end in case it's |mapped_host_resolver|. |
198 storage_->set_host_resolver(host_resolver.Pass()); | 200 storage_->set_host_resolver(host_resolver.Pass()); |
199 network_session_params.host_resolver = | 201 network_session_params.host_resolver = |
200 url_request_context_->host_resolver(); | 202 url_request_context_->host_resolver(); |
201 | 203 |
202 net::HttpCache* main_cache = new net::HttpCache( | 204 storage_->set_http_transaction_factory( |
203 network_session_params, main_backend); | 205 make_scoped_ptr( |
204 storage_->set_http_transaction_factory(main_cache); | 206 new net::HttpCache(network_session_params, main_backend)) |
207 .Pass()); | |
davidben
2015/09/08 17:02:45
Ditto.
| |
205 | 208 |
206 scoped_ptr<net::URLRequestJobFactoryImpl> job_factory( | 209 scoped_ptr<net::URLRequestJobFactoryImpl> job_factory( |
207 new net::URLRequestJobFactoryImpl()); | 210 new net::URLRequestJobFactoryImpl()); |
208 // Keep ProtocolHandlers added in sync with | 211 // Keep ProtocolHandlers added in sync with |
209 // ShellContentBrowserClient::IsHandledURL(). | 212 // ShellContentBrowserClient::IsHandledURL(). |
210 InstallProtocolHandlers(job_factory.get(), &protocol_handlers_); | 213 InstallProtocolHandlers(job_factory.get(), &protocol_handlers_); |
211 bool set_protocol = job_factory->SetProtocolHandler( | 214 bool set_protocol = job_factory->SetProtocolHandler( |
212 url::kDataScheme, make_scoped_ptr(new net::DataProtocolHandler)); | 215 url::kDataScheme, make_scoped_ptr(new net::DataProtocolHandler)); |
213 DCHECK(set_protocol); | 216 DCHECK(set_protocol); |
214 #if !defined(DISABLE_FILE_SUPPORT) | 217 #if !defined(DISABLE_FILE_SUPPORT) |
(...skipping 10 matching lines...) Expand all Loading... | |
225 job_factory.Pass(); | 228 job_factory.Pass(); |
226 for (URLRequestInterceptorScopedVector::reverse_iterator i = | 229 for (URLRequestInterceptorScopedVector::reverse_iterator i = |
227 request_interceptors_.rbegin(); | 230 request_interceptors_.rbegin(); |
228 i != request_interceptors_.rend(); | 231 i != request_interceptors_.rend(); |
229 ++i) { | 232 ++i) { |
230 top_job_factory.reset(new net::URLRequestInterceptingJobFactory( | 233 top_job_factory.reset(new net::URLRequestInterceptingJobFactory( |
231 top_job_factory.Pass(), make_scoped_ptr(*i))); | 234 top_job_factory.Pass(), make_scoped_ptr(*i))); |
232 } | 235 } |
233 request_interceptors_.weak_clear(); | 236 request_interceptors_.weak_clear(); |
234 | 237 |
235 storage_->set_job_factory(top_job_factory.release()); | 238 storage_->set_job_factory(top_job_factory.Pass()); |
236 } | 239 } |
237 | 240 |
238 return url_request_context_.get(); | 241 return url_request_context_.get(); |
239 } | 242 } |
240 | 243 |
241 scoped_refptr<base::SingleThreadTaskRunner> | 244 scoped_refptr<base::SingleThreadTaskRunner> |
242 ShellURLRequestContextGetter::GetNetworkTaskRunner() const { | 245 ShellURLRequestContextGetter::GetNetworkTaskRunner() const { |
243 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); | 246 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); |
244 } | 247 } |
245 | 248 |
246 net::HostResolver* ShellURLRequestContextGetter::host_resolver() { | 249 net::HostResolver* ShellURLRequestContextGetter::host_resolver() { |
247 return url_request_context_->host_resolver(); | 250 return url_request_context_->host_resolver(); |
248 } | 251 } |
249 | 252 |
250 } // namespace content | 253 } // namespace content |
OLD | NEW |