Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "net/url_request/url_request_context_builder.h" | 5 #include "net/url_request/url_request_context_builder.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 125 DISALLOW_COPY_AND_ASSIGN(BasicNetworkDelegate); | 125 DISALLOW_COPY_AND_ASSIGN(BasicNetworkDelegate); |
| 126 }; | 126 }; |
| 127 | 127 |
| 128 // Define a context class that can self-manage the ownership of its components | 128 // Define a context class that can self-manage the ownership of its components |
| 129 // via a UrlRequestContextStorage object. | 129 // via a UrlRequestContextStorage object. |
| 130 class ContainerURLRequestContext : public URLRequestContext { | 130 class ContainerURLRequestContext : public URLRequestContext { |
| 131 public: | 131 public: |
| 132 explicit ContainerURLRequestContext( | 132 explicit ContainerURLRequestContext( |
| 133 const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner) | 133 const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner) |
| 134 : file_task_runner_(file_task_runner), storage_(this) {} | 134 : file_task_runner_(file_task_runner), storage_(this) {} |
| 135 ~ContainerURLRequestContext() override { AssertNoURLRequests(); } | |
| 135 | 136 |
| 136 URLRequestContextStorage* storage() { | 137 URLRequestContextStorage* storage() { |
| 137 return &storage_; | 138 return &storage_; |
| 138 } | 139 } |
| 139 | 140 |
| 140 scoped_refptr<base::SingleThreadTaskRunner>& GetFileTaskRunner() { | 141 scoped_refptr<base::SingleThreadTaskRunner>& GetFileTaskRunner() { |
| 141 // Create a new thread to run file tasks, if needed. | 142 // Create a new thread to run file tasks, if needed. |
| 142 if (!file_task_runner_) { | 143 if (!file_task_runner_) { |
| 143 DCHECK(!file_thread_); | 144 DCHECK(!file_thread_); |
| 144 file_thread_.reset(new base::Thread("Network File Thread")); | 145 file_thread_.reset(new base::Thread("Network File Thread")); |
| 145 file_thread_->StartWithOptions( | 146 file_thread_->StartWithOptions( |
| 146 base::Thread::Options(base::MessageLoop::TYPE_DEFAULT, 0)); | 147 base::Thread::Options(base::MessageLoop::TYPE_DEFAULT, 0)); |
| 147 file_task_runner_ = file_thread_->task_runner(); | 148 file_task_runner_ = file_thread_->task_runner(); |
| 148 } | 149 } |
| 149 return file_task_runner_; | 150 return file_task_runner_; |
| 150 } | 151 } |
| 151 | 152 |
| 152 void set_transport_security_persister( | 153 void set_transport_security_persister( |
| 153 scoped_ptr<TransportSecurityPersister> transport_security_persister) { | 154 scoped_ptr<TransportSecurityPersister> transport_security_persister) { |
| 154 transport_security_persister = transport_security_persister.Pass(); | 155 transport_security_persister = transport_security_persister.Pass(); |
| 155 } | 156 } |
| 156 | 157 |
| 157 protected: | |
| 158 ~ContainerURLRequestContext() override { AssertNoURLRequests(); } | |
| 159 | |
| 160 private: | 158 private: |
| 161 // The thread should be torn down last. | 159 // The thread should be torn down last. |
| 162 scoped_ptr<base::Thread> file_thread_; | 160 scoped_ptr<base::Thread> file_thread_; |
| 163 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_; | 161 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_; |
| 164 | 162 |
| 165 URLRequestContextStorage storage_; | 163 URLRequestContextStorage storage_; |
| 166 scoped_ptr<TransportSecurityPersister> transport_security_persister_; | 164 scoped_ptr<TransportSecurityPersister> transport_security_persister_; |
| 167 | 165 |
| 168 DISALLOW_COPY_AND_ASSIGN(ContainerURLRequestContext); | 166 DISALLOW_COPY_AND_ASSIGN(ContainerURLRequestContext); |
| 169 }; | 167 }; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 201 : data_enabled_(false), | 199 : data_enabled_(false), |
| 202 #if !defined(DISABLE_FILE_SUPPORT) | 200 #if !defined(DISABLE_FILE_SUPPORT) |
| 203 file_enabled_(false), | 201 file_enabled_(false), |
| 204 #endif | 202 #endif |
| 205 #if !defined(DISABLE_FTP_SUPPORT) | 203 #if !defined(DISABLE_FTP_SUPPORT) |
| 206 ftp_enabled_(false), | 204 ftp_enabled_(false), |
| 207 #endif | 205 #endif |
| 208 http_cache_enabled_(true), | 206 http_cache_enabled_(true), |
| 209 throttling_enabled_(false), | 207 throttling_enabled_(false), |
| 210 backoff_enabled_(false), | 208 backoff_enabled_(false), |
| 211 sdch_enabled_(false) { | 209 sdch_enabled_(false), |
| 210 net_log_(nullptr) { | |
| 212 } | 211 } |
| 213 | 212 |
| 214 URLRequestContextBuilder::~URLRequestContextBuilder() {} | 213 URLRequestContextBuilder::~URLRequestContextBuilder() {} |
| 215 | 214 |
| 216 void URLRequestContextBuilder::EnableHttpCache(const HttpCacheParams& params) { | 215 void URLRequestContextBuilder::EnableHttpCache(const HttpCacheParams& params) { |
| 217 http_cache_enabled_ = true; | 216 http_cache_enabled_ = true; |
| 218 http_cache_params_ = params; | 217 http_cache_params_ = params; |
| 219 } | 218 } |
| 220 | 219 |
| 221 void URLRequestContextBuilder::DisableHttpCache() { | 220 void URLRequestContextBuilder::DisableHttpCache() { |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 246 void URLRequestContextBuilder::SetFileTaskRunner( | 245 void URLRequestContextBuilder::SetFileTaskRunner( |
| 247 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) { | 246 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) { |
| 248 file_task_runner_ = task_runner; | 247 file_task_runner_ = task_runner; |
| 249 } | 248 } |
| 250 | 249 |
| 251 void URLRequestContextBuilder::SetHttpServerProperties( | 250 void URLRequestContextBuilder::SetHttpServerProperties( |
| 252 scoped_ptr<HttpServerProperties> http_server_properties) { | 251 scoped_ptr<HttpServerProperties> http_server_properties) { |
| 253 http_server_properties_ = http_server_properties.Pass(); | 252 http_server_properties_ = http_server_properties.Pass(); |
| 254 } | 253 } |
| 255 | 254 |
| 256 URLRequestContext* URLRequestContextBuilder::Build() { | 255 scoped_ptr<URLRequestContext> URLRequestContextBuilder::Build() { |
| 257 ContainerURLRequestContext* context = | 256 scoped_ptr<ContainerURLRequestContext> context( |
| 258 new ContainerURLRequestContext(file_task_runner_); | 257 new ContainerURLRequestContext(file_task_runner_)); |
| 259 URLRequestContextStorage* storage = context->storage(); | 258 URLRequestContextStorage* storage = context->storage(); |
| 260 | 259 |
| 261 storage->set_http_user_agent_settings(new StaticHttpUserAgentSettings( | 260 storage->set_http_user_agent_settings(new StaticHttpUserAgentSettings( |
| 262 accept_language_, user_agent_)); | 261 accept_language_, user_agent_)); |
| 263 | 262 |
| 264 if (!network_delegate_) | 263 if (!network_delegate_) |
| 265 network_delegate_.reset(new BasicNetworkDelegate); | 264 network_delegate_.reset(new BasicNetworkDelegate); |
| 266 NetworkDelegate* network_delegate = network_delegate_.release(); | 265 NetworkDelegate* network_delegate = network_delegate_.release(); |
| 267 storage->set_network_delegate(network_delegate); | 266 storage->set_network_delegate(network_delegate); |
| 268 | 267 |
| 269 if (net_log_) { | 268 if (net_log_) { |
|
mmenke
2015/08/20 15:51:07
Again, suggest a short comment about this.
pauljensen
2015/08/20 21:45:14
Done.
| |
| 270 storage->set_net_log(net_log_.release()); | 269 context->set_net_log(net_log_); |
| 271 } else { | 270 } else { |
| 272 storage->set_net_log(new NetLog); | 271 storage->set_net_log(new NetLog); |
| 273 } | 272 } |
| 274 | 273 |
| 275 if (!host_resolver_) { | 274 if (!host_resolver_) { |
| 276 host_resolver_ = HostResolver::CreateDefaultResolver(context->net_log()); | 275 host_resolver_ = HostResolver::CreateDefaultResolver(context->net_log()); |
| 277 } | 276 } |
| 278 storage->set_host_resolver(host_resolver_.Pass()); | 277 storage->set_host_resolver(host_resolver_.Pass()); |
| 279 | 278 |
| 280 if (!proxy_service_) { | 279 if (!proxy_service_) { |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 437 url_request_interceptors_.rbegin(); | 436 url_request_interceptors_.rbegin(); |
| 438 i != url_request_interceptors_.rend(); ++i) { | 437 i != url_request_interceptors_.rend(); ++i) { |
| 439 top_job_factory.reset(new net::URLRequestInterceptingJobFactory( | 438 top_job_factory.reset(new net::URLRequestInterceptingJobFactory( |
| 440 top_job_factory.Pass(), make_scoped_ptr(*i))); | 439 top_job_factory.Pass(), make_scoped_ptr(*i))); |
| 441 } | 440 } |
| 442 url_request_interceptors_.weak_clear(); | 441 url_request_interceptors_.weak_clear(); |
| 443 } | 442 } |
| 444 storage->set_job_factory(top_job_factory.release()); | 443 storage->set_job_factory(top_job_factory.release()); |
| 445 // TODO(willchan): Support sdch. | 444 // TODO(willchan): Support sdch. |
| 446 | 445 |
| 447 return context; | 446 return context.Pass(); |
| 448 } | 447 } |
| 449 | 448 |
| 450 } // namespace net | 449 } // namespace net |
| OLD | NEW |