OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef CHROME_BROWSER_SYNC_GLUE_HTTP_BRIDGE_H_ | 5 #ifndef CHROME_BROWSER_SYNC_GLUE_HTTP_BRIDGE_H_ |
6 #define CHROME_BROWSER_SYNC_GLUE_HTTP_BRIDGE_H_ | 6 #define CHROME_BROWSER_SYNC_GLUE_HTTP_BRIDGE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/ref_counted.h" | 11 #include "base/ref_counted.h" |
(...skipping 22 matching lines...) Expand all Loading... |
34 public: | 34 public: |
35 // A request context used for HTTP requests bridged from the sync backend. | 35 // A request context used for HTTP requests bridged from the sync backend. |
36 // A bridged RequestContext has a dedicated in-memory cookie store and does | 36 // A bridged RequestContext has a dedicated in-memory cookie store and does |
37 // not use a cache. Thus the same type can be used for incognito mode. | 37 // not use a cache. Thus the same type can be used for incognito mode. |
38 // TODO(timsteele): We subclass here instead of add a factory method on | 38 // TODO(timsteele): We subclass here instead of add a factory method on |
39 // ChromeURLRequestContext because: | 39 // ChromeURLRequestContext because: |
40 // 1) we want the ability to set_user_agent | 40 // 1) we want the ability to set_user_agent |
41 // 2) avoids ifdefs for now | 41 // 2) avoids ifdefs for now |
42 // 3) not sure we want to strictly follow settings for cookie policy, | 42 // 3) not sure we want to strictly follow settings for cookie policy, |
43 // accept lang/charset, since changing these could break syncing. | 43 // accept lang/charset, since changing these could break syncing. |
44 class RequestContext : public URLRequestContext { | 44 class RequestContext : public net::URLRequestContext { |
45 public: | 45 public: |
46 // |baseline_context| is used to obtain the accept-language, | 46 // |baseline_context| is used to obtain the accept-language, |
47 // accept-charsets, and proxy service information for bridged requests. | 47 // accept-charsets, and proxy service information for bridged requests. |
48 // Typically |baseline_context| should be the URLRequestContext of the | 48 // Typically |baseline_context| should be the URLRequestContext of the |
49 // currently active profile. | 49 // currently active profile. |
50 explicit RequestContext(URLRequestContext* baseline_context); | 50 explicit RequestContext(net::URLRequestContext* baseline_context); |
51 | 51 |
52 // Set the user agent for requests using this context. The default is | 52 // Set the user agent for requests using this context. The default is |
53 // the browser's UA string. | 53 // the browser's UA string. |
54 void set_user_agent(const std::string& ua) { user_agent_ = ua; } | 54 void set_user_agent(const std::string& ua) { user_agent_ = ua; } |
55 | 55 |
56 virtual const std::string& GetUserAgent(const GURL& url) const { | 56 virtual const std::string& GetUserAgent(const GURL& url) const { |
57 // If the user agent is set explicitly return that, otherwise call the | 57 // If the user agent is set explicitly return that, otherwise call the |
58 // base class method to return default value. | 58 // base class method to return default value. |
59 return user_agent_.empty() ? | 59 return user_agent_.empty() ? |
60 URLRequestContext::GetUserAgent(url) : user_agent_; | 60 net::URLRequestContext::GetUserAgent(url) : user_agent_; |
61 } | 61 } |
62 | 62 |
63 virtual bool AllowSendingCookies(const net::URLRequest* request) const { | 63 virtual bool AllowSendingCookies(const net::URLRequest* request) const { |
64 return false; | 64 return false; |
65 } | 65 } |
66 | 66 |
67 private: | 67 private: |
68 // The destructor MUST be called on the IO thread. | 68 // The destructor MUST be called on the IO thread. |
69 ~RequestContext(); | 69 ~RequestContext(); |
70 | 70 |
71 std::string user_agent_; | 71 std::string user_agent_; |
72 URLRequestContext* baseline_context_; | 72 net::URLRequestContext* baseline_context_; |
73 | 73 |
74 DISALLOW_COPY_AND_ASSIGN(RequestContext); | 74 DISALLOW_COPY_AND_ASSIGN(RequestContext); |
75 }; | 75 }; |
76 | 76 |
77 // Lazy-getter for RequestContext objects. | 77 // Lazy-getter for RequestContext objects. |
78 class RequestContextGetter : public URLRequestContextGetter { | 78 class RequestContextGetter : public URLRequestContextGetter { |
79 public: | 79 public: |
80 explicit RequestContextGetter( | 80 explicit RequestContextGetter( |
81 URLRequestContextGetter* baseline_context_getter); | 81 URLRequestContextGetter* baseline_context_getter); |
82 | 82 |
83 void set_user_agent(const std::string& ua) { user_agent_ = ua; } | 83 void set_user_agent(const std::string& ua) { user_agent_ = ua; } |
84 bool is_user_agent_set() const { return !user_agent_.empty(); } | 84 bool is_user_agent_set() const { return !user_agent_.empty(); } |
85 | 85 |
86 // URLRequestContextGetter implementation. | 86 // URLRequestContextGetter implementation. |
87 virtual URLRequestContext* GetURLRequestContext(); | 87 virtual net::URLRequestContext* GetURLRequestContext(); |
88 virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() const; | 88 virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() const; |
89 | 89 |
90 private: | 90 private: |
91 ~RequestContextGetter() {} | 91 ~RequestContextGetter() {} |
92 | 92 |
93 // User agent to apply to the URLRequestContext. | 93 // User agent to apply to the URLRequestContext. |
94 std::string user_agent_; | 94 std::string user_agent_; |
95 | 95 |
96 scoped_refptr<URLRequestContextGetter> baseline_context_getter_; | 96 scoped_refptr<URLRequestContextGetter> baseline_context_getter_; |
97 | 97 |
(...skipping 16 matching lines...) Expand all Loading... |
114 // WARNING: these response content methods are used to extract plain old data | 114 // WARNING: these response content methods are used to extract plain old data |
115 // and not null terminated strings, so you should make sure you have read | 115 // and not null terminated strings, so you should make sure you have read |
116 // GetResponseContentLength() characters when using GetResponseContent. e.g | 116 // GetResponseContentLength() characters when using GetResponseContent. e.g |
117 // string r(b->GetResponseContent(), b->GetResponseContentLength()). | 117 // string r(b->GetResponseContent(), b->GetResponseContentLength()). |
118 virtual int GetResponseContentLength() const; | 118 virtual int GetResponseContentLength() const; |
119 virtual const char* GetResponseContent() const; | 119 virtual const char* GetResponseContent() const; |
120 virtual const std::string GetResponseHeaderValue( | 120 virtual const std::string GetResponseHeaderValue( |
121 const std::string& name) const; | 121 const std::string& name) const; |
122 | 122 |
123 // URLFetcher::Delegate implementation. | 123 // URLFetcher::Delegate implementation. |
124 virtual void OnURLFetchComplete(const URLFetcher* source, const GURL& url, | 124 virtual void OnURLFetchComplete(const URLFetcher* source, |
125 const URLRequestStatus& status, | 125 const GURL& url, |
| 126 const net::URLRequestStatus& status, |
126 int response_code, | 127 int response_code, |
127 const ResponseCookies& cookies, | 128 const ResponseCookies& cookies, |
128 const std::string& data); | 129 const std::string& data); |
129 | 130 |
130 #if defined(UNIT_TEST) | 131 #if defined(UNIT_TEST) |
131 URLRequestContextGetter* GetRequestContextGetter() const { | 132 URLRequestContextGetter* GetRequestContextGetter() const { |
132 return context_getter_for_request_; | 133 return context_getter_for_request_; |
133 } | 134 } |
134 #endif | 135 #endif |
135 | 136 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 // common components. | 204 // common components. |
204 HttpBridge::RequestContextGetter* GetRequestContextGetter(); | 205 HttpBridge::RequestContextGetter* GetRequestContextGetter(); |
205 scoped_refptr<HttpBridge::RequestContextGetter> request_context_getter_; | 206 scoped_refptr<HttpBridge::RequestContextGetter> request_context_getter_; |
206 DISALLOW_COPY_AND_ASSIGN(HttpBridgeFactory); | 207 DISALLOW_COPY_AND_ASSIGN(HttpBridgeFactory); |
207 }; | 208 }; |
208 | 209 |
209 } // namespace browser_sync | 210 } // namespace browser_sync |
210 | 211 |
211 #endif // CHROME_BROWSER_SYNC_GLUE_HTTP_BRIDGE_H_ | 212 #endif // CHROME_BROWSER_SYNC_GLUE_HTTP_BRIDGE_H_ |
212 | 213 |
OLD | NEW |