| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "webkit/tools/test_shell/test_shell_request_context.h" | 5 #include "webkit/tools/test_shell/test_shell_request_context.h" |
| 6 | 6 |
| 7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
| 8 | 8 |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "net/base/cookie_monster.h" | 10 #include "net/base/cookie_monster.h" |
| 11 #include "net/base/host_resolver.h" | 11 #include "net/base/host_resolver.h" |
| 12 #include "net/base/ssl_config_service.h" | 12 #include "net/base/ssl_config_service.h" |
| 13 #include "net/base/static_cookie_policy.h" | 13 #include "net/base/static_cookie_policy.h" |
| 14 #include "net/ftp/ftp_network_layer.h" | 14 #include "net/ftp/ftp_network_layer.h" |
| 15 #include "net/http/http_auth_handler_factory.h" | 15 #include "net/http/http_auth_handler_factory.h" |
| 16 #include "net/proxy/proxy_config_service.h" | 16 #include "net/proxy/proxy_config_service.h" |
| 17 #include "net/proxy/proxy_config_service_fixed.h" | 17 #include "net/proxy/proxy_config_service_fixed.h" |
| 18 #include "net/proxy/proxy_service.h" | 18 #include "net/proxy/proxy_service.h" |
| 19 #include "webkit/glue/webkit_glue.h" | 19 #include "webkit/glue/webkit_glue.h" |
| 20 #include "webkit/tools/test_shell/simple_resource_loader_bridge.h" |
| 20 | 21 |
| 21 TestShellRequestContext::TestShellRequestContext() : cache_thread_("cache") { | 22 TestShellRequestContext::TestShellRequestContext() { |
| 22 Init(FilePath(), net::HttpCache::NORMAL, false); | 23 Init(FilePath(), net::HttpCache::NORMAL, false); |
| 23 } | 24 } |
| 24 | 25 |
| 25 TestShellRequestContext::TestShellRequestContext( | 26 TestShellRequestContext::TestShellRequestContext( |
| 26 const FilePath& cache_path, | 27 const FilePath& cache_path, |
| 27 net::HttpCache::Mode cache_mode, | 28 net::HttpCache::Mode cache_mode, |
| 28 bool no_proxy) : cache_thread_("cache") { | 29 bool no_proxy) { |
| 29 Init(cache_path, cache_mode, no_proxy); | 30 Init(cache_path, cache_mode, no_proxy); |
| 30 } | 31 } |
| 31 | 32 |
| 32 void TestShellRequestContext::Init( | 33 void TestShellRequestContext::Init( |
| 33 const FilePath& cache_path, | 34 const FilePath& cache_path, |
| 34 net::HttpCache::Mode cache_mode, | 35 net::HttpCache::Mode cache_mode, |
| 35 bool no_proxy) { | 36 bool no_proxy) { |
| 36 cookie_store_ = new net::CookieMonster(NULL, NULL); | 37 cookie_store_ = new net::CookieMonster(NULL, NULL); |
| 37 cookie_policy_ = new net::StaticCookiePolicy(); | 38 cookie_policy_ = new net::StaticCookiePolicy(); |
| 38 | 39 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 56 scoped_ptr<net::ProxyConfigService> proxy_config_service( | 57 scoped_ptr<net::ProxyConfigService> proxy_config_service( |
| 57 net::ProxyService::CreateSystemProxyConfigService(NULL, NULL)); | 58 net::ProxyService::CreateSystemProxyConfigService(NULL, NULL)); |
| 58 #endif | 59 #endif |
| 59 host_resolver_ = net::CreateSystemHostResolver(NULL); | 60 host_resolver_ = net::CreateSystemHostResolver(NULL); |
| 60 proxy_service_ = net::ProxyService::Create(proxy_config_service.release(), | 61 proxy_service_ = net::ProxyService::Create(proxy_config_service.release(), |
| 61 false, NULL, NULL, NULL, NULL); | 62 false, NULL, NULL, NULL, NULL); |
| 62 ssl_config_service_ = net::SSLConfigService::CreateSystemSSLConfigService(); | 63 ssl_config_service_ = net::SSLConfigService::CreateSystemSSLConfigService(); |
| 63 | 64 |
| 64 http_auth_handler_factory_ = net::HttpAuthHandlerFactory::CreateDefault(); | 65 http_auth_handler_factory_ = net::HttpAuthHandlerFactory::CreateDefault(); |
| 65 | 66 |
| 66 if (!cache_path.empty()) | |
| 67 CHECK(cache_thread_.StartWithOptions( | |
| 68 base::Thread::Options(MessageLoop::TYPE_IO, 0))); | |
| 69 | |
| 70 net::HttpCache::DefaultBackend* backend = new net::HttpCache::DefaultBackend( | 67 net::HttpCache::DefaultBackend* backend = new net::HttpCache::DefaultBackend( |
| 71 cache_path.empty() ? net::MEMORY_CACHE : net::DISK_CACHE, | 68 cache_path.empty() ? net::MEMORY_CACHE : net::DISK_CACHE, |
| 72 cache_path, 0, cache_thread_.message_loop_proxy()); | 69 cache_path, 0, SimpleResourceLoaderBridge::GetCacheThread()); |
| 73 | 70 |
| 74 net::HttpCache* cache = | 71 net::HttpCache* cache = |
| 75 new net::HttpCache(NULL, host_resolver_, proxy_service_, | 72 new net::HttpCache(NULL, host_resolver_, proxy_service_, |
| 76 ssl_config_service_, http_auth_handler_factory_, | 73 ssl_config_service_, http_auth_handler_factory_, |
| 77 NULL, backend); | 74 NULL, backend); |
| 78 | 75 |
| 79 cache->set_mode(cache_mode); | 76 cache->set_mode(cache_mode); |
| 80 http_transaction_factory_ = cache; | 77 http_transaction_factory_ = cache; |
| 81 | 78 |
| 82 ftp_transaction_factory_ = new net::FtpNetworkLayer(host_resolver_); | 79 ftp_transaction_factory_ = new net::FtpNetworkLayer(host_resolver_); |
| 83 } | 80 } |
| 84 | 81 |
| 85 TestShellRequestContext::~TestShellRequestContext() { | 82 TestShellRequestContext::~TestShellRequestContext() { |
| 86 delete ftp_transaction_factory_; | 83 delete ftp_transaction_factory_; |
| 87 delete http_transaction_factory_; | 84 delete http_transaction_factory_; |
| 88 delete http_auth_handler_factory_; | 85 delete http_auth_handler_factory_; |
| 89 delete static_cast<net::StaticCookiePolicy*>(cookie_policy_); | 86 delete static_cast<net::StaticCookiePolicy*>(cookie_policy_); |
| 90 } | 87 } |
| 91 | 88 |
| 92 const std::string& TestShellRequestContext::GetUserAgent( | 89 const std::string& TestShellRequestContext::GetUserAgent( |
| 93 const GURL& url) const { | 90 const GURL& url) const { |
| 94 return webkit_glue::GetUserAgent(url); | 91 return webkit_glue::GetUserAgent(url); |
| 95 } | 92 } |
| OLD | NEW |