| 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" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/string_util.h" |
| 12 #include "base/threading/thread.h" | 13 #include "base/threading/thread.h" |
| 13 #include "base/thread_task_runner_handle.h" | 14 #include "base/thread_task_runner_handle.h" |
| 14 #include "net/base/cert_verifier.h" | 15 #include "net/base/cert_verifier.h" |
| 15 #include "net/base/host_resolver.h" | 16 #include "net/base/host_resolver.h" |
| 16 #include "net/base/net_errors.h" | 17 #include "net/base/net_errors.h" |
| 17 #include "net/base/network_delegate.h" | 18 #include "net/base/network_delegate.h" |
| 18 #include "net/base/ssl_config_service_defaults.h" | 19 #include "net/base/ssl_config_service_defaults.h" |
| 19 #include "net/base/transport_security_state.h" | 20 #include "net/base/transport_security_state.h" |
| 20 #include "net/cookies/cookie_monster.h" | 21 #include "net/cookies/cookie_monster.h" |
| 21 #include "net/ftp/ftp_network_layer.h" | 22 #include "net/ftp/ftp_network_layer.h" |
| 22 #include "net/http/http_auth_handler_factory.h" | 23 #include "net/http/http_auth_handler_factory.h" |
| 23 #include "net/http/http_cache.h" | 24 #include "net/http/http_cache.h" |
| 24 #include "net/http/http_network_layer.h" | 25 #include "net/http/http_network_layer.h" |
| 25 #include "net/http/http_network_session.h" | 26 #include "net/http/http_network_session.h" |
| 26 #include "net/http/http_server_properties_impl.h" | 27 #include "net/http/http_server_properties_impl.h" |
| 27 #include "net/proxy/proxy_service.h" | 28 #include "net/proxy/proxy_service.h" |
| 29 #include "net/url_request/static_http_user_agent_settings.h" |
| 28 #include "net/url_request/url_request_context.h" | 30 #include "net/url_request/url_request_context.h" |
| 29 #include "net/url_request/url_request_context_storage.h" | 31 #include "net/url_request/url_request_context_storage.h" |
| 30 | 32 |
| 31 namespace net { | 33 namespace net { |
| 32 | 34 |
| 33 namespace { | 35 namespace { |
| 34 | 36 |
| 35 class BasicNetworkDelegate : public NetworkDelegate { | 37 class BasicNetworkDelegate : public NetworkDelegate { |
| 36 public: | 38 public: |
| 37 BasicNetworkDelegate() {} | 39 BasicNetworkDelegate() {} |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 public: | 124 public: |
| 123 BasicURLRequestContext() | 125 BasicURLRequestContext() |
| 124 : cache_thread_("Cache Thread"), | 126 : cache_thread_("Cache Thread"), |
| 125 file_thread_("File Thread"), | 127 file_thread_("File Thread"), |
| 126 ALLOW_THIS_IN_INITIALIZER_LIST(storage_(this)) {} | 128 ALLOW_THIS_IN_INITIALIZER_LIST(storage_(this)) {} |
| 127 | 129 |
| 128 URLRequestContextStorage* storage() { | 130 URLRequestContextStorage* storage() { |
| 129 return &storage_; | 131 return &storage_; |
| 130 } | 132 } |
| 131 | 133 |
| 132 void set_user_agent(const std::string& user_agent) { | |
| 133 user_agent_ = user_agent; | |
| 134 } | |
| 135 | |
| 136 void StartCacheThread() { | 134 void StartCacheThread() { |
| 137 cache_thread_.StartWithOptions( | 135 cache_thread_.StartWithOptions( |
| 138 base::Thread::Options(MessageLoop::TYPE_IO, 0)); | 136 base::Thread::Options(MessageLoop::TYPE_IO, 0)); |
| 139 } | 137 } |
| 140 | 138 |
| 141 scoped_refptr<base::MessageLoopProxy> cache_message_loop_proxy() { | 139 scoped_refptr<base::MessageLoopProxy> cache_message_loop_proxy() { |
| 142 DCHECK(cache_thread_.IsRunning()); | 140 DCHECK(cache_thread_.IsRunning()); |
| 143 return cache_thread_.message_loop_proxy(); | 141 return cache_thread_.message_loop_proxy(); |
| 144 } | 142 } |
| 145 | 143 |
| 146 void StartFileThread() { | 144 void StartFileThread() { |
| 147 file_thread_.StartWithOptions( | 145 file_thread_.StartWithOptions( |
| 148 base::Thread::Options(MessageLoop::TYPE_DEFAULT, 0)); | 146 base::Thread::Options(MessageLoop::TYPE_DEFAULT, 0)); |
| 149 } | 147 } |
| 150 | 148 |
| 151 MessageLoop* file_message_loop() { | 149 MessageLoop* file_message_loop() { |
| 152 DCHECK(file_thread_.IsRunning()); | 150 DCHECK(file_thread_.IsRunning()); |
| 153 return file_thread_.message_loop(); | 151 return file_thread_.message_loop(); |
| 154 } | 152 } |
| 155 | 153 |
| 156 virtual const std::string& GetUserAgent( | |
| 157 const GURL& /* url */) const OVERRIDE { | |
| 158 return user_agent_; | |
| 159 } | |
| 160 | |
| 161 protected: | 154 protected: |
| 162 virtual ~BasicURLRequestContext() {} | 155 virtual ~BasicURLRequestContext() {} |
| 163 | 156 |
| 164 private: | 157 private: |
| 165 std::string user_agent_; | |
| 166 base::Thread cache_thread_; | 158 base::Thread cache_thread_; |
| 167 base::Thread file_thread_; | 159 base::Thread file_thread_; |
| 168 URLRequestContextStorage storage_; | 160 URLRequestContextStorage storage_; |
| 169 DISALLOW_COPY_AND_ASSIGN(BasicURLRequestContext); | 161 DISALLOW_COPY_AND_ASSIGN(BasicURLRequestContext); |
| 170 }; | 162 }; |
| 171 | 163 |
| 172 } // namespace | 164 } // namespace |
| 173 | 165 |
| 174 URLRequestContextBuilder::HttpCacheParams::HttpCacheParams() | 166 URLRequestContextBuilder::HttpCacheParams::HttpCacheParams() |
| 175 : type(IN_MEMORY), | 167 : type(IN_MEMORY), |
| (...skipping 20 matching lines...) Expand all Loading... |
| 196 void URLRequestContextBuilder::set_proxy_config_service( | 188 void URLRequestContextBuilder::set_proxy_config_service( |
| 197 ProxyConfigService* proxy_config_service) { | 189 ProxyConfigService* proxy_config_service) { |
| 198 proxy_config_service_.reset(proxy_config_service); | 190 proxy_config_service_.reset(proxy_config_service); |
| 199 } | 191 } |
| 200 #endif // defined(OS_LINUX) || defined(OS_ANDROID) | 192 #endif // defined(OS_LINUX) || defined(OS_ANDROID) |
| 201 | 193 |
| 202 URLRequestContext* URLRequestContextBuilder::Build() { | 194 URLRequestContext* URLRequestContextBuilder::Build() { |
| 203 BasicURLRequestContext* context = new BasicURLRequestContext; | 195 BasicURLRequestContext* context = new BasicURLRequestContext; |
| 204 URLRequestContextStorage* storage = context->storage(); | 196 URLRequestContextStorage* storage = context->storage(); |
| 205 | 197 |
| 206 context->set_user_agent(user_agent_); | 198 storage->set_http_user_agent_settings(new StaticHttpUserAgentSettings( |
| 199 accept_language_, accept_charset_, user_agent_)); |
| 207 | 200 |
| 208 if (!network_delegate_) | 201 if (!network_delegate_) |
| 209 network_delegate_.reset(new BasicNetworkDelegate); | 202 network_delegate_.reset(new BasicNetworkDelegate); |
| 210 storage->set_network_delegate(network_delegate_.release()); | 203 storage->set_network_delegate(network_delegate_.release()); |
| 211 | 204 |
| 212 storage->set_host_resolver(net::HostResolver::CreateDefaultResolver(NULL)); | 205 storage->set_host_resolver(net::HostResolver::CreateDefaultResolver(NULL)); |
| 213 | 206 |
| 214 if (ftp_enabled_) { | 207 if (ftp_enabled_) { |
| 215 storage->set_ftp_transaction_factory( | 208 storage->set_ftp_transaction_factory( |
| 216 new FtpNetworkLayer(context->host_resolver())); | 209 new FtpNetworkLayer(context->host_resolver())); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 http_transaction_factory = new HttpNetworkLayer(network_session); | 289 http_transaction_factory = new HttpNetworkLayer(network_session); |
| 297 } | 290 } |
| 298 storage->set_http_transaction_factory(http_transaction_factory); | 291 storage->set_http_transaction_factory(http_transaction_factory); |
| 299 | 292 |
| 300 // TODO(willchan): Support sdch. | 293 // TODO(willchan): Support sdch. |
| 301 | 294 |
| 302 return context; | 295 return context; |
| 303 } | 296 } |
| 304 | 297 |
| 305 } // namespace net | 298 } // namespace net |
| OLD | NEW |