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