| Index: sync/notifier/invalidation_notifier_base.cc
|
| diff --git a/sync/notifier/invalidation_notifier_base.cc b/sync/notifier/invalidation_notifier_base.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..695cf205b33be564fedec42264f0bde5decbe59d
|
| --- /dev/null
|
| +++ b/sync/notifier/invalidation_notifier_base.cc
|
| @@ -0,0 +1,62 @@
|
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "base/stl_util.h"
|
| +#include "sync/notifier/invalidation_notifier_base.h"
|
| +
|
| +namespace syncer {
|
| +
|
| +InvalidationNotifierBase::InvalidationNotifierBase() {}
|
| +InvalidationNotifierBase::~InvalidationNotifierBase() {}
|
| +
|
| +void InvalidationNotifierBase::AddHandler(SyncNotifierObserver* observer) {
|
| + observers_.AddObserver(observer);
|
| +}
|
| +void InvalidationNotifierBase::RemoveHandler(SyncNotifierObserver* observer) {
|
| + observers_.RemoveObserver(observer);
|
| + UpdateObjectIdObserverMap();
|
| +}
|
| +
|
| +ObjectIdSet InvalidationNotifierBase::UpdateObjectIdObserverMap() {
|
| + ObjectIdSet ids_in_map;
|
| + id_to_observer_map_.clear();
|
| + if (observers_.might_have_observers()) {
|
| + ObserverListBase<SyncNotifierObserver>::Iterator observer_it(observers_);
|
| + SyncNotifierObserver* observer;
|
| + while ((observer = observer_it.GetNext()) != NULL) {
|
| + const ObjectIdSet& ids = observer->GetHandledIds();
|
| + for (ObjectIdSet::const_iterator it = ids.begin(); it != ids.end();
|
| + ++it) {
|
| + DCHECK(!ContainsKey(id_to_observer_map_, *it));
|
| + id_to_observer_map_[*it] = observer;
|
| + ids_in_map.insert(*it);
|
| + }
|
| + }
|
| + }
|
| + return ids_in_map;
|
| +}
|
| +
|
| +void InvalidationNotifierBase::DispatchInvalidationsToObservers(
|
| + const ObjectIdPayloadMap& id_payloads,
|
| + IncomingNotificationSource source) {
|
| + std::map<SyncNotifierObserver*, ObjectIdPayloadMap> dispatch_map;
|
| + for (ObjectIdPayloadMap::const_iterator it = id_payloads.begin();
|
| + it != id_payloads.end(); ++it) {
|
| + ObjectIdObserverMap::const_iterator find_it =
|
| + id_to_observer_map_.find(it->first);
|
| + // If we get an invalidation for an object ID that we can't map to an
|
| + // observer, just drop it--the observer was unregistered while the
|
| + // invalidation was in flight.
|
| + if (find_it == id_to_observer_map_.end())
|
| + continue;
|
| + dispatch_map[find_it->second].insert(*it);
|
| + }
|
| + for (std::map<SyncNotifierObserver*, ObjectIdPayloadMap>::const_iterator it =
|
| + dispatch_map.begin(); it != dispatch_map.end(); ++it) {
|
| + DCHECK(observers_.HasObserver(it->first));
|
| + it->first->OnIncomingNotification(it->second, source);
|
| + }
|
| +}
|
| +
|
| +} // namespace syncer
|
|
|