Index: sync/notifier/p2p_notifier.cc |
diff --git a/sync/notifier/p2p_notifier.cc b/sync/notifier/p2p_notifier.cc |
index c72895e349190f080a281ed95f1be04d9c859180..c4cc27016b3d86bb984430223daf1fc3d8bfeded 100644 |
--- a/sync/notifier/p2p_notifier.cc |
+++ b/sync/notifier/p2p_notifier.cc |
@@ -12,6 +12,7 @@ |
#include "base/values.h" |
#include "jingle/notifier/listener/push_client.h" |
#include "sync/internal_api/public/base/model_type_payload_map.h" |
+#include "sync/notifier/invalidation_util.h" |
#include "sync/notifier/sync_notifier_observer.h" |
namespace syncer { |
@@ -156,14 +157,25 @@ P2PNotifier::~P2PNotifier() { |
push_client_->RemoveObserver(this); |
} |
-void P2PNotifier::AddObserver(SyncNotifierObserver* observer) { |
+void P2PNotifier::AddHandler(SyncNotifierObserver* observer) { |
DCHECK(thread_checker_.CalledOnValidThread()); |
- observer_list_.AddObserver(observer); |
+ InvalidationNotifierBase::AddHandler(observer); |
} |
-void P2PNotifier::RemoveObserver(SyncNotifierObserver* observer) { |
+void P2PNotifier::RemoveHandler(SyncNotifierObserver* observer) { |
DCHECK(thread_checker_.CalledOnValidThread()); |
- observer_list_.RemoveObserver(observer); |
+ InvalidationNotifierBase::RemoveHandler(observer); |
+} |
+ |
+void P2PNotifier::ReloadHandlers() { |
+ const ObjectIdSet& enabled_ids = UpdateObjectIdObserverMap(); |
+ const ModelTypeSet& enabled_types = ObjectIdSetToModelTypeSet(enabled_ids); |
+ const ModelTypeSet new_enabled_types = |
+ Difference(enabled_types, enabled_types_); |
+ enabled_types_ = enabled_types; |
+ const P2PNotificationData notification_data( |
+ unique_id_, NOTIFY_SELF, new_enabled_types); |
+ SendNotificationData(notification_data); |
} |
void P2PNotifier::SetUniqueId(const std::string& unique_id) { |
@@ -193,17 +205,6 @@ void P2PNotifier::UpdateCredentials( |
logged_in_ = true; |
} |
-void P2PNotifier::UpdateEnabledTypes( |
- syncer::ModelTypeSet enabled_types) { |
- DCHECK(thread_checker_.CalledOnValidThread()); |
- const syncer::ModelTypeSet new_enabled_types = |
- Difference(enabled_types, enabled_types_); |
- enabled_types_ = enabled_types; |
- const P2PNotificationData notification_data( |
- unique_id_, NOTIFY_SELF, new_enabled_types); |
- SendNotificationData(notification_data); |
-} |
- |
void P2PNotifier::SendNotification( |
syncer::ModelTypeSet changed_types) { |
DCHECK(thread_checker_.CalledOnValidThread()); |
@@ -216,9 +217,8 @@ void P2PNotifier::OnNotificationsEnabled() { |
DCHECK(thread_checker_.CalledOnValidThread()); |
bool just_turned_on = (notifications_enabled_ == false); |
notifications_enabled_ = true; |
- FOR_EACH_OBSERVER( |
- SyncNotifierObserver, observer_list_, |
- OnNotificationsEnabled()); |
+ FOR_EACH_OBSERVER(SyncNotifierObserver, observers(), |
+ OnNotificationsEnabled()); |
if (just_turned_on) { |
const P2PNotificationData notification_data( |
unique_id_, NOTIFY_SELF, enabled_types_); |
@@ -229,9 +229,8 @@ void P2PNotifier::OnNotificationsEnabled() { |
void P2PNotifier::OnNotificationsDisabled( |
notifier::NotificationsDisabledReason reason) { |
DCHECK(thread_checker_.CalledOnValidThread()); |
- FOR_EACH_OBSERVER( |
- SyncNotifierObserver, observer_list_, |
- OnNotificationsDisabled(FromNotifierReason(reason))); |
+ FOR_EACH_OBSERVER(SyncNotifierObserver, observers(), |
+ OnNotificationsDisabled(FromNotifierReason(reason))); |
} |
void P2PNotifier::OnIncomingNotification( |
@@ -266,11 +265,11 @@ void P2PNotifier::OnIncomingNotification( |
DVLOG(1) << "No changed types -- not emitting notification"; |
return; |
} |
- const syncer::ModelTypePayloadMap& type_payloads = |
- syncer::ModelTypePayloadMapFromEnumSet( |
- notification_data.GetChangedTypes(), std::string()); |
- FOR_EACH_OBSERVER(SyncNotifierObserver, observer_list_, |
- OnIncomingNotification(type_payloads, REMOTE_NOTIFICATION)); |
+ const ModelTypePayloadMap& type_payloads = ModelTypePayloadMapFromEnumSet( |
+ notification_data.GetChangedTypes(), std::string()); |
+ DispatchInvalidationsToObservers( |
+ ModelTypePayloadMapToObjectIdPayloadMap(type_payloads), |
+ REMOTE_NOTIFICATION); |
} |
void P2PNotifier::SendNotificationDataForTest( |