OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 #include "sync/notifier/non_blocking_invalidation_notifier.h" | 5 #include "sync/notifier/non_blocking_invalidation_notifier.h" |
6 | 6 |
7 #include "base/location.h" | 7 #include "base/location.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 invalidation_state_tracker, | 35 invalidation_state_tracker, |
36 const std::string& client_info); | 36 const std::string& client_info); |
37 void Teardown(); | 37 void Teardown(); |
38 void SetUniqueId(const std::string& unique_id); | 38 void SetUniqueId(const std::string& unique_id); |
39 void SetStateDeprecated(const std::string& state); | 39 void SetStateDeprecated(const std::string& state); |
40 void UpdateCredentials(const std::string& email, const std::string& token); | 40 void UpdateCredentials(const std::string& email, const std::string& token); |
41 void UpdateEnabledTypes(syncable::ModelTypeSet enabled_types); | 41 void UpdateEnabledTypes(syncable::ModelTypeSet enabled_types); |
42 | 42 |
43 // SyncNotifierObserver implementation (all called on I/O thread by | 43 // SyncNotifierObserver implementation (all called on I/O thread by |
44 // InvalidationNotifier). | 44 // InvalidationNotifier). |
| 45 virtual void OnNotificationsEnabled() OVERRIDE; |
| 46 virtual void OnNotificationsDisabled( |
| 47 NotificationsDisabledReason reason) OVERRIDE; |
45 virtual void OnIncomingNotification( | 48 virtual void OnIncomingNotification( |
46 const syncable::ModelTypePayloadMap& type_payloads, | 49 const syncable::ModelTypePayloadMap& type_payloads, |
47 IncomingNotificationSource source); | 50 IncomingNotificationSource source) OVERRIDE; |
48 virtual void OnNotificationStateChange(bool notifications_enabled); | |
49 | 51 |
50 private: | 52 private: |
51 friend class | 53 friend class |
52 base::RefCountedThreadSafe<NonBlockingInvalidationNotifier::Core>; | 54 base::RefCountedThreadSafe<NonBlockingInvalidationNotifier::Core>; |
53 // Called on parent or I/O thread. | 55 // Called on parent or I/O thread. |
54 ~Core(); | 56 ~Core(); |
55 | 57 |
56 // The variables below should be used only on the I/O thread. | 58 // The variables below should be used only on the I/O thread. |
57 const browser_sync::WeakHandle<SyncNotifierObserver> delegate_observer_; | 59 const browser_sync::WeakHandle<SyncNotifierObserver> delegate_observer_; |
58 scoped_ptr<InvalidationNotifier> invalidation_notifier_; | 60 scoped_ptr<InvalidationNotifier> invalidation_notifier_; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 DCHECK(network_task_runner_->BelongsToCurrentThread()); | 121 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
120 invalidation_notifier_->UpdateCredentials(email, token); | 122 invalidation_notifier_->UpdateCredentials(email, token); |
121 } | 123 } |
122 | 124 |
123 void NonBlockingInvalidationNotifier::Core::UpdateEnabledTypes( | 125 void NonBlockingInvalidationNotifier::Core::UpdateEnabledTypes( |
124 syncable::ModelTypeSet enabled_types) { | 126 syncable::ModelTypeSet enabled_types) { |
125 DCHECK(network_task_runner_->BelongsToCurrentThread()); | 127 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
126 invalidation_notifier_->UpdateEnabledTypes(enabled_types); | 128 invalidation_notifier_->UpdateEnabledTypes(enabled_types); |
127 } | 129 } |
128 | 130 |
| 131 void NonBlockingInvalidationNotifier::Core::OnNotificationsEnabled() { |
| 132 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
| 133 delegate_observer_.Call(FROM_HERE, |
| 134 &SyncNotifierObserver::OnNotificationsEnabled); |
| 135 } |
| 136 |
| 137 void NonBlockingInvalidationNotifier::Core::OnNotificationsDisabled( |
| 138 NotificationsDisabledReason reason) { |
| 139 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
| 140 delegate_observer_.Call( |
| 141 FROM_HERE, &SyncNotifierObserver::OnNotificationsDisabled, reason); |
| 142 } |
| 143 |
129 void NonBlockingInvalidationNotifier::Core::OnIncomingNotification( | 144 void NonBlockingInvalidationNotifier::Core::OnIncomingNotification( |
130 const syncable::ModelTypePayloadMap& type_payloads, | 145 const syncable::ModelTypePayloadMap& type_payloads, |
131 IncomingNotificationSource source) { | 146 IncomingNotificationSource source) { |
132 DCHECK(network_task_runner_->BelongsToCurrentThread()); | 147 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
133 delegate_observer_.Call(FROM_HERE, | 148 delegate_observer_.Call(FROM_HERE, |
134 &SyncNotifierObserver::OnIncomingNotification, | 149 &SyncNotifierObserver::OnIncomingNotification, |
135 type_payloads, | 150 type_payloads, |
136 source); | 151 source); |
137 } | 152 } |
138 | 153 |
139 void NonBlockingInvalidationNotifier::Core::OnNotificationStateChange( | |
140 bool notifications_enabled) { | |
141 DCHECK(network_task_runner_->BelongsToCurrentThread()); | |
142 delegate_observer_.Call(FROM_HERE, | |
143 &SyncNotifierObserver::OnNotificationStateChange, | |
144 notifications_enabled); | |
145 } | |
146 | |
147 NonBlockingInvalidationNotifier::NonBlockingInvalidationNotifier( | 154 NonBlockingInvalidationNotifier::NonBlockingInvalidationNotifier( |
148 const notifier::NotifierOptions& notifier_options, | 155 const notifier::NotifierOptions& notifier_options, |
149 const InvalidationVersionMap& initial_max_invalidation_versions, | 156 const InvalidationVersionMap& initial_max_invalidation_versions, |
150 const std::string& initial_invalidation_state, | 157 const std::string& initial_invalidation_state, |
151 const browser_sync::WeakHandle<InvalidationStateTracker>& | 158 const browser_sync::WeakHandle<InvalidationStateTracker>& |
152 invalidation_state_tracker, | 159 invalidation_state_tracker, |
153 const std::string& client_info) | 160 const std::string& client_info) |
154 : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 161 : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
155 core_( | 162 core_( |
156 new Core(browser_sync::MakeWeakHandle( | 163 new Core(browser_sync::MakeWeakHandle( |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 } | 247 } |
241 } | 248 } |
242 | 249 |
243 void NonBlockingInvalidationNotifier::SendNotification( | 250 void NonBlockingInvalidationNotifier::SendNotification( |
244 syncable::ModelTypeSet changed_types) { | 251 syncable::ModelTypeSet changed_types) { |
245 DCHECK(parent_task_runner_->BelongsToCurrentThread()); | 252 DCHECK(parent_task_runner_->BelongsToCurrentThread()); |
246 // InvalidationClient doesn't implement SendNotification(), so no | 253 // InvalidationClient doesn't implement SendNotification(), so no |
247 // need to forward on the call. | 254 // need to forward on the call. |
248 } | 255 } |
249 | 256 |
| 257 void NonBlockingInvalidationNotifier::OnNotificationsEnabled() { |
| 258 DCHECK(parent_task_runner_->BelongsToCurrentThread()); |
| 259 FOR_EACH_OBSERVER(SyncNotifierObserver, observers_, |
| 260 OnNotificationsEnabled()); |
| 261 } |
| 262 |
| 263 void NonBlockingInvalidationNotifier::OnNotificationsDisabled( |
| 264 NotificationsDisabledReason reason) { |
| 265 DCHECK(parent_task_runner_->BelongsToCurrentThread()); |
| 266 FOR_EACH_OBSERVER(SyncNotifierObserver, observers_, |
| 267 OnNotificationsDisabled(reason)); |
| 268 } |
| 269 |
250 void NonBlockingInvalidationNotifier::OnIncomingNotification( | 270 void NonBlockingInvalidationNotifier::OnIncomingNotification( |
251 const syncable::ModelTypePayloadMap& type_payloads, | 271 const syncable::ModelTypePayloadMap& type_payloads, |
252 IncomingNotificationSource source) { | 272 IncomingNotificationSource source) { |
253 DCHECK(parent_task_runner_->BelongsToCurrentThread()); | 273 DCHECK(parent_task_runner_->BelongsToCurrentThread()); |
254 FOR_EACH_OBSERVER(SyncNotifierObserver, observers_, | 274 FOR_EACH_OBSERVER(SyncNotifierObserver, observers_, |
255 OnIncomingNotification(type_payloads, source)); | 275 OnIncomingNotification(type_payloads, source)); |
256 } | 276 } |
257 | 277 |
258 void NonBlockingInvalidationNotifier::OnNotificationStateChange( | |
259 bool notifications_enabled) { | |
260 DCHECK(parent_task_runner_->BelongsToCurrentThread()); | |
261 FOR_EACH_OBSERVER(SyncNotifierObserver, observers_, | |
262 OnNotificationStateChange(notifications_enabled)); | |
263 } | |
264 | |
265 } // namespace sync_notifier | 278 } // namespace sync_notifier |
OLD | NEW |