diff options
author | rlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-03 21:20:54 +0000 |
---|---|---|
committer | rlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-03 21:20:54 +0000 |
commit | ba85740ffef8b4622d7fc94c71672cc207b4365c (patch) | |
tree | dd7de7ac6903ec690e15dd9090bce3e01bf9f7c8 /sync/internal_api | |
parent | ad554bcfe7ea960662f05fbd61c6aadcf71c04bf (diff) | |
download | chromium_src-ba85740ffef8b4622d7fc94c71672cc207b4365c.zip chromium_src-ba85740ffef8b4622d7fc94c71672cc207b4365c.tar.gz chromium_src-ba85740ffef8b4622d7fc94c71672cc207b4365c.tar.bz2 |
sync: Remove ModelTypeInvalidationMap
Removes the definition and all uses of ModelTypeInvalidationMap.
The ModelTypeInvalidationMap was useful only for sync-related
invalidations. Its existence made sense when sync was the only client
for invalidations. Now that we have many invalidations clients, it
makes sense to replace it with the more generic ObjectIdInvalidationMap.
The reason for doing this now is that the ObjectIdInvalidationMap will
soon be modified to be incompatible with the current definition of
ModelTypeInvalidationMap. In order to support trickles it will be
modified to allow it to contain several invalidations per ObjectId.
Although it would have been possible to maintain compatibility by making
a corresponding modification to ModelTypeInvalidationMap, there's really
no point in having two invalidation map types. In the long run, it
makes more sense to deprecate ModelTypeInvalidationMap.
BUG=233437
Review URL: https://chromiumcodereview.appspot.com/23238005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@221025 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sync/internal_api')
16 files changed, 76 insertions, 403 deletions
diff --git a/sync/internal_api/debug_info_event_listener.cc b/sync/internal_api/debug_info_event_listener.cc index 66953d4..64bbab8 100644 --- a/sync/internal_api/debug_info_event_listener.cc +++ b/sync/internal_api/debug_info_event_listener.cc @@ -4,6 +4,7 @@ #include "sync/internal_api/debug_info_event_listener.h" +#include "sync/notifier/object_id_invalidation_map.h" #include "sync/util/cryptographer.h" namespace syncer { @@ -134,14 +135,19 @@ void DebugInfoEventListener::OnNudgeFromDatatype(ModelType datatype) { } void DebugInfoEventListener::OnIncomingNotification( - const ModelTypeInvalidationMap& invalidation_map) { + const ObjectIdInvalidationMap& invalidations) { DCHECK(thread_checker_.CalledOnValidThread()); sync_pb::DebugEventInfo event_info; - ModelTypeSet types = ModelTypeInvalidationMapToSet(invalidation_map); - - for (ModelTypeSet::Iterator it = types.First(); it.Good(); it.Inc()) { - event_info.add_datatypes_notified_from_server( - GetSpecificsFieldNumberFromModelType(it.Get())); + ModelTypeSet types = ObjectIdSetToModelTypeSet(ObjectIdInvalidationMapToSet( + invalidations)); + + for (ObjectIdInvalidationMap::const_iterator it = invalidations.begin(); + it != invalidations.end(); ++it) { + ModelType type = UNSPECIFIED; + if (ObjectIdToRealModelType(it->first, &type)) { + event_info.add_datatypes_notified_from_server( + GetSpecificsFieldNumberFromModelType(type)); + } } AddEventToQueue(event_info); diff --git a/sync/internal_api/debug_info_event_listener.h b/sync/internal_api/debug_info_event_listener.h index a3c15eb..022fafb 100644 --- a/sync/internal_api/debug_info_event_listener.h +++ b/sync/internal_api/debug_info_event_listener.h @@ -71,8 +71,7 @@ class SYNC_EXPORT_PRIVATE DebugInfoEventListener // Sync manager events. void OnNudgeFromDatatype(ModelType datatype); - void OnIncomingNotification( - const ModelTypeInvalidationMap& invalidation_map); + void OnIncomingNotification(const ObjectIdInvalidationMap& invalidations); // DebugInfoGetter implementation. virtual void GetAndClearDebugInfo(sync_pb::DebugInfo* debug_info) OVERRIDE; diff --git a/sync/internal_api/public/base/DEPS b/sync/internal_api/public/base/DEPS index 29a82b7..6eae52a 100644 --- a/sync/internal_api/public/base/DEPS +++ b/sync/internal_api/public/base/DEPS @@ -3,4 +3,5 @@ include_rules = [ "+sync/base", "+sync/internal_api/public/base", "+sync/protocol", + "+sync/notifier" ] diff --git a/sync/internal_api/public/base/model_type_invalidation_map.cc b/sync/internal_api/public/base/model_type_invalidation_map.cc deleted file mode 100644 index 7ced0ff..0000000 --- a/sync/internal_api/public/base/model_type_invalidation_map.cc +++ /dev/null @@ -1,78 +0,0 @@ -// 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 "sync/internal_api/public/base/model_type_invalidation_map.h" - -#include <vector> - -#include "base/json/json_writer.h" -#include "base/json/string_escape.h" -#include "base/memory/scoped_ptr.h" -#include "base/values.h" - -namespace syncer { - -ModelTypeInvalidationMap ModelTypeSetToInvalidationMap( - ModelTypeSet types, const std::string& payload) { - ModelTypeInvalidationMap invalidation_map; - for (ModelTypeSet::Iterator it = types.First(); it.Good(); it.Inc()) { - // TODO(dcheng): Do we need to set ack_handle? - invalidation_map[it.Get()].payload = payload; - } - return invalidation_map; -} - -ModelTypeSet ModelTypeInvalidationMapToSet( - const ModelTypeInvalidationMap& invalidation_map) { - ModelTypeSet types; - for (ModelTypeInvalidationMap::const_iterator it = invalidation_map.begin(); - it != invalidation_map.end(); ++it) { - types.Put(it->first); - } - return types; -} - -std::string ModelTypeInvalidationMapToString( - const ModelTypeInvalidationMap& invalidation_map) { - scoped_ptr<base::DictionaryValue> value( - ModelTypeInvalidationMapToValue(invalidation_map)); - std::string json; - base::JSONWriter::Write(value.get(), &json); - return json; -} - -base::DictionaryValue* ModelTypeInvalidationMapToValue( - const ModelTypeInvalidationMap& invalidation_map) { - base::DictionaryValue* value = new base::DictionaryValue(); - for (ModelTypeInvalidationMap::const_iterator it = invalidation_map.begin(); - it != invalidation_map.end(); ++it) { - std::string printable_payload; - base::JsonDoubleQuote(it->second.payload, - false /* put_in_quotes */, - &printable_payload); - value->SetString(ModelTypeToString(it->first), printable_payload); - } - return value; -} - -void CoalesceStates(const ModelTypeInvalidationMap& update, - ModelTypeInvalidationMap* original) { - // TODO(dcheng): Where is this called? Do we need to add more clever logic for - // handling ack_handle? We probably want to always use the "latest" - // ack_handle, which might imply always using the one in update? - for (ModelTypeInvalidationMap::const_iterator i = update.begin(); - i != update.end(); ++i) { - if (original->count(i->first) == 0) { - // If this datatype isn't already in our map, add it with - // whatever payload it has. - (*original)[i->first] = i->second; - } else if (i->second.payload.length() > 0) { - // If this datatype is already in our map, we only overwrite the - // payload if the new one is non-empty. - (*original)[i->first].payload = i->second.payload; - } - } -} - -} // namespace syncer diff --git a/sync/internal_api/public/base/model_type_invalidation_map.h b/sync/internal_api/public/base/model_type_invalidation_map.h deleted file mode 100644 index 462e17e..0000000 --- a/sync/internal_api/public/base/model_type_invalidation_map.h +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright 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. -// -// Definition of ModelTypeInvalidationMap and various utility functions. - -#ifndef SYNC_INTERNAL_PUBLIC_API_BASE_MODEL_TYPE_INVALIDATION_MAP_H_ -#define SYNC_INTERNAL_PUBLIC_API_BASE_MODEL_TYPE_INVALIDATION_MAP_H_ - -#include <map> -#include <string> - -#include "sync/base/sync_export.h" -#include "sync/internal_api/public/base/invalidation.h" -#include "sync/internal_api/public/base/model_type.h" - -// TODO(akalin): Move the non-exported functions in this file to a -// private header. - -namespace base { -class DictionaryValue; -} - -namespace syncer { - -// A map between sync data types and their associated invalidation. -typedef std::map<ModelType, Invalidation> ModelTypeInvalidationMap; - -// Helper functions for building ModelTypeInvalidationMaps. - -// Make a ModelTypeInvalidationMap from all the types in a ModelTypeSet using a -// default payload. -SYNC_EXPORT ModelTypeInvalidationMap ModelTypeSetToInvalidationMap( - ModelTypeSet model_types, const std::string& payload); - -SYNC_EXPORT_PRIVATE ModelTypeSet ModelTypeInvalidationMapToSet( - const ModelTypeInvalidationMap& invalidation_map); - -std::string ModelTypeInvalidationMapToString( - const ModelTypeInvalidationMap& invalidation_map); - -// Caller takes ownership of the returned dictionary. -SYNC_EXPORT_PRIVATE base::DictionaryValue* ModelTypeInvalidationMapToValue( - const ModelTypeInvalidationMap& invalidation_map); - -// Coalesce |update| into |original|, overwriting only when |update| has -// a non-empty payload. -SYNC_EXPORT_PRIVATE void CoalesceStates( - const ModelTypeInvalidationMap& update, ModelTypeInvalidationMap* original); - -} // namespace syncer - -#endif // SYNC_INTERNAL_PUBLIC_API_BASE_MODEL_TYPE_INVALIDATION_MAP_H_ diff --git a/sync/internal_api/public/base/model_type_invalidation_map_test_util.cc b/sync/internal_api/public/base/model_type_invalidation_map_test_util.cc deleted file mode 100644 index 991a6e1..0000000 --- a/sync/internal_api/public/base/model_type_invalidation_map_test_util.cc +++ /dev/null @@ -1,114 +0,0 @@ -// 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 "sync/internal_api/public/base/model_type_invalidation_map_test_util.h" - -#include <algorithm> - -#include "base/basictypes.h" -#include "sync/internal_api/public/base/model_type_test_util.h" - -namespace syncer { - -using ::testing::MakeMatcher; -using ::testing::MatchResultListener; -using ::testing::Matcher; -using ::testing::MatcherInterface; -using ::testing::PrintToString; - -namespace { - -class ModelTypeInvalidationMapEqMatcher - : public MatcherInterface<const ModelTypeInvalidationMap&> { - public: - explicit ModelTypeInvalidationMapEqMatcher( - const ModelTypeInvalidationMap& expected); - - virtual bool MatchAndExplain(const ModelTypeInvalidationMap& lhs, - MatchResultListener* listener) const; - virtual void DescribeTo(::std::ostream* os) const; - virtual void DescribeNegationTo(::std::ostream* os) const; - - private: - const ModelTypeInvalidationMap expected_; - - DISALLOW_COPY_AND_ASSIGN(ModelTypeInvalidationMapEqMatcher); -}; - -ModelTypeInvalidationMapEqMatcher::ModelTypeInvalidationMapEqMatcher( - const ModelTypeInvalidationMap& expected) : expected_(expected) { -} - -bool ModelTypeInvalidationMapEqMatcher::MatchAndExplain( - const ModelTypeInvalidationMap& actual, - MatchResultListener* listener) const { - ModelTypeInvalidationMap expected_only; - ModelTypeInvalidationMap actual_only; - typedef std::pair<ModelType, std::pair<Invalidation, Invalidation> > - ValueDifference; - std::vector<ValueDifference> value_differences; - - std::set_difference(expected_.begin(), expected_.end(), - actual.begin(), actual.end(), - std::inserter(expected_only, expected_only.begin()), - expected_.value_comp()); - std::set_difference(actual.begin(), actual.end(), - expected_.begin(), expected_.end(), - std::inserter(actual_only, actual_only.begin()), - actual.value_comp()); - - for (ModelTypeInvalidationMap::const_iterator it = expected_.begin(); - it != expected_.end(); ++it) { - ModelTypeInvalidationMap::const_iterator find_it = - actual.find(it->first); - if (find_it != actual.end() && - !Matches(Eq(it->second))(find_it->second)) { - value_differences.push_back(std::make_pair( - it->first, std::make_pair(it->second, find_it->second))); - } - } - - if (expected_only.empty() && actual_only.empty() && value_differences.empty()) - return true; - - bool printed_header = false; - if (!actual_only.empty()) { - *listener << " which has these unexpected elements: " - << PrintToString(actual_only); - printed_header = true; - } - - if (!expected_only.empty()) { - *listener << (printed_header ? ",\nand" : "which") - << " doesn't have these expected elements: " - << PrintToString(expected_only); - printed_header = true; - } - - if (!value_differences.empty()) { - *listener << (printed_header ? ",\nand" : "which") - << " differ in the following values: " - << PrintToString(value_differences); - } - - return false; -} - -void ModelTypeInvalidationMapEqMatcher::DescribeTo(::std::ostream* os) const { - *os << " is equal to " << PrintToString(expected_); -} - -void ModelTypeInvalidationMapEqMatcher::DescribeNegationTo( - ::std::ostream* os) const { - *os << " isn't equal to " << PrintToString(expected_); -} - -} // namespace - -Matcher<const ModelTypeInvalidationMap&> Eq( - const ModelTypeInvalidationMap& expected) { - return MakeMatcher(new ModelTypeInvalidationMapEqMatcher(expected)); -} - -} // namespace syncer diff --git a/sync/internal_api/public/base/model_type_invalidation_map_test_util.h b/sync/internal_api/public/base/model_type_invalidation_map_test_util.h deleted file mode 100644 index 20a2819..0000000 --- a/sync/internal_api/public/base/model_type_invalidation_map_test_util.h +++ /dev/null @@ -1,20 +0,0 @@ -// 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. - -#ifndef SYNC_INTERNAL_API_PUBLIC_BASE_MODEL_TYPE_STATE_MAP_TEST_UTIL_H_ -#define SYNC_INTERNAL_API_PUBLIC_BASE_MODEL_TYPE_STATE_MAP_TEST_UTIL_H_ - -// Convince googletest to use the correct overload for PrintTo(). -#include "sync/internal_api/public/base/invalidation_test_util.h" -#include "sync/internal_api/public/base/model_type_invalidation_map.h" -#include "testing/gmock/include/gmock/gmock.h" - -namespace syncer { - -::testing::Matcher<const ModelTypeInvalidationMap&> Eq( - const ModelTypeInvalidationMap& expected); - -} // namespace syncer - -#endif // SYNC_INTERNAL_API_PUBLIC_BASE_MODEL_TYPE_STATE_MAP_TEST_UTIL_H_ diff --git a/sync/internal_api/public/base/model_type_invalidation_map_unittest.cc b/sync/internal_api/public/base/model_type_invalidation_map_unittest.cc deleted file mode 100644 index 016e167..0000000 --- a/sync/internal_api/public/base/model_type_invalidation_map_unittest.cc +++ /dev/null @@ -1,71 +0,0 @@ -// 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 "sync/internal_api/public/base/model_type_invalidation_map.h" - -#include <string> - -#include "base/memory/scoped_ptr.h" -#include "base/test/values_test_util.h" -#include "base/values.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace syncer { -namespace { - -using base::ExpectDictStringValue; - -class ModelTypeInvalidationMapTest : public testing::Test {}; - -TEST_F(ModelTypeInvalidationMapTest, TypeInvalidationMapToSet) { - ModelTypeInvalidationMap states; - states[BOOKMARKS].payload = "bookmarkpayload"; - states[APPS].payload = ""; - - const ModelTypeSet types(BOOKMARKS, APPS); - EXPECT_TRUE(ModelTypeInvalidationMapToSet(states).Equals(types)); -} - -TEST_F(ModelTypeInvalidationMapTest, TypeInvalidationMapToValue) { - ModelTypeInvalidationMap states; - states[BOOKMARKS].payload = "bookmarkpayload"; - states[APPS].payload = ""; - - scoped_ptr<base::DictionaryValue> value( - ModelTypeInvalidationMapToValue(states)); - EXPECT_EQ(2u, value->size()); - ExpectDictStringValue(states[BOOKMARKS].payload, *value, "Bookmarks"); - ExpectDictStringValue(std::string(), *value, "Apps"); - EXPECT_FALSE(value->HasKey("Preferences")); -} - -TEST_F(ModelTypeInvalidationMapTest, CoalesceStates) { - ModelTypeInvalidationMap original; - std::string empty_payload; - std::string payload1 = "payload1"; - std::string payload2 = "payload2"; - std::string payload3 = "payload3"; - original[BOOKMARKS].payload = empty_payload; - original[PASSWORDS].payload = payload1; - original[AUTOFILL].payload = payload2; - original[THEMES].payload = payload3; - - ModelTypeInvalidationMap update; - update[BOOKMARKS].payload = empty_payload; // Same. - update[PASSWORDS].payload = empty_payload; // Overwrite with empty. - update[AUTOFILL].payload = payload1; // Overwrite with non-empty. - update[SESSIONS].payload = payload2; // New. - // Themes untouched. - - CoalesceStates(update, &original); - ASSERT_EQ(5U, original.size()); - EXPECT_EQ(empty_payload, original[BOOKMARKS].payload); - EXPECT_EQ(payload1, original[PASSWORDS].payload); - EXPECT_EQ(payload1, original[AUTOFILL].payload); - EXPECT_EQ(payload2, original[SESSIONS].payload); - EXPECT_EQ(payload3, original[THEMES].payload); -} - -} // namespace -} // namespace syncer diff --git a/sync/internal_api/public/base/model_type_test_util.cc b/sync/internal_api/public/base/model_type_test_util.cc index 8c1164b..242b398 100644 --- a/sync/internal_api/public/base/model_type_test_util.cc +++ b/sync/internal_api/public/base/model_type_test_util.cc @@ -6,6 +6,25 @@ namespace syncer { +ObjectIdInvalidationMap BuildInvalidationMap( + ModelType type, + int version, + const std::string& payload) { + ObjectIdInvalidationMap map; + invalidation::ObjectId id; + Invalidation invalidation; + + bool result = RealModelTypeToObjectId(type, &id); + DCHECK(result) + << "Conversion of model type to object id failed: " + << ModelTypeToString(type); + invalidation.version = version; + invalidation.payload = payload; + + map.insert(std::make_pair(id, invalidation)); + return map; +} + void PrintTo(ModelTypeSet model_types, ::std::ostream* os) { *os << ModelTypeSetToString(model_types); } diff --git a/sync/internal_api/public/base/model_type_test_util.h b/sync/internal_api/public/base/model_type_test_util.h index cd347cb..c724bf5 100644 --- a/sync/internal_api/public/base/model_type_test_util.h +++ b/sync/internal_api/public/base/model_type_test_util.h @@ -8,10 +8,19 @@ #include <ostream> #include "sync/internal_api/public/base/model_type.h" +#include "sync/notifier/object_id_invalidation_map.h" #include "testing/gmock/include/gmock/gmock.h" namespace syncer { +// Builds an invaliation map that contains a single invalidation with specified +// type, version, and payload. The type will be converted from a ModelType to +// and ObjectId. +ObjectIdInvalidationMap BuildInvalidationMap( + ModelType type, + int version, + const std::string& payload); + // Defined for googletest. Forwards to ModelTypeSetToString(). void PrintTo(ModelTypeSet model_types, ::std::ostream* os); diff --git a/sync/internal_api/public/engine/model_safe_worker.cc b/sync/internal_api/public/engine/model_safe_worker.cc index 5c91715..eb3fc1f 100644 --- a/sync/internal_api/public/engine/model_safe_worker.cc +++ b/sync/internal_api/public/engine/model_safe_worker.cc @@ -31,17 +31,6 @@ std::string ModelSafeRoutingInfoToString( return json; } -ModelTypeInvalidationMap ModelSafeRoutingInfoToInvalidationMap( - const ModelSafeRoutingInfo& routes, - const std::string& payload) { - ModelTypeInvalidationMap invalidation_map; - for (ModelSafeRoutingInfo::const_iterator i = routes.begin(); - i != routes.end(); ++i) { - invalidation_map[i->first].payload = payload; - } - return invalidation_map; -} - ModelTypeSet GetRoutingInfoTypes(const ModelSafeRoutingInfo& routing_info) { ModelTypeSet types; for (ModelSafeRoutingInfo::const_iterator it = routing_info.begin(); diff --git a/sync/internal_api/public/engine/model_safe_worker.h b/sync/internal_api/public/engine/model_safe_worker.h index 0f41594..75f0345 100644 --- a/sync/internal_api/public/engine/model_safe_worker.h +++ b/sync/internal_api/public/engine/model_safe_worker.h @@ -16,7 +16,6 @@ #include "base/synchronization/waitable_event.h" #include "sync/base/sync_export.h" #include "sync/internal_api/public/base/model_type.h" -#include "sync/internal_api/public/base/model_type_invalidation_map.h" #include "sync/internal_api/public/util/syncer_error.h" namespace base { @@ -149,13 +148,6 @@ SYNC_EXPORT_PRIVATE base::DictionaryValue* ModelSafeRoutingInfoToValue( SYNC_EXPORT std::string ModelSafeRoutingInfoToString( const ModelSafeRoutingInfo& routing_info); -// Make a ModelTypeInvalidationMap for all the enabled types in a -// ModelSafeRoutingInfo using a default payload. -SYNC_EXPORT_PRIVATE ModelTypeInvalidationMap - ModelSafeRoutingInfoToInvalidationMap( - const ModelSafeRoutingInfo& routes, - const std::string& payload); - SYNC_EXPORT ModelTypeSet GetRoutingInfoTypes( const ModelSafeRoutingInfo& routing_info); diff --git a/sync/internal_api/public/engine/model_safe_worker_unittest.cc b/sync/internal_api/public/engine/model_safe_worker_unittest.cc index acddb7a7..f2e8c0e 100644 --- a/sync/internal_api/public/engine/model_safe_worker_unittest.cc +++ b/sync/internal_api/public/engine/model_safe_worker_unittest.cc @@ -48,21 +48,5 @@ TEST_F(ModelSafeWorkerTest, GetRoutingInfoTypes) { EXPECT_TRUE(GetRoutingInfoTypes(routing_info).Equals(expected_types)); } -TEST_F(ModelSafeWorkerTest, ModelSafeRoutingInfoToInvalidationMap) { - std::string payload = "test"; - ModelSafeRoutingInfo routing_info; - routing_info[BOOKMARKS] = GROUP_PASSIVE; - routing_info[NIGORI] = GROUP_UI; - routing_info[PREFERENCES] = GROUP_DB; - ModelTypeInvalidationMap invalidation_map = - ModelSafeRoutingInfoToInvalidationMap(routing_info, payload); - ASSERT_EQ(routing_info.size(), invalidation_map.size()); - for (ModelSafeRoutingInfo::iterator iter = routing_info.begin(); - iter != routing_info.end(); - ++iter) { - EXPECT_EQ(payload, invalidation_map[iter->first].payload); - } -} - } // namespace } // namespace syncer diff --git a/sync/internal_api/sync_manager_impl.cc b/sync/internal_api/sync_manager_impl.cc index a541032..091ed28 100644 --- a/sync/internal_api/sync_manager_impl.cc +++ b/sync/internal_api/sync_manager_impl.cc @@ -20,7 +20,6 @@ #include "sync/engine/syncer_types.h" #include "sync/internal_api/change_reorder_buffer.h" #include "sync/internal_api/public/base/model_type.h" -#include "sync/internal_api/public/base/model_type_invalidation_map.h" #include "sync/internal_api/public/base_node.h" #include "sync/internal_api/public/configure_reason.h" #include "sync/internal_api/public/engine/polling_constants.h" @@ -1152,12 +1151,15 @@ JsArgList SyncManagerImpl::GetChildNodeIds(const JsArgList& args) { } void SyncManagerImpl::UpdateNotificationInfo( - const ModelTypeInvalidationMap& invalidation_map) { - for (ModelTypeInvalidationMap::const_iterator it = invalidation_map.begin(); + const ObjectIdInvalidationMap& invalidation_map) { + for (ObjectIdInvalidationMap::const_iterator it = invalidation_map.begin(); it != invalidation_map.end(); ++it) { - NotificationInfo* info = ¬ification_info_map_[it->first]; - info->total_count++; - info->payload = it->second.payload; + ModelType type = UNSPECIFIED; + if (ObjectIdToRealModelType(it->first, &type)) { + NotificationInfo* info = ¬ification_info_map_[type]; + info->total_count++; + info->payload = it->second.payload; + } } } @@ -1186,29 +1188,37 @@ void SyncManagerImpl::OnIncomingInvalidation( const ObjectIdInvalidationMap& invalidation_map) { DCHECK(thread_checker_.CalledOnValidThread()); - const ModelTypeInvalidationMap& type_invalidation_map = - ObjectIdInvalidationMapToModelTypeInvalidationMap(invalidation_map); - if (type_invalidation_map.empty()) { + // We should never receive IDs from non-sync objects. + ObjectIdSet ids = ObjectIdInvalidationMapToSet(invalidation_map); + for (ObjectIdSet::const_iterator it = ids.begin(); it != ids.end(); ++it) { + ModelType type; + if (!ObjectIdToRealModelType(*it, &type)) { + DLOG(WARNING) << "Notification has invalid id: " << ObjectIdToString(*it); + } + } + + if (invalidation_map.empty()) { LOG(WARNING) << "Sync received invalidation without any type information."; } else { allstatus_.IncrementNudgeCounter(NUDGE_SOURCE_NOTIFICATION); scheduler_->ScheduleInvalidationNudge( TimeDelta::FromMilliseconds(kSyncSchedulerDelayMsec), - type_invalidation_map, FROM_HERE); + invalidation_map, FROM_HERE); allstatus_.IncrementNotificationsReceived(); - UpdateNotificationInfo(type_invalidation_map); - debug_info_event_listener_.OnIncomingNotification(type_invalidation_map); + UpdateNotificationInfo(invalidation_map); + debug_info_event_listener_.OnIncomingNotification(invalidation_map); } if (js_event_handler_.IsInitialized()) { base::DictionaryValue details; base::ListValue* changed_types = new base::ListValue(); details.Set("changedTypes", changed_types); - for (ModelTypeInvalidationMap::const_iterator it = - type_invalidation_map.begin(); it != type_invalidation_map.end(); - ++it) { - const std::string& model_type_str = - ModelTypeToString(it->first); + ObjectIdSet id_set = ObjectIdInvalidationMapToSet(invalidation_map); + ModelTypeSet nudged_types = ObjectIdSetToModelTypeSet(id_set); + DCHECK(!nudged_types.Empty()); + for (ModelTypeSet::Iterator it = nudged_types.First(); + it.Good(); it.Inc()) { + const std::string model_type_str = ModelTypeToString(it.Get()); changed_types->Append(new base::StringValue(model_type_str)); } details.SetString("source", "REMOTE_INVALIDATION"); diff --git a/sync/internal_api/sync_manager_impl.h b/sync/internal_api/sync_manager_impl.h index 712c268..03d6636 100644 --- a/sync/internal_api/sync_manager_impl.h +++ b/sync/internal_api/sync_manager_impl.h @@ -251,8 +251,7 @@ class SYNC_EXPORT_PRIVATE SyncManagerImpl : // Called for every notification. This updates the notification statistics // to be displayed in about:sync. - void UpdateNotificationInfo( - const ModelTypeInvalidationMap& invalidation_map); + void UpdateNotificationInfo(const ObjectIdInvalidationMap& invalidation_map); // Checks for server reachabilty and requests a nudge. void OnNetworkConnectivityChangedImpl(); diff --git a/sync/internal_api/sync_manager_impl_unittest.cc b/sync/internal_api/sync_manager_impl_unittest.cc index 06bc783..06e65e2 100644 --- a/sync/internal_api/sync_manager_impl_unittest.cc +++ b/sync/internal_api/sync_manager_impl_unittest.cc @@ -982,11 +982,12 @@ class SyncManagerTest : public testing::Test, void TriggerOnIncomingNotificationForTest(ModelTypeSet model_types) { DCHECK(sync_manager_.thread_checker_.CalledOnValidThread()); - ModelTypeInvalidationMap invalidation_map = - ModelTypeSetToInvalidationMap(model_types, std::string()); - sync_manager_.OnIncomingInvalidation( - ModelTypeInvalidationMapToObjectIdInvalidationMap( - invalidation_map)); + ObjectIdSet id_set = ModelTypeSetToObjectIdSet(model_types); + ObjectIdInvalidationMap invalidation_map = + ObjectIdSetToInvalidationMap(id_set, + Invalidation::kUnknownVersion, + std::string()); + sync_manager_.OnIncomingInvalidation(invalidation_map); } void SetProgressMarkerForType(ModelType type, bool set) { |