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 // An implementation of SyncNotifier that wraps InvalidationNotifier | 5 // An implementation of SyncNotifier that wraps InvalidationNotifier |
6 // on its own thread. | 6 // on its own thread. |
7 | 7 |
8 #ifndef SYNC_NOTIFIER_NON_BLOCKING_INVALIDATOR_H_ | 8 #ifndef SYNC_NOTIFIER_NON_BLOCKING_INVALIDATOR_H_ |
9 #define SYNC_NOTIFIER_NON_BLOCKING_INVALIDATOR_H_ | 9 #define SYNC_NOTIFIER_NON_BLOCKING_INVALIDATOR_H_ |
10 | 10 |
11 #include <string> | 11 #include <string> |
12 | 12 |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #include "base/callback.h" | 14 #include "base/callback.h" |
15 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
17 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
18 #include "jingle/notifier/base/notifier_options.h" | 18 #include "jingle/notifier/base/notifier_options.h" |
19 #include "sync/base/sync_export.h" | 19 #include "sync/base/sync_export.h" |
20 #include "sync/internal_api/public/util/weak_handle.h" | |
21 #include "sync/notifier/invalidation_handler.h" | 20 #include "sync/notifier/invalidation_handler.h" |
22 #include "sync/notifier/invalidation_state_tracker.h" | 21 #include "sync/notifier/invalidation_state_tracker.h" |
23 #include "sync/notifier/invalidator.h" | 22 #include "sync/notifier/invalidator.h" |
24 #include "sync/notifier/invalidator_registrar.h" | 23 #include "sync/notifier/invalidator_registrar.h" |
25 | 24 |
26 namespace base { | 25 namespace base { |
27 class SingleThreadTaskRunner; | 26 class SingleThreadTaskRunner; |
28 } // namespace base | 27 } // namespace base |
29 | 28 |
30 namespace syncer { | 29 namespace syncer { |
31 class SyncNetworkChannel; | 30 class SyncNetworkChannel; |
32 class GCMNetworkChannelDelegate; | 31 class GCMNetworkChannelDelegate; |
33 | 32 |
34 // Callback type for function that creates SyncNetworkChannel. This function | 33 // Callback type for function that creates SyncNetworkChannel. This function |
35 // gets passed into NonBlockingInvalidator constructor. | 34 // gets passed into NonBlockingInvalidator constructor. |
36 typedef base::Callback<scoped_ptr<SyncNetworkChannel>(void)> | 35 typedef base::Callback<scoped_ptr<SyncNetworkChannel>(void)> |
37 NetworkChannelCreator; | 36 NetworkChannelCreator; |
38 | 37 |
39 class SYNC_EXPORT_PRIVATE NonBlockingInvalidator | 38 class SYNC_EXPORT_PRIVATE NonBlockingInvalidator |
40 : public Invalidator, | 39 : public Invalidator, |
41 // InvalidationHandler to "observe" our Core via WeakHandle. | 40 // InvalidationHandler to "observe" our Core via WeakHandle. |
42 public InvalidationHandler { | 41 public InvalidationHandler { |
43 public: | 42 public: |
44 // |invalidation_state_tracker| must be initialized. | 43 // |invalidation_state_tracker| must be initialized and must outlive |this|. |
45 NonBlockingInvalidator( | 44 NonBlockingInvalidator( |
46 NetworkChannelCreator network_channel_creator, | 45 NetworkChannelCreator network_channel_creator, |
47 const std::string& invalidator_client_id, | 46 const std::string& invalidator_client_id, |
48 const UnackedInvalidationsMap& saved_invalidations, | 47 const UnackedInvalidationsMap& saved_invalidations, |
49 const std::string& invalidation_bootstrap_data, | 48 const std::string& invalidation_bootstrap_data, |
50 const WeakHandle<InvalidationStateTracker>& | 49 InvalidationStateTracker* invalidation_state_tracker, |
51 invalidation_state_tracker, | |
52 const std::string& client_info, | 50 const std::string& client_info, |
53 const scoped_refptr<net::URLRequestContextGetter>& | 51 const scoped_refptr<net::URLRequestContextGetter>& |
54 request_context_getter); | 52 request_context_getter); |
55 | 53 |
56 virtual ~NonBlockingInvalidator(); | 54 virtual ~NonBlockingInvalidator(); |
57 | 55 |
58 // Invalidator implementation. | 56 // Invalidator implementation. |
59 virtual void RegisterHandler(InvalidationHandler* handler) OVERRIDE; | 57 virtual void RegisterHandler(InvalidationHandler* handler) OVERRIDE; |
60 virtual void UpdateRegisteredIds(InvalidationHandler* handler, | 58 virtual void UpdateRegisteredIds(InvalidationHandler* handler, |
61 const ObjectIdSet& ids) OVERRIDE; | 59 const ObjectIdSet& ids) OVERRIDE; |
(...skipping 25 matching lines...) Expand all Loading... |
87 class Core; | 85 class Core; |
88 | 86 |
89 InvalidatorRegistrar registrar_; | 87 InvalidatorRegistrar registrar_; |
90 | 88 |
91 // The real guts of NonBlockingInvalidator, which allows this class to live | 89 // The real guts of NonBlockingInvalidator, which allows this class to live |
92 // completely on the parent thread. | 90 // completely on the parent thread. |
93 scoped_refptr<Core> core_; | 91 scoped_refptr<Core> core_; |
94 scoped_refptr<base::SingleThreadTaskRunner> parent_task_runner_; | 92 scoped_refptr<base::SingleThreadTaskRunner> parent_task_runner_; |
95 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; | 93 scoped_refptr<base::SingleThreadTaskRunner> network_task_runner_; |
96 | 94 |
| 95 base::WeakPtrFactory<InvalidationStateTracker> |
| 96 invalidation_state_tracker_weak_ptr_factory_; |
97 base::WeakPtrFactory<NonBlockingInvalidator> weak_ptr_factory_; | 97 base::WeakPtrFactory<NonBlockingInvalidator> weak_ptr_factory_; |
98 | 98 |
99 DISALLOW_COPY_AND_ASSIGN(NonBlockingInvalidator); | 99 DISALLOW_COPY_AND_ASSIGN(NonBlockingInvalidator); |
100 }; | 100 }; |
101 | 101 |
102 } // namespace syncer | 102 } // namespace syncer |
103 | 103 |
104 #endif // SYNC_NOTIFIER_NON_BLOCKING_INVALIDATOR_H_ | 104 #endif // SYNC_NOTIFIER_NON_BLOCKING_INVALIDATOR_H_ |
OLD | NEW |