Commit d052da3e authored by Marc Treib's avatar Marc Treib Committed by Commit Bot

Merge InvalidatorRegistrar into InvalidatorRegistrarWithMemory

InvalidatorRegistrarWithMemory was a subclass of InvalidatorRegistrar,
but the base InvalidatorRegistrar was never actually used itself. So no
reason to have two separate classes and split the implementation between
two places.

Bug: none
Change-Id: I6892ccf7d01293a357665a588e433716208dd042
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1890313
Commit-Queue: Marc Treib <treib@chromium.org>
Commit-Queue: Tatiana Gornak <melandory@chromium.org>
Reviewed-by: default avatarTatiana Gornak <melandory@chromium.org>
Cr-Commit-Position: refs/heads/master@{#710798}
parent b8863f18
......@@ -42,8 +42,6 @@ static_library("impl") {
"invalidation_state_tracker.h",
"invalidator.cc",
"invalidator.h",
"invalidator_registrar.cc",
"invalidator_registrar.h",
"invalidator_registrar_with_memory.cc",
"invalidator_registrar_with_memory.h",
"invalidator_storage.cc",
......@@ -133,7 +131,6 @@ source_set("unit_tests") {
"fcm_invalidation_service_unittest.cc",
"fcm_network_handler_unittests.cc",
"invalidation_logger_unittest.cc",
"invalidator_registrar_unittest.cc",
"invalidator_registrar_with_memory_unittest.cc",
"per_user_topic_registration_manager_unittest.cc",
"per_user_topic_registration_request_unittest.cc",
......
// Copyright 2018 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 "components/invalidation/impl/invalidator_registrar.h"
#include <cstddef>
#include <iterator>
#include <utility>
#include "base/logging.h"
#include "components/invalidation/public/object_id_invalidation_map.h"
#include "components/invalidation/public/topic_invalidation_map.h"
namespace syncer {
InvalidatorRegistrar::InvalidatorRegistrar()
: state_(DEFAULT_INVALIDATION_ERROR) {}
InvalidatorRegistrar::~InvalidatorRegistrar() {
DCHECK(thread_checker_.CalledOnValidThread());
CHECK(handler_to_topics_map_.empty());
}
void InvalidatorRegistrar::RegisterHandler(InvalidationHandler* handler) {
DCHECK(thread_checker_.CalledOnValidThread());
CHECK(handler);
CHECK(!handlers_.HasObserver(handler));
handlers_.AddObserver(handler);
}
bool InvalidatorRegistrar::UpdateRegisteredTopics(InvalidationHandler* handler,
const Topics& topics) {
DCHECK(thread_checker_.CalledOnValidThread());
CHECK(handler);
CHECK(handlers_.HasObserver(handler));
for (const auto& handler_and_topics : handler_to_topics_map_) {
if (handler_and_topics.first == handler) {
continue;
}
if (auto* duplicate =
FindMatchingTopic(topics, handler_and_topics.second)) {
DVLOG(1) << "Duplicate registration: trying to register " << *duplicate
<< " for " << handler << " when it's already registered for "
<< handler_and_topics.first;
return false;
}
}
if (topics.empty()) {
handler_to_topics_map_.erase(handler);
} else {
handler_to_topics_map_[handler] = topics;
}
return true;
}
void InvalidatorRegistrar::UnregisterHandler(InvalidationHandler* handler) {
DCHECK(thread_checker_.CalledOnValidThread());
CHECK(handler);
CHECK(handlers_.HasObserver(handler));
handlers_.RemoveObserver(handler);
handler_to_topics_map_.erase(handler);
}
Topics InvalidatorRegistrar::GetRegisteredTopics(
InvalidationHandler* handler) const {
DCHECK(thread_checker_.CalledOnValidThread());
auto lookup = handler_to_topics_map_.find(handler);
return lookup != handler_to_topics_map_.end() ? lookup->second : Topics();
}
Topics InvalidatorRegistrar::GetAllRegisteredIds() const {
DCHECK(thread_checker_.CalledOnValidThread());
Topics registered_ids;
for (const auto& handler_and_topics : handler_to_topics_map_) {
const Topics& topics = handler_and_topics.second;
registered_ids.insert(topics.begin(), topics.end());
}
return registered_ids;
}
void InvalidatorRegistrar::DispatchInvalidationsToHandlers(
const TopicInvalidationMap& invalidation_map) {
DCHECK(thread_checker_.CalledOnValidThread());
// If we have no handlers, there's nothing to do.
if (!handlers_.might_have_observers()) {
return;
}
for (const auto& handler_and_topics : handler_to_topics_map_) {
TopicInvalidationMap to_emit =
invalidation_map.GetSubsetWithTopics(handler_and_topics.second);
ObjectIdInvalidationMap object_ids_to_emit;
std::vector<syncer::Invalidation> invalidations;
to_emit.GetAllInvalidations(&invalidations);
for (const auto& invalidation : invalidations) {
object_ids_to_emit.Insert(invalidation);
}
if (!to_emit.Empty()) {
handler_and_topics.first->OnIncomingInvalidation(object_ids_to_emit);
}
}
}
void InvalidatorRegistrar::UpdateInvalidatorState(InvalidatorState state) {
DCHECK(thread_checker_.CalledOnValidThread());
DVLOG(1) << "New invalidator state: " << InvalidatorStateToString(state_)
<< " -> " << InvalidatorStateToString(state);
state_ = state;
for (auto& observer : handlers_)
observer.OnInvalidatorStateChange(state);
}
void InvalidatorRegistrar::UpdateInvalidatorId(const std::string& id) {
for (auto& observer : handlers_)
observer.OnInvalidatorClientIdChange(id);
}
InvalidatorState InvalidatorRegistrar::GetInvalidatorState() const {
DCHECK(thread_checker_.CalledOnValidThread());
return state_;
}
std::map<std::string, Topics>
InvalidatorRegistrar::GetSanitizedHandlersIdsMap() {
DCHECK(thread_checker_.CalledOnValidThread());
std::map<std::string, Topics> clean_handlers_to_topics;
for (const auto& handler_and_topics : handler_to_topics_map_)
clean_handlers_to_topics[handler_and_topics.first->GetOwnerName()] =
Topics(handler_and_topics.second);
return clean_handlers_to_topics;
}
bool InvalidatorRegistrar::IsHandlerRegistered(
const InvalidationHandler* handler) const {
DCHECK(thread_checker_.CalledOnValidThread());
return handlers_.HasObserver(handler);
}
void InvalidatorRegistrar::DetachFromThreadForTest() {
DCHECK(thread_checker_.CalledOnValidThread());
thread_checker_.DetachFromThread();
}
} // namespace syncer
// Copyright 2018 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.
#ifndef COMPONENTS_INVALIDATION_IMPL_INVALIDATOR_REGISTRAR_H_
#define COMPONENTS_INVALIDATION_IMPL_INVALIDATOR_REGISTRAR_H_
#include <map>
#include "base/macros.h"
#include "base/observer_list.h"
#include "base/threading/thread_checker.h"
#include "components/invalidation/public/invalidation_export.h"
#include "components/invalidation/public/invalidation_handler.h"
#include "components/invalidation/public/invalidation_util.h"
namespace syncer {
class TopicInvalidationMap;
// A helper class for implementations of the Invalidator interface. It helps
// keep track of registered handlers and which object ID registrations are
// associated with which handlers, so implementors can just reuse the logic
// here to dispatch invalidations and other interesting notifications.
class INVALIDATION_EXPORT InvalidatorRegistrar {
public:
InvalidatorRegistrar();
// It is an error to have registered handlers on destruction.
virtual ~InvalidatorRegistrar();
// Starts sending notifications to |handler|. |handler| must not be NULL,
// and it must not already be registered.
void RegisterHandler(InvalidationHandler* handler);
// Stops sending notifications to |handler|. |handler| must not be NULL, and
// it must already be registered. Note that this doesn't unregister the
// topics associated with |handler| from the server.
void UnregisterHandler(InvalidationHandler* handler);
// Updates the set of topics associated with |handler|. |handler| must
// not be NULL, and must already be registered. A topic must be registered
// for at most one handler. If any of the |topics| is already registered
// to a different handler, returns false.
virtual bool UpdateRegisteredTopics(InvalidationHandler* handler,
const Topics& topics) WARN_UNUSED_RESULT;
virtual Topics GetRegisteredTopics(InvalidationHandler* handler) const;
// Returns the set of all topics that are registered to some handler.
virtual Topics GetAllRegisteredIds() const;
// Sorts incoming invalidations into a bucket for each handler and then
// dispatches the batched invalidations to the corresponding handler.
// Invalidations for topics with no corresponding handler are dropped, as are
// invalidations for handlers that are not added.
void DispatchInvalidationsToHandlers(
const TopicInvalidationMap& invalidation_map);
// Updates the invalidator state to the given one and then notifies
// all handlers. Note that the order is important; handlers that
// call GetInvalidatorState() when notified will see the new state.
void UpdateInvalidatorState(InvalidatorState state);
// Updates the invalidator id to the given one and then notifies
// all handlers.
void UpdateInvalidatorId(const std::string& id);
// Returns the current invalidator state. When called from within
// InvalidationHandler::OnInvalidatorStateChange(), this returns the
// updated state.
InvalidatorState GetInvalidatorState() const;
// Gets a new map for the name of invalidator handlers and their
// objects id. This is used by the InvalidatorLogger to be able
// to display every registered handler and its topics.
std::map<std::string, Topics> GetSanitizedHandlersIdsMap();
bool IsHandlerRegistered(const InvalidationHandler* handler) const;
// Needed for death tests.
void DetachFromThreadForTest();
private:
base::ThreadChecker thread_checker_;
base::ObserverList<InvalidationHandler, true>::Unchecked handlers_;
std::map<InvalidationHandler*, Topics> handler_to_topics_map_;
InvalidatorState state_;
DISALLOW_COPY_AND_ASSIGN(InvalidatorRegistrar);
};
} // namespace syncer
#endif // COMPONENTS_INVALIDATION_IMPL_INVALIDATOR_REGISTRAR_H_
// Copyright 2018 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 "components/invalidation/impl/invalidator_registrar.h"
#include <memory>
#include "base/compiler_specific.h"
#include "base/macros.h"
#include "components/invalidation/impl/fake_invalidation_handler.h"
#include "components/invalidation/impl/invalidator_test_template.h"
#include "components/invalidation/public/topic_invalidation_map.h"
#include "google/cacheinvalidation/types.pb.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace syncer {
namespace {
// We test DeprecatedInvalidatorRegistrar by wrapping it in an Invalidator and
// running the usual Invalidator tests.
// Thin Invalidator wrapper around DeprecatedInvalidatorRegistrar.
class RegistrarInvalidator : public Invalidator {
public:
RegistrarInvalidator() {}
~RegistrarInvalidator() override {}
InvalidatorRegistrar* GetRegistrar() { return &registrar_; }
// Invalidator implementation.
void RegisterHandler(InvalidationHandler* handler) override {
registrar_.RegisterHandler(handler);
}
bool UpdateRegisteredIds(InvalidationHandler* handler,
const ObjectIdSet& ids) override {
return registrar_.UpdateRegisteredTopics(handler,
ConvertIdsToTopics(ids, handler));
}
bool UpdateRegisteredIds(InvalidationHandler* handler,
const Topics& ids) override {
NOTREACHED();
return false;
}
void UnregisterHandler(InvalidationHandler* handler) override {
registrar_.UnregisterHandler(handler);
}
InvalidatorState GetInvalidatorState() const override {
return registrar_.GetInvalidatorState();
}
void UpdateCredentials(const CoreAccountId& account_id,
const std::string& token) override {
// Do nothing.
}
void RequestDetailedStatus(
base::Callback<void(const base::DictionaryValue&)> call) const override {
// Do nothing.
}
private:
InvalidatorRegistrar registrar_;
DISALLOW_COPY_AND_ASSIGN(RegistrarInvalidator);
};
class RegistrarInvalidatorTestDelegate {
public:
RegistrarInvalidatorTestDelegate() {}
~RegistrarInvalidatorTestDelegate() { DestroyInvalidator(); }
void CreateInvalidator(const std::string& invalidator_client_id,
const std::string& initial_state,
const base::WeakPtr<InvalidationStateTracker>&
invalidation_state_tracker) {
DCHECK(!invalidator_);
invalidator_.reset(new RegistrarInvalidator());
}
RegistrarInvalidator* GetInvalidator() { return invalidator_.get(); }
void DestroyInvalidator() { invalidator_.reset(); }
void WaitForInvalidator() {
// Do nothing.
}
void TriggerOnInvalidatorStateChange(InvalidatorState state) {
invalidator_->GetRegistrar()->UpdateInvalidatorState(state);
}
void TriggerOnIncomingInvalidation(
const ObjectIdInvalidationMap& invalidation_map) {
TopicInvalidationMap topics_map;
std::vector<syncer::Invalidation> invalidations;
invalidation_map.GetAllInvalidations(&invalidations);
for (const auto& invalidation : invalidations) {
topics_map.Insert(invalidation);
}
invalidator_->GetRegistrar()->DispatchInvalidationsToHandlers(topics_map);
}
private:
std::unique_ptr<RegistrarInvalidator> invalidator_;
};
INSTANTIATE_TYPED_TEST_SUITE_P(RegistrarInvalidatorTest,
InvalidatorTest,
RegistrarInvalidatorTestDelegate);
} // namespace
} // namespace syncer
......@@ -60,7 +60,9 @@ InvalidatorRegistrarWithMemory::InvalidatorRegistrarWithMemory(
PrefService* local_state,
const std::string& sender_id,
bool migrate_old_prefs)
: InvalidatorRegistrar(), local_state_(local_state), sender_id_(sender_id) {
: state_(DEFAULT_INVALIDATION_ERROR),
local_state_(local_state),
sender_id_(sender_id) {
if (migrate_old_prefs) {
MigratePrefs(local_state_, sender_id_);
}
......@@ -74,8 +76,8 @@ InvalidatorRegistrarWithMemory::InvalidatorRegistrarWithMemory(
for (const auto& it : pref_data->DictItems()) {
Topic topic = it.first;
if (it.second.is_dict()) {
const auto* handler = it.second.FindDictKey(kHandler);
const auto* is_public = it.second.FindDictKey(kIsPublic);
const base::Value* handler = it.second.FindDictKey(kHandler);
const base::Value* is_public = it.second.FindDictKey(kIsPublic);
if (!handler || !is_public) {
continue;
}
......@@ -90,17 +92,66 @@ InvalidatorRegistrarWithMemory::InvalidatorRegistrarWithMemory(
}
}
InvalidatorRegistrarWithMemory::~InvalidatorRegistrarWithMemory() {}
InvalidatorRegistrarWithMemory::~InvalidatorRegistrarWithMemory() {
DCHECK(thread_checker_.CalledOnValidThread());
CHECK(handler_to_topics_map_.empty());
}
void InvalidatorRegistrarWithMemory::RegisterHandler(
InvalidationHandler* handler) {
DCHECK(thread_checker_.CalledOnValidThread());
CHECK(handler);
CHECK(!handlers_.HasObserver(handler));
handlers_.AddObserver(handler);
}
void InvalidatorRegistrarWithMemory::UnregisterHandler(
InvalidationHandler* handler) {
DCHECK(thread_checker_.CalledOnValidThread());
CHECK(handler);
CHECK(handlers_.HasObserver(handler));
handlers_.RemoveObserver(handler);
handler_to_topics_map_.erase(handler);
// Note: Do *not* remove the entry from |handler_name_to_topics_map_| so that
// GetAllRegisteredIds() still returns the registered topics.
}
bool InvalidatorRegistrarWithMemory::IsHandlerRegistered(
const InvalidationHandler* handler) const {
DCHECK(thread_checker_.CalledOnValidThread());
return handlers_.HasObserver(handler);
}
bool InvalidatorRegistrarWithMemory::UpdateRegisteredTopics(
InvalidationHandler* handler,
const Topics& topics) {
DCHECK(thread_checker_.CalledOnValidThread());
CHECK(handler);
CHECK(handlers_.HasObserver(handler));
Topics old_topics = GetRegisteredTopics(handler);
bool success = InvalidatorRegistrar::UpdateRegisteredTopics(handler, topics);
if (!InvalidatorRegistrar::IsHandlerRegistered(handler)) {
bool success = !HasDuplicateTopicRegistration(handler, topics);
if (success) {
if (topics.empty()) {
handler_to_topics_map_.erase(handler);
} else {
handler_to_topics_map_[handler] = topics;
}
}
// TODO(treib): This is unreachable, |handler| couldn't have been removed
// from |handlers_|. What was the intention behind this check?
if (!IsHandlerRegistered(handler)) {
NOTREACHED();
return success;
}
// TODO(treib): This seems inconsistent - if there's a duplicate, we don't
// update |handler_to_topics_map_| but we *do* still update
// |handler_name_to_topics_map_| and the prefs?!
DictionaryPrefUpdate update(local_state_, kTopicsToHandler);
base::Value* pref_data = update->FindDictKey(sender_id_);
auto to_unregister = FindRemovedTopics(old_topics, topics);
......@@ -121,6 +172,13 @@ bool InvalidatorRegistrarWithMemory::UpdateRegisteredTopics(
return success;
}
Topics InvalidatorRegistrarWithMemory::GetRegisteredTopics(
InvalidationHandler* handler) const {
DCHECK(thread_checker_.CalledOnValidThread());
auto lookup = handler_to_topics_map_.find(handler);
return lookup != handler_to_topics_map_.end() ? lookup->second : Topics();
}
Topics InvalidatorRegistrarWithMemory::GetAllRegisteredIds() const {
Topics registered_topics;
for (const auto& handler_to_topic : handler_name_to_topics_map_) {
......@@ -130,12 +188,85 @@ Topics InvalidatorRegistrarWithMemory::GetAllRegisteredIds() const {
return registered_topics;
}
void InvalidatorRegistrarWithMemory::DispatchInvalidationsToHandlers(
const TopicInvalidationMap& invalidation_map) {
DCHECK(thread_checker_.CalledOnValidThread());
// If we have no handlers, there's nothing to do.
if (!handlers_.might_have_observers()) {
return;
}
for (const auto& handler_and_topics : handler_to_topics_map_) {
TopicInvalidationMap to_emit =
invalidation_map.GetSubsetWithTopics(handler_and_topics.second);
ObjectIdInvalidationMap object_ids_to_emit;
std::vector<syncer::Invalidation> invalidations;
to_emit.GetAllInvalidations(&invalidations);
for (const auto& invalidation : invalidations) {
object_ids_to_emit.Insert(invalidation);
}
if (!to_emit.Empty()) {
handler_and_topics.first->OnIncomingInvalidation(object_ids_to_emit);
}
}
}
void InvalidatorRegistrarWithMemory::UpdateInvalidatorState(
InvalidatorState state) {
DCHECK(thread_checker_.CalledOnValidThread());
DVLOG(1) << "New invalidator state: " << InvalidatorStateToString(state_)
<< " -> " << InvalidatorStateToString(state);
state_ = state;
for (auto& observer : handlers_)
observer.OnInvalidatorStateChange(state);
}
InvalidatorState InvalidatorRegistrarWithMemory::GetInvalidatorState() const {
DCHECK(thread_checker_.CalledOnValidThread());
return state_;
}
void InvalidatorRegistrarWithMemory::UpdateInvalidatorId(
const std::string& id) {
for (auto& observer : handlers_)
observer.OnInvalidatorClientIdChange(id);
}
std::map<std::string, Topics>
InvalidatorRegistrarWithMemory::GetSanitizedHandlersIdsMap() {
DCHECK(thread_checker_.CalledOnValidThread());
std::map<std::string, Topics> clean_handlers_to_topics;
for (const auto& handler_and_topics : handler_to_topics_map_)
clean_handlers_to_topics[handler_and_topics.first->GetOwnerName()] =
Topics(handler_and_topics.second);
return clean_handlers_to_topics;
}
void InvalidatorRegistrarWithMemory::RequestDetailedStatus(
base::RepeatingCallback<void(const base::DictionaryValue&)> callback)
const {
callback.Run(CollectDebugData());
}
bool InvalidatorRegistrarWithMemory::HasDuplicateTopicRegistration(
InvalidationHandler* handler,
const Topics& topics) const {
for (const auto& handler_and_topics : handler_to_topics_map_) {
if (handler_and_topics.first == handler) {
continue;
}
if (auto* duplicate =
FindMatchingTopic(topics, handler_and_topics.second)) {
DVLOG(1) << "Duplicate registration: trying to register " << *duplicate
<< " for " << handler << " when it's already registered for "
<< handler_and_topics.first;
return true;
}
}
return false;
}
base::DictionaryValue InvalidatorRegistrarWithMemory::CollectDebugData() const {
base::DictionaryValue return_value;
return_value.SetInteger("InvalidatorRegistrarWithMemory.Handlers",
......
......@@ -10,10 +10,10 @@
#include "base/macros.h"
#include "base/observer_list.h"
#include "base/threading/thread_checker.h"
#include "components/invalidation/impl/invalidator_registrar.h"
#include "components/invalidation/public/invalidation_export.h"
#include "components/invalidation/public/invalidation_handler.h"
#include "components/invalidation/public/invalidation_util.h"
#include "components/invalidation/public/topic_invalidation_map.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
......@@ -27,15 +27,14 @@ namespace syncer {
// keep track of registered handlers and which object ID registrations are
// associated with which handlers, so implementors can just reuse the logic
// here to dispatch invalidations and other interesting notifications.
class INVALIDATION_EXPORT InvalidatorRegistrarWithMemory
: public InvalidatorRegistrar {
class INVALIDATION_EXPORT InvalidatorRegistrarWithMemory {
public:
InvalidatorRegistrarWithMemory(PrefService* local_state,
const std::string& sender_id,
bool migrate_old_prefs);
// It is an error to have registered handlers on destruction.
~InvalidatorRegistrarWithMemory() override;
~InvalidatorRegistrarWithMemory();
// RegisterProfilePrefs and RegisterPrefs register the same prefs, because on
// device level (sign in screen, device local account) we spin up separate
......@@ -46,27 +45,85 @@ class INVALIDATION_EXPORT InvalidatorRegistrarWithMemory
static void RegisterProfilePrefs(PrefRegistrySimple* registry);
static void RegisterPrefs(PrefRegistrySimple* registry);
// Starts sending notifications to |handler|. |handler| must not be nullptr,
// and it must not already be registered.
void RegisterHandler(InvalidationHandler* handler);
// Stops sending notifications to |handler|. |handler| must not be nullptr,
// and it must already be registered. Note that this doesn't unregister the
// topics associated with |handler| from the server.
void UnregisterHandler(InvalidationHandler* handler);
bool IsHandlerRegistered(const InvalidationHandler* handler) const;
// Updates the set of topics associated with |handler|. |handler| must
// not be NULL, and must already be registered. A topic must be registered
// for at most one handler. If topic is already registered function returns
// false.
// not be nullptr, and must already be registered. A topic must be registered
// for at most one handler. If any of the |topics| is already registered
// to a different handler, returns false.
bool UpdateRegisteredTopics(InvalidationHandler* handler,
const Topics& topics) override WARN_UNUSED_RESULT;
const Topics& topics) WARN_UNUSED_RESULT;
Topics GetRegisteredTopics(InvalidationHandler* handler) const;
// Returns the set of all IDs that are registered to some handler (even
// handlers that have been unregistered).
Topics GetAllRegisteredIds() const override;
// TODO(treib): Rename "Ids" to "Topics".
Topics GetAllRegisteredIds() const;
// Sorts incoming invalidations into a bucket for each handler and then
// dispatches the batched invalidations to the corresponding handler.
// Invalidations for topics with no corresponding handler are dropped, as are
// invalidations for handlers that are not added.
void DispatchInvalidationsToHandlers(
const TopicInvalidationMap& invalidation_map);
// Updates the invalidator state to the given one and then notifies
// all handlers. Note that the order is important; handlers that
// call GetInvalidatorState() when notified will see the new state.
void UpdateInvalidatorState(InvalidatorState state);
// Returns the current invalidator state. When called from within
// InvalidationHandler::OnInvalidatorStateChange(), this returns the
// updated state.
InvalidatorState GetInvalidatorState() const;
// Updates the invalidator id to the given one and then notifies
// all handlers.
void UpdateInvalidatorId(const std::string& id);
// Gets a new map for the name of invalidator handlers and their
// objects id. This is used by the InvalidatorLogger to be able
// to display every registered handler and its topics.
// TODO(treib): Rename "Ids" to "Topics".
std::map<std::string, Topics> GetSanitizedHandlersIdsMap();
void RequestDetailedStatus(
base::RepeatingCallback<void(const base::DictionaryValue&)> callback)
const;
private:
// Checks if any of the |topics| is already registered for a *different*
// handler than the given one.
bool HasDuplicateTopicRegistration(InvalidationHandler* handler,
const Topics& topics) const;
// Generate a Dictionary with all the debugging information.
base::DictionaryValue CollectDebugData() const;
// TODO(treib): Switch to SequenceChecker.
base::ThreadChecker thread_checker_;
base::ObserverList<InvalidationHandler, true>::Unchecked handlers_;
// Note: When a handler is unregistered, its entry is removed from
// |handler_to_topics_map_| but NOT from |handler_name_to_topics_map_|.
std::map<InvalidationHandler*, Topics> handler_to_topics_map_;
std::map<std::string, Topics> handler_name_to_topics_map_;
PrefService* local_state_;
InvalidatorState state_;
// This can be either a regular (Profile-attached) PrefService or the local
// state PrefService.
PrefService* const local_state_;
const std::string sender_id_;
DISALLOW_COPY_AND_ASSIGN(InvalidatorRegistrarWithMemory);
......
......@@ -26,7 +26,7 @@ class RegistrarInvalidator : public Invalidator {
}
~RegistrarInvalidator() override {}
InvalidatorRegistrar* GetRegistrar() { return registrar_.get(); }
InvalidatorRegistrarWithMemory* GetRegistrar() { return registrar_.get(); }
// Invalidator implementation.
void RegisterHandler(InvalidationHandler* handler) override {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment