Commit 840f3541 authored by akalin@chromium.org's avatar akalin@chromium.org

[Sync] Address msw's comments for r149747

See http://codereview.chromium.org/10805002/.

BUG=137087


Review URL: https://chromiumcodereview.appspot.com/10828158

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@150008 0039d316-1c4b-4281-b951-d872f2087c98
parent f9eda276
...@@ -552,10 +552,9 @@ class ProfileSyncService : public browser_sync::SyncFrontend, ...@@ -552,10 +552,9 @@ class ProfileSyncService : public browser_sync::SyncFrontend,
// been cleared yet. Virtual for testing purposes. // been cleared yet. Virtual for testing purposes.
virtual bool waiting_for_auth() const; virtual bool waiting_for_auth() const;
// Updates the set of ObjectIds associated with a given // Updates the set of ObjectIds associated with a given |handler|.
// |handler|. Passing an empty ObjectIdSet will unregister // Passing an empty ObjectIdSet will unregister |handler|.
// |handler|. There should be at most one handler registered per // There should be at most one handler registered per object id.
// object id.
// //
// The handler -> registered ids map is persisted across restarts of // The handler -> registered ids map is persisted across restarts of
// sync. // sync.
......
...@@ -384,10 +384,10 @@ TEST_F(ProfileSyncServiceTest, UpdateRegisteredInvalidationIds) { ...@@ -384,10 +384,10 @@ TEST_F(ProfileSyncServiceTest, UpdateRegisteredInvalidationIds) {
StrictMock<syncer::MockSyncNotifierObserver> observer; StrictMock<syncer::MockSyncNotifierObserver> observer;
EXPECT_CALL(observer, OnNotificationsEnabled()); EXPECT_CALL(observer, OnNotificationsEnabled());
EXPECT_CALL(observer, OnNotificationsDisabled(
syncer::TRANSIENT_NOTIFICATION_ERROR));
EXPECT_CALL(observer, OnIncomingNotification( EXPECT_CALL(observer, OnIncomingNotification(
payloads, syncer::REMOTE_NOTIFICATION)); payloads, syncer::REMOTE_NOTIFICATION));
EXPECT_CALL(observer, OnNotificationsDisabled(
syncer::TRANSIENT_NOTIFICATION_ERROR));
service_->UpdateRegisteredInvalidationIds(&observer, ids); service_->UpdateRegisteredInvalidationIds(&observer, ids);
...@@ -395,16 +395,16 @@ TEST_F(ProfileSyncServiceTest, UpdateRegisteredInvalidationIds) { ...@@ -395,16 +395,16 @@ TEST_F(ProfileSyncServiceTest, UpdateRegisteredInvalidationIds) {
service_->GetBackendForTest(); service_->GetBackendForTest();
backend->EmitOnNotificationsEnabled(); backend->EmitOnNotificationsEnabled();
backend->EmitOnNotificationsDisabled(syncer::TRANSIENT_NOTIFICATION_ERROR);
backend->EmitOnIncomingNotification(payloads, syncer::REMOTE_NOTIFICATION); backend->EmitOnIncomingNotification(payloads, syncer::REMOTE_NOTIFICATION);
backend->EmitOnNotificationsDisabled(syncer::TRANSIENT_NOTIFICATION_ERROR);
Mock::VerifyAndClearExpectations(&observer); Mock::VerifyAndClearExpectations(&observer);
service_->UpdateRegisteredInvalidationIds(&observer, syncer::ObjectIdSet()); service_->UpdateRegisteredInvalidationIds(&observer, syncer::ObjectIdSet());
backend->EmitOnNotificationsEnabled(); backend->EmitOnNotificationsEnabled();
backend->EmitOnNotificationsDisabled(syncer::TRANSIENT_NOTIFICATION_ERROR);
backend->EmitOnIncomingNotification(payloads, syncer::REMOTE_NOTIFICATION); backend->EmitOnIncomingNotification(payloads, syncer::REMOTE_NOTIFICATION);
backend->EmitOnNotificationsDisabled(syncer::TRANSIENT_NOTIFICATION_ERROR);
} }
// Register for some IDs with the ProfileSyncService, restart sync, // Register for some IDs with the ProfileSyncService, restart sync,
...@@ -413,17 +413,29 @@ TEST_F(ProfileSyncServiceTest, UpdateRegisteredInvalidationIds) { ...@@ -413,17 +413,29 @@ TEST_F(ProfileSyncServiceTest, UpdateRegisteredInvalidationIds) {
TEST_F(ProfileSyncServiceTest, UpdateRegisteredInvalidationIdsPersistence) { TEST_F(ProfileSyncServiceTest, UpdateRegisteredInvalidationIdsPersistence) {
StartSyncService(); StartSyncService();
syncer::ObjectIdSet ids;
ids.insert(invalidation::ObjectId(3, "id3"));
const syncer::ObjectIdPayloadMap& payloads =
syncer::ObjectIdSetToPayloadMap(ids, "payload");
StrictMock<syncer::MockSyncNotifierObserver> observer; StrictMock<syncer::MockSyncNotifierObserver> observer;
EXPECT_CALL(observer, OnNotificationsEnabled()); EXPECT_CALL(observer, OnNotificationsEnabled());
EXPECT_CALL(observer, OnIncomingNotification(
payloads, syncer::REMOTE_NOTIFICATION));
EXPECT_CALL(observer, OnNotificationsDisabled(
syncer::TRANSIENT_NOTIFICATION_ERROR));
syncer::ObjectIdSet ids;
ids.insert(invalidation::ObjectId(3, "id3"));
service_->UpdateRegisteredInvalidationIds(&observer, ids); service_->UpdateRegisteredInvalidationIds(&observer, ids);
service_->StopAndSuppress(); service_->StopAndSuppress();
service_->UnsuppressAndStart(); service_->UnsuppressAndStart();
service_->GetBackendForTest()->EmitOnNotificationsEnabled(); SyncBackendHostForProfileSyncTest* const backend =
service_->GetBackendForTest();
backend->EmitOnNotificationsEnabled();
backend->EmitOnIncomingNotification(payloads, syncer::REMOTE_NOTIFICATION);
backend->EmitOnNotificationsDisabled(syncer::TRANSIENT_NOTIFICATION_ERROR);
} }
} // namespace } // namespace
......
...@@ -30,6 +30,7 @@ class EncryptedData; ...@@ -30,6 +30,7 @@ class EncryptedData;
} // namespace sync_pb } // namespace sync_pb
namespace syncer { namespace syncer {
class BaseTransaction; class BaseTransaction;
class Encryptor; class Encryptor;
struct Experiments; struct Experiments;
...@@ -409,7 +410,8 @@ class SyncManager { ...@@ -409,7 +410,8 @@ class SyncManager {
// Forwards to the underlying notifier (see // Forwards to the underlying notifier (see
// SyncNotifier::UpdateRegisteredIds()). // SyncNotifier::UpdateRegisteredIds()).
virtual void UpdateRegisteredInvalidationIds( virtual void UpdateRegisteredInvalidationIds(
SyncNotifierObserver* handler, const ObjectIdSet& ids) = 0; SyncNotifierObserver* handler,
const ObjectIdSet& ids) = 0;
// Put the syncer in normal mode ready to perform nudges and polls. // Put the syncer in normal mode ready to perform nudges and polls.
virtual void StartSyncingNormally( virtual void StartSyncingNormally(
......
...@@ -54,8 +54,7 @@ class FakeSyncManager : public SyncManager { ...@@ -54,8 +54,7 @@ class FakeSyncManager : public SyncManager {
ModelTypeSet GetAndResetEnabledTypes(); ModelTypeSet GetAndResetEnabledTypes();
// Posts a method to invalidate the given IDs on the sync thread. // Posts a method to invalidate the given IDs on the sync thread.
void Invalidate( void Invalidate(const ObjectIdPayloadMap& id_payloads,
const ObjectIdPayloadMap& id_payloads,
IncomingNotificationSource source); IncomingNotificationSource source);
// Posts a method to enable notifications on the sync thread. // Posts a method to enable notifications on the sync thread.
...@@ -96,7 +95,8 @@ class FakeSyncManager : public SyncManager { ...@@ -96,7 +95,8 @@ class FakeSyncManager : public SyncManager {
virtual void UpdateCredentials(const SyncCredentials& credentials) OVERRIDE; virtual void UpdateCredentials(const SyncCredentials& credentials) OVERRIDE;
virtual void UpdateEnabledTypes(const ModelTypeSet& types) OVERRIDE; virtual void UpdateEnabledTypes(const ModelTypeSet& types) OVERRIDE;
virtual void UpdateRegisteredInvalidationIds( virtual void UpdateRegisteredInvalidationIds(
SyncNotifierObserver* handler, const ObjectIdSet& ids) OVERRIDE; SyncNotifierObserver* handler,
const ObjectIdSet& ids) OVERRIDE;
virtual void StartSyncingNormally( virtual void StartSyncingNormally(
const ModelSafeRoutingInfo& routing_info) OVERRIDE; const ModelSafeRoutingInfo& routing_info) OVERRIDE;
virtual void SetEncryptionPassphrase(const std::string& passphrase, virtual void SetEncryptionPassphrase(const std::string& passphrase,
......
...@@ -739,7 +739,8 @@ void SyncManagerImpl::UpdateEnabledTypes( ...@@ -739,7 +739,8 @@ void SyncManagerImpl::UpdateEnabledTypes(
} }
void SyncManagerImpl::UpdateRegisteredInvalidationIds( void SyncManagerImpl::UpdateRegisteredInvalidationIds(
SyncNotifierObserver* handler, const ObjectIdSet& ids) { SyncNotifierObserver* handler,
const ObjectIdSet& ids) {
DCHECK(thread_checker_.CalledOnValidThread()); DCHECK(thread_checker_.CalledOnValidThread());
sync_notifier_->UpdateRegisteredIds(handler, ids); sync_notifier_->UpdateRegisteredIds(handler, ids);
} }
......
...@@ -87,7 +87,8 @@ class SyncManagerImpl : public SyncManager, ...@@ -87,7 +87,8 @@ class SyncManagerImpl : public SyncManager,
virtual void UpdateEnabledTypes( virtual void UpdateEnabledTypes(
const ModelTypeSet& enabled_types) OVERRIDE; const ModelTypeSet& enabled_types) OVERRIDE;
virtual void UpdateRegisteredInvalidationIds( virtual void UpdateRegisteredInvalidationIds(
SyncNotifierObserver* handler, const ObjectIdSet& ids) OVERRIDE; SyncNotifierObserver* handler,
const ObjectIdSet& ids) OVERRIDE;
virtual void StartSyncingNormally( virtual void StartSyncingNormally(
const ModelSafeRoutingInfo& routing_info) OVERRIDE; const ModelSafeRoutingInfo& routing_info) OVERRIDE;
virtual void SetEncryptionPassphrase(const std::string& passphrase, virtual void SetEncryptionPassphrase(const std::string& passphrase,
......
...@@ -55,8 +55,7 @@ ModelTypeSet FakeSyncManager::GetAndResetEnabledTypes() { ...@@ -55,8 +55,7 @@ ModelTypeSet FakeSyncManager::GetAndResetEnabledTypes() {
return enabled_types; return enabled_types;
} }
void FakeSyncManager::Invalidate( void FakeSyncManager::Invalidate(const ObjectIdPayloadMap& id_payloads,
const ObjectIdPayloadMap& id_payloads,
IncomingNotificationSource source) { IncomingNotificationSource source) {
if (!sync_task_runner_->PostTask( if (!sync_task_runner_->PostTask(
FROM_HERE, FROM_HERE,
...@@ -151,7 +150,8 @@ void FakeSyncManager::UpdateEnabledTypes(const ModelTypeSet& types) { ...@@ -151,7 +150,8 @@ void FakeSyncManager::UpdateEnabledTypes(const ModelTypeSet& types) {
} }
void FakeSyncManager::UpdateRegisteredInvalidationIds( void FakeSyncManager::UpdateRegisteredInvalidationIds(
SyncNotifierObserver* handler, const ObjectIdSet& ids) { SyncNotifierObserver* handler,
const ObjectIdSet& ids) {
notifier_helper_.UpdateRegisteredIds(handler, ids); notifier_helper_.UpdateRegisteredIds(handler, ids);
} }
......
...@@ -16,8 +16,8 @@ ObjectIdSet ObjectIdPayloadMapToSet( ...@@ -16,8 +16,8 @@ ObjectIdSet ObjectIdPayloadMapToSet(
return ids; return ids;
} }
ObjectIdPayloadMap ObjectIdSetToPayloadMap( ObjectIdPayloadMap ObjectIdSetToPayloadMap(ObjectIdSet ids,
ObjectIdSet ids, const std::string& payload) { const std::string& payload) {
ObjectIdPayloadMap id_payloads; ObjectIdPayloadMap id_payloads;
for (ObjectIdSet::const_iterator it = ids.begin(); it != ids.end(); ++it) { for (ObjectIdSet::const_iterator it = ids.begin(); it != ids.end(); ++it) {
id_payloads[*it] = payload; id_payloads[*it] = payload;
......
...@@ -20,8 +20,8 @@ typedef std::map<invalidation::ObjectId, ...@@ -20,8 +20,8 @@ typedef std::map<invalidation::ObjectId,
// Converts between ObjectIdPayloadMaps and ObjectIdSets. // Converts between ObjectIdPayloadMaps and ObjectIdSets.
ObjectIdSet ObjectIdPayloadMapToSet(const ObjectIdPayloadMap& id_payloads); ObjectIdSet ObjectIdPayloadMapToSet(const ObjectIdPayloadMap& id_payloads);
ObjectIdPayloadMap ObjectIdSetToPayloadMap( ObjectIdPayloadMap ObjectIdSetToPayloadMap(ObjectIdSet ids,
ObjectIdSet ids, const std::string& payload); const std::string& payload);
// Converts between ObjectIdPayloadMaps and ModelTypePayloadMaps. // Converts between ObjectIdPayloadMaps and ModelTypePayloadMaps.
ModelTypePayloadMap ObjectIdPayloadMapToModelTypePayloadMap( ModelTypePayloadMap ObjectIdPayloadMapToModelTypePayloadMap(
......
...@@ -22,10 +22,9 @@ class SyncNotifier { ...@@ -22,10 +22,9 @@ class SyncNotifier {
SyncNotifier() {} SyncNotifier() {}
virtual ~SyncNotifier() {} virtual ~SyncNotifier() {}
// Updates the set of ObjectIds associated with a given // Updates the set of ObjectIds associated with a given |handler|.
// |handler|. Passing an empty ObjectIdSet will unregister // Passing an empty ObjectIdSet will unregister |handler|.
// |handler|. There should be at most one handler registered per // There should be at most one handler registered per object id.
// object id.
virtual void UpdateRegisteredIds(SyncNotifierObserver* handler, virtual void UpdateRegisteredIds(SyncNotifierObserver* handler,
const ObjectIdSet& ids) = 0; const ObjectIdSet& ids) = 0;
......
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