Chromium Code Reviews| Index: sync/notifier/non_blocking_invalidation_notifier.cc |
| diff --git a/sync/notifier/non_blocking_invalidation_notifier.cc b/sync/notifier/non_blocking_invalidation_notifier.cc |
| index cf5e51ab7c221038c6cbefa3e9fda7ce3efad6f7..e90ec915045c4670d4ecc0f1339b40c1648a7713 100644 |
| --- a/sync/notifier/non_blocking_invalidation_notifier.cc |
| +++ b/sync/notifier/non_blocking_invalidation_notifier.cc |
| @@ -35,10 +35,10 @@ class NonBlockingInvalidationNotifier::Core |
| invalidation_state_tracker, |
| const std::string& client_info); |
| void Teardown(); |
| + void UpdateRegisteredIds(const ObjectIdSet& ids); |
| void SetUniqueId(const std::string& unique_id); |
| void SetStateDeprecated(const std::string& state); |
| void UpdateCredentials(const std::string& email, const std::string& token); |
| - void UpdateEnabledTypes(syncer::ModelTypeSet enabled_types); |
| // SyncNotifierObserver implementation (all called on I/O thread by |
| // InvalidationNotifier). |
| @@ -46,7 +46,7 @@ class NonBlockingInvalidationNotifier::Core |
| virtual void OnNotificationsDisabled( |
| NotificationsDisabledReason reason) OVERRIDE; |
| virtual void OnIncomingNotification( |
| - const syncer::ModelTypePayloadMap& type_payloads, |
| + const ObjectIdPayloadMap& id_payloads, |
| IncomingNotificationSource source) OVERRIDE; |
| private: |
| @@ -93,17 +93,22 @@ void NonBlockingInvalidationNotifier::Core::Initialize( |
| initial_invalidation_state, |
| invalidation_state_tracker, |
| client_info)); |
| - invalidation_notifier_->AddObserver(this); |
| } |
| void NonBlockingInvalidationNotifier::Core::Teardown() { |
| DCHECK(network_task_runner_->BelongsToCurrentThread()); |
| - invalidation_notifier_->RemoveObserver(this); |
| + invalidation_notifier_->UpdateRegisteredIds(this, ObjectIdSet()); |
| invalidation_notifier_.reset(); |
| network_task_runner_ = NULL; |
| } |
| +void NonBlockingInvalidationNotifier::Core::UpdateRegisteredIds( |
| + const ObjectIdSet& ids) { |
| + DCHECK(network_task_runner_->BelongsToCurrentThread()); |
| + invalidation_notifier_->UpdateRegisteredIds(this, ids); |
| +} |
| + |
| void NonBlockingInvalidationNotifier::Core::SetUniqueId( |
| const std::string& unique_id) { |
| DCHECK(network_task_runner_->BelongsToCurrentThread()); |
| @@ -122,12 +127,6 @@ void NonBlockingInvalidationNotifier::Core::UpdateCredentials( |
| invalidation_notifier_->UpdateCredentials(email, token); |
| } |
| -void NonBlockingInvalidationNotifier::Core::UpdateEnabledTypes( |
| - syncer::ModelTypeSet enabled_types) { |
| - DCHECK(network_task_runner_->BelongsToCurrentThread()); |
| - invalidation_notifier_->UpdateEnabledTypes(enabled_types); |
| -} |
| - |
| void NonBlockingInvalidationNotifier::Core::OnNotificationsEnabled() { |
| DCHECK(network_task_runner_->BelongsToCurrentThread()); |
| delegate_observer_.Call(FROM_HERE, |
| @@ -142,12 +141,11 @@ void NonBlockingInvalidationNotifier::Core::OnNotificationsDisabled( |
| } |
| void NonBlockingInvalidationNotifier::Core::OnIncomingNotification( |
| - const syncer::ModelTypePayloadMap& type_payloads, |
| - IncomingNotificationSource source) { |
| + const ObjectIdPayloadMap& id_payloads, IncomingNotificationSource source) { |
| DCHECK(network_task_runner_->BelongsToCurrentThread()); |
| delegate_observer_.Call(FROM_HERE, |
| &SyncNotifierObserver::OnIncomingNotification, |
| - type_payloads, |
| + id_payloads, |
| source); |
| } |
| @@ -190,16 +188,21 @@ NonBlockingInvalidationNotifier::~NonBlockingInvalidationNotifier() { |
| } |
| } |
| -void NonBlockingInvalidationNotifier::AddObserver( |
| - SyncNotifierObserver* observer) { |
| +void NonBlockingInvalidationNotifier::UpdateRegisteredIds( |
| + SyncNotifierObserver* handler, const ObjectIdSet& ids) { |
| DCHECK(parent_task_runner_->BelongsToCurrentThread()); |
| - observers_.AddObserver(observer); |
| -} |
| - |
| -void NonBlockingInvalidationNotifier::RemoveObserver( |
| - SyncNotifierObserver* observer) { |
| - DCHECK(parent_task_runner_->BelongsToCurrentThread()); |
| - observers_.RemoveObserver(observer); |
| + if (!network_task_runner_->PostTask( |
| + FROM_HERE, |
| + base::Bind( |
| + &NonBlockingInvalidationNotifier::Core::UpdateRegisteredIds, |
| + core_.get(), |
| + // SyncNotifierHelper::UpdateRegisteredIds updates its internal |
|
akalin
2012/07/20 19:04:54
Yeah, maybe the comment isn't that helpful. On se
dcheng
2012/07/21 00:09:54
Done.
|
| + // mappings, then returns all the registered IDs. Pass it to the |
| + // Core to update our registrations with the actual |
| + // InvalidationNotifier. |
| + helper_.UpdateRegisteredIds(handler, ids)))) { |
| + NOTREACHED(); |
| + } |
| } |
| void NonBlockingInvalidationNotifier::SetUniqueId( |
| @@ -236,17 +239,6 @@ void NonBlockingInvalidationNotifier::UpdateCredentials( |
| } |
| } |
| -void NonBlockingInvalidationNotifier::UpdateEnabledTypes( |
| - syncer::ModelTypeSet enabled_types) { |
| - DCHECK(parent_task_runner_->BelongsToCurrentThread()); |
| - if (!network_task_runner_->PostTask( |
| - FROM_HERE, |
| - base::Bind(&NonBlockingInvalidationNotifier::Core::UpdateEnabledTypes, |
| - core_.get(), enabled_types))) { |
| - NOTREACHED(); |
| - } |
| -} |
| - |
| void NonBlockingInvalidationNotifier::SendNotification( |
| syncer::ModelTypeSet changed_types) { |
| DCHECK(parent_task_runner_->BelongsToCurrentThread()); |
| @@ -256,23 +248,20 @@ void NonBlockingInvalidationNotifier::SendNotification( |
| void NonBlockingInvalidationNotifier::OnNotificationsEnabled() { |
| DCHECK(parent_task_runner_->BelongsToCurrentThread()); |
| - FOR_EACH_OBSERVER(SyncNotifierObserver, observers_, |
| - OnNotificationsEnabled()); |
| + helper_.OnNotificationsEnabled(); |
| } |
| void NonBlockingInvalidationNotifier::OnNotificationsDisabled( |
| NotificationsDisabledReason reason) { |
| DCHECK(parent_task_runner_->BelongsToCurrentThread()); |
| - FOR_EACH_OBSERVER(SyncNotifierObserver, observers_, |
| - OnNotificationsDisabled(reason)); |
| + helper_.OnNotificationsDisabled(reason); |
| } |
| void NonBlockingInvalidationNotifier::OnIncomingNotification( |
| - const syncer::ModelTypePayloadMap& type_payloads, |
| + const ObjectIdPayloadMap& id_payloads, |
| IncomingNotificationSource source) { |
| DCHECK(parent_task_runner_->BelongsToCurrentThread()); |
| - FOR_EACH_OBSERVER(SyncNotifierObserver, observers_, |
| - OnIncomingNotification(type_payloads, source)); |
| + helper_.DispatchInvalidationsToHandlers(id_payloads, source); |
| } |
| } // namespace syncer |