diff options
author | rlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-06 06:51:36 +0000 |
---|---|---|
committer | rlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-06 06:51:36 +0000 |
commit | 8925eca81cf7b5f2261e7fa6e933fd5225a73985 (patch) | |
tree | f8b74c38b41539a13365c04db63ede034980eda1 /sync | |
parent | 05315b8f1bc81ea6e3aa0ed187d9485f527bc66a (diff) | |
download | chromium_src-8925eca81cf7b5f2261e7fa6e933fd5225a73985.zip chromium_src-8925eca81cf7b5f2261e7fa6e933fd5225a73985.tar.gz chromium_src-8925eca81cf7b5f2261e7fa6e933fd5225a73985.tar.bz2 |
Migrate invalidator client IDs out of sync
We want to store invalidator client IDs somewhere other than the sync
DB. Unfortunately, changing in the ID would require us to clear any
existing client state, which is something we'd prefer to avoid.
This commit makes the SyncInvalidationListener copy its sync-assigned
client ID to the InvalidationStateTracker when it is initialized. When
we decide to fully separate the sync and notifier IDs, the clients that
have run through this code path will find that their notifier client ID
has already been initialized correctly. This allows us to avoid
clearing their client state.
It's impossible to guarantee that all clients will hit this code path.
Fortunately, we don't have to. The goal of this patch is to avoid
deleting the state of too many clients all at once. It's not a big
problem if we have to clear the state of a few stragglers that haven't
hit the migration path yet.
BUG=124142
Review URL: https://chromiumcodereview.appspot.com/12094113
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@180907 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sync')
-rw-r--r-- | sync/notifier/fake_invalidation_state_tracker.cc | 9 | ||||
-rw-r--r-- | sync/notifier/fake_invalidation_state_tracker.h | 3 | ||||
-rw-r--r-- | sync/notifier/invalidation_state_tracker.h | 6 | ||||
-rw-r--r-- | sync/notifier/sync_invalidation_listener.cc | 10 | ||||
-rw-r--r-- | sync/notifier/sync_invalidation_listener_unittest.cc | 17 | ||||
-rw-r--r-- | sync/tools/null_invalidation_state_tracker.cc | 9 | ||||
-rw-r--r-- | sync/tools/null_invalidation_state_tracker.h | 3 |
7 files changed, 57 insertions, 0 deletions
diff --git a/sync/notifier/fake_invalidation_state_tracker.cc b/sync/notifier/fake_invalidation_state_tracker.cc index 2af5db5..a228922 100644 --- a/sync/notifier/fake_invalidation_state_tracker.cc +++ b/sync/notifier/fake_invalidation_state_tracker.cc @@ -47,6 +47,15 @@ void FakeInvalidationStateTracker::Forget(const ObjectIdSet& ids) { } } +void FakeInvalidationStateTracker::SetInvalidatorClientId( + const std::string& client_id) { + invalidator_client_id_ = client_id; +} + +std::string FakeInvalidationStateTracker::GetInvalidatorClientId() const { + return invalidator_client_id_; +} + void FakeInvalidationStateTracker::SetBootstrapData( const std::string& data) { bootstrap_data_ = data; diff --git a/sync/notifier/fake_invalidation_state_tracker.h b/sync/notifier/fake_invalidation_state_tracker.h index a3ea0bf..79606ee 100644 --- a/sync/notifier/fake_invalidation_state_tracker.h +++ b/sync/notifier/fake_invalidation_state_tracker.h @@ -27,6 +27,8 @@ class FakeInvalidationStateTracker int64 max_version, const std::string& payload) OVERRIDE; virtual void Forget(const ObjectIdSet& ids) OVERRIDE; + virtual void SetInvalidatorClientId(const std::string& client_id) OVERRIDE; + virtual std::string GetInvalidatorClientId() const OVERRIDE; virtual void SetBootstrapData(const std::string& data) OVERRIDE; virtual std::string GetBootstrapData() const OVERRIDE; virtual void GenerateAckHandles( @@ -40,6 +42,7 @@ class FakeInvalidationStateTracker private: InvalidationStateMap state_map_; + std::string invalidator_client_id_; std::string bootstrap_data_; }; diff --git a/sync/notifier/invalidation_state_tracker.h b/sync/notifier/invalidation_state_tracker.h index 957b9c4..58a5bc8 100644 --- a/sync/notifier/invalidation_state_tracker.h +++ b/sync/notifier/invalidation_state_tracker.h @@ -62,6 +62,12 @@ class InvalidationStateTracker { // Removes all state tracked for |ids|. virtual void Forget(const ObjectIdSet& ids) = 0; + // The per-client unique ID used to register the invalidation client with the + // server. This is used to squelch invalidation notifications that originate + // from changes made by this client. + virtual void SetInvalidatorClientId(const std::string& data) = 0; + virtual std::string GetInvalidatorClientId() const = 0; + // Used by invalidation::InvalidationClient for persistence. |data| is an // opaque blob that an invalidation client can use after a restart to // bootstrap itself. |data| is binary data (not valid UTF8, embedded nulls, diff --git a/sync/notifier/sync_invalidation_listener.cc b/sync/notifier/sync_invalidation_listener.cc index e84bc38..4e57bb8 100644 --- a/sync/notifier/sync_invalidation_listener.cc +++ b/sync/notifier/sync_invalidation_listener.cc @@ -95,6 +95,16 @@ void SyncInvalidationListener::Start( registration_manager_.reset( new RegistrationManager(invalidation_client_.get())); + + // TODO(rlarocque): This call exists as part of an effort to move the + // invalidator's ID out of sync. It writes the provided (sync-managed) ID to + // storage that lives on the UI thread. Once this has been in place for a + // milestone or two, we can remove it and start looking for invalidator client + // IDs exclusively in the InvalidationStateTracker. See crbug.com/124142. + invalidation_state_tracker_.Call( + FROM_HERE, + &InvalidationStateTracker::SetInvalidatorClientId, + client_id); } void SyncInvalidationListener::UpdateCredentials( diff --git a/sync/notifier/sync_invalidation_listener_unittest.cc b/sync/notifier/sync_invalidation_listener_unittest.cc index 4ab5b99..37016a8 100644 --- a/sync/notifier/sync_invalidation_listener_unittest.cc +++ b/sync/notifier/sync_invalidation_listener_unittest.cc @@ -226,6 +226,10 @@ class SyncInvalidationListenerTest : public testing::Test { return fake_tracker_.GetMaxVersion(id); } + std::string GetInvalidatorClientId() const { + return fake_tracker_.GetInvalidatorClientId(); + } + std::string GetBootstrapData() const { return fake_tracker_.GetBootstrapData(); } @@ -300,6 +304,11 @@ class SyncInvalidationListenerTest : public testing::Test { MakeWeakHandle(fake_tracker_.AsWeakPtr()), &fake_delegate_); DCHECK(fake_invalidation_client_); + + // TODO(rlarocque): This is necessary for the deferred write of the client + // ID to take place. We can remove this statement when we remove the + // WriteInvalidatorClientId test. See crbug.com/124142. + message_loop_.RunUntilIdle(); } void StopClient() { @@ -326,6 +335,14 @@ class SyncInvalidationListenerTest : public testing::Test { SyncInvalidationListener client_; }; +// Verify the client ID is written to the state tracker on client start. +// TODO(rlarocque): Remove this test when migration code is removed. +// See crbug.com/124142. +TEST_F(SyncInvalidationListenerTest, WriteInvalidatorClientId) { + // The client is started by the harness, so we don't have to do anything here. + EXPECT_EQ(kClientId, GetInvalidatorClientId()); +} + // Write a new state to the client. It should propagate to the // tracker. TEST_F(SyncInvalidationListenerTest, WriteState) { diff --git a/sync/tools/null_invalidation_state_tracker.cc b/sync/tools/null_invalidation_state_tracker.cc index 5eb5f78..084630c 100644 --- a/sync/tools/null_invalidation_state_tracker.cc +++ b/sync/tools/null_invalidation_state_tracker.cc @@ -37,6 +37,15 @@ void NullInvalidationStateTracker::Forget(const ObjectIdSet& ids) { } } +void NullInvalidationStateTracker::SetInvalidatorClientId( + const std::string& data) { + LOG(INFO) << "Setting invalidator client ID to: " << data; +} + +std::string NullInvalidationStateTracker::GetInvalidatorClientId() const { + return std::string(); +} + std::string NullInvalidationStateTracker::GetBootstrapData() const { return std::string(); } diff --git a/sync/tools/null_invalidation_state_tracker.h b/sync/tools/null_invalidation_state_tracker.h index 13e55c7..c6274e9 100644 --- a/sync/tools/null_invalidation_state_tracker.h +++ b/sync/tools/null_invalidation_state_tracker.h @@ -24,6 +24,9 @@ class NullInvalidationStateTracker const std::string& payload) OVERRIDE; virtual void Forget(const ObjectIdSet& ids) OVERRIDE; + virtual void SetInvalidatorClientId(const std::string& data) OVERRIDE; + virtual std::string GetInvalidatorClientId() const OVERRIDE; + virtual std::string GetBootstrapData() const OVERRIDE; virtual void SetBootstrapData(const std::string& data) OVERRIDE; |