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 Invalidator that wraps an invalidation | 5 // An implementation of Invalidator that wraps an invalidation |
6 // client. Handles the details of connecting to XMPP and hooking it | 6 // client. Handles the details of connecting to XMPP and hooking it |
7 // up to the invalidation client. | 7 // up to the invalidation client. |
8 // | 8 // |
9 // You probably don't want to use this directly; use | 9 // You probably don't want to use this directly; use |
10 // NonBlockingInvalidator. | 10 // NonBlockingInvalidator. |
11 | 11 |
12 #ifndef SYNC_NOTIFIER_INVALIDATION_NOTIFIER_H_ | 12 #ifndef SYNC_NOTIFIER_INVALIDATION_NOTIFIER_H_ |
13 #define SYNC_NOTIFIER_INVALIDATION_NOTIFIER_H_ | 13 #define SYNC_NOTIFIER_INVALIDATION_NOTIFIER_H_ |
14 | 14 |
15 #include <string> | 15 #include <string> |
16 | 16 |
17 #include "base/basictypes.h" | 17 #include "base/basictypes.h" |
18 #include "base/compiler_specific.h" | 18 #include "base/compiler_specific.h" |
19 #include "base/memory/scoped_ptr.h" | 19 #include "base/memory/scoped_ptr.h" |
20 #include "base/threading/non_thread_safe.h" | 20 #include "base/threading/non_thread_safe.h" |
21 #include "base/time/default_tick_clock.h" | |
22 #include "sync/base/sync_export.h" | 21 #include "sync/base/sync_export.h" |
23 #include "sync/internal_api/public/base/model_type.h" | 22 #include "sync/internal_api/public/base/model_type.h" |
24 #include "sync/internal_api/public/util/weak_handle.h" | 23 #include "sync/internal_api/public/util/weak_handle.h" |
25 #include "sync/notifier/invalidation_state_tracker.h" | 24 #include "sync/notifier/invalidation_state_tracker.h" |
26 #include "sync/notifier/invalidator.h" | 25 #include "sync/notifier/invalidator.h" |
27 #include "sync/notifier/invalidator_registrar.h" | 26 #include "sync/notifier/invalidator_registrar.h" |
28 #include "sync/notifier/sync_invalidation_listener.h" | 27 #include "sync/notifier/sync_invalidation_listener.h" |
29 | 28 |
30 namespace notifier { | 29 namespace notifier { |
31 class PushClient; | 30 class PushClient; |
32 } // namespace notifier | 31 } // namespace notifier |
33 | 32 |
34 namespace syncer { | 33 namespace syncer { |
35 | 34 |
36 // This class must live on the IO thread. | 35 // This class must live on the IO thread. |
37 // TODO(dcheng): Think of a name better than InvalidationInvalidator. | |
38 class SYNC_EXPORT_PRIVATE InvalidationNotifier | 36 class SYNC_EXPORT_PRIVATE InvalidationNotifier |
39 : public Invalidator, | 37 : public Invalidator, |
40 public SyncInvalidationListener::Delegate, | 38 public SyncInvalidationListener::Delegate, |
41 public base::NonThreadSafe { | 39 public base::NonThreadSafe { |
42 public: | 40 public: |
43 // |invalidation_state_tracker| must be initialized. | 41 // |invalidation_state_tracker| must be initialized. |
44 InvalidationNotifier( | 42 InvalidationNotifier( |
45 scoped_ptr<notifier::PushClient> push_client, | 43 scoped_ptr<notifier::PushClient> push_client, |
46 const std::string& invalidator_client_id, | 44 const std::string& invalidator_client_id, |
47 const InvalidationStateMap& initial_invalidation_state_map, | 45 const UnackedInvalidationsMap& saved_invalidations, |
48 const std::string& invalidation_bootstrap_data, | 46 const std::string& invalidation_bootstrap_data, |
49 const WeakHandle<InvalidationStateTracker>& | 47 const WeakHandle<InvalidationStateTracker>& |
50 invalidation_state_tracker, | 48 invalidation_state_tracker, |
51 const std::string& client_info); | 49 const std::string& client_info); |
52 | 50 |
53 virtual ~InvalidationNotifier(); | 51 virtual ~InvalidationNotifier(); |
54 | 52 |
55 // Invalidator implementation. | 53 // Invalidator implementation. |
56 virtual void RegisterHandler(InvalidationHandler* handler) OVERRIDE; | 54 virtual void RegisterHandler(InvalidationHandler* handler) OVERRIDE; |
57 virtual void UpdateRegisteredIds(InvalidationHandler* handler, | 55 virtual void UpdateRegisteredIds(InvalidationHandler* handler, |
58 const ObjectIdSet& ids) OVERRIDE; | 56 const ObjectIdSet& ids) OVERRIDE; |
59 virtual void UnregisterHandler(InvalidationHandler* handler) OVERRIDE; | 57 virtual void UnregisterHandler(InvalidationHandler* handler) OVERRIDE; |
60 virtual void Acknowledge(const invalidation::ObjectId& id, | |
61 const AckHandle& ack_handle) OVERRIDE; | |
62 virtual InvalidatorState GetInvalidatorState() const OVERRIDE; | 58 virtual InvalidatorState GetInvalidatorState() const OVERRIDE; |
63 virtual void UpdateCredentials( | 59 virtual void UpdateCredentials( |
64 const std::string& email, const std::string& token) OVERRIDE; | 60 const std::string& email, const std::string& token) OVERRIDE; |
65 | 61 |
66 // SyncInvalidationListener::Delegate implementation. | 62 // SyncInvalidationListener::Delegate implementation. |
67 virtual void OnInvalidate( | 63 virtual void OnInvalidate( |
68 const ObjectIdInvalidationMap& invalidation_map) OVERRIDE; | 64 const ObjectIdInvalidationMap& invalidation_map) OVERRIDE; |
69 virtual void OnInvalidatorStateChange(InvalidatorState state) OVERRIDE; | 65 virtual void OnInvalidatorStateChange(InvalidatorState state) OVERRIDE; |
70 | 66 |
71 private: | 67 private: |
72 // We start off in the STOPPED state. When we get our initial | 68 // We start off in the STOPPED state. When we get our initial |
73 // credentials, we connect and move to the CONNECTING state. When | 69 // credentials, we connect and move to the CONNECTING state. When |
74 // we're connected we start the invalidation client and move to the | 70 // we're connected we start the invalidation client and move to the |
75 // STARTED state. We never go back to a previous state. | 71 // STARTED state. We never go back to a previous state. |
76 enum State { | 72 enum State { |
77 STOPPED, | 73 STOPPED, |
78 CONNECTING, | 74 CONNECTING, |
79 STARTED | 75 STARTED |
80 }; | 76 }; |
81 State state_; | 77 State state_; |
82 | 78 |
83 InvalidatorRegistrar registrar_; | 79 InvalidatorRegistrar registrar_; |
84 | 80 |
85 // Passed to |invalidation_listener_|. | 81 // Passed to |invalidation_listener_|. |
86 const InvalidationStateMap initial_invalidation_state_map_; | 82 const UnackedInvalidationsMap saved_invalidations_; |
87 | 83 |
88 // Passed to |invalidation_listener_|. | 84 // Passed to |invalidation_listener_|. |
89 const WeakHandle<InvalidationStateTracker> | 85 const WeakHandle<InvalidationStateTracker> |
90 invalidation_state_tracker_; | 86 invalidation_state_tracker_; |
91 | 87 |
92 // Passed to |invalidation_listener_|. | 88 // Passed to |invalidation_listener_|. |
93 const std::string client_info_; | 89 const std::string client_info_; |
94 | 90 |
95 // The client ID to pass to |invalidation_listener_|. | 91 // The client ID to pass to |invalidation_listener_|. |
96 const std::string invalidator_client_id_; | 92 const std::string invalidator_client_id_; |
97 | 93 |
98 // The initial bootstrap data to pass to |invalidation_listener_|. | 94 // The initial bootstrap data to pass to |invalidation_listener_|. |
99 const std::string invalidation_bootstrap_data_; | 95 const std::string invalidation_bootstrap_data_; |
100 | 96 |
101 // TODO(akalin): Clean up this reference to DefaultTickClock. Ideally, we | |
102 // should simply be using TaskRunner's tick clock. See http://crbug.com/179211 | |
103 base::DefaultTickClock tick_clock_; | |
104 | |
105 // The invalidation listener. | 97 // The invalidation listener. |
106 SyncInvalidationListener invalidation_listener_; | 98 SyncInvalidationListener invalidation_listener_; |
107 | 99 |
108 DISALLOW_COPY_AND_ASSIGN(InvalidationNotifier); | 100 DISALLOW_COPY_AND_ASSIGN(InvalidationNotifier); |
109 }; | 101 }; |
110 | 102 |
111 } // namespace syncer | 103 } // namespace syncer |
112 | 104 |
113 #endif // SYNC_NOTIFIER_INVALIDATION_NOTIFIER_H_ | 105 #endif // SYNC_NOTIFIER_INVALIDATION_NOTIFIER_H_ |
OLD | NEW |