| 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/browser/policy/device_management_service.h" | 5 #include "chrome/browser/policy/device_management_service.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.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/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
| 16 #include "chrome/browser/net/basic_http_user_agent_settings.h" |
| 16 #include "chrome/browser/net/chrome_net_log.h" | 17 #include "chrome/browser/net/chrome_net_log.h" |
| 17 #include "chrome/common/chrome_version_info.h" | 18 #include "chrome/common/chrome_version_info.h" |
| 18 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 19 #include "content/public/common/content_client.h" | 20 #include "content/public/common/content_client.h" |
| 20 #include "googleurl/src/gurl.h" | 21 #include "googleurl/src/gurl.h" |
| 21 #include "net/base/escape.h" | 22 #include "net/base/escape.h" |
| 22 #include "net/base/host_resolver.h" | 23 #include "net/base/host_resolver.h" |
| 23 #include "net/base/load_flags.h" | 24 #include "net/base/load_flags.h" |
| 24 #include "net/base/net_errors.h" | 25 #include "net/base/net_errors.h" |
| 25 #include "net/base/ssl_config_service_defaults.h" | 26 #include "net/base/ssl_config_service_defaults.h" |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 | 179 |
| 179 // Custom request context implementation that allows to override the user agent, | 180 // Custom request context implementation that allows to override the user agent, |
| 180 // amongst others. Wraps a baseline request context from which we reuse the | 181 // amongst others. Wraps a baseline request context from which we reuse the |
| 181 // networking components. | 182 // networking components. |
| 182 class DeviceManagementRequestContext : public net::URLRequestContext { | 183 class DeviceManagementRequestContext : public net::URLRequestContext { |
| 183 public: | 184 public: |
| 184 explicit DeviceManagementRequestContext(net::URLRequestContext* base_context); | 185 explicit DeviceManagementRequestContext(net::URLRequestContext* base_context); |
| 185 virtual ~DeviceManagementRequestContext(); | 186 virtual ~DeviceManagementRequestContext(); |
| 186 | 187 |
| 187 private: | 188 private: |
| 188 // Overridden from net::URLRequestContext: | 189 BasicHttpUserAgentSettings basic_http_user_agent_settings_; |
| 189 virtual const std::string& GetUserAgent(const GURL& url) const OVERRIDE; | |
| 190 }; | 190 }; |
| 191 | 191 |
| 192 DeviceManagementRequestContext::DeviceManagementRequestContext( | 192 DeviceManagementRequestContext::DeviceManagementRequestContext( |
| 193 net::URLRequestContext* base_context) { | 193 net::URLRequestContext* base_context) |
| 194 // Use sane Accept-Language and Accept-Charset values for our purposes. |
| 195 : basic_http_user_agent_settings_("*", "*") { |
| 194 // Share resolver, proxy service and ssl bits with the baseline context. This | 196 // Share resolver, proxy service and ssl bits with the baseline context. This |
| 195 // is important so we don't make redundant requests (e.g. when resolving proxy | 197 // is important so we don't make redundant requests (e.g. when resolving proxy |
| 196 // auto configuration). | 198 // auto configuration). |
| 197 set_net_log(base_context->net_log()); | 199 set_net_log(base_context->net_log()); |
| 198 set_host_resolver(base_context->host_resolver()); | 200 set_host_resolver(base_context->host_resolver()); |
| 199 set_proxy_service(base_context->proxy_service()); | 201 set_proxy_service(base_context->proxy_service()); |
| 200 set_ssl_config_service(base_context->ssl_config_service()); | 202 set_ssl_config_service(base_context->ssl_config_service()); |
| 201 | 203 |
| 202 // Share the http session. | 204 // Share the http session. |
| 203 set_http_transaction_factory( | 205 set_http_transaction_factory( |
| 204 new net::HttpNetworkLayer( | 206 new net::HttpNetworkLayer( |
| 205 base_context->http_transaction_factory()->GetSession())); | 207 base_context->http_transaction_factory()->GetSession())); |
| 206 | 208 |
| 207 // No cookies, please. | 209 // No cookies, please. |
| 208 set_cookie_store(new net::CookieMonster(NULL, NULL)); | 210 set_cookie_store(new net::CookieMonster(NULL, NULL)); |
| 209 | 211 |
| 210 // Initialize these to sane values for our purposes. | 212 set_http_user_agent_settings(&basic_http_user_agent_settings_); |
| 211 set_accept_language("*"); | |
| 212 set_accept_charset("*"); | |
| 213 } | 213 } |
| 214 | 214 |
| 215 DeviceManagementRequestContext::~DeviceManagementRequestContext() { | 215 DeviceManagementRequestContext::~DeviceManagementRequestContext() { |
| 216 delete http_transaction_factory(); | 216 delete http_transaction_factory(); |
| 217 } | 217 } |
| 218 | 218 |
| 219 const std::string& DeviceManagementRequestContext::GetUserAgent( | |
| 220 const GURL& url) const { | |
| 221 return content::GetUserAgent(url); | |
| 222 } | |
| 223 | |
| 224 // Request context holder. | 219 // Request context holder. |
| 225 class DeviceManagementRequestContextGetter | 220 class DeviceManagementRequestContextGetter |
| 226 : public net::URLRequestContextGetter { | 221 : public net::URLRequestContextGetter { |
| 227 public: | 222 public: |
| 228 explicit DeviceManagementRequestContextGetter( | 223 explicit DeviceManagementRequestContextGetter( |
| 229 net::URLRequestContextGetter* base_context_getter) | 224 net::URLRequestContextGetter* base_context_getter) |
| 230 : base_context_getter_(base_context_getter) {} | 225 : base_context_getter_(base_context_getter) {} |
| 231 | 226 |
| 232 // Overridden from net::URLRequestContextGetter: | 227 // Overridden from net::URLRequestContextGetter: |
| 233 virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE; | 228 virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE; |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 585 } | 580 } |
| 586 } | 581 } |
| 587 | 582 |
| 588 const JobQueue::iterator elem = | 583 const JobQueue::iterator elem = |
| 589 std::find(queued_jobs_.begin(), queued_jobs_.end(), job); | 584 std::find(queued_jobs_.begin(), queued_jobs_.end(), job); |
| 590 if (elem != queued_jobs_.end()) | 585 if (elem != queued_jobs_.end()) |
| 591 queued_jobs_.erase(elem); | 586 queued_jobs_.erase(elem); |
| 592 } | 587 } |
| 593 | 588 |
| 594 } // namespace policy | 589 } // namespace policy |
| OLD | NEW |