OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/sync/notifier/non_blocking_invalidation_notifier.h" | 5 #include "chrome/browser/sync/notifier/non_blocking_invalidation_notifier.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/threading/thread.h" | 10 #include "base/threading/thread.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 void Initialize( | 26 void Initialize( |
27 const notifier::NotifierOptions& notifier_options, | 27 const notifier::NotifierOptions& notifier_options, |
28 const InvalidationVersionMap& initial_max_invalidation_versions, | 28 const InvalidationVersionMap& initial_max_invalidation_versions, |
29 const browser_sync::WeakHandle<InvalidationVersionTracker>& | 29 const browser_sync::WeakHandle<InvalidationVersionTracker>& |
30 invalidation_version_tracker, | 30 invalidation_version_tracker, |
31 const std::string& client_info); | 31 const std::string& client_info); |
32 void Teardown(); | 32 void Teardown(); |
33 void SetUniqueId(const std::string& unique_id); | 33 void SetUniqueId(const std::string& unique_id); |
34 void SetState(const std::string& state); | 34 void SetState(const std::string& state); |
35 void UpdateCredentials(const std::string& email, const std::string& token); | 35 void UpdateCredentials(const std::string& email, const std::string& token); |
36 void UpdateEnabledTypes(syncable::ModelEnumSet enabled_types); | 36 void UpdateEnabledTypes(syncable::ModelTypeSet enabled_types); |
37 | 37 |
38 // SyncNotifierObserver implementation (all called on I/O thread). | 38 // SyncNotifierObserver implementation (all called on I/O thread). |
39 virtual void OnIncomingNotification( | 39 virtual void OnIncomingNotification( |
40 const syncable::ModelTypePayloadMap& type_payloads); | 40 const syncable::ModelTypePayloadMap& type_payloads); |
41 virtual void OnNotificationStateChange(bool notifications_enabled); | 41 virtual void OnNotificationStateChange(bool notifications_enabled); |
42 virtual void StoreState(const std::string& state); | 42 virtual void StoreState(const std::string& state); |
43 | 43 |
44 private: | 44 private: |
45 friend class | 45 friend class |
46 base::RefCountedThreadSafe<NonBlockingInvalidationNotifier::Core>; | 46 base::RefCountedThreadSafe<NonBlockingInvalidationNotifier::Core>; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 invalidation_notifier_->SetState(state); | 106 invalidation_notifier_->SetState(state); |
107 } | 107 } |
108 | 108 |
109 void NonBlockingInvalidationNotifier::Core::UpdateCredentials( | 109 void NonBlockingInvalidationNotifier::Core::UpdateCredentials( |
110 const std::string& email, const std::string& token) { | 110 const std::string& email, const std::string& token) { |
111 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 111 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
112 invalidation_notifier_->UpdateCredentials(email, token); | 112 invalidation_notifier_->UpdateCredentials(email, token); |
113 } | 113 } |
114 | 114 |
115 void NonBlockingInvalidationNotifier::Core::UpdateEnabledTypes( | 115 void NonBlockingInvalidationNotifier::Core::UpdateEnabledTypes( |
116 syncable::ModelEnumSet enabled_types) { | 116 syncable::ModelTypeSet enabled_types) { |
117 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 117 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
118 invalidation_notifier_->UpdateEnabledTypes(enabled_types); | 118 invalidation_notifier_->UpdateEnabledTypes(enabled_types); |
119 } | 119 } |
120 | 120 |
121 void NonBlockingInvalidationNotifier::Core::OnIncomingNotification( | 121 void NonBlockingInvalidationNotifier::Core::OnIncomingNotification( |
122 const syncable::ModelTypePayloadMap& type_payloads) { | 122 const syncable::ModelTypePayloadMap& type_payloads) { |
123 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 123 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
124 delegate_observer_.Call(FROM_HERE, | 124 delegate_observer_.Call(FROM_HERE, |
125 &SyncNotifierObserver::OnIncomingNotification, | 125 &SyncNotifierObserver::OnIncomingNotification, |
126 type_payloads); | 126 type_payloads); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread()); | 216 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread()); |
217 if (!io_message_loop_proxy_->PostTask( | 217 if (!io_message_loop_proxy_->PostTask( |
218 FROM_HERE, | 218 FROM_HERE, |
219 base::Bind(&NonBlockingInvalidationNotifier::Core::UpdateCredentials, | 219 base::Bind(&NonBlockingInvalidationNotifier::Core::UpdateCredentials, |
220 core_.get(), email, token))) { | 220 core_.get(), email, token))) { |
221 NOTREACHED(); | 221 NOTREACHED(); |
222 } | 222 } |
223 } | 223 } |
224 | 224 |
225 void NonBlockingInvalidationNotifier::UpdateEnabledTypes( | 225 void NonBlockingInvalidationNotifier::UpdateEnabledTypes( |
226 syncable::ModelEnumSet enabled_types) { | 226 syncable::ModelTypeSet enabled_types) { |
227 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread()); | 227 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread()); |
228 if (!io_message_loop_proxy_->PostTask( | 228 if (!io_message_loop_proxy_->PostTask( |
229 FROM_HERE, | 229 FROM_HERE, |
230 base::Bind(&NonBlockingInvalidationNotifier::Core::UpdateEnabledTypes, | 230 base::Bind(&NonBlockingInvalidationNotifier::Core::UpdateEnabledTypes, |
231 core_.get(), enabled_types))) { | 231 core_.get(), enabled_types))) { |
232 NOTREACHED(); | 232 NOTREACHED(); |
233 } | 233 } |
234 } | 234 } |
235 | 235 |
236 void NonBlockingInvalidationNotifier::SendNotification( | 236 void NonBlockingInvalidationNotifier::SendNotification( |
237 syncable::ModelEnumSet changed_types) { | 237 syncable::ModelTypeSet changed_types) { |
238 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread()); | 238 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread()); |
239 // InvalidationClient doesn't implement SendNotification(), so no | 239 // InvalidationClient doesn't implement SendNotification(), so no |
240 // need to forward on the call. | 240 // need to forward on the call. |
241 } | 241 } |
242 | 242 |
243 void NonBlockingInvalidationNotifier::OnIncomingNotification( | 243 void NonBlockingInvalidationNotifier::OnIncomingNotification( |
244 const syncable::ModelTypePayloadMap& type_payloads) { | 244 const syncable::ModelTypePayloadMap& type_payloads) { |
245 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread()); | 245 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread()); |
246 FOR_EACH_OBSERVER(SyncNotifierObserver, observers_, | 246 FOR_EACH_OBSERVER(SyncNotifierObserver, observers_, |
247 OnIncomingNotification(type_payloads)); | 247 OnIncomingNotification(type_payloads)); |
248 } | 248 } |
249 | 249 |
250 void NonBlockingInvalidationNotifier::OnNotificationStateChange( | 250 void NonBlockingInvalidationNotifier::OnNotificationStateChange( |
251 bool notifications_enabled) { | 251 bool notifications_enabled) { |
252 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread()); | 252 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread()); |
253 FOR_EACH_OBSERVER(SyncNotifierObserver, observers_, | 253 FOR_EACH_OBSERVER(SyncNotifierObserver, observers_, |
254 OnNotificationStateChange(notifications_enabled)); | 254 OnNotificationStateChange(notifications_enabled)); |
255 } | 255 } |
256 | 256 |
257 void NonBlockingInvalidationNotifier::StoreState( | 257 void NonBlockingInvalidationNotifier::StoreState( |
258 const std::string& state) { | 258 const std::string& state) { |
259 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread()); | 259 DCHECK(parent_message_loop_proxy_->BelongsToCurrentThread()); |
260 FOR_EACH_OBSERVER(SyncNotifierObserver, observers_, | 260 FOR_EACH_OBSERVER(SyncNotifierObserver, observers_, |
261 StoreState(state)); | 261 StoreState(state)); |
262 } | 262 } |
263 | 263 |
264 } // namespace sync_notifier | 264 } // namespace sync_notifier |
OLD | NEW |