OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 #ifndef SYNC_INTERNAL_API_PUBLIC_HTTP_BRIDGE_H_ | 5 #ifndef SYNC_INTERNAL_API_PUBLIC_HTTP_BRIDGE_H_ |
6 #define SYNC_INTERNAL_API_PUBLIC_HTTP_BRIDGE_H_ | 6 #define SYNC_INTERNAL_API_PUBLIC_HTTP_BRIDGE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 // This is a one-time use bridge. Create one for each request you want to make. | 47 // This is a one-time use bridge. Create one for each request you want to make. |
48 // It is RefCountedThreadSafe because it can PostTask to the io loop, and thus | 48 // It is RefCountedThreadSafe because it can PostTask to the io loop, and thus |
49 // needs to stick around across context switches, etc. | 49 // needs to stick around across context switches, etc. |
50 class SYNC_EXPORT_PRIVATE HttpBridge | 50 class SYNC_EXPORT_PRIVATE HttpBridge |
51 : public base::RefCountedThreadSafe<HttpBridge>, | 51 : public base::RefCountedThreadSafe<HttpBridge>, |
52 public HttpPostProviderInterface, | 52 public HttpPostProviderInterface, |
53 public net::URLFetcherDelegate { | 53 public net::URLFetcherDelegate { |
54 public: | 54 public: |
55 HttpBridge(const std::string& user_agent, | 55 HttpBridge(const std::string& user_agent, |
56 const scoped_refptr<net::URLRequestContextGetter>& context, | 56 const scoped_refptr<net::URLRequestContextGetter>& context, |
57 const NetworkTimeUpdateCallback& network_time_update_callback, | 57 const NetworkTimeUpdateCallback& network_time_update_callback); |
58 const BindToTrackerCallback& bind_to_tracker_callback); | |
59 | 58 |
60 // HttpPostProvider implementation. | 59 // HttpPostProvider implementation. |
61 void SetExtraRequestHeaders(const char* headers) override; | 60 void SetExtraRequestHeaders(const char* headers) override; |
62 void SetURL(const char* url, int port) override; | 61 void SetURL(const char* url, int port) override; |
63 void SetPostPayload(const char* content_type, | 62 void SetPostPayload(const char* content_type, |
64 int content_length, | 63 int content_length, |
65 const char* content) override; | 64 const char* content) override; |
66 bool MakeSynchronousPost(int* error_code, int* response_code) override; | 65 bool MakeSynchronousPost(int* error_code, int* response_code) override; |
67 void Abort() override; | 66 void Abort() override; |
68 | 67 |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 mutable base::Lock fetch_state_lock_; | 173 mutable base::Lock fetch_state_lock_; |
175 URLFetchState fetch_state_; | 174 URLFetchState fetch_state_; |
176 | 175 |
177 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; | 176 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; |
178 | 177 |
179 const scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; | 178 const scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; |
180 | 179 |
181 // Callback for updating network time. | 180 // Callback for updating network time. |
182 NetworkTimeUpdateCallback network_time_update_callback_; | 181 NetworkTimeUpdateCallback network_time_update_callback_; |
183 | 182 |
184 // A callback to tag Sync request to be able to record data use of this | |
185 // service by data_use_measurement component. | |
186 BindToTrackerCallback bind_to_tracker_callback_; | |
187 | |
188 DISALLOW_COPY_AND_ASSIGN(HttpBridge); | 183 DISALLOW_COPY_AND_ASSIGN(HttpBridge); |
189 }; | 184 }; |
190 | 185 |
191 class SYNC_EXPORT HttpBridgeFactory : public HttpPostProviderFactory, | 186 class SYNC_EXPORT HttpBridgeFactory : public HttpPostProviderFactory, |
192 public CancelationObserver { | 187 public CancelationObserver { |
193 public: | 188 public: |
194 HttpBridgeFactory( | 189 HttpBridgeFactory( |
195 const scoped_refptr<net::URLRequestContextGetter>& | 190 const scoped_refptr<net::URLRequestContextGetter>& |
196 baseline_context_getter, | 191 baseline_context_getter, |
197 const NetworkTimeUpdateCallback& network_time_update_callback, | 192 const NetworkTimeUpdateCallback& network_time_update_callback, |
198 CancelationSignal* cancelation_signal); | 193 CancelationSignal* cancelation_signal); |
199 ~HttpBridgeFactory() override; | 194 ~HttpBridgeFactory() override; |
200 | 195 |
201 // HttpPostProviderFactory: | 196 // HttpPostProviderFactory: |
202 void Init(const std::string& user_agent, | 197 void Init(const std::string& user_agent) override; |
203 const BindToTrackerCallback& bind_to_tracker_callback) override; | |
204 HttpPostProviderInterface* Create() override; | 198 HttpPostProviderInterface* Create() override; |
205 void Destroy(HttpPostProviderInterface* http) override; | 199 void Destroy(HttpPostProviderInterface* http) override; |
206 | 200 |
207 // CancelationObserver implementation: | 201 // CancelationObserver implementation: |
208 void OnSignalReceived() override; | 202 void OnSignalReceived() override; |
209 | 203 |
210 private: | 204 private: |
211 // The user agent to use in all requests. | 205 // The user agent to use in all requests. |
212 std::string user_agent_; | 206 std::string user_agent_; |
213 | 207 |
214 // Protects |request_context_getter_| to allow releasing it's reference from | 208 // Protects |request_context_getter_| to allow releasing it's reference from |
215 // the sync thread, even when it's in use on the IO thread. | 209 // the sync thread, even when it's in use on the IO thread. |
216 base::Lock request_context_getter_lock_; | 210 base::Lock request_context_getter_lock_; |
217 | 211 |
218 // The request context getter used for making all requests. | 212 // The request context getter used for making all requests. |
219 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; | 213 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; |
220 | 214 |
221 NetworkTimeUpdateCallback network_time_update_callback_; | 215 NetworkTimeUpdateCallback network_time_update_callback_; |
222 | 216 |
223 CancelationSignal* const cancelation_signal_; | 217 CancelationSignal* const cancelation_signal_; |
224 | 218 |
225 // A callback to tag Sync request to be able to record data use of this | |
226 // service by data_use_measurement component. | |
227 BindToTrackerCallback bind_to_tracker_callback_; | |
228 | |
229 DISALLOW_COPY_AND_ASSIGN(HttpBridgeFactory); | 219 DISALLOW_COPY_AND_ASSIGN(HttpBridgeFactory); |
230 }; | 220 }; |
231 | 221 |
232 } // namespace syncer | 222 } // namespace syncer |
233 | 223 |
234 #endif // SYNC_INTERNAL_API_PUBLIC_HTTP_BRIDGE_H_ | 224 #endif // SYNC_INTERNAL_API_PUBLIC_HTTP_BRIDGE_H_ |
OLD | NEW |