Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Side by Side Diff: sync/internal_api/public/http_bridge.h

Issue 23717047: Retry: sync: Gracefully handle early shutdown (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Renames Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/callback.h"
12 #include "base/compiler_specific.h" 12 #include "base/compiler_specific.h"
13 #include "base/gtest_prod_util.h" 13 #include "base/gtest_prod_util.h"
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/synchronization/lock.h" 15 #include "base/synchronization/lock.h"
16 #include "base/synchronization/waitable_event.h" 16 #include "base/synchronization/waitable_event.h"
17 #include "net/base/network_time_notifier.h" 17 #include "net/base/network_time_notifier.h"
18 #include "net/url_request/url_fetcher_delegate.h" 18 #include "net/url_request/url_fetcher_delegate.h"
19 #include "net/url_request/url_request_context.h" 19 #include "net/url_request/url_request_context.h"
20 #include "net/url_request/url_request_context_getter.h" 20 #include "net/url_request/url_request_context_getter.h"
21 #include "sync/base/sync_export.h" 21 #include "sync/base/sync_export.h"
22 #include "sync/internal_api/public/base/cancelation_observer.h"
22 #include "sync/internal_api/public/http_post_provider_factory.h" 23 #include "sync/internal_api/public/http_post_provider_factory.h"
23 #include "sync/internal_api/public/http_post_provider_interface.h" 24 #include "sync/internal_api/public/http_post_provider_interface.h"
24 #include "url/gurl.h" 25 #include "url/gurl.h"
25 26
26 class HttpBridgeTest; 27 class HttpBridgeTest;
27 28
28 namespace base { 29 namespace base {
29 class MessageLoop; 30 class MessageLoop;
30 } 31 }
31 32
32 namespace net { 33 namespace net {
33 class HttpResponseHeaders; 34 class HttpResponseHeaders;
34 class HttpUserAgentSettings; 35 class HttpUserAgentSettings;
35 class URLFetcher; 36 class URLFetcher;
36 } 37 }
37 38
38 namespace syncer { 39 namespace syncer {
39 40
41 class CancelationSignal;
42
40 // Callback for updating the network time. 43 // Callback for updating the network time.
41 // Params: 44 // Params:
42 // const base::Time& network_time - the new network time. 45 // const base::Time& network_time - the new network time.
43 // const base::TimeDelta& resolution - how precise the reading is. 46 // const base::TimeDelta& resolution - how precise the reading is.
44 // const base::TimeDelta& latency - the http request's latency. 47 // const base::TimeDelta& latency - the http request's latency.
45 typedef base::Callback<void(const base::Time&, 48 typedef base::Callback<void(const base::Time&,
46 const base::TimeDelta&, 49 const base::TimeDelta&,
47 const base::TimeDelta&)> NetworkTimeUpdateCallback; 50 const base::TimeDelta&)> NetworkTimeUpdateCallback;
48 51
49 // A bridge between the syncer and Chromium HTTP layers. 52 // A bridge between the syncer and Chromium HTTP layers.
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 scoped_refptr<RequestContextGetter> context_getter_for_request_; 225 scoped_refptr<RequestContextGetter> context_getter_for_request_;
223 226
224 const scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; 227 const scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_;
225 228
226 // Callback for updating network time. 229 // Callback for updating network time.
227 NetworkTimeUpdateCallback network_time_update_callback_; 230 NetworkTimeUpdateCallback network_time_update_callback_;
228 231
229 DISALLOW_COPY_AND_ASSIGN(HttpBridge); 232 DISALLOW_COPY_AND_ASSIGN(HttpBridge);
230 }; 233 };
231 234
232 class SYNC_EXPORT HttpBridgeFactory : public HttpPostProviderFactory { 235 class SYNC_EXPORT HttpBridgeFactory : public HttpPostProviderFactory,
236 public CancelationObserver {
233 public: 237 public:
234 HttpBridgeFactory( 238 HttpBridgeFactory(
235 net::URLRequestContextGetter* baseline_context_getter, 239 net::URLRequestContextGetter* baseline_context_getter,
236 const std::string& user_agent, 240 const NetworkTimeUpdateCallback& network_time_update_callback,
237 const NetworkTimeUpdateCallback& network_time_update_callback); 241 CancelationSignal* cancelation_signal);
238 virtual ~HttpBridgeFactory(); 242 virtual ~HttpBridgeFactory();
239 243
240 // HttpPostProviderFactory: 244 // HttpPostProviderFactory:
245 virtual void Init(const std::string& user_agent) OVERRIDE;
241 virtual HttpPostProviderInterface* Create() OVERRIDE; 246 virtual HttpPostProviderInterface* Create() OVERRIDE;
242 virtual void Destroy(HttpPostProviderInterface* http) OVERRIDE; 247 virtual void Destroy(HttpPostProviderInterface* http) OVERRIDE;
243 virtual void Shutdown() OVERRIDE; 248
249 // CancelationObserver implementation:
250 virtual void OnSignalReceived() OVERRIDE;
244 251
245 private: 252 private:
246 // Protects |request_context_getter_|. 253 // Protects |request_context_getter_| and |baseline_request_context_getter_|.
247 base::Lock context_getter_lock_; 254 base::Lock context_getter_lock_;
248 255
256 // This request context is the starting point for the request_context_getter_
257 // that we eventually use to make requests. During shutdown we must drop all
258 // references to it before the ProfileSyncService's Shutdown() call is
259 // complete.
260 scoped_refptr<net::URLRequestContextGetter> baseline_request_context_getter_;
261
249 // This request context is built on top of the baseline context and shares 262 // This request context is built on top of the baseline context and shares
250 // common components. It's mostly used on sync thread when creating 263 // common components. Takes a reference to the
251 // connection but is released as soon as possible during shutdown. Protected 264 // baseline_request_context_getter_. It's mostly used on sync thread when
252 // by |context_getter_lock_|. 265 // creating connection but is released as soon as possible during shutdown.
266 // Protected by |context_getter_lock_|.
253 scoped_refptr<HttpBridge::RequestContextGetter> request_context_getter_; 267 scoped_refptr<HttpBridge::RequestContextGetter> request_context_getter_;
254 268
255 NetworkTimeUpdateCallback network_time_update_callback_; 269 NetworkTimeUpdateCallback network_time_update_callback_;
256 270
271 CancelationSignal* const cancelation_signal_;
272
257 DISALLOW_COPY_AND_ASSIGN(HttpBridgeFactory); 273 DISALLOW_COPY_AND_ASSIGN(HttpBridgeFactory);
258 }; 274 };
259 275
260 } // namespace syncer 276 } // namespace syncer
261 277
262 #endif // SYNC_INTERNAL_API_PUBLIC_HTTP_BRIDGE_H_ 278 #endif // SYNC_INTERNAL_API_PUBLIC_HTTP_BRIDGE_H_
OLDNEW
« no previous file with comments | « sync/internal_api/public/base/cancelation_signal_unittest.cc ('k') | sync/internal_api/public/http_post_provider_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698