Index: sync/notifier/invalidation_notifier.cc |
diff --git a/sync/notifier/invalidation_notifier.cc b/sync/notifier/invalidation_notifier.cc |
index 3a72f32fa61ace7acc53ca566d9ccfe210599e51..0c629c609ce11f2461b3da65eb4d3e5076089482 100644 |
--- a/sync/notifier/invalidation_notifier.cc |
+++ b/sync/notifier/invalidation_notifier.cc |
@@ -34,10 +34,14 @@ InvalidationNotifier::~InvalidationNotifier() { |
DCHECK(CalledOnValidThread()); |
} |
-void InvalidationNotifier::UpdateRegisteredIds(SyncNotifierObserver* handler, |
- const ObjectIdSet& ids) { |
+void InvalidationNotifier::AddObserver(SyncNotifierObserver* observer) { |
DCHECK(CalledOnValidThread()); |
- invalidation_client_.RegisterIds(helper_.UpdateRegisteredIds(handler, ids)); |
+ observers_.AddObserver(observer); |
+} |
+ |
+void InvalidationNotifier::RemoveObserver(SyncNotifierObserver* observer) { |
+ DCHECK(CalledOnValidThread()); |
+ observers_.RemoveObserver(observer); |
} |
void InvalidationNotifier::SetUniqueId(const std::string& unique_id) { |
@@ -81,6 +85,22 @@ void InvalidationNotifier::UpdateCredentials( |
invalidation_client_.UpdateCredentials(email, token); |
} |
+void InvalidationNotifier::UpdateEnabledTypes(ModelTypeSet enabled_types) { |
+ DCHECK(CalledOnValidThread()); |
+ CHECK(!invalidation_client_id_.empty()); |
+ ObjectIdSet ids; |
+ for (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(ModelTypeSet changed_types) { |
DCHECK(CalledOnValidThread()); |
// Do nothing. |
@@ -88,18 +108,33 @@ void InvalidationNotifier::SendNotification(ModelTypeSet changed_types) { |
void InvalidationNotifier::OnInvalidate(const ObjectIdPayloadMap& id_payloads) { |
DCHECK(CalledOnValidThread()); |
- helper_.DispatchInvalidationsToHandlers(id_payloads, REMOTE_NOTIFICATION); |
+ // TODO(dcheng): This should probably be a utility function somewhere... |
+ ModelTypePayloadMap type_payloads; |
+ for (ObjectIdPayloadMap::const_iterator it = id_payloads.begin(); |
+ it != id_payloads.end(); ++it) { |
+ 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, REMOTE_NOTIFICATION)); |
} |
void InvalidationNotifier::OnNotificationsEnabled() { |
DCHECK(CalledOnValidThread()); |
- helper_.EmitOnNotificationsEnabled(); |
+ FOR_EACH_OBSERVER(SyncNotifierObserver, observers_, |
+ OnNotificationsEnabled()); |
} |
void InvalidationNotifier::OnNotificationsDisabled( |
NotificationsDisabledReason reason) { |
DCHECK(CalledOnValidThread()); |
- helper_.EmitOnNotificationsDisabled(reason); |
+ FOR_EACH_OBSERVER(SyncNotifierObserver, observers_, |
+ OnNotificationsDisabled(reason)); |
} |
} // namespace syncer |