OLD | NEW |
1 // Copyright (c) 2011 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 |
(...skipping 27 matching lines...) Expand all Loading... |
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 net::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 net::URLRequestContext of the |
49 // currently active profile. | 49 // currently active profile. |
50 explicit RequestContext(net::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. |
(...skipping 20 matching lines...) Expand all Loading... |
79 void set_user_agent(const std::string& ua) { user_agent_ = ua; } | 79 void set_user_agent(const std::string& ua) { user_agent_ = ua; } |
80 bool is_user_agent_set() const { return !user_agent_.empty(); } | 80 bool is_user_agent_set() const { return !user_agent_.empty(); } |
81 | 81 |
82 // URLRequestContextGetter implementation. | 82 // URLRequestContextGetter implementation. |
83 virtual net::URLRequestContext* GetURLRequestContext(); | 83 virtual net::URLRequestContext* GetURLRequestContext(); |
84 virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() const; | 84 virtual scoped_refptr<base::MessageLoopProxy> GetIOMessageLoopProxy() const; |
85 | 85 |
86 private: | 86 private: |
87 ~RequestContextGetter() {} | 87 ~RequestContextGetter() {} |
88 | 88 |
89 // User agent to apply to the URLRequestContext. | 89 // User agent to apply to the net::URLRequestContext. |
90 std::string user_agent_; | 90 std::string user_agent_; |
91 | 91 |
92 scoped_refptr<URLRequestContextGetter> baseline_context_getter_; | 92 scoped_refptr<URLRequestContextGetter> baseline_context_getter_; |
93 | 93 |
94 // Lazily initialized by GetURLRequestContext(). | 94 // Lazily initialized by GetURLRequestContext(). |
95 scoped_refptr<RequestContext> context_; | 95 scoped_refptr<RequestContext> context_; |
96 | 96 |
97 DISALLOW_COPY_AND_ASSIGN(RequestContextGetter); | 97 DISALLOW_COPY_AND_ASSIGN(RequestContextGetter); |
98 }; | 98 }; |
99 | 99 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 virtual void MakeAsynchronousPost(); | 139 virtual void MakeAsynchronousPost(); |
140 | 140 |
141 private: | 141 private: |
142 friend class ::HttpBridgeTest; | 142 friend class ::HttpBridgeTest; |
143 | 143 |
144 // Called on the IO loop to issue the network request. The extra level | 144 // Called on the IO loop to issue the network request. The extra level |
145 // of indirection is so that the unit test can override this behavior but we | 145 // of indirection is so that the unit test can override this behavior but we |
146 // still have a function to statically pass to PostTask. | 146 // still have a function to statically pass to PostTask. |
147 void CallMakeAsynchronousPost() { MakeAsynchronousPost(); } | 147 void CallMakeAsynchronousPost() { MakeAsynchronousPost(); } |
148 | 148 |
149 // Gets a customized URLRequestContext for bridged requests. See | 149 // Gets a customized net::URLRequestContext for bridged requests. See |
150 // RequestContext definition for details. | 150 // RequestContext definition for details. |
151 scoped_refptr<RequestContextGetter> context_getter_for_request_; | 151 scoped_refptr<RequestContextGetter> context_getter_for_request_; |
152 | 152 |
153 // Our hook into the network layer is a URLFetcher. USED ONLY ON THE IO LOOP, | 153 // Our hook into the network layer is a URLFetcher. USED ONLY ON THE IO LOOP, |
154 // so we can block created_on_loop_ while the fetch is in progress. | 154 // so we can block created_on_loop_ while the fetch is in progress. |
155 // NOTE: This is not a scoped_ptr for a reason. It must be deleted on the same | 155 // NOTE: This is not a scoped_ptr for a reason. It must be deleted on the same |
156 // thread that created it, which isn't the same thread |this| gets deleted on. | 156 // thread that created it, which isn't the same thread |this| gets deleted on. |
157 // We must manually delete url_poster_ on the IO loop. | 157 // We must manually delete url_poster_ on the IO loop. |
158 URLFetcher* url_poster_; | 158 URLFetcher* url_poster_; |
159 | 159 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 // common components. | 200 // common components. |
201 HttpBridge::RequestContextGetter* GetRequestContextGetter(); | 201 HttpBridge::RequestContextGetter* GetRequestContextGetter(); |
202 scoped_refptr<HttpBridge::RequestContextGetter> request_context_getter_; | 202 scoped_refptr<HttpBridge::RequestContextGetter> request_context_getter_; |
203 DISALLOW_COPY_AND_ASSIGN(HttpBridgeFactory); | 203 DISALLOW_COPY_AND_ASSIGN(HttpBridgeFactory); |
204 }; | 204 }; |
205 | 205 |
206 } // namespace browser_sync | 206 } // namespace browser_sync |
207 | 207 |
208 #endif // CHROME_BROWSER_SYNC_GLUE_HTTP_BRIDGE_H_ | 208 #endif // CHROME_BROWSER_SYNC_GLUE_HTTP_BRIDGE_H_ |
209 | 209 |
OLD | NEW |