Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Unified Diff: sync/notifier/invalidation_notifier.cc

Issue 10702074: Refactor sync-specific parts out of SyncNotifier/SyncNotifierObserver (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Now with tests Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sync/notifier/invalidation_notifier.cc
diff --git a/sync/notifier/invalidation_notifier.cc b/sync/notifier/invalidation_notifier.cc
index 58ef89a0b7f14a123902675e16e1e26005eb4bc8..456c02e2179608dbabbf8f65b2221f9f89b5cd62 100644
--- a/sync/notifier/invalidation_notifier.cc
+++ b/sync/notifier/invalidation_notifier.cc
@@ -35,14 +35,10 @@ InvalidationNotifier::~InvalidationNotifier() {
DCHECK(CalledOnValidThread());
}
-void InvalidationNotifier::AddObserver(SyncNotifierObserver* observer) {
+void InvalidationNotifier::UpdateRegisteredIds(SyncNotifierObserver* handler,
+ const ObjectIdSet& ids) {
DCHECK(CalledOnValidThread());
- observers_.AddObserver(observer);
-}
-
-void InvalidationNotifier::RemoveObserver(SyncNotifierObserver* observer) {
- DCHECK(CalledOnValidThread());
- observers_.RemoveObserver(observer);
+ invalidation_client_.RegisterIds(helper_.UpdateRegisteredIds(handler, ids));
}
void InvalidationNotifier::SetUniqueId(const std::string& unique_id) {
@@ -86,23 +82,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,34 +90,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));
+ helper_.DispatchInvalidationsToHandlers(
+ id_payloads, syncer::REMOTE_NOTIFICATION);
}
void InvalidationNotifier::OnNotificationsEnabled() {
DCHECK(CalledOnValidThread());
- FOR_EACH_OBSERVER(SyncNotifierObserver, observers_,
- OnNotificationsEnabled());
+ helper_.OnNotificationsEnabled();
}
void InvalidationNotifier::OnNotificationsDisabled(
NotificationsDisabledReason reason) {
DCHECK(CalledOnValidThread());
- FOR_EACH_OBSERVER(SyncNotifierObserver, observers_,
- OnNotificationsDisabled(reason));
+ helper_.OnNotificationsDisabled(reason);
}
} // namespace syncer

Powered by Google App Engine
This is Rietveld 408576698