Commit ac2be120 authored by Maksim Moskvitin's avatar Maksim Moskvitin Committed by Commit Bot

[Invalidations] Use Topic API in InvalidationLogger

This CL is a part of ObjectID -> Topic API migration. It replaces
ObjectID with Topic in InvalidationLogger and its dependencies.

There should be only one behavioral change: chrome://invalidations page
would expose 0 as an ObjectID::source for any subscription. It's not a
real change, because |source| was already deprecated and the same value
used. In the future chrome://invalidations should be updated to use
Topic instead of ObjectID.

chrome.invalidations.logInvalidations now receives
TopicInvalidationMap::ToValue() instead of
ObjectIDInalidationMap::ToValue(), but their ToValue() implementations
are the same, so there should be no changes.

Bug: 1029698
Change-Id: I17f36f7c43b664185bf87da4edb8d7d99a0afec9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2074877
Commit-Queue: Maksim Moskvitin <mmoskvitin@google.com>
Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Cr-Commit-Position: refs/heads/master@{#746338}
parent be8daa80
...@@ -14,15 +14,13 @@ ...@@ -14,15 +14,13 @@
#include "components/invalidation/impl/profile_invalidation_provider.h" #include "components/invalidation/impl/profile_invalidation_provider.h"
#include "components/invalidation/public/invalidation_handler.h" #include "components/invalidation/public/invalidation_handler.h"
#include "components/invalidation/public/invalidation_service.h" #include "components/invalidation/public/invalidation_service.h"
#include "components/invalidation/public/topic_invalidation_map.h"
#include "content/public/browser/web_ui.h" #include "content/public/browser/web_ui.h"
namespace invalidation { namespace invalidation {
class InvalidationLogger; class InvalidationLogger;
} // namespace invalidation } // namespace invalidation
namespace syncer {
class ObjectIdInvalidationMap;
} // namespace syncer
namespace { namespace {
...@@ -100,15 +98,19 @@ void InvalidationsMessageHandler::OnStateChange( ...@@ -100,15 +98,19 @@ void InvalidationsMessageHandler::OnStateChange(
base::Value(last_changed_timestamp.ToJsTime())); base::Value(last_changed_timestamp.ToJsTime()));
} }
void InvalidationsMessageHandler::OnUpdateIds( void InvalidationsMessageHandler::OnUpdatedTopics(
const std::string& handler_name, const std::string& handler_name,
const syncer::ObjectIdCountMap& ids) { const syncer::TopicCountMap& topics) {
base::ListValue list_of_objects; base::ListValue list_of_objects;
for (auto it = ids.begin(); it != ids.end(); ++it) { for (const auto& topic_item : topics) {
std::unique_ptr<base::DictionaryValue> dic(new base::DictionaryValue()); std::unique_ptr<base::DictionaryValue> dic(new base::DictionaryValue());
dic->SetString("name", (it->first).name()); dic->SetString("name", topic_item.first);
dic->SetInteger("source", (it->first).source()); // TODO(crbug.com/1056181): source has been deprecated and after Topic->
dic->SetInteger("totalCount", it->second); // ObjectID refactoring completely makes no sense. It needs to be cleaned
// up together with other ObjectID references in js counterpart. Pass 0
// temporary to avoid changes in js counterpart.
dic->SetInteger("source", 0);
dic->SetInteger("totalCount", topic_item.second);
list_of_objects.Append(std::move(dic)); list_of_objects.Append(std::move(dic));
} }
web_ui()->CallJavascriptFunctionUnsafe("chrome.invalidations.updateIds", web_ui()->CallJavascriptFunctionUnsafe("chrome.invalidations.updateIds",
...@@ -119,7 +121,7 @@ void InvalidationsMessageHandler::OnDebugMessage( ...@@ -119,7 +121,7 @@ void InvalidationsMessageHandler::OnDebugMessage(
const base::DictionaryValue& details) {} const base::DictionaryValue& details) {}
void InvalidationsMessageHandler::OnInvalidation( void InvalidationsMessageHandler::OnInvalidation(
const syncer::ObjectIdInvalidationMap& new_invalidations) { const syncer::TopicInvalidationMap& new_invalidations) {
std::unique_ptr<base::ListValue> invalidations_list = std::unique_ptr<base::ListValue> invalidations_list =
new_invalidations.ToValue(); new_invalidations.ToValue();
web_ui()->CallJavascriptFunctionUnsafe( web_ui()->CallJavascriptFunctionUnsafe(
......
...@@ -32,11 +32,11 @@ class InvalidationsMessageHandler ...@@ -32,11 +32,11 @@ class InvalidationsMessageHandler
const std::multiset<std::string>& registered_handlers) override; const std::multiset<std::string>& registered_handlers) override;
void OnStateChange(const syncer::InvalidatorState& new_state, void OnStateChange(const syncer::InvalidatorState& new_state,
const base::Time& last_change_timestamp) override; const base::Time& last_change_timestamp) override;
void OnUpdateIds(const std::string& handler_name, void OnUpdatedTopics(const std::string& handler_name,
const syncer::ObjectIdCountMap& ids_set) override; const syncer::TopicCountMap& topics_counts) override;
void OnDebugMessage(const base::DictionaryValue& details) override; void OnDebugMessage(const base::DictionaryValue& details) override;
void OnInvalidation( void OnInvalidation(
const syncer::ObjectIdInvalidationMap& new_invalidations) override; const syncer::TopicInvalidationMap& new_invalidations) override;
void OnDetailedStatus(const base::DictionaryValue& network_details) override; void OnDetailedStatus(const base::DictionaryValue& network_details) override;
// Implementation of WebUIMessageHandler. // Implementation of WebUIMessageHandler.
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include "base/callback.h" #include "base/callback.h"
#include "base/logging.h" #include "base/logging.h"
#include "components/invalidation/public/invalidation_util.h" #include "components/invalidation/public/invalidation_util.h"
#include "components/invalidation/public/object_id_invalidation_map.h"
#include "components/invalidation/public/topic_invalidation_map.h" #include "components/invalidation/public/topic_invalidation_map.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "google/cacheinvalidation/include/types.h" #include "google/cacheinvalidation/include/types.h"
......
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
#include "components/invalidation/impl/per_user_topic_subscription_manager.h" #include "components/invalidation/impl/per_user_topic_subscription_manager.h"
#include "components/invalidation/public/invalidation_util.h" #include "components/invalidation/public/invalidation_util.h"
#include "components/invalidation/public/invalidator_state.h" #include "components/invalidation/public/invalidator_state.h"
#include "components/invalidation/public/object_id_invalidation_map.h"
#include "components/invalidation/public/topic_invalidation_map.h" #include "components/invalidation/public/topic_invalidation_map.h"
#include "services/data_decoder/public/cpp/test_support/in_process_data_decoder.h" #include "services/data_decoder/public/cpp/test_support/in_process_data_decoder.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
......
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
#include "components/invalidation/impl/fcm_network_handler.h" #include "components/invalidation/impl/fcm_network_handler.h"
#include "components/invalidation/impl/invalidation_prefs.h" #include "components/invalidation/impl/invalidation_prefs.h"
#include "components/invalidation/public/invalidator_state.h" #include "components/invalidation/public/invalidator_state.h"
#include "components/invalidation/public/object_id_invalidation_map.h"
#include "components/invalidation/public/topic_invalidation_map.h" #include "components/invalidation/public/topic_invalidation_map.h"
#include "components/prefs/scoped_user_pref_update.h" #include "components/prefs/scoped_user_pref_update.h"
...@@ -104,7 +103,7 @@ bool FCMInvalidationServiceBase::UpdateInterestedTopics( ...@@ -104,7 +103,7 @@ bool FCMInvalidationServiceBase::UpdateInterestedTopics(
if (!invalidator_registrar_.UpdateRegisteredTopics(handler, topic_map)) if (!invalidator_registrar_.UpdateRegisteredTopics(handler, topic_map))
return false; return false;
DoUpdateSubscribedTopicsIfNeeded(); DoUpdateSubscribedTopicsIfNeeded();
logger_.OnUpdateTopics(invalidator_registrar_.GetHandlerNameToTopicsMap()); logger_.OnUpdatedTopics(invalidator_registrar_.GetHandlerNameToTopicsMap());
return true; return true;
} }
...@@ -151,8 +150,7 @@ void FCMInvalidationServiceBase::OnInvalidate( ...@@ -151,8 +150,7 @@ void FCMInvalidationServiceBase::OnInvalidate(
const syncer::TopicInvalidationMap& invalidation_map) { const syncer::TopicInvalidationMap& invalidation_map) {
invalidator_registrar_.DispatchInvalidationsToHandlers(invalidation_map); invalidator_registrar_.DispatchInvalidationsToHandlers(invalidation_map);
logger_.OnInvalidation( logger_.OnInvalidation(invalidation_map);
ConvertTopicInvalidationMapToObjectIdInvalidationMap(invalidation_map));
} }
void FCMInvalidationServiceBase::OnInvalidatorStateChange( void FCMInvalidationServiceBase::OnInvalidatorStateChange(
......
...@@ -8,9 +8,9 @@ ...@@ -8,9 +8,9 @@
#include "components/invalidation/impl/invalidation_logger_observer.h" #include "components/invalidation/impl/invalidation_logger_observer.h"
#include "components/invalidation/public/invalidation_handler.h" #include "components/invalidation/public/invalidation_handler.h"
#include "components/invalidation/public/invalidation_util.h" #include "components/invalidation/public/invalidation_util.h"
#include "components/invalidation/public/topic_invalidation_map.h"
namespace invalidation { namespace invalidation {
class InvalidationLoggerObserver;
InvalidationLogger::InvalidationLogger() InvalidationLogger::InvalidationLogger()
: last_invalidator_state_(syncer::TRANSIENT_INVALIDATION_ERROR), : last_invalidator_state_(syncer::TRANSIENT_INVALIDATION_ERROR),
...@@ -53,35 +53,25 @@ void InvalidationLogger::EmitState() { ...@@ -53,35 +53,25 @@ void InvalidationLogger::EmitState() {
} }
} }
void InvalidationLogger::OnUpdateTopics( void InvalidationLogger::OnUpdatedTopics(
std::map<std::string, syncer::Topics> updated_topics) { std::map<std::string, syncer::Topics> handler_updated_topics_map) {
for (const auto& updated_topic : updated_topics) { for (const auto& updated_topics : handler_updated_topics_map) {
latest_ids_[updated_topic.first] = handler_latest_topics_map_[updated_topics.first] = updated_topics.second;
syncer::ConvertTopicsToIds(updated_topic.second);
} }
EmitUpdatedIds(); EmitUpdatedTopics();
} }
void InvalidationLogger::OnUpdateIds( void InvalidationLogger::EmitUpdatedTopics() {
std::map<std::string, syncer::ObjectIdSet> updated_ids) { for (const auto& handler_name_and_topics : handler_latest_topics_map_) {
for (std::map<std::string, syncer::ObjectIdSet>::const_iterator it = syncer::TopicCountMap per_handler_invalidation_count;
updated_ids.begin(); it != updated_ids.end(); ++it) { for (const auto& topic_item : handler_name_and_topics.second) {
latest_ids_[it->first] = syncer::ObjectIdSet(it->second); const syncer::Topic& topic = topic_item.first;
per_handler_invalidation_count[topic] = invalidation_count_[topic];
} }
EmitUpdatedIds(); for (auto& observer : observer_list_) {
} observer.OnUpdatedTopics(handler_name_and_topics.first,
per_handler_invalidation_count);
void InvalidationLogger::EmitUpdatedIds() {
for (std::map<std::string, syncer::ObjectIdSet>::const_iterator it =
latest_ids_.begin(); it != latest_ids_.end(); ++it) {
const syncer::ObjectIdSet& object_ids_for_handler = it->second;
syncer::ObjectIdCountMap per_object_invalidation_count;
for (auto oid_it = object_ids_for_handler.begin();
oid_it != object_ids_for_handler.end(); ++oid_it) {
per_object_invalidation_count[*oid_it] = invalidation_count_[*oid_it];
} }
for (auto& observer : observer_list_)
observer.OnUpdateIds(it->first, per_object_invalidation_count);
} }
} }
...@@ -91,22 +81,17 @@ void InvalidationLogger::OnDebugMessage(const base::DictionaryValue& details) { ...@@ -91,22 +81,17 @@ void InvalidationLogger::OnDebugMessage(const base::DictionaryValue& details) {
} }
void InvalidationLogger::OnInvalidation( void InvalidationLogger::OnInvalidation(
const syncer::ObjectIdInvalidationMap& details) { const syncer::TopicInvalidationMap& invalidations) {
std::vector<syncer::Invalidation> internal_invalidations; for (const auto& topic : invalidations.GetTopics()) {
details.GetAllInvalidations(&internal_invalidations); invalidation_count_[topic] += invalidations.ForTopic(topic).GetSize();
for (std::vector<syncer::Invalidation>::const_iterator it =
internal_invalidations.begin();
it != internal_invalidations.end();
++it) {
invalidation_count_[it->object_id()]++;
} }
for (auto& observer : observer_list_) for (auto& observer : observer_list_)
observer.OnInvalidation(details); observer.OnInvalidation(invalidations);
} }
void InvalidationLogger::EmitContent() { void InvalidationLogger::EmitContent() {
EmitState(); EmitState();
EmitUpdatedIds(); EmitUpdatedTopics();
EmitRegisteredHandlers(); EmitRegisteredHandlers();
} }
......
...@@ -18,7 +18,7 @@ class DictionaryValue; ...@@ -18,7 +18,7 @@ class DictionaryValue;
} // namespace base } // namespace base
namespace syncer { namespace syncer {
class ObjectIdInvalidationMap; class TopicInvalidationMap;
} // namespace syncer } // namespace syncer
namespace invalidation { namespace invalidation {
...@@ -26,17 +26,16 @@ namespace invalidation { ...@@ -26,17 +26,16 @@ namespace invalidation {
class InvalidationLoggerObserver; class InvalidationLoggerObserver;
// This class is in charge of logging invalidation-related information. // This class is in charge of logging invalidation-related information.
// It is used store the state of the InvalidatorService that owns this object // It is used store the state of the InvalidationService that owns this object
// and then rebroadcast it to observers than can display it accordingly // and then rebroadcast it to observers than can display it accordingly
// (like a debugging page). This class only stores lightweight state, as in // (like a debugging page). This class only stores lightweight state, as in
// which services are registered and listening for certain objects, and the // which services are registered and listening for certain topics, and the
// status of the InvalidatorService (in order not to increase unnecessary // status of the InvalidationService (in order not to increase unnecessary
// memory usage). // memory usage).
// //
// Observers can be registered and will be called to be notified of any // Observers can be registered and will be called to be notified of any
// status change immediatly. They can log there the history of what messages // status change immediatly. They can log there the history of what messages
// they receive. // they receive.
class InvalidationLogger { class InvalidationLogger {
public: public:
...@@ -48,10 +47,10 @@ class InvalidationLogger { ...@@ -48,10 +47,10 @@ class InvalidationLogger {
void OnRegistration(const std::string& details); void OnRegistration(const std::string& details);
void OnUnregistration(const std::string& details); void OnUnregistration(const std::string& details);
void OnStateChange(const syncer::InvalidatorState& new_state); void OnStateChange(const syncer::InvalidatorState& new_state);
void OnUpdateIds(std::map<std::string, syncer::ObjectIdSet> updated_ids); void OnUpdatedTopics(
void OnUpdateTopics(std::map<std::string, syncer::Topics> updated_topics); std::map<std::string, syncer::Topics> handler_updated_topics_map);
void OnDebugMessage(const base::DictionaryValue& details); void OnDebugMessage(const base::DictionaryValue& details);
void OnInvalidation(const syncer::ObjectIdInvalidationMap& details); void OnInvalidation(const syncer::TopicInvalidationMap& invalidations);
// Triggers messages to be sent to the Observers to provide them with // Triggers messages to be sent to the Observers to provide them with
// the current state of the logging. // the current state of the logging.
...@@ -67,9 +66,9 @@ class InvalidationLogger { ...@@ -67,9 +66,9 @@ class InvalidationLogger {
// Send to every Observer a OnStateChange event with the latest state. // Send to every Observer a OnStateChange event with the latest state.
void EmitState(); void EmitState();
// Send to every Observer many OnUpdateIds events, each with one registrar // Send to every Observer many OnUpdatedTopics() events, each with one
// and every objectId it currently has registered. // handler and every Topic it currently has registered.
void EmitUpdatedIds(); void EmitUpdatedTopics();
// Send to every Observer a vector with the all the current registered // Send to every Observer a vector with the all the current registered
// handlers. // handlers.
...@@ -84,14 +83,16 @@ class InvalidationLogger { ...@@ -84,14 +83,16 @@ class InvalidationLogger {
// The map that contains every object id that is currently registered // The map that contains every object id that is currently registered
// and its owner. // and its owner.
std::map<std::string, syncer::ObjectIdSet> latest_ids_; std::map<std::string, syncer::Topics> handler_latest_topics_map_;
// The map that counts how many invalidations per objectId there has been. // The map that counts how many invalidations per Topic there has been.
syncer::ObjectIdCountMap invalidation_count_; syncer::TopicCountMap invalidation_count_;
// The name of all invalidatorHandler registered (note that this is not // The name of all invalidatorHandler registered (note that this is not
// necessarily the same as the keys of latest_ids_, because they might // necessarily the same as the keys of latest_topics_, because they might
// have not registered any object id). // have not registered any Topic).
// TODO(crbug.com/1049591): it should be std::set, once handlers names are
// unique.
std::multiset<std::string> registered_handlers_; std::multiset<std::string> registered_handlers_;
DISALLOW_COPY_AND_ASSIGN(InvalidationLogger); DISALLOW_COPY_AND_ASSIGN(InvalidationLogger);
......
...@@ -7,32 +7,30 @@ ...@@ -7,32 +7,30 @@
#include "components/invalidation/public/invalidation_util.h" #include "components/invalidation/public/invalidation_util.h"
#include "components/invalidation/public/invalidator_state.h" #include "components/invalidation/public/invalidator_state.h"
#include "components/invalidation/public/object_id_invalidation_map.h"
namespace base { namespace base {
class DictionaryValue; class DictionaryValue;
} // namespace base } // namespace base
namespace syncer { namespace syncer {
class ObjectIdInvalidationMap; class TopicInvalidationMap;
} // namespace syncer } // namespace syncer
namespace invalidation { namespace invalidation {
// This class provides the possibilty to register as an observer for the // This class provides the possibility to register as an observer for the
// InvalidationLogger notifications whenever an InvalidatorService changes // InvalidationLogger notifications whenever an InvalidationService changes
// its internal state. // its internal state.
// (i.e. A new registration, a new invalidation, a TICL/GCM state change) // (i.e. A new registration, a new invalidation, a GCM state change)
class InvalidationLoggerObserver { class InvalidationLoggerObserver {
public: public:
virtual void OnRegistrationChange( virtual void OnRegistrationChange(
const std::multiset<std::string>& registered_handlers) = 0; const std::multiset<std::string>& registered_handlers) = 0;
virtual void OnStateChange(const syncer::InvalidatorState& new_state, virtual void OnStateChange(const syncer::InvalidatorState& new_state,
const base::Time& last_change_timestamp) = 0; const base::Time& last_change_timestamp) = 0;
virtual void OnUpdateIds(const std::string& handler_name, virtual void OnUpdatedTopics(const std::string& handler_name,
const syncer::ObjectIdCountMap& details) = 0; const syncer::TopicCountMap& details) = 0;
virtual void OnDebugMessage(const base::DictionaryValue& details) = 0; virtual void OnDebugMessage(const base::DictionaryValue& details) = 0;
virtual void OnInvalidation( virtual void OnInvalidation(const syncer::TopicInvalidationMap& details) = 0;
const syncer::ObjectIdInvalidationMap& details) = 0;
virtual void OnDetailedStatus(const base::DictionaryValue& details) = 0; virtual void OnDetailedStatus(const base::DictionaryValue& details) = 0;
protected: protected:
......
...@@ -3,8 +3,10 @@ ...@@ -3,8 +3,10 @@
// found in the LICENSE file. // found in the LICENSE file.
#include "components/invalidation/impl/invalidation_logger.h" #include "components/invalidation/impl/invalidation_logger.h"
#include "components/invalidation/impl/invalidation_logger_observer.h"
#include "components/invalidation/impl/invalidation_logger_observer.h"
#include "components/invalidation/public/invalidation.h"
#include "components/invalidation/public/topic_invalidation_map.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
namespace invalidation { namespace invalidation {
...@@ -20,7 +22,7 @@ class InvalidationLoggerObserverTest : public InvalidationLoggerObserver { ...@@ -20,7 +22,7 @@ class InvalidationLoggerObserverTest : public InvalidationLoggerObserver {
debug_message_received = false; debug_message_received = false;
invalidation_received = false; invalidation_received = false;
detailed_status_received = false; detailed_status_received = false;
update_id_replicated = std::map<std::string, syncer::ObjectIdCountMap>(); updated_topics_replicated = std::map<std::string, syncer::TopicCountMap>();
registered_handlers = std::multiset<std::string>(); registered_handlers = std::multiset<std::string>();
} }
...@@ -35,10 +37,10 @@ class InvalidationLoggerObserverTest : public InvalidationLoggerObserver { ...@@ -35,10 +37,10 @@ class InvalidationLoggerObserverTest : public InvalidationLoggerObserver {
state_received = true; state_received = true;
} }
void OnUpdateIds(const std::string& handler, void OnUpdatedTopics(const std::string& handler,
const syncer::ObjectIdCountMap& details) override { const syncer::TopicCountMap& topics_counts) override {
update_id_received = true; update_id_received = true;
update_id_replicated[handler] = details; updated_topics_replicated[handler] = topics_counts;
} }
void OnDebugMessage(const base::DictionaryValue& details) override { void OnDebugMessage(const base::DictionaryValue& details) override {
...@@ -46,7 +48,7 @@ class InvalidationLoggerObserverTest : public InvalidationLoggerObserver { ...@@ -46,7 +48,7 @@ class InvalidationLoggerObserverTest : public InvalidationLoggerObserver {
} }
void OnInvalidation( void OnInvalidation(
const syncer::ObjectIdInvalidationMap& new_invalidations) override { const syncer::TopicInvalidationMap& new_invalidations) override {
invalidation_received = true; invalidation_received = true;
} }
...@@ -60,7 +62,7 @@ class InvalidationLoggerObserverTest : public InvalidationLoggerObserver { ...@@ -60,7 +62,7 @@ class InvalidationLoggerObserverTest : public InvalidationLoggerObserver {
bool debug_message_received; bool debug_message_received;
bool invalidation_received; bool invalidation_received;
bool detailed_status_received; bool detailed_status_received;
std::map<std::string, syncer::ObjectIdCountMap> update_id_replicated; std::map<std::string, syncer::TopicCountMap> updated_topics_replicated;
std::multiset<std::string> registered_handlers; std::multiset<std::string> registered_handlers;
}; };
...@@ -81,7 +83,7 @@ TEST(InvalidationLoggerTest, TestCallbacks) { ...@@ -81,7 +83,7 @@ TEST(InvalidationLoggerTest, TestCallbacks) {
observer_test.ResetStates(); observer_test.ResetStates();
log.OnInvalidation(syncer::ObjectIdInvalidationMap()); log.OnInvalidation(syncer::TopicInvalidationMap());
EXPECT_TRUE(observer_test.invalidation_received); EXPECT_TRUE(observer_test.invalidation_received);
EXPECT_FALSE(observer_test.state_received); EXPECT_FALSE(observer_test.state_received);
EXPECT_FALSE(observer_test.update_id_received); EXPECT_FALSE(observer_test.update_id_received);
...@@ -102,12 +104,12 @@ TEST(InvalidationLoggerTest, TestReleaseOfObserver) { ...@@ -102,12 +104,12 @@ TEST(InvalidationLoggerTest, TestReleaseOfObserver) {
log.RegisterObserver(&observer_test); log.RegisterObserver(&observer_test);
log.UnregisterObserver(&observer_test); log.UnregisterObserver(&observer_test);
log.OnInvalidation(syncer::ObjectIdInvalidationMap()); log.OnInvalidation(syncer::TopicInvalidationMap());
log.OnStateChange(syncer::INVALIDATIONS_ENABLED); log.OnStateChange(syncer::INVALIDATIONS_ENABLED);
log.OnRegistration(std::string()); log.OnRegistration(std::string());
log.OnUnregistration(std::string()); log.OnUnregistration(std::string());
log.OnDebugMessage(base::DictionaryValue()); log.OnDebugMessage(base::DictionaryValue());
log.OnUpdateIds(std::map<std::string, syncer::ObjectIdSet>()); log.OnUpdatedTopics(std::map<std::string, syncer::Topics>());
EXPECT_FALSE(observer_test.registration_change_received); EXPECT_FALSE(observer_test.registration_change_received);
EXPECT_FALSE(observer_test.update_id_received); EXPECT_FALSE(observer_test.update_id_received);
EXPECT_FALSE(observer_test.invalidation_received); EXPECT_FALSE(observer_test.invalidation_received);
...@@ -135,9 +137,9 @@ TEST(InvalidationLoggerTest, TestEmitContent) { ...@@ -135,9 +137,9 @@ TEST(InvalidationLoggerTest, TestEmitContent) {
EXPECT_FALSE(observer_test.detailed_status_received); EXPECT_FALSE(observer_test.detailed_status_received);
observer_test.ResetStates(); observer_test.ResetStates();
std::map<std::string, syncer::ObjectIdSet> test_map; std::map<std::string, syncer::Topics> test_map;
test_map["Test"] = syncer::ObjectIdSet(); test_map["Test"] = syncer::Topics();
log.OnUpdateIds(test_map); log.OnUpdatedTopics(test_map);
EXPECT_TRUE(observer_test.update_id_received); EXPECT_TRUE(observer_test.update_id_received);
observer_test.ResetStates(); observer_test.ResetStates();
...@@ -158,60 +160,60 @@ TEST(InvalidationLoggerTest, TestEmitContent) { ...@@ -158,60 +160,60 @@ TEST(InvalidationLoggerTest, TestEmitContent) {
TEST(InvalidationLoggerTest, TestUpdateIdsMap) { TEST(InvalidationLoggerTest, TestUpdateIdsMap) {
InvalidationLogger log; InvalidationLogger log;
InvalidationLoggerObserverTest observer_test; InvalidationLoggerObserverTest observer_test;
std::map<std::string, syncer::ObjectIdSet> send_test_map; std::map<std::string, syncer::Topics> send_test_map;
std::map<std::string, syncer::ObjectIdCountMap> expected_received_map; std::map<std::string, syncer::TopicCountMap> expected_received_map;
log.RegisterObserver(&observer_test); log.RegisterObserver(&observer_test);
syncer::ObjectIdSet sync_set_A; syncer::Topics topics_a;
syncer::ObjectIdCountMap counted_sync_set_A; syncer::TopicCountMap topics_counts_a;
ObjectId o1(1000, "DataType1"); syncer::Topic t1 = "Topic1";
sync_set_A.insert(o1); topics_a.emplace(t1, syncer::TopicMetadata{/*is_public=*/false});
counted_sync_set_A[o1] = 0; topics_counts_a[t1] = 0;
ObjectId o2(1000, "DataType2"); syncer::Topic t2 = "Topic2";
sync_set_A.insert(o2); topics_a.emplace(t2, syncer::TopicMetadata{/*is_public=*/false});
counted_sync_set_A[o2] = 0; topics_counts_a[t2] = 0;
syncer::ObjectIdSet sync_set_B; syncer::Topics topics_b;
syncer::ObjectIdCountMap counted_sync_set_B; syncer::TopicCountMap topics_counts_b;
ObjectId o3(1020, "DataTypeA"); syncer::Topic t3 = "Topic3";
sync_set_B.insert(o3); topics_b.emplace(t3, syncer::TopicMetadata{/*is_public=*/false});
counted_sync_set_B[o3] = 0; topics_counts_b[t3] = 0;
send_test_map["TestA"] = sync_set_A; send_test_map["TestA"] = topics_a;
send_test_map["TestB"] = sync_set_B; send_test_map["TestB"] = topics_b;
expected_received_map["TestA"] = counted_sync_set_A; expected_received_map["TestA"] = topics_counts_a;
expected_received_map["TestB"] = counted_sync_set_B; expected_received_map["TestB"] = topics_counts_b;
// Send the objects ids registered for the two different handler name. // Send the topics registered for the two different handler name.
log.OnUpdateIds(send_test_map); log.OnUpdatedTopics(send_test_map);
EXPECT_EQ(expected_received_map, observer_test.update_id_replicated); EXPECT_EQ(expected_received_map, observer_test.updated_topics_replicated);
syncer::ObjectIdSet sync_set_B2; syncer::Topics topics_b2;
syncer::ObjectIdCountMap counted_sync_set_B2; syncer::TopicCountMap topics_counts_b2;
ObjectId o4(1020, "DataTypeF"); syncer::Topic t4 = "Topic4";
sync_set_B2.insert(o4); topics_b2.emplace(t4, syncer::TopicMetadata{/*is_public=*/false});
counted_sync_set_B2[o4] = 0; topics_counts_b2[t4] = 0;
ObjectId o5(1020, "DataTypeG"); syncer::Topic t5 = "Topic5";
sync_set_B2.insert(o5); topics_b2.emplace(t5, syncer::TopicMetadata{/*is_public=*/false});
counted_sync_set_B2[o5] = 0; topics_counts_b2[t5] = 0;
send_test_map["TestB"] = sync_set_B2; send_test_map["TestB"] = topics_b2;
expected_received_map["TestB"] = counted_sync_set_B2; expected_received_map["TestB"] = topics_counts_b2;
// Test now that if we replace the registered datatypes for TestB, the // Test now that if we replace the registered topics for TestB, the
// original don't show up again. // original don't show up again.
log.OnUpdateIds(send_test_map); log.OnUpdatedTopics(send_test_map);
EXPECT_EQ(expected_received_map, observer_test.update_id_replicated); EXPECT_EQ(expected_received_map, observer_test.updated_topics_replicated);
// The emit content should return the same map too. // The emit content should return the same map too.
observer_test.ResetStates(); observer_test.ResetStates();
log.EmitContent(); log.EmitContent();
EXPECT_EQ(expected_received_map, observer_test.update_id_replicated); EXPECT_EQ(expected_received_map, observer_test.updated_topics_replicated);
log.UnregisterObserver(&observer_test); log.UnregisterObserver(&observer_test);
} }
...@@ -222,36 +224,35 @@ TEST(InvalidationLoggerTest, TestInvalidtionsTotalCount) { ...@@ -222,36 +224,35 @@ TEST(InvalidationLoggerTest, TestInvalidtionsTotalCount) {
InvalidationLoggerObserverTest observer_test; InvalidationLoggerObserverTest observer_test;
log.RegisterObserver(&observer_test); log.RegisterObserver(&observer_test);
std::map<std::string, syncer::ObjectIdSet> send_test_map; std::map<std::string, syncer::Topics> send_test_map;
std::map<std::string, syncer::ObjectIdCountMap> expected_received_map; std::map<std::string, syncer::TopicCountMap> expected_received_map;
syncer::ObjectIdSet sync_set; syncer::Topics topics;
syncer::ObjectIdCountMap counted_sync_set; syncer::TopicCountMap topics_counts;
ObjectId o1(1020, "DataTypeA"); syncer::Topic t1 = "Topic1";
sync_set.insert(o1); topics.emplace(t1, syncer::TopicMetadata{/*is_public=*/false});
counted_sync_set[o1] = 1; topics_counts[t1] = 1;
// Generate invalidation for datatype A only. // Generate invalidation for |t1| only.
syncer::ObjectIdInvalidationMap fake_invalidations = syncer::TopicInvalidationMap fake_invalidations;
syncer::ObjectIdInvalidationMap::InvalidateAll(sync_set); fake_invalidations.Insert(syncer::Invalidation::InitUnknownVersion(t1));
ObjectId o2(1040, "DataTypeB"); syncer::Topic t2 = "Topic2";
sync_set.insert(o2); topics.emplace(t2, syncer::TopicMetadata{/*is_public=*/false});
counted_sync_set[o2] = 0; topics_counts[t2] = 0;
// Registed the two objectIds and send an invalidation only for the // Register the two Topics and send an invalidation only for |t1|.
// Datatype A. send_test_map["Test"] = topics;
send_test_map["Test"] = sync_set; log.OnUpdatedTopics(send_test_map);
log.OnUpdateIds(send_test_map);
log.OnInvalidation(fake_invalidations); log.OnInvalidation(fake_invalidations);
expected_received_map["Test"] = counted_sync_set; expected_received_map["Test"] = topics_counts;
// Reset the state of the observer to receive the ObjectIds with the // Reset the state of the observer to receive the Topics with the count of
// count of invalidations received (1 and 0). // invalidations received (1 and 0).
observer_test.ResetStates(); observer_test.ResetStates();
log.EmitContent(); log.EmitContent();
EXPECT_EQ(expected_received_map, observer_test.update_id_replicated); EXPECT_EQ(expected_received_map, observer_test.updated_topics_replicated);
log.UnregisterObserver(&observer_test); log.UnregisterObserver(&observer_test);
} }
......
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/values.h" #include "base/values.h"
#include "components/invalidation/public/object_id_invalidation_map.h"
#include "components/invalidation/public/topic_invalidation_map.h" #include "components/invalidation/public/topic_invalidation_map.h"
#include "components/prefs/pref_registry_simple.h" #include "components/prefs/pref_registry_simple.h"
#include "components/prefs/scoped_user_pref_update.h" #include "components/prefs/scoped_user_pref_update.h"
......
...@@ -65,13 +65,12 @@ struct INVALIDATION_EXPORT InvalidationVersionLessThan { ...@@ -65,13 +65,12 @@ struct INVALIDATION_EXPORT InvalidationVersionLessThan {
typedef std::set<invalidation::ObjectId, ObjectIdLessThan> ObjectIdSet; typedef std::set<invalidation::ObjectId, ObjectIdLessThan> ObjectIdSet;
typedef std::map<invalidation::ObjectId, int, ObjectIdLessThan>
ObjectIdCountMap;
using Topic = std::string; using Topic = std::string;
// It should be std::set, since std::set_difference is used for it. // It should be std::set, since std::set_difference is used for it.
using TopicSet = std::set<std::string>; using TopicSet = std::set<std::string>;
using TopicCountMap = std::map<Topic, int>;
INVALIDATION_EXPORT struct TopicMetadata { INVALIDATION_EXPORT struct TopicMetadata {
// Whether the topic is public. // Whether the topic is public.
bool is_public; bool is_public;
......
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