| 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 20 matching lines...) Expand all Loading... |
| 31 const notifier::NotifierOptions& notifier_options, | 31 const notifier::NotifierOptions& notifier_options, |
| 32 const InvalidationVersionMap& initial_max_invalidation_versions, | 32 const InvalidationVersionMap& initial_max_invalidation_versions, |
| 33 const std::string& initial_invalidation_state, | 33 const std::string& initial_invalidation_state, |
| 34 const syncer::WeakHandle<InvalidationStateTracker>& | 34 const syncer::WeakHandle<InvalidationStateTracker>& |
| 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(syncer::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; | 45 virtual void OnNotificationsEnabled() OVERRIDE; |
| 46 virtual void OnNotificationsDisabled( | 46 virtual void OnNotificationsDisabled( |
| 47 NotificationsDisabledReason reason) OVERRIDE; | 47 NotificationsDisabledReason reason) OVERRIDE; |
| 48 virtual void OnIncomingNotification( | 48 virtual void OnIncomingNotification( |
| 49 const syncable::ModelTypePayloadMap& type_payloads, | 49 const syncer::ModelTypePayloadMap& type_payloads, |
| 50 IncomingNotificationSource source) OVERRIDE; | 50 IncomingNotificationSource source) OVERRIDE; |
| 51 | 51 |
| 52 private: | 52 private: |
| 53 friend class | 53 friend class |
| 54 base::RefCountedThreadSafe<NonBlockingInvalidationNotifier::Core>; | 54 base::RefCountedThreadSafe<NonBlockingInvalidationNotifier::Core>; |
| 55 // Called on parent or I/O thread. | 55 // Called on parent or I/O thread. |
| 56 ~Core(); | 56 ~Core(); |
| 57 | 57 |
| 58 // 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. |
| 59 const syncer::WeakHandle<SyncNotifierObserver> delegate_observer_; | 59 const syncer::WeakHandle<SyncNotifierObserver> delegate_observer_; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 invalidation_notifier_->SetStateDeprecated(state); | 116 invalidation_notifier_->SetStateDeprecated(state); |
| 117 } | 117 } |
| 118 | 118 |
| 119 void NonBlockingInvalidationNotifier::Core::UpdateCredentials( | 119 void NonBlockingInvalidationNotifier::Core::UpdateCredentials( |
| 120 const std::string& email, const std::string& token) { | 120 const std::string& email, const std::string& token) { |
| 121 DCHECK(network_task_runner_->BelongsToCurrentThread()); | 121 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
| 122 invalidation_notifier_->UpdateCredentials(email, token); | 122 invalidation_notifier_->UpdateCredentials(email, token); |
| 123 } | 123 } |
| 124 | 124 |
| 125 void NonBlockingInvalidationNotifier::Core::UpdateEnabledTypes( | 125 void NonBlockingInvalidationNotifier::Core::UpdateEnabledTypes( |
| 126 syncable::ModelTypeSet enabled_types) { | 126 syncer::ModelTypeSet enabled_types) { |
| 127 DCHECK(network_task_runner_->BelongsToCurrentThread()); | 127 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
| 128 invalidation_notifier_->UpdateEnabledTypes(enabled_types); | 128 invalidation_notifier_->UpdateEnabledTypes(enabled_types); |
| 129 } | 129 } |
| 130 | 130 |
| 131 void NonBlockingInvalidationNotifier::Core::OnNotificationsEnabled() { | 131 void NonBlockingInvalidationNotifier::Core::OnNotificationsEnabled() { |
| 132 DCHECK(network_task_runner_->BelongsToCurrentThread()); | 132 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
| 133 delegate_observer_.Call(FROM_HERE, | 133 delegate_observer_.Call(FROM_HERE, |
| 134 &SyncNotifierObserver::OnNotificationsEnabled); | 134 &SyncNotifierObserver::OnNotificationsEnabled); |
| 135 } | 135 } |
| 136 | 136 |
| 137 void NonBlockingInvalidationNotifier::Core::OnNotificationsDisabled( | 137 void NonBlockingInvalidationNotifier::Core::OnNotificationsDisabled( |
| 138 NotificationsDisabledReason reason) { | 138 NotificationsDisabledReason reason) { |
| 139 DCHECK(network_task_runner_->BelongsToCurrentThread()); | 139 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
| 140 delegate_observer_.Call( | 140 delegate_observer_.Call( |
| 141 FROM_HERE, &SyncNotifierObserver::OnNotificationsDisabled, reason); | 141 FROM_HERE, &SyncNotifierObserver::OnNotificationsDisabled, reason); |
| 142 } | 142 } |
| 143 | 143 |
| 144 void NonBlockingInvalidationNotifier::Core::OnIncomingNotification( | 144 void NonBlockingInvalidationNotifier::Core::OnIncomingNotification( |
| 145 const syncable::ModelTypePayloadMap& type_payloads, | 145 const syncer::ModelTypePayloadMap& type_payloads, |
| 146 IncomingNotificationSource source) { | 146 IncomingNotificationSource source) { |
| 147 DCHECK(network_task_runner_->BelongsToCurrentThread()); | 147 DCHECK(network_task_runner_->BelongsToCurrentThread()); |
| 148 delegate_observer_.Call(FROM_HERE, | 148 delegate_observer_.Call(FROM_HERE, |
| 149 &SyncNotifierObserver::OnIncomingNotification, | 149 &SyncNotifierObserver::OnIncomingNotification, |
| 150 type_payloads, | 150 type_payloads, |
| 151 source); | 151 source); |
| 152 } | 152 } |
| 153 | 153 |
| 154 NonBlockingInvalidationNotifier::NonBlockingInvalidationNotifier( | 154 NonBlockingInvalidationNotifier::NonBlockingInvalidationNotifier( |
| 155 const notifier::NotifierOptions& notifier_options, | 155 const notifier::NotifierOptions& notifier_options, |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 DCHECK(parent_task_runner_->BelongsToCurrentThread()); | 230 DCHECK(parent_task_runner_->BelongsToCurrentThread()); |
| 231 if (!network_task_runner_->PostTask( | 231 if (!network_task_runner_->PostTask( |
| 232 FROM_HERE, | 232 FROM_HERE, |
| 233 base::Bind(&NonBlockingInvalidationNotifier::Core::UpdateCredentials, | 233 base::Bind(&NonBlockingInvalidationNotifier::Core::UpdateCredentials, |
| 234 core_.get(), email, token))) { | 234 core_.get(), email, token))) { |
| 235 NOTREACHED(); | 235 NOTREACHED(); |
| 236 } | 236 } |
| 237 } | 237 } |
| 238 | 238 |
| 239 void NonBlockingInvalidationNotifier::UpdateEnabledTypes( | 239 void NonBlockingInvalidationNotifier::UpdateEnabledTypes( |
| 240 syncable::ModelTypeSet enabled_types) { | 240 syncer::ModelTypeSet enabled_types) { |
| 241 DCHECK(parent_task_runner_->BelongsToCurrentThread()); | 241 DCHECK(parent_task_runner_->BelongsToCurrentThread()); |
| 242 if (!network_task_runner_->PostTask( | 242 if (!network_task_runner_->PostTask( |
| 243 FROM_HERE, | 243 FROM_HERE, |
| 244 base::Bind(&NonBlockingInvalidationNotifier::Core::UpdateEnabledTypes, | 244 base::Bind(&NonBlockingInvalidationNotifier::Core::UpdateEnabledTypes, |
| 245 core_.get(), enabled_types))) { | 245 core_.get(), enabled_types))) { |
| 246 NOTREACHED(); | 246 NOTREACHED(); |
| 247 } | 247 } |
| 248 } | 248 } |
| 249 | 249 |
| 250 void NonBlockingInvalidationNotifier::SendNotification( | 250 void NonBlockingInvalidationNotifier::SendNotification( |
| 251 syncable::ModelTypeSet changed_types) { | 251 syncer::ModelTypeSet changed_types) { |
| 252 DCHECK(parent_task_runner_->BelongsToCurrentThread()); | 252 DCHECK(parent_task_runner_->BelongsToCurrentThread()); |
| 253 // InvalidationClient doesn't implement SendNotification(), so no | 253 // InvalidationClient doesn't implement SendNotification(), so no |
| 254 // need to forward on the call. | 254 // need to forward on the call. |
| 255 } | 255 } |
| 256 | 256 |
| 257 void NonBlockingInvalidationNotifier::OnNotificationsEnabled() { | 257 void NonBlockingInvalidationNotifier::OnNotificationsEnabled() { |
| 258 DCHECK(parent_task_runner_->BelongsToCurrentThread()); | 258 DCHECK(parent_task_runner_->BelongsToCurrentThread()); |
| 259 FOR_EACH_OBSERVER(SyncNotifierObserver, observers_, | 259 FOR_EACH_OBSERVER(SyncNotifierObserver, observers_, |
| 260 OnNotificationsEnabled()); | 260 OnNotificationsEnabled()); |
| 261 } | 261 } |
| 262 | 262 |
| 263 void NonBlockingInvalidationNotifier::OnNotificationsDisabled( | 263 void NonBlockingInvalidationNotifier::OnNotificationsDisabled( |
| 264 NotificationsDisabledReason reason) { | 264 NotificationsDisabledReason reason) { |
| 265 DCHECK(parent_task_runner_->BelongsToCurrentThread()); | 265 DCHECK(parent_task_runner_->BelongsToCurrentThread()); |
| 266 FOR_EACH_OBSERVER(SyncNotifierObserver, observers_, | 266 FOR_EACH_OBSERVER(SyncNotifierObserver, observers_, |
| 267 OnNotificationsDisabled(reason)); | 267 OnNotificationsDisabled(reason)); |
| 268 } | 268 } |
| 269 | 269 |
| 270 void NonBlockingInvalidationNotifier::OnIncomingNotification( | 270 void NonBlockingInvalidationNotifier::OnIncomingNotification( |
| 271 const syncable::ModelTypePayloadMap& type_payloads, | 271 const syncer::ModelTypePayloadMap& type_payloads, |
| 272 IncomingNotificationSource source) { | 272 IncomingNotificationSource source) { |
| 273 DCHECK(parent_task_runner_->BelongsToCurrentThread()); | 273 DCHECK(parent_task_runner_->BelongsToCurrentThread()); |
| 274 FOR_EACH_OBSERVER(SyncNotifierObserver, observers_, | 274 FOR_EACH_OBSERVER(SyncNotifierObserver, observers_, |
| 275 OnIncomingNotification(type_payloads, source)); | 275 OnIncomingNotification(type_payloads, source)); |
| 276 } | 276 } |
| 277 | 277 |
| 278 } // namespace syncer | 278 } // namespace syncer |
| OLD | NEW |