| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_SERVICE_NET_SERVICE_URL_REQUEST_CONTEXT_H_ |
| 6 #define CHROME_SERVICE_NET_SERVICE_URL_REQUEST_CONTEXT_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/message_loop_proxy.h" |
| 11 #include "chrome/common/net/url_request_context_getter.h" |
| 12 #include "net/base/cookie_monster.h" |
| 13 #include "net/base/cookie_policy.h" |
| 14 #include "net/base/host_resolver.h" |
| 15 #include "net/base/ssl_config_service_defaults.h" |
| 16 #include "net/disk_cache/disk_cache.h" |
| 17 #include "net/ftp/ftp_network_layer.h" |
| 18 #include "net/http/http_auth_handler_factory.h" |
| 19 #include "net/http/http_cache.h" |
| 20 #include "net/http/http_network_layer.h" |
| 21 #include "net/proxy/proxy_service.h" |
| 22 #include "net/url_request/url_request_context.h" |
| 23 |
| 24 // Subclass of URLRequestContext which can be used to store extra information |
| 25 // for requests. This subclass is meant to be used in the service process where |
| 26 // the profile is not available. |
| 27 // |
| 28 class ServiceURLRequestContext : public URLRequestContext { |
| 29 public: |
| 30 ServiceURLRequestContext(); |
| 31 void set_cookie_policy(net::CookiePolicy* policy) { |
| 32 cookie_policy_ = policy; |
| 33 } |
| 34 void set_user_agent(const std::string& ua) { |
| 35 user_agent_ = ua; |
| 36 } |
| 37 |
| 38 // URLRequestContext overrides |
| 39 virtual const std::string& GetUserAgent(const GURL& url) const { |
| 40 // If the user agent is set explicitly return that, otherwise call the |
| 41 // base class method to return default value. |
| 42 return user_agent_.empty() ? |
| 43 URLRequestContext::GetUserAgent(url) : user_agent_; |
| 44 } |
| 45 |
| 46 protected: |
| 47 virtual ~ServiceURLRequestContext(); |
| 48 |
| 49 private: |
| 50 std::string user_agent_; |
| 51 }; |
| 52 |
| 53 class ServiceURLRequestContextGetter : public URLRequestContextGetter { |
| 54 public: |
| 55 ServiceURLRequestContextGetter(); |
| 56 |
| 57 virtual URLRequestContext* GetURLRequestContext() { |
| 58 if (!url_request_context_) |
| 59 url_request_context_ = new ServiceURLRequestContext(); |
| 60 return url_request_context_; |
| 61 } |
| 62 virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() { |
| 63 return io_message_loop_proxy_; |
| 64 } |
| 65 |
| 66 void set_user_agent(const std::string& ua) { |
| 67 user_agent_ = ua; |
| 68 } |
| 69 private: |
| 70 ~ServiceURLRequestContextGetter() {} |
| 71 |
| 72 std::string user_agent_; |
| 73 scoped_refptr<URLRequestContext> url_request_context_; |
| 74 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy_; |
| 75 }; |
| 76 |
| 77 #endif // CHROME_SERVICE_NET_SERVICE_URL_REQUEST_CONTEXT_H_ |
| 78 |
| OLD | NEW |