| 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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 } | 118 } |
| 119 | 119 |
| 120 bool OnCanAccessFile(const URLRequest& request, | 120 bool OnCanAccessFile(const URLRequest& request, |
| 121 const base::FilePath& path) const override { | 121 const base::FilePath& path) const override { |
| 122 return true; | 122 return true; |
| 123 } | 123 } |
| 124 | 124 |
| 125 DISALLOW_COPY_AND_ASSIGN(BasicNetworkDelegate); | 125 DISALLOW_COPY_AND_ASSIGN(BasicNetworkDelegate); |
| 126 }; | 126 }; |
| 127 | 127 |
| 128 class BasicURLRequestContext : public URLRequestContext { | 128 // Define a context class that can self-manage the ownership of its components |
| 129 // via a UrlRequestContextStorage object. |
| 130 class ContainerURLRequestContext : public URLRequestContext { |
| 129 public: | 131 public: |
| 130 explicit BasicURLRequestContext( | 132 explicit ContainerURLRequestContext( |
| 131 const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner) | 133 const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner) |
| 132 : file_task_runner_(file_task_runner), storage_(this) {} | 134 : file_task_runner_(file_task_runner), storage_(this) {} |
| 133 | 135 |
| 134 URLRequestContextStorage* storage() { | 136 URLRequestContextStorage* storage() { |
| 135 return &storage_; | 137 return &storage_; |
| 136 } | 138 } |
| 137 | 139 |
| 138 scoped_refptr<base::SingleThreadTaskRunner>& GetFileTaskRunner() { | 140 scoped_refptr<base::SingleThreadTaskRunner>& GetFileTaskRunner() { |
| 139 // Create a new thread to run file tasks, if needed. | 141 // Create a new thread to run file tasks, if needed. |
| 140 if (!file_task_runner_) { | 142 if (!file_task_runner_) { |
| 141 DCHECK(!file_thread_); | 143 DCHECK(!file_thread_); |
| 142 file_thread_.reset(new base::Thread("Network File Thread")); | 144 file_thread_.reset(new base::Thread("Network File Thread")); |
| 143 file_thread_->StartWithOptions( | 145 file_thread_->StartWithOptions( |
| 144 base::Thread::Options(base::MessageLoop::TYPE_DEFAULT, 0)); | 146 base::Thread::Options(base::MessageLoop::TYPE_DEFAULT, 0)); |
| 145 file_task_runner_ = file_thread_->task_runner(); | 147 file_task_runner_ = file_thread_->task_runner(); |
| 146 } | 148 } |
| 147 return file_task_runner_; | 149 return file_task_runner_; |
| 148 } | 150 } |
| 149 | 151 |
| 150 void set_transport_security_persister( | 152 void set_transport_security_persister( |
| 151 scoped_ptr<TransportSecurityPersister> transport_security_persister) { | 153 scoped_ptr<TransportSecurityPersister> transport_security_persister) { |
| 152 transport_security_persister = transport_security_persister.Pass(); | 154 transport_security_persister = transport_security_persister.Pass(); |
| 153 } | 155 } |
| 154 | 156 |
| 155 protected: | 157 protected: |
| 156 ~BasicURLRequestContext() override { AssertNoURLRequests(); } | 158 ~ContainerURLRequestContext() override { AssertNoURLRequests(); } |
| 157 | 159 |
| 158 private: | 160 private: |
| 159 // The thread should be torn down last. | 161 // The thread should be torn down last. |
| 160 scoped_ptr<base::Thread> file_thread_; | 162 scoped_ptr<base::Thread> file_thread_; |
| 161 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_; | 163 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner_; |
| 162 | 164 |
| 163 URLRequestContextStorage storage_; | 165 URLRequestContextStorage storage_; |
| 164 scoped_ptr<TransportSecurityPersister> transport_security_persister_; | 166 scoped_ptr<TransportSecurityPersister> transport_security_persister_; |
| 165 | 167 |
| 166 DISALLOW_COPY_AND_ASSIGN(BasicURLRequestContext); | 168 DISALLOW_COPY_AND_ASSIGN(ContainerURLRequestContext); |
| 167 }; | 169 }; |
| 168 | 170 |
| 169 } // namespace | 171 } // namespace |
| 170 | 172 |
| 171 URLRequestContextBuilder::HttpCacheParams::HttpCacheParams() | 173 URLRequestContextBuilder::HttpCacheParams::HttpCacheParams() |
| 172 : type(IN_MEMORY), | 174 : type(IN_MEMORY), |
| 173 max_size(0) {} | 175 max_size(0) {} |
| 174 URLRequestContextBuilder::HttpCacheParams::~HttpCacheParams() {} | 176 URLRequestContextBuilder::HttpCacheParams::~HttpCacheParams() {} |
| 175 | 177 |
| 176 URLRequestContextBuilder::HttpNetworkSessionParams::HttpNetworkSessionParams() | 178 URLRequestContextBuilder::HttpNetworkSessionParams::HttpNetworkSessionParams() |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) { | 247 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) { |
| 246 file_task_runner_ = task_runner; | 248 file_task_runner_ = task_runner; |
| 247 } | 249 } |
| 248 | 250 |
| 249 void URLRequestContextBuilder::SetHttpServerProperties( | 251 void URLRequestContextBuilder::SetHttpServerProperties( |
| 250 scoped_ptr<HttpServerProperties> http_server_properties) { | 252 scoped_ptr<HttpServerProperties> http_server_properties) { |
| 251 http_server_properties_ = http_server_properties.Pass(); | 253 http_server_properties_ = http_server_properties.Pass(); |
| 252 } | 254 } |
| 253 | 255 |
| 254 URLRequestContext* URLRequestContextBuilder::Build() { | 256 URLRequestContext* URLRequestContextBuilder::Build() { |
| 255 BasicURLRequestContext* context = | 257 ContainerURLRequestContext* context = |
| 256 new BasicURLRequestContext(file_task_runner_); | 258 new ContainerURLRequestContext(file_task_runner_); |
| 257 URLRequestContextStorage* storage = context->storage(); | 259 URLRequestContextStorage* storage = context->storage(); |
| 258 | 260 |
| 259 storage->set_http_user_agent_settings(new StaticHttpUserAgentSettings( | 261 storage->set_http_user_agent_settings(new StaticHttpUserAgentSettings( |
| 260 accept_language_, user_agent_)); | 262 accept_language_, user_agent_)); |
| 261 | 263 |
| 262 if (!network_delegate_) | 264 if (!network_delegate_) |
| 263 network_delegate_.reset(new BasicNetworkDelegate); | 265 network_delegate_.reset(new BasicNetworkDelegate); |
| 264 NetworkDelegate* network_delegate = network_delegate_.release(); | 266 NetworkDelegate* network_delegate = network_delegate_.release(); |
| 265 storage->set_network_delegate(network_delegate); | 267 storage->set_network_delegate(network_delegate); |
| 266 | 268 |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 } | 441 } |
| 440 url_request_interceptors_.weak_clear(); | 442 url_request_interceptors_.weak_clear(); |
| 441 } | 443 } |
| 442 storage->set_job_factory(top_job_factory.release()); | 444 storage->set_job_factory(top_job_factory.release()); |
| 443 // TODO(willchan): Support sdch. | 445 // TODO(willchan): Support sdch. |
| 444 | 446 |
| 445 return context; | 447 return context; |
| 446 } | 448 } |
| 447 | 449 |
| 448 } // namespace net | 450 } // namespace net |
| OLD | NEW |