| 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 "chrome/service/net/service_url_request_context.h" | 5 #include "chrome/service/net/service_url_request_context.h" |
| 6 | 6 |
| 7 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 7 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
| 8 #include <sys/utsname.h> | 8 #include <sys/utsname.h> |
| 9 #endif | 9 #endif |
| 10 | 10 |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/message_loop_proxy.h" | 12 #include "base/message_loop_proxy.h" |
| 13 #include "base/stringprintf.h" | 13 #include "base/stringprintf.h" |
| 14 #include "base/sys_info.h" | 14 #include "base/sys_info.h" |
| 15 #include "chrome/common/chrome_version_info.h" | 15 #include "chrome/common/chrome_version_info.h" |
| 16 #include "chrome/service/service_process.h" | 16 #include "chrome/service/service_process.h" |
| 17 #include "net/base/cert_verifier.h" | 17 #include "net/base/cert_verifier.h" |
| 18 #include "net/base/host_resolver.h" | 18 #include "net/base/host_resolver.h" |
| 19 #include "net/base/ssl_config_service_defaults.h" | 19 #include "net/base/ssl_config_service_defaults.h" |
| 20 #include "net/cookies/cookie_monster.h" | 20 #include "net/cookies/cookie_monster.h" |
| 21 #include "net/ftp/ftp_network_layer.h" | 21 #include "net/ftp/ftp_network_layer.h" |
| 22 #include "net/http/http_auth_handler_factory.h" | 22 #include "net/http/http_auth_handler_factory.h" |
| 23 #include "net/http/http_cache.h" | 23 #include "net/http/http_cache.h" |
| 24 #include "net/http/http_network_session.h" | 24 #include "net/http/http_network_session.h" |
| 25 #include "net/http/http_server_properties_impl.h" | 25 #include "net/http/http_server_properties_impl.h" |
| 26 #include "net/proxy/proxy_config_service.h" | 26 #include "net/proxy/proxy_config_service.h" |
| 27 #include "net/proxy/proxy_service.h" | 27 #include "net/proxy/proxy_service.h" |
| 28 #include "net/url_request/static_http_user_agent_settings.h" |
| 28 #include "net/url_request/url_request_throttler_manager.h" | 29 #include "net/url_request/url_request_throttler_manager.h" |
| 29 | 30 |
| 30 namespace { | 31 namespace { |
| 31 // Copied from webkit/glue/user_agent.cc. We don't want to pull in a dependency | 32 // Copied from webkit/glue/user_agent.cc. We don't want to pull in a dependency |
| 32 // on webkit/glue which also pulls in the renderer. Also our user-agent is | 33 // on webkit/glue which also pulls in the renderer. Also our user-agent is |
| 33 // totally different from the user-agent used by the browser, just the | 34 // totally different from the user-agent used by the browser, just the |
| 34 // OS-specific parts are common. | 35 // OS-specific parts are common. |
| 35 std::string BuildOSCpuInfo() { | 36 std::string BuildOSCpuInfo() { |
| 36 std::string os_cpu; | 37 std::string os_cpu; |
| 37 | 38 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 extra_version_info.c_str(), | 102 extra_version_info.c_str(), |
| 102 BuildOSCpuInfo().c_str()); | 103 BuildOSCpuInfo().c_str()); |
| 103 return user_agent; | 104 return user_agent; |
| 104 } | 105 } |
| 105 | 106 |
| 106 } // namespace | 107 } // namespace |
| 107 | 108 |
| 108 ServiceURLRequestContext::ServiceURLRequestContext( | 109 ServiceURLRequestContext::ServiceURLRequestContext( |
| 109 const std::string& user_agent, | 110 const std::string& user_agent, |
| 110 net::ProxyConfigService* net_proxy_config_service) | 111 net::ProxyConfigService* net_proxy_config_service) |
| 111 : user_agent_(user_agent), | 112 : ALLOW_THIS_IN_INITIALIZER_LIST(storage_(this)) { |
| 112 ALLOW_THIS_IN_INITIALIZER_LIST(storage_(this)) { | |
| 113 storage_.set_host_resolver(net::HostResolver::CreateDefaultResolver(NULL)); | 113 storage_.set_host_resolver(net::HostResolver::CreateDefaultResolver(NULL)); |
| 114 storage_.set_proxy_service(net::ProxyService::CreateUsingSystemProxyResolver( | 114 storage_.set_proxy_service(net::ProxyService::CreateUsingSystemProxyResolver( |
| 115 net_proxy_config_service, 0u, NULL)); | 115 net_proxy_config_service, 0u, NULL)); |
| 116 storage_.set_cert_verifier(net::CertVerifier::CreateDefault()); | 116 storage_.set_cert_verifier(net::CertVerifier::CreateDefault()); |
| 117 storage_.set_ftp_transaction_factory( | 117 storage_.set_ftp_transaction_factory( |
| 118 new net::FtpNetworkLayer(host_resolver())); | 118 new net::FtpNetworkLayer(host_resolver())); |
| 119 storage_.set_ssl_config_service(new net::SSLConfigServiceDefaults); | 119 storage_.set_ssl_config_service(new net::SSLConfigServiceDefaults); |
| 120 storage_.set_http_auth_handler_factory( | 120 storage_.set_http_auth_handler_factory( |
| 121 net::HttpAuthHandlerFactory::CreateDefault(host_resolver())); | 121 net::HttpAuthHandlerFactory::CreateDefault(host_resolver())); |
| 122 storage_.set_http_server_properties(new net::HttpServerPropertiesImpl); | 122 storage_.set_http_server_properties(new net::HttpServerPropertiesImpl); |
| 123 storage_.set_transport_security_state(new net::TransportSecurityState); | 123 storage_.set_transport_security_state(new net::TransportSecurityState); |
| 124 storage_.set_throttler_manager(new net::URLRequestThrottlerManager); | 124 storage_.set_throttler_manager(new net::URLRequestThrottlerManager); |
| 125 | 125 |
| 126 net::HttpNetworkSession::Params session_params; | 126 net::HttpNetworkSession::Params session_params; |
| 127 session_params.host_resolver = host_resolver(); | 127 session_params.host_resolver = host_resolver(); |
| 128 session_params.cert_verifier = cert_verifier(); | 128 session_params.cert_verifier = cert_verifier(); |
| 129 session_params.proxy_service = proxy_service(); | 129 session_params.proxy_service = proxy_service(); |
| 130 session_params.ssl_config_service = ssl_config_service(); | 130 session_params.ssl_config_service = ssl_config_service(); |
| 131 session_params.http_auth_handler_factory = http_auth_handler_factory(); | 131 session_params.http_auth_handler_factory = http_auth_handler_factory(); |
| 132 session_params.http_server_properties = http_server_properties(); | 132 session_params.http_server_properties = http_server_properties(); |
| 133 scoped_refptr<net::HttpNetworkSession> network_session( | 133 scoped_refptr<net::HttpNetworkSession> network_session( |
| 134 new net::HttpNetworkSession(session_params)); | 134 new net::HttpNetworkSession(session_params)); |
| 135 storage_.set_http_transaction_factory( | 135 storage_.set_http_transaction_factory( |
| 136 new net::HttpCache( | 136 new net::HttpCache( |
| 137 network_session, | 137 network_session, |
| 138 net::HttpCache::DefaultBackend::InMemory(0))); | 138 net::HttpCache::DefaultBackend::InMemory(0))); |
| 139 // In-memory cookie store. | 139 // In-memory cookie store. |
| 140 storage_.set_cookie_store(new net::CookieMonster(NULL, NULL)); | 140 storage_.set_cookie_store(new net::CookieMonster(NULL, NULL)); |
| 141 set_accept_language("en-us,fr"); | 141 storage_.set_http_user_agent_settings(new net::StaticHttpUserAgentSettings( |
| 142 set_accept_charset("iso-8859-1,*,utf-8"); | 142 "en-us,fr", "iso-8859-1,*,utf-8", user_agent)); |
| 143 } | |
| 144 | |
| 145 const std::string& ServiceURLRequestContext::GetUserAgent( | |
| 146 const GURL& url) const { | |
| 147 // If the user agent is set explicitly return that, otherwise call the | |
| 148 // base class method to return default value. | |
| 149 return user_agent_.empty() ? | |
| 150 net::URLRequestContext::GetUserAgent(url) : user_agent_; | |
| 151 } | 143 } |
| 152 | 144 |
| 153 ServiceURLRequestContext::~ServiceURLRequestContext() { | 145 ServiceURLRequestContext::~ServiceURLRequestContext() { |
| 154 } | 146 } |
| 155 | 147 |
| 156 ServiceURLRequestContextGetter::ServiceURLRequestContextGetter() | 148 ServiceURLRequestContextGetter::ServiceURLRequestContextGetter() |
| 157 : network_task_runner_( | 149 : network_task_runner_( |
| 158 g_service_process->io_thread()->message_loop_proxy()) { | 150 g_service_process->io_thread()->message_loop_proxy()) { |
| 159 // Build the default user agent. | 151 // Build the default user agent. |
| 160 user_agent_ = MakeUserAgentForServiceProcess(); | 152 user_agent_ = MakeUserAgentForServiceProcess(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 176 proxy_config_service_.release())); | 168 proxy_config_service_.release())); |
| 177 return url_request_context_.get(); | 169 return url_request_context_.get(); |
| 178 } | 170 } |
| 179 | 171 |
| 180 scoped_refptr<base::SingleThreadTaskRunner> | 172 scoped_refptr<base::SingleThreadTaskRunner> |
| 181 ServiceURLRequestContextGetter::GetNetworkTaskRunner() const { | 173 ServiceURLRequestContextGetter::GetNetworkTaskRunner() const { |
| 182 return network_task_runner_; | 174 return network_task_runner_; |
| 183 } | 175 } |
| 184 | 176 |
| 185 ServiceURLRequestContextGetter::~ServiceURLRequestContextGetter() {} | 177 ServiceURLRequestContextGetter::~ServiceURLRequestContextGetter() {} |
| OLD | NEW |