diff options
author | stepco@chromium.org <stepco@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-18 22:05:43 +0000 |
---|---|---|
committer | stepco@chromium.org <stepco@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-18 22:05:43 +0000 |
commit | ba79a799579a5417511d472071e3f8fc5e2b67a5 (patch) | |
tree | fee95deef4ce493dba01f14a9f0fdd604fefb451 /sync/notifier | |
parent | 686e985ee27bb868dc2ca361e9fe59658387f95b (diff) | |
download | chromium_src-ba79a799579a5417511d472071e3f8fc5e2b67a5.zip chromium_src-ba79a799579a5417511d472071e3f8fc5e2b67a5.tar.gz chromium_src-ba79a799579a5417511d472071e3f8fc5e2b67a5.tar.bz2 |
Add version field to syncer::Invalidation.
BUG=260021
Review URL: https://chromiumcodereview.appspot.com/19381005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@212448 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sync/notifier')
-rw-r--r-- | sync/notifier/object_id_invalidation_map.cc | 3 | ||||
-rw-r--r-- | sync/notifier/object_id_invalidation_map.h | 5 | ||||
-rw-r--r-- | sync/notifier/p2p_invalidator.cc | 6 | ||||
-rw-r--r-- | sync/notifier/p2p_invalidator_unittest.cc | 7 | ||||
-rw-r--r-- | sync/notifier/sync_invalidation_listener.cc | 22 | ||||
-rw-r--r-- | sync/notifier/sync_invalidation_listener.h | 2 | ||||
-rw-r--r-- | sync/notifier/sync_invalidation_listener_unittest.cc | 34 |
7 files changed, 69 insertions, 10 deletions
diff --git a/sync/notifier/object_id_invalidation_map.cc b/sync/notifier/object_id_invalidation_map.cc index 47b08e6..3dc7514 100644 --- a/sync/notifier/object_id_invalidation_map.cc +++ b/sync/notifier/object_id_invalidation_map.cc @@ -22,10 +22,11 @@ ObjectIdSet ObjectIdInvalidationMapToSet( } ObjectIdInvalidationMap ObjectIdSetToInvalidationMap( - const ObjectIdSet& ids, const std::string& payload) { + const ObjectIdSet& ids, int64 version, const std::string& payload) { ObjectIdInvalidationMap invalidation_map; for (ObjectIdSet::const_iterator it = ids.begin(); it != ids.end(); ++it) { // TODO(dcheng): Do we need to provide a way to set AckHandle? + invalidation_map[*it].version = version; invalidation_map[*it].payload = payload; } return invalidation_map; diff --git a/sync/notifier/object_id_invalidation_map.h b/sync/notifier/object_id_invalidation_map.h index 6560b3b..0a6a95e 100644 --- a/sync/notifier/object_id_invalidation_map.h +++ b/sync/notifier/object_id_invalidation_map.h @@ -8,6 +8,7 @@ #include <map> #include <string> +#include "base/basictypes.h" #include "base/memory/scoped_ptr.h" #include "google/cacheinvalidation/include/types.h" #include "sync/base/sync_export.h" @@ -29,7 +30,7 @@ typedef std::map<invalidation::ObjectId, ObjectIdSet ObjectIdInvalidationMapToSet( const ObjectIdInvalidationMap& invalidation_map); SYNC_EXPORT ObjectIdInvalidationMap ObjectIdSetToInvalidationMap( - const ObjectIdSet& ids, const std::string& payload); + const ObjectIdSet& ids, int64 version, const std::string& payload); SYNC_EXPORT bool ObjectIdInvalidationMapEquals( const ObjectIdInvalidationMap& invalidation_map1, @@ -51,4 +52,4 @@ SYNC_EXPORT ObjectIdInvalidationMap } // namespace syncer -#endif // HOME_DCHENG_SRC_CHROMIUM_SRC_SYNC_NOTIFIER_OBJECT_ID_STATE_MAP_H_ +#endif // SYNC_NOTIFIER_OBJECT_ID_INVALIDATION_MAP_H_ diff --git a/sync/notifier/p2p_invalidator.cc b/sync/notifier/p2p_invalidator.cc index 8b54c04..05ec183 100644 --- a/sync/notifier/p2p_invalidator.cc +++ b/sync/notifier/p2p_invalidator.cc @@ -173,7 +173,9 @@ void P2PInvalidator::UpdateRegisteredIds(InvalidationHandler* handler, const P2PNotificationData notification_data( invalidator_client_id_, NOTIFY_SELF, - ObjectIdSetToInvalidationMap(new_ids, std::string())); + ObjectIdSetToInvalidationMap(new_ids, + Invalidation::kUnknownVersion, + std::string())); SendNotificationData(notification_data); } @@ -228,6 +230,7 @@ void P2PInvalidator::OnNotificationsEnabled() { invalidator_client_id_, NOTIFY_SELF, ObjectIdSetToInvalidationMap(registrar_.GetAllRegisteredIds(), + Invalidation::kUnknownVersion, std::string())); SendNotificationData(notification_data); } @@ -263,6 +266,7 @@ void P2PInvalidator::OnIncomingNotification( invalidator_client_id_, NOTIFY_ALL, ObjectIdSetToInvalidationMap(registrar_.GetAllRegisteredIds(), + Invalidation::kUnknownVersion, std::string())); } if (!notification_data.IsTargeted(invalidator_client_id_)) { diff --git a/sync/notifier/p2p_invalidator_unittest.cc b/sync/notifier/p2p_invalidator_unittest.cc index 6acc3d1..be9ee3f 100644 --- a/sync/notifier/p2p_invalidator_unittest.cc +++ b/sync/notifier/p2p_invalidator_unittest.cc @@ -180,6 +180,7 @@ TEST_F(P2PInvalidatorTest, P2PNotificationDataNonDefault) { const ObjectIdInvalidationMap& invalidation_map = ObjectIdSetToInvalidationMap( ModelTypeSetToObjectIdSet(ModelTypeSet(BOOKMARKS, THEMES)), + Invalidation::kUnknownVersion, std::string()); const P2PNotificationData notification_data( "sender", NOTIFY_ALL, invalidation_map); @@ -193,10 +194,10 @@ TEST_F(P2PInvalidatorTest, P2PNotificationDataNonDefault) { "{\"idInvalidationMap\":[" "{\"objectId\":{\"name\":\"BOOKMARK\",\"source\":1004}," "\"state\":{\"ackHandle\":{\"state\":\"\",\"timestamp\":\"0\"}," - "\"payload\":\"\"}}," + "\"payload\":\"\",\"version\":\"-1\"}}," "{\"objectId\":{\"name\":\"THEME\",\"source\":1004}," "\"state\":{\"ackHandle\":{\"state\":\"\",\"timestamp\":\"0\"}," - "\"payload\":\"\"}}" + "\"payload\":\"\",\"version\":\"-1\"}}" "],\"notificationType\":\"notifyAll\"," "\"senderId\":\"sender\"}", notification_data_str); @@ -249,6 +250,7 @@ TEST_F(P2PInvalidatorTest, NotificationsBasic) { const ObjectIdInvalidationMap& invalidation_map = ObjectIdSetToInvalidationMap( ModelTypeSetToObjectIdSet(ModelTypeSet(THEMES, APPS)), + Invalidation::kUnknownVersion, std::string()); invalidator->SendInvalidation(invalidation_map); } @@ -267,6 +269,7 @@ TEST_F(P2PInvalidatorTest, SendNotificationData) { const ObjectIdInvalidationMap& invalidation_map = ObjectIdSetToInvalidationMap(ModelTypeSetToObjectIdSet(changed_types), + Invalidation::kUnknownVersion, std::string()); P2PInvalidator* const invalidator = delegate_.GetInvalidator(); diff --git a/sync/notifier/sync_invalidation_listener.cc b/sync/notifier/sync_invalidation_listener.cc index ddb9e35..ed07f20 100644 --- a/sync/notifier/sync_invalidation_listener.cc +++ b/sync/notifier/sync_invalidation_listener.cc @@ -205,7 +205,7 @@ void SyncInvalidationListener::Invalidate( ObjectIdSet ids; ids.insert(id); - PrepareInvalidation(ids, payload, client, ack_handle); + PrepareInvalidation(ids, invalidation.version(), payload, client, ack_handle); } void SyncInvalidationListener::InvalidateUnknownVersion( @@ -218,7 +218,12 @@ void SyncInvalidationListener::InvalidateUnknownVersion( ObjectIdSet ids; ids.insert(object_id); - PrepareInvalidation(ids, std::string(), client, ack_handle); + PrepareInvalidation( + ids, + Invalidation::kUnknownVersion, + std::string(), + client, + ack_handle); } // This should behave as if we got an invalidation with version @@ -230,11 +235,17 @@ void SyncInvalidationListener::InvalidateAll( DCHECK_EQ(client, invalidation_client_.get()); DVLOG(1) << "InvalidateAll"; - PrepareInvalidation(registered_ids_, std::string(), client, ack_handle); + PrepareInvalidation( + registered_ids_, + Invalidation::kUnknownVersion, + std::string(), + client, + ack_handle); } void SyncInvalidationListener::PrepareInvalidation( const ObjectIdSet& ids, + int64 version, const std::string& payload, invalidation::InvalidationClient* client, const invalidation::AckHandle& ack_handle) { @@ -250,6 +261,7 @@ void SyncInvalidationListener::PrepareInvalidation( base::Bind(&SyncInvalidationListener::EmitInvalidation, weak_ptr_factory_.GetWeakPtr(), ids, + version, payload, client, ack_handle)); @@ -257,13 +269,14 @@ void SyncInvalidationListener::PrepareInvalidation( void SyncInvalidationListener::EmitInvalidation( const ObjectIdSet& ids, + int64 version, const std::string& payload, invalidation::InvalidationClient* client, const invalidation::AckHandle& ack_handle, const AckHandleMap& local_ack_handles) { DCHECK(CalledOnValidThread()); ObjectIdInvalidationMap invalidation_map = - ObjectIdSetToInvalidationMap(ids, payload); + ObjectIdSetToInvalidationMap(ids, version, payload); for (AckHandleMap::const_iterator it = local_ack_handles.begin(); it != local_ack_handles.end(); ++it) { // Update in-memory copy of the invalidation state. @@ -280,6 +293,7 @@ void SyncInvalidationListener::OnTimeout(const ObjectIdSet& ids) { for (ObjectIdSet::const_iterator it = ids.begin(); it != ids.end(); ++it) { Invalidation invalidation; invalidation.ack_handle = invalidation_state_map_[*it].expected; + invalidation.version = invalidation_state_map_[*it].version; invalidation.payload = invalidation_state_map_[*it].payload; invalidation_map.insert(std::make_pair(*it, invalidation)); } diff --git a/sync/notifier/sync_invalidation_listener.h b/sync/notifier/sync_invalidation_listener.h index 3613551..d280e2e 100644 --- a/sync/notifier/sync_invalidation_listener.h +++ b/sync/notifier/sync_invalidation_listener.h @@ -151,10 +151,12 @@ class SYNC_EXPORT_PRIVATE SyncInvalidationListener void EmitStateChange(); void PrepareInvalidation(const ObjectIdSet& ids, + int64 version, const std::string& payload, invalidation::InvalidationClient* client, const invalidation::AckHandle& ack_handle); void EmitInvalidation(const ObjectIdSet& ids, + int64 version, const std::string& payload, invalidation::InvalidationClient* client, const invalidation::AckHandle& ack_handle, diff --git a/sync/notifier/sync_invalidation_listener_unittest.cc b/sync/notifier/sync_invalidation_listener_unittest.cc index 3dee40c..d3aa712 100644 --- a/sync/notifier/sync_invalidation_listener_unittest.cc +++ b/sync/notifier/sync_invalidation_listener_unittest.cc @@ -146,6 +146,11 @@ class FakeDelegate : public SyncInvalidationListener::Delegate { return (it == invalidation_counts_.end()) ? 0 : it->second; } + int64 GetVersion(const ObjectId& id) const { + ObjectIdInvalidationMap::const_iterator it = invalidations_.find(id); + return (it == invalidations_.end()) ? 0 : it->second.version; + } + std::string GetPayload(const ObjectId& id) const { ObjectIdInvalidationMap::const_iterator it = invalidations_.find(id); return (it == invalidations_.end()) ? std::string() : it->second.payload; @@ -295,6 +300,10 @@ class SyncInvalidationListenerTest : public testing::Test { return fake_delegate_.GetInvalidationCount(id); } + int64 GetVersion(const ObjectId& id) const { + return fake_delegate_.GetVersion(id); + } + std::string GetPayload(const ObjectId& id) const { return fake_delegate_.GetPayload(id); } @@ -437,6 +446,7 @@ TEST_F(SyncInvalidationListenerTest, InvalidateNoPayload) { FireInvalidate(id, kVersion1, NULL); EXPECT_EQ(1, GetInvalidationCount(id)); + EXPECT_EQ(kVersion1, GetVersion(id)); EXPECT_EQ("", GetPayload(id)); EXPECT_EQ(kVersion1, GetMaxVersion(id)); AcknowledgeAndVerify(id); @@ -451,6 +461,7 @@ TEST_F(SyncInvalidationListenerTest, InvalidateEmptyPayload) { FireInvalidate(id, kVersion1, ""); EXPECT_EQ(1, GetInvalidationCount(id)); + EXPECT_EQ(kVersion1, GetVersion(id)); EXPECT_EQ("", GetPayload(id)); EXPECT_EQ(kVersion1, GetMaxVersion(id)); AcknowledgeAndVerify(id); @@ -464,6 +475,7 @@ TEST_F(SyncInvalidationListenerTest, InvalidateWithPayload) { FireInvalidate(id, kVersion1, kPayload1); EXPECT_EQ(1, GetInvalidationCount(id)); + EXPECT_EQ(kVersion1, GetVersion(id)); EXPECT_EQ(kPayload1, GetPayload(id)); EXPECT_EQ(kVersion1, GetMaxVersion(id)); AcknowledgeAndVerify(id); @@ -483,6 +495,7 @@ TEST_F(SyncInvalidationListenerTest, InvalidateUnregisteredWithPayload) { FireInvalidate(id, kVersion1, "unregistered payload"); EXPECT_EQ(1, GetInvalidationCount(id)); + EXPECT_EQ(kVersion1, GetVersion(id)); EXPECT_EQ("unregistered payload", GetPayload(id)); EXPECT_EQ(kVersion1, GetMaxVersion(id)); AcknowledgeAndVerify(id); @@ -497,6 +510,7 @@ TEST_F(SyncInvalidationListenerTest, InvalidateVersion) { FireInvalidate(id, kVersion2, kPayload2); EXPECT_EQ(1, GetInvalidationCount(id)); + EXPECT_EQ(kVersion2, GetVersion(id)); EXPECT_EQ(kPayload2, GetPayload(id)); EXPECT_EQ(kVersion2, GetMaxVersion(id)); AcknowledgeAndVerify(id); @@ -504,6 +518,7 @@ TEST_F(SyncInvalidationListenerTest, InvalidateVersion) { FireInvalidate(id, kVersion1, kPayload1); EXPECT_EQ(1, GetInvalidationCount(id)); + EXPECT_EQ(kVersion2, GetVersion(id)); EXPECT_EQ(kPayload2, GetPayload(id)); EXPECT_EQ(kVersion2, GetMaxVersion(id)); VerifyAcknowledged(id); @@ -518,6 +533,7 @@ TEST_F(SyncInvalidationListenerTest, InvalidateUnknownVersion) { FireInvalidateUnknownVersion(id); EXPECT_EQ(1, GetInvalidationCount(id)); + EXPECT_EQ(Invalidation::kUnknownVersion, GetVersion(id)); EXPECT_EQ("", GetPayload(id)); EXPECT_EQ(kMinVersion, GetMaxVersion(id)); AcknowledgeAndVerify(id); @@ -525,6 +541,7 @@ TEST_F(SyncInvalidationListenerTest, InvalidateUnknownVersion) { FireInvalidateUnknownVersion(id); EXPECT_EQ(2, GetInvalidationCount(id)); + EXPECT_EQ(Invalidation::kUnknownVersion, GetVersion(id)); EXPECT_EQ("", GetPayload(id)); EXPECT_EQ(kMinVersion, GetMaxVersion(id)); AcknowledgeAndVerify(id); @@ -538,6 +555,7 @@ TEST_F(SyncInvalidationListenerTest, InvalidateAll) { for (ObjectIdSet::const_iterator it = registered_ids_.begin(); it != registered_ids_.end(); ++it) { EXPECT_EQ(1, GetInvalidationCount(*it)); + EXPECT_EQ(Invalidation::kUnknownVersion, GetVersion(*it)); EXPECT_EQ("", GetPayload(*it)); EXPECT_EQ(kMinVersion, GetMaxVersion(*it)); AcknowledgeAndVerify(*it); @@ -549,6 +567,7 @@ TEST_F(SyncInvalidationListenerTest, InvalidateMultipleIds) { FireInvalidate(kBookmarksId_, 3, NULL); EXPECT_EQ(1, GetInvalidationCount(kBookmarksId_)); + EXPECT_EQ(3, GetVersion(kBookmarksId_)); EXPECT_EQ("", GetPayload(kBookmarksId_)); EXPECT_EQ(3, GetMaxVersion(kBookmarksId_)); AcknowledgeAndVerify(kBookmarksId_); @@ -556,6 +575,7 @@ TEST_F(SyncInvalidationListenerTest, InvalidateMultipleIds) { FireInvalidate(kExtensionsId_, 2, NULL); EXPECT_EQ(1, GetInvalidationCount(kExtensionsId_)); + EXPECT_EQ(2, GetVersion(kExtensionsId_)); EXPECT_EQ("", GetPayload(kExtensionsId_)); EXPECT_EQ(2, GetMaxVersion(kExtensionsId_)); AcknowledgeAndVerify(kExtensionsId_); @@ -565,12 +585,14 @@ TEST_F(SyncInvalidationListenerTest, InvalidateMultipleIds) { FireInvalidate(kBookmarksId_, 1, NULL); EXPECT_EQ(1, GetInvalidationCount(kBookmarksId_)); + EXPECT_EQ(3, GetVersion(kBookmarksId_)); EXPECT_EQ("", GetPayload(kBookmarksId_)); EXPECT_EQ(3, GetMaxVersion(kBookmarksId_)); FireInvalidate(kExtensionsId_, 1, NULL); EXPECT_EQ(1, GetInvalidationCount(kExtensionsId_)); + EXPECT_EQ(2, GetVersion(kExtensionsId_)); EXPECT_EQ("", GetPayload(kExtensionsId_)); EXPECT_EQ(2, GetMaxVersion(kExtensionsId_)); @@ -579,11 +601,13 @@ TEST_F(SyncInvalidationListenerTest, InvalidateMultipleIds) { FireInvalidateAll(); EXPECT_EQ(2, GetInvalidationCount(kBookmarksId_)); + EXPECT_EQ(Invalidation::kUnknownVersion, GetVersion(kBookmarksId_)); EXPECT_EQ("", GetPayload(kBookmarksId_)); EXPECT_EQ(3, GetMaxVersion(kBookmarksId_)); AcknowledgeAndVerify(kBookmarksId_); EXPECT_EQ(1, GetInvalidationCount(kPreferencesId_)); + EXPECT_EQ(Invalidation::kUnknownVersion, GetVersion(kPreferencesId_)); EXPECT_EQ("", GetPayload(kPreferencesId_)); EXPECT_EQ(kMinVersion, GetMaxVersion(kPreferencesId_)); AcknowledgeAndVerify(kPreferencesId_); @@ -591,6 +615,7 @@ TEST_F(SyncInvalidationListenerTest, InvalidateMultipleIds) { // Note that kExtensionsId_ is not registered, so InvalidateAll() shouldn't // affect it. EXPECT_EQ(1, GetInvalidationCount(kExtensionsId_)); + EXPECT_EQ(2, GetVersion(kExtensionsId_)); EXPECT_EQ("", GetPayload(kExtensionsId_)); EXPECT_EQ(2, GetMaxVersion(kExtensionsId_)); VerifyAcknowledged(kExtensionsId_); @@ -599,18 +624,21 @@ TEST_F(SyncInvalidationListenerTest, InvalidateMultipleIds) { FireInvalidate(kPreferencesId_, 5, NULL); EXPECT_EQ(2, GetInvalidationCount(kPreferencesId_)); + EXPECT_EQ(5, GetVersion(kPreferencesId_)); EXPECT_EQ("", GetPayload(kPreferencesId_)); EXPECT_EQ(5, GetMaxVersion(kPreferencesId_)); AcknowledgeAndVerify(kPreferencesId_); FireInvalidate(kExtensionsId_, 3, NULL); EXPECT_EQ(2, GetInvalidationCount(kExtensionsId_)); + EXPECT_EQ(3, GetVersion(kExtensionsId_)); EXPECT_EQ("", GetPayload(kExtensionsId_)); EXPECT_EQ(3, GetMaxVersion(kExtensionsId_)); AcknowledgeAndVerify(kExtensionsId_); FireInvalidate(kBookmarksId_, 4, NULL); EXPECT_EQ(3, GetInvalidationCount(kBookmarksId_)); + EXPECT_EQ(4, GetVersion(kBookmarksId_)); EXPECT_EQ("", GetPayload(kBookmarksId_)); EXPECT_EQ(4, GetMaxVersion(kBookmarksId_)); AcknowledgeAndVerify(kBookmarksId_); @@ -628,6 +656,7 @@ TEST_F(SyncInvalidationListenerTest, InvalidateOneTimeout) { // Trigger the initial invalidation. FireInvalidate(kBookmarksId_, 3, NULL); EXPECT_EQ(1, GetInvalidationCount(kBookmarksId_)); + EXPECT_EQ(3, GetVersion(kBookmarksId_)); EXPECT_EQ("", GetPayload(kBookmarksId_)); EXPECT_EQ(3, GetMaxVersion(kBookmarksId_)); VerifyUnacknowledged(kBookmarksId_); @@ -638,6 +667,7 @@ TEST_F(SyncInvalidationListenerTest, InvalidateOneTimeout) { tick_clock_.NowTicks())); EXPECT_EQ(2, GetInvalidationCount(kBookmarksId_)); // Other properties should remain the same. + EXPECT_EQ(3, GetVersion(kBookmarksId_)); EXPECT_EQ("", GetPayload(kBookmarksId_)); EXPECT_EQ(3, GetMaxVersion(kBookmarksId_)); @@ -655,6 +685,7 @@ TEST_F(SyncInvalidationListenerTest, InvalidationTimeoutRestart) { FireInvalidate(kBookmarksId_, 3, NULL); EXPECT_EQ(1, GetInvalidationCount(kBookmarksId_)); + EXPECT_EQ(3, GetVersion(kBookmarksId_)); EXPECT_EQ("", GetPayload(kBookmarksId_)); EXPECT_EQ(3, GetMaxVersion(kBookmarksId_)); @@ -664,6 +695,7 @@ TEST_F(SyncInvalidationListenerTest, InvalidationTimeoutRestart) { tick_clock_.NowTicks())); EXPECT_EQ(2, GetInvalidationCount(kBookmarksId_)); // Other properties should remain the same. + EXPECT_EQ(3, GetVersion(kBookmarksId_)); EXPECT_EQ("", GetPayload(kBookmarksId_)); EXPECT_EQ(3, GetMaxVersion(kBookmarksId_)); @@ -676,6 +708,7 @@ TEST_F(SyncInvalidationListenerTest, InvalidationTimeoutRestart) { // The bookmark invalidation state should not have changed. EXPECT_EQ(2, GetInvalidationCount(kBookmarksId_)); + EXPECT_EQ(3, GetVersion(kBookmarksId_)); EXPECT_EQ("", GetPayload(kBookmarksId_)); EXPECT_EQ(3, GetMaxVersion(kBookmarksId_)); @@ -685,6 +718,7 @@ TEST_F(SyncInvalidationListenerTest, InvalidationTimeoutRestart) { tick_clock_.NowTicks())); EXPECT_EQ(3, GetInvalidationCount(kBookmarksId_)); // Other properties should remain the same. + EXPECT_EQ(3, GetVersion(kBookmarksId_)); EXPECT_EQ("", GetPayload(kBookmarksId_)); EXPECT_EQ(3, GetMaxVersion(kBookmarksId_)); |