Index: sync/notifier/invalidation_notifier.cc |
diff --git a/sync/notifier/invalidation_notifier.cc b/sync/notifier/invalidation_notifier.cc |
index 58ef89a0b7f14a123902675e16e1e26005eb4bc8..fc99fee3ed9c27e216c186a256ceb4bd9c41ae93 100644 |
--- a/sync/notifier/invalidation_notifier.cc |
+++ b/sync/notifier/invalidation_notifier.cc |
@@ -35,14 +35,24 @@ InvalidationNotifier::~InvalidationNotifier() { |
DCHECK(CalledOnValidThread()); |
} |
-void InvalidationNotifier::AddObserver(SyncNotifierObserver* observer) { |
+void InvalidationNotifier::AddHandler(SyncNotifierObserver* observer) { |
DCHECK(CalledOnValidThread()); |
- observers_.AddObserver(observer); |
+ InvalidationNotifierBase::AddHandler(observer); |
} |
-void InvalidationNotifier::RemoveObserver(SyncNotifierObserver* observer) { |
+void InvalidationNotifier::RemoveHandler(SyncNotifierObserver* observer) { |
DCHECK(CalledOnValidThread()); |
- observers_.RemoveObserver(observer); |
+ InvalidationNotifierBase::RemoveHandler(observer); |
+} |
+ |
+void InvalidationNotifier::ReloadHandlers() { |
+ // TODO(dcheng): Do we want to use something else like std::set<> or |
+ // std::vector<>? This is really clunky. But ObserverList gives us some nice |
+ // things, such as amortizing the cost of removing observers and asserts that |
+ // we don't try to add an observer twice/remove it twice, etc. |
+ // It also lets us iterate safely through a list that might change... |
+ const ObjectIdSet& ids_to_register = UpdateObjectIdObserverMap(); |
+ invalidation_client_.RegisterIds(ids_to_register); |
} |
void InvalidationNotifier::SetUniqueId(const std::string& unique_id) { |
@@ -86,23 +96,6 @@ void InvalidationNotifier::UpdateCredentials( |
invalidation_client_.UpdateCredentials(email, token); |
} |
-void InvalidationNotifier::UpdateEnabledTypes( |
- syncer::ModelTypeSet enabled_types) { |
- DCHECK(CalledOnValidThread()); |
- CHECK(!invalidation_client_id_.empty()); |
- ObjectIdSet ids; |
- for (syncer::ModelTypeSet::Iterator it = enabled_types.First(); it.Good(); |
- it.Inc()) { |
- invalidation::ObjectId id; |
- if (!RealModelTypeToObjectId(it.Get(), &id)) { |
- DLOG(WARNING) << "Invalid model type " << it.Get(); |
- continue; |
- } |
- ids.insert(id); |
- } |
- invalidation_client_.RegisterIds(ids); |
-} |
- |
void InvalidationNotifier::SendNotification( |
syncer::ModelTypeSet changed_types) { |
DCHECK(CalledOnValidThread()); |
@@ -111,33 +104,19 @@ void InvalidationNotifier::SendNotification( |
void InvalidationNotifier::OnInvalidate(const ObjectIdPayloadMap& id_payloads) { |
DCHECK(CalledOnValidThread()); |
- // TODO(dcheng): This should probably be a utility function somewhere... |
- syncer::ModelTypePayloadMap type_payloads; |
- for (ObjectIdPayloadMap::const_iterator it = id_payloads.begin(); |
- it != id_payloads.end(); ++it) { |
- syncer::ModelType model_type; |
- if (!ObjectIdToRealModelType(it->first, &model_type)) { |
- DLOG(WARNING) << "Invalid object ID: " << ObjectIdToString(it->first); |
- continue; |
- } |
- type_payloads[model_type] = it->second; |
- } |
- FOR_EACH_OBSERVER( |
- SyncNotifierObserver, observers_, |
- OnIncomingNotification(type_payloads, |
- syncer::REMOTE_NOTIFICATION)); |
+ DispatchInvalidationsToObservers(id_payloads, syncer::REMOTE_NOTIFICATION); |
} |
void InvalidationNotifier::OnNotificationsEnabled() { |
DCHECK(CalledOnValidThread()); |
- FOR_EACH_OBSERVER(SyncNotifierObserver, observers_, |
+ FOR_EACH_OBSERVER(SyncNotifierObserver, observers(), |
OnNotificationsEnabled()); |
} |
void InvalidationNotifier::OnNotificationsDisabled( |
NotificationsDisabledReason reason) { |
DCHECK(CalledOnValidThread()); |
- FOR_EACH_OBSERVER(SyncNotifierObserver, observers_, |
+ FOR_EACH_OBSERVER(SyncNotifierObserver, observers(), |
OnNotificationsDisabled(reason)); |
} |