| 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 // A simple wrapper around invalidation::InvalidationClient that | 5 // A simple wrapper around invalidation::InvalidationClient that |
| 6 // handles all the startup/shutdown details and hookups. | 6 // handles all the startup/shutdown details and hookups. |
| 7 | 7 |
| 8 #ifndef SYNC_NOTIFIER_SYNC_INVALIDATION_LISTENER_H_ | 8 #ifndef SYNC_NOTIFIER_SYNC_INVALIDATION_LISTENER_H_ |
| 9 #define SYNC_NOTIFIER_SYNC_INVALIDATION_LISTENER_H_ | 9 #define SYNC_NOTIFIER_SYNC_INVALIDATION_LISTENER_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_forward.h" | 14 #include "base/callback_forward.h" |
| 15 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
| 16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
| 17 #include "base/memory/weak_ptr.h" | 17 #include "base/memory/weak_ptr.h" |
| 18 #include "base/threading/non_thread_safe.h" | 18 #include "base/threading/non_thread_safe.h" |
| 19 #include "google/cacheinvalidation/include/invalidation-listener.h" | 19 #include "google/cacheinvalidation/include/invalidation-listener.h" |
| 20 #include "jingle/notifier/listener/push_client_observer.h" | 20 #include "jingle/notifier/listener/push_client_observer.h" |
| 21 #include "sync/base/sync_export.h" | 21 #include "sync/base/sync_export.h" |
| 22 #include "sync/internal_api/public/util/weak_handle.h" | 22 #include "sync/internal_api/public/util/weak_handle.h" |
| 23 #include "sync/notifier/ack_tracker.h" |
| 23 #include "sync/notifier/invalidation_state_tracker.h" | 24 #include "sync/notifier/invalidation_state_tracker.h" |
| 24 #include "sync/notifier/invalidator_state.h" | 25 #include "sync/notifier/invalidator_state.h" |
| 25 #include "sync/notifier/object_id_invalidation_map.h" | 26 #include "sync/notifier/object_id_invalidation_map.h" |
| 26 #include "sync/notifier/state_writer.h" | 27 #include "sync/notifier/state_writer.h" |
| 27 #include "sync/notifier/sync_system_resources.h" | 28 #include "sync/notifier/sync_system_resources.h" |
| 28 | 29 |
| 30 namespace base { |
| 31 class TickClock; |
| 32 } // namespace base |
| 33 |
| 29 namespace buzz { | 34 namespace buzz { |
| 30 class XmppTaskParentInterface; | 35 class XmppTaskParentInterface; |
| 31 } // namespace buzz | 36 } // namespace buzz |
| 32 | 37 |
| 33 namespace notifier { | 38 namespace notifier { |
| 34 class PushClient; | 39 class PushClient; |
| 35 } // namespace notifier | 40 } // namespace notifier |
| 36 | 41 |
| 37 namespace syncer { | 42 namespace syncer { |
| 38 | 43 |
| 39 class RegistrationManager; | 44 class RegistrationManager; |
| 40 | 45 |
| 41 // SyncInvalidationListener is not thread-safe and lives on the sync | 46 // SyncInvalidationListener is not thread-safe and lives on the sync |
| 42 // thread. | 47 // thread. |
| 43 class SYNC_EXPORT_PRIVATE SyncInvalidationListener | 48 class SYNC_EXPORT_PRIVATE SyncInvalidationListener |
| 44 : public NON_EXPORTED_BASE(invalidation::InvalidationListener), | 49 : public NON_EXPORTED_BASE(invalidation::InvalidationListener), |
| 45 public StateWriter, | 50 public StateWriter, |
| 46 public NON_EXPORTED_BASE(notifier::PushClientObserver), | 51 public NON_EXPORTED_BASE(notifier::PushClientObserver), |
| 47 public base::NonThreadSafe { | 52 public base::NonThreadSafe, |
| 53 public AckTracker::Delegate { |
| 48 public: | 54 public: |
| 49 typedef base::Callback<invalidation::InvalidationClient*( | 55 typedef base::Callback<invalidation::InvalidationClient*( |
| 50 invalidation::SystemResources*, | 56 invalidation::SystemResources*, |
| 51 int, | 57 int, |
| 52 const invalidation::string&, | 58 const invalidation::string&, |
| 53 const invalidation::string&, | 59 const invalidation::string&, |
| 54 invalidation::InvalidationListener*)> CreateInvalidationClientCallback; | 60 invalidation::InvalidationListener*)> CreateInvalidationClientCallback; |
| 55 | 61 |
| 56 class SYNC_EXPORT_PRIVATE Delegate { | 62 class SYNC_EXPORT_PRIVATE Delegate { |
| 57 public: | 63 public: |
| 58 virtual ~Delegate(); | 64 virtual ~Delegate(); |
| 59 | 65 |
| 60 virtual void OnInvalidate( | 66 virtual void OnInvalidate( |
| 61 const ObjectIdInvalidationMap& invalidation_map) = 0; | 67 const ObjectIdInvalidationMap& invalidation_map) = 0; |
| 62 | 68 |
| 63 virtual void OnInvalidatorStateChange(InvalidatorState state) = 0; | 69 virtual void OnInvalidatorStateChange(InvalidatorState state) = 0; |
| 64 }; | 70 }; |
| 65 | 71 |
| 66 explicit SyncInvalidationListener( | 72 explicit SyncInvalidationListener( |
| 73 base::TickClock* tick_clock, |
| 67 scoped_ptr<notifier::PushClient> push_client); | 74 scoped_ptr<notifier::PushClient> push_client); |
| 68 | 75 |
| 69 // Calls Stop(). | 76 // Calls Stop(). |
| 70 virtual ~SyncInvalidationListener(); | 77 virtual ~SyncInvalidationListener(); |
| 71 | 78 |
| 72 // Does not take ownership of |delegate| or |state_writer|. | 79 // Does not take ownership of |delegate| or |state_writer|. |
| 73 // |invalidation_state_tracker| must be initialized. | 80 // |invalidation_state_tracker| must be initialized. |
| 74 void Start( | 81 void Start( |
| 75 const CreateInvalidationClientCallback& | 82 const CreateInvalidationClientCallback& |
| 76 create_invalidation_client_callback, | 83 create_invalidation_client_callback, |
| 77 const std::string& client_id, const std::string& client_info, | 84 const std::string& client_id, const std::string& client_info, |
| 78 const std::string& invalidation_bootstrap_data, | 85 const std::string& invalidation_bootstrap_data, |
| 79 const InvalidationStateMap& initial_invalidation_state_map, | 86 const InvalidationStateMap& initial_invalidation_state_map, |
| 80 const WeakHandle<InvalidationStateTracker>& invalidation_state_tracker, | 87 const WeakHandle<InvalidationStateTracker>& invalidation_state_tracker, |
| 81 Delegate* delegate); | 88 Delegate* delegate); |
| 82 | 89 |
| 83 void UpdateCredentials(const std::string& email, const std::string& token); | 90 void UpdateCredentials(const std::string& email, const std::string& token); |
| 84 | 91 |
| 85 // Update the set of object IDs that we're interested in getting | 92 // Update the set of object IDs that we're interested in getting |
| 86 // notifications for. May be called at any time. | 93 // notifications for. May be called at any time. |
| 87 void UpdateRegisteredIds(const ObjectIdSet& ids); | 94 void UpdateRegisteredIds(const ObjectIdSet& ids); |
| 95 // Acknowledge that an invalidation for |id| was handled. |
| 96 void Acknowledge(const invalidation::ObjectId& id, |
| 97 const AckHandle& ack_handle); |
| 88 | 98 |
| 89 // invalidation::InvalidationListener implementation. | 99 // invalidation::InvalidationListener implementation. |
| 90 virtual void Ready( | 100 virtual void Ready( |
| 91 invalidation::InvalidationClient* client) OVERRIDE; | 101 invalidation::InvalidationClient* client) OVERRIDE; |
| 92 virtual void Invalidate( | 102 virtual void Invalidate( |
| 93 invalidation::InvalidationClient* client, | 103 invalidation::InvalidationClient* client, |
| 94 const invalidation::Invalidation& invalidation, | 104 const invalidation::Invalidation& invalidation, |
| 95 const invalidation::AckHandle& ack_handle) OVERRIDE; | 105 const invalidation::AckHandle& ack_handle) OVERRIDE; |
| 96 virtual void InvalidateUnknownVersion( | 106 virtual void InvalidateUnknownVersion( |
| 97 invalidation::InvalidationClient* client, | 107 invalidation::InvalidationClient* client, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 124 virtual void OnNotificationsEnabled() OVERRIDE; | 134 virtual void OnNotificationsEnabled() OVERRIDE; |
| 125 virtual void OnNotificationsDisabled( | 135 virtual void OnNotificationsDisabled( |
| 126 notifier::NotificationsDisabledReason reason) OVERRIDE; | 136 notifier::NotificationsDisabledReason reason) OVERRIDE; |
| 127 virtual void OnIncomingNotification( | 137 virtual void OnIncomingNotification( |
| 128 const notifier::Notification& notification) OVERRIDE; | 138 const notifier::Notification& notification) OVERRIDE; |
| 129 | 139 |
| 130 void DoRegistrationUpdate(); | 140 void DoRegistrationUpdate(); |
| 131 | 141 |
| 132 void StopForTest(); | 142 void StopForTest(); |
| 133 InvalidationStateMap GetStateMapForTest() const; | 143 InvalidationStateMap GetStateMapForTest() const; |
| 144 AckTracker* GetAckTrackerForTest(); |
| 134 | 145 |
| 135 private: | 146 private: |
| 136 void Stop(); | 147 void Stop(); |
| 137 | 148 |
| 138 InvalidatorState GetState() const; | 149 InvalidatorState GetState() const; |
| 139 | 150 |
| 140 void EmitStateChange(); | 151 void EmitStateChange(); |
| 141 | 152 |
| 142 void EmitInvalidation(const ObjectIdInvalidationMap& invalidation_map); | 153 void PrepareInvalidation(const ObjectIdSet& ids, |
| 154 const std::string& payload, |
| 155 invalidation::InvalidationClient* client, |
| 156 const invalidation::AckHandle& ack_handle); |
| 157 void EmitInvalidation(const ObjectIdSet& ids, |
| 158 const std::string& payload, |
| 159 invalidation::InvalidationClient* client, |
| 160 const invalidation::AckHandle& ack_handle, |
| 161 const AckHandleMap& local_ack_handles); |
| 162 |
| 163 // AckTracker::Delegate implementation. |
| 164 virtual void OnTimeout(const ObjectIdSet& ids) OVERRIDE; |
| 165 |
| 166 base::WeakPtrFactory<SyncInvalidationListener> weak_ptr_factory_; |
| 167 AckTracker ack_tracker_; |
| 143 | 168 |
| 144 // Owned by |sync_system_resources_|. | 169 // Owned by |sync_system_resources_|. |
| 145 notifier::PushClient* const push_client_; | 170 notifier::PushClient* const push_client_; |
| 146 SyncSystemResources sync_system_resources_; | 171 SyncSystemResources sync_system_resources_; |
| 147 InvalidationStateMap invalidation_state_map_; | 172 InvalidationStateMap invalidation_state_map_; |
| 148 WeakHandle<InvalidationStateTracker> invalidation_state_tracker_; | 173 WeakHandle<InvalidationStateTracker> invalidation_state_tracker_; |
| 149 Delegate* delegate_; | 174 Delegate* delegate_; |
| 150 scoped_ptr<invalidation::InvalidationClient> invalidation_client_; | 175 scoped_ptr<invalidation::InvalidationClient> invalidation_client_; |
| 151 scoped_ptr<RegistrationManager> registration_manager_; | 176 scoped_ptr<RegistrationManager> registration_manager_; |
| 152 // Stored to pass to |registration_manager_| on start. | 177 // Stored to pass to |registration_manager_| on start. |
| 153 ObjectIdSet registered_ids_; | 178 ObjectIdSet registered_ids_; |
| 154 | 179 |
| 155 // The states of the ticl and the push client. | 180 // The states of the ticl and the push client. |
| 156 InvalidatorState ticl_state_; | 181 InvalidatorState ticl_state_; |
| 157 InvalidatorState push_client_state_; | 182 InvalidatorState push_client_state_; |
| 158 | 183 |
| 159 DISALLOW_COPY_AND_ASSIGN(SyncInvalidationListener); | 184 DISALLOW_COPY_AND_ASSIGN(SyncInvalidationListener); |
| 160 }; | 185 }; |
| 161 | 186 |
| 162 } // namespace syncer | 187 } // namespace syncer |
| 163 | 188 |
| 164 #endif // SYNC_NOTIFIER_SYNC_INVALIDATION_LISTENER_H_ | 189 #endif // SYNC_NOTIFIER_SYNC_INVALIDATION_LISTENER_H_ |
| OLD | NEW |