From ba79a799579a5417511d472071e3f8fc5e2b67a5 Mon Sep 17 00:00:00 2001 From: "stepco@chromium.org" Date: Thu, 18 Jul 2013 22:05:43 +0000 Subject: 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 --- sync/notifier/object_id_invalidation_map.cc | 3 +- sync/notifier/object_id_invalidation_map.h | 5 ++-- sync/notifier/p2p_invalidator.cc | 6 +++- sync/notifier/p2p_invalidator_unittest.cc | 7 +++-- sync/notifier/sync_invalidation_listener.cc | 22 +++++++++++--- sync/notifier/sync_invalidation_listener.h | 2 ++ .../sync_invalidation_listener_unittest.cc | 34 ++++++++++++++++++++++ 7 files changed, 69 insertions(+), 10 deletions(-) (limited to 'sync/notifier') 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 #include +#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::mapSendInvalidation(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_)); -- cgit v1.1