diff options
author | dcheng@chromium.org <dcheng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-24 04:29:44 +0000 |
---|---|---|
committer | dcheng@chromium.org <dcheng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-24 04:29:44 +0000 |
commit | bd6007ea79376728e7096a3261e812908933ba85 (patch) | |
tree | a794320cf3d5a922c7af84f965c5f6a30624cf4e /sync | |
parent | 3e59af452cc296f22e14ee738594fec9cee38e7c (diff) | |
download | chromium_src-bd6007ea79376728e7096a3261e812908933ba85.zip chromium_src-bd6007ea79376728e7096a3261e812908933ba85.tar.gz chromium_src-bd6007ea79376728e7096a3261e812908933ba85.tar.bz2 |
Refactor ModelTypePayloadMap and ObjectIdPayloadMap to StateMaps.
This lays the groundwork for allowing us to pass ack handles for object IDs to
SyncNotifierObservers.
BUG=124149
TEST=none, there should be no behavior change.
Review URL: https://chromiumcodereview.appspot.com/10837214
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@153158 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sync')
69 files changed, 1011 insertions, 614 deletions
diff --git a/sync/engine/download_updates_command.cc b/sync/engine/download_updates_command.cc index 65677fb..0c413b6 100644 --- a/sync/engine/download_updates_command.cc +++ b/sync/engine/download_updates_command.cc @@ -9,7 +9,7 @@ #include "base/command_line.h" #include "sync/engine/syncer.h" #include "sync/engine/syncer_proto_util.h" -#include "sync/internal_api/public/base/model_type_payload_map.h" +#include "sync/internal_api/public/base/model_type_state_map.h" #include "sync/syncable/directory.h" #include "sync/syncable/read_transaction.h" @@ -71,7 +71,7 @@ SyncerError DownloadUpdatesCommand::ExecuteImpl(SyncSession* session) { << ModelTypeSetToString(enabled_types); DCHECK(!enabled_types.Empty()); - const ModelTypePayloadMap& type_payload_map = session->source().types; + const ModelTypeStateMap& type_state_map = session->source().types; for (ModelTypeSet::Iterator it = enabled_types.First(); it.Good(); it.Inc()) { sync_pb::DataTypeProgressMarker* progress_marker = @@ -79,10 +79,10 @@ SyncerError DownloadUpdatesCommand::ExecuteImpl(SyncSession* session) { dir->GetDownloadProgress(it.Get(), progress_marker); // Set notification hint if present. - ModelTypePayloadMap::const_iterator type_payload = - type_payload_map.find(it.Get()); - if (type_payload != type_payload_map.end()) { - progress_marker->set_notification_hint(type_payload->second); + ModelTypeStateMap::const_iterator type_state = + type_state_map.find(it.Get()); + if (type_state != type_state_map.end()) { + progress_marker->set_notification_hint(type_state->second.payload); } } diff --git a/sync/engine/download_updates_command_unittest.cc b/sync/engine/download_updates_command_unittest.cc index f7bbcb6..0b4d5c9 100644 --- a/sync/engine/download_updates_command_unittest.cc +++ b/sync/engine/download_updates_command_unittest.cc @@ -39,22 +39,22 @@ class DownloadUpdatesCommandTest : public SyncerCommandTest { DISALLOW_COPY_AND_ASSIGN(DownloadUpdatesCommandTest); }; -TEST_F(DownloadUpdatesCommandTest, ExecuteNoPayloads) { +TEST_F(DownloadUpdatesCommandTest, ExecuteNoStates) { ConfigureMockServerConnection(); mock_server()->ExpectGetUpdatesRequestTypes( GetRoutingInfoTypes(routing_info())); command_.ExecuteImpl(session()); } -TEST_F(DownloadUpdatesCommandTest, ExecuteWithPayloads) { +TEST_F(DownloadUpdatesCommandTest, ExecuteWithStates) { ConfigureMockServerConnection(); sessions::SyncSourceInfo source; - source.types[AUTOFILL] = "autofill_payload"; - source.types[BOOKMARKS] = "bookmark_payload"; - source.types[PREFERENCES] = "preferences_payload"; + source.types[AUTOFILL].payload = "autofill_payload"; + source.types[BOOKMARKS].payload = "bookmark_payload"; + source.types[PREFERENCES].payload = "preferences_payload"; mock_server()->ExpectGetUpdatesRequestTypes( GetRoutingInfoTypes(routing_info())); - mock_server()->ExpectGetUpdatesRequestPayloads(source.types); + mock_server()->ExpectGetUpdatesRequestStates(source.types); command_.ExecuteImpl(session(source)); } diff --git a/sync/engine/sync_scheduler.h b/sync/engine/sync_scheduler.h index 8967a83..702163b 100644 --- a/sync/engine/sync_scheduler.h +++ b/sync/engine/sync_scheduler.h @@ -12,7 +12,7 @@ #include "base/compiler_specific.h" #include "base/time.h" #include "sync/engine/nudge_source.h" -#include "sync/internal_api/public/base/model_type_payload_map.h" +#include "sync/internal_api/public/base/model_type_state_map.h" #include "sync/sessions/sync_session.h" class MessageLoop; @@ -90,9 +90,9 @@ class SyncScheduler : public sessions::SyncSession::Delegate { NudgeSource source, ModelTypeSet types, const tracked_objects::Location& nudge_location) = 0; - virtual void ScheduleNudgeWithPayloadsAsync( + virtual void ScheduleNudgeWithStatesAsync( const base::TimeDelta& delay, NudgeSource source, - const ModelTypePayloadMap& types_with_payloads, + const ModelTypeStateMap& type_state_map, const tracked_objects::Location& nudge_location) = 0; // Change status of notifications in the SyncSessionContext. diff --git a/sync/engine/sync_scheduler_impl.cc b/sync/engine/sync_scheduler_impl.cc index ff177b4..dab9b1b 100644 --- a/sync/engine/sync_scheduler_impl.cc +++ b/sync/engine/sync_scheduler_impl.cc @@ -351,7 +351,7 @@ bool SyncSchedulerImpl::ScheduleConfiguration( session_context_, this, SyncSourceInfo(params.source, - ModelSafeRoutingInfoToPayloadMap( + ModelSafeRoutingInfoToStateMap( restricted_routes, std::string())), restricted_routes, @@ -423,7 +423,7 @@ SyncSchedulerImpl::JobProcessDecision SyncSchedulerImpl::DecideOnJob( if (job.purpose == SyncSessionJob::NUDGE && job.session->source().updates_source == GetUpdatesCallerInfo::LOCAL) { ModelTypeSet requested_types; - for (ModelTypePayloadMap::const_iterator i = + for (ModelTypeStateMap::const_iterator i = job.session->source().types.begin(); i != job.session->source().types.end(); ++i) { @@ -554,29 +554,29 @@ void SyncSchedulerImpl::ScheduleNudgeAsync( << "source " << GetNudgeSourceString(source) << ", " << "types " << ModelTypeSetToString(types); - ModelTypePayloadMap types_with_payloads = - ModelTypePayloadMapFromEnumSet(types, std::string()); + ModelTypeStateMap type_state_map = + ModelTypeSetToStateMap(types, std::string()); SyncSchedulerImpl::ScheduleNudgeImpl(delay, GetUpdatesFromNudgeSource(source), - types_with_payloads, + type_state_map, false, nudge_location); } -void SyncSchedulerImpl::ScheduleNudgeWithPayloadsAsync( +void SyncSchedulerImpl::ScheduleNudgeWithStatesAsync( const TimeDelta& delay, - NudgeSource source, const ModelTypePayloadMap& types_with_payloads, + NudgeSource source, const ModelTypeStateMap& type_state_map, const tracked_objects::Location& nudge_location) { DCHECK_EQ(MessageLoop::current(), sync_loop_); SDVLOG_LOC(nudge_location, 2) << "Nudge scheduled with delay " << delay.InMilliseconds() << " ms, " << "source " << GetNudgeSourceString(source) << ", " << "payloads " - << ModelTypePayloadMapToString(types_with_payloads); + << ModelTypeStateMapToString(type_state_map); SyncSchedulerImpl::ScheduleNudgeImpl(delay, GetUpdatesFromNudgeSource(source), - types_with_payloads, + type_state_map, false, nudge_location); } @@ -584,7 +584,7 @@ void SyncSchedulerImpl::ScheduleNudgeWithPayloadsAsync( void SyncSchedulerImpl::ScheduleNudgeImpl( const TimeDelta& delay, GetUpdatesCallerInfo::GetUpdatesSource source, - const ModelTypePayloadMap& types_with_payloads, + const ModelTypeStateMap& type_state_map, bool is_canary_job, const tracked_objects::Location& nudge_location) { DCHECK_EQ(MessageLoop::current(), sync_loop_); @@ -593,10 +593,10 @@ void SyncSchedulerImpl::ScheduleNudgeImpl( << delay.InMilliseconds() << " ms, " << "source " << GetUpdatesSourceString(source) << ", " << "payloads " - << ModelTypePayloadMapToString(types_with_payloads) + << ModelTypeStateMapToString(type_state_map) << (is_canary_job ? " (canary)" : ""); - SyncSourceInfo info(source, types_with_payloads); + SyncSourceInfo info(source, type_state_map); SyncSession* session(CreateSyncSession(info)); SyncSessionJob job(SyncSessionJob::NUDGE, TimeTicks::Now() + delay, @@ -774,7 +774,7 @@ void SyncSchedulerImpl::FinishSyncSessionJob(const SyncSessionJob& job) { // Update timing information for how often datatypes are triggering nudges. base::TimeTicks now = TimeTicks::Now(); if (!last_sync_session_end_time_.is_null()) { - ModelTypePayloadMap::const_iterator iter; + ModelTypeStateMap::const_iterator iter; for (iter = job.session->source().types.begin(); iter != job.session->source().types.end(); ++iter) { @@ -1013,9 +1013,9 @@ SyncSession* SyncSchedulerImpl::CreateSyncSession( void SyncSchedulerImpl::PollTimerCallback() { DCHECK_EQ(MessageLoop::current(), sync_loop_); ModelSafeRoutingInfo r; - ModelTypePayloadMap types_with_payloads = - ModelSafeRoutingInfoToPayloadMap(r, std::string()); - SyncSourceInfo info(GetUpdatesCallerInfo::PERIODIC, types_with_payloads); + ModelTypeStateMap type_state_map = + ModelSafeRoutingInfoToStateMap(r, std::string()); + SyncSourceInfo info(GetUpdatesCallerInfo::PERIODIC, type_state_map); SyncSession* s = CreateSyncSession(info); SyncSessionJob job(SyncSessionJob::POLL, TimeTicks::Now(), diff --git a/sync/engine/sync_scheduler_impl.h b/sync/engine/sync_scheduler_impl.h index e5f3acf..461455a 100644 --- a/sync/engine/sync_scheduler_impl.h +++ b/sync/engine/sync_scheduler_impl.h @@ -20,7 +20,7 @@ #include "sync/engine/nudge_source.h" #include "sync/engine/sync_scheduler.h" #include "sync/engine/syncer.h" -#include "sync/internal_api/public/base/model_type_payload_map.h" +#include "sync/internal_api/public/base/model_type_state_map.h" #include "sync/internal_api/public/engine/polling_constants.h" #include "sync/internal_api/public/util/weak_handle.h" #include "sync/sessions/sync_session.h" @@ -51,9 +51,9 @@ class SyncSchedulerImpl : public SyncScheduler { NudgeSource source, ModelTypeSet types, const tracked_objects::Location& nudge_location) OVERRIDE; - virtual void ScheduleNudgeWithPayloadsAsync( + virtual void ScheduleNudgeWithStatesAsync( const base::TimeDelta& delay, NudgeSource source, - const ModelTypePayloadMap& types_with_payloads, + const ModelTypeStateMap& type_state_map, const tracked_objects::Location& nudge_location) OVERRIDE; virtual void SetNotificationsEnabled(bool notifications_enabled) OVERRIDE; @@ -241,7 +241,7 @@ class SyncSchedulerImpl : public SyncScheduler { void ScheduleNudgeImpl( const base::TimeDelta& delay, sync_pb::GetUpdatesCallerInfo::GetUpdatesSource source, - const ModelTypePayloadMap& types_with_payloads, + const ModelTypeStateMap& type_state_map, bool is_canary_job, const tracked_objects::Location& nudge_location); // Returns true if the client is currently in exponential backoff. diff --git a/sync/engine/sync_scheduler_unittest.cc b/sync/engine/sync_scheduler_unittest.cc index 53d2ed4..c9f68af 100644 --- a/sync/engine/sync_scheduler_unittest.cc +++ b/sync/engine/sync_scheduler_unittest.cc @@ -12,6 +12,7 @@ #include "sync/engine/sync_scheduler_impl.h" #include "sync/engine/syncer.h" #include "sync/engine/throttled_data_type_tracker.h" +#include "sync/internal_api/public/base/model_type_state_map_test_util.h" #include "sync/sessions/test_util.h" #include "sync/test/callback_counter.h" #include "sync/test/engine/fake_model_worker.h" @@ -198,13 +199,13 @@ class SyncSchedulerTest : public testing::Test { scheduler_->delay_provider_.reset(delay_); } - // Compare a ModelTypeSet to a ModelTypePayloadMap, ignoring - // payload values. - bool CompareModelTypeSetToModelTypePayloadMap( + // Compare a ModelTypeSet to a ModelTypeStateMap, ignoring + // state values. + bool CompareModelTypeSetToModelTypeStateMap( ModelTypeSet lhs, - const ModelTypePayloadMap& rhs) { + const ModelTypeStateMap& rhs) { size_t count = 0; - for (ModelTypePayloadMap::const_iterator i = rhs.begin(); + for (ModelTypeStateMap::const_iterator i = rhs.begin(); i != rhs.end(); ++i, ++count) { if (!lhs.Has(i->first)) return false; @@ -280,7 +281,7 @@ TEST_F(SyncSchedulerTest, Nudge) { RunLoop(); ASSERT_EQ(1U, records.snapshots.size()); - EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types, + EXPECT_TRUE(CompareModelTypeSetToModelTypeStateMap(model_types, records.snapshots[0].source().types)); EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, records.snapshots[0].source().updates_source); @@ -299,7 +300,7 @@ TEST_F(SyncSchedulerTest, Nudge) { RunLoop(); ASSERT_EQ(1U, records2.snapshots.size()); - EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types, + EXPECT_TRUE(CompareModelTypeSetToModelTypeStateMap(model_types, records2.snapshots[0].source().types)); EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, records2.snapshots[0].source().updates_source); @@ -327,7 +328,7 @@ TEST_F(SyncSchedulerTest, Config) { ASSERT_EQ(1, counter.times_called()); ASSERT_EQ(1U, records.snapshots.size()); - EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types, + EXPECT_TRUE(CompareModelTypeSetToModelTypeStateMap(model_types, records.snapshots[0].source().types)); EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION, records.snapshots[0].source().updates_source); @@ -364,7 +365,7 @@ TEST_F(SyncSchedulerTest, ConfigWithBackingOff) { ASSERT_EQ(2U, records.snapshots.size()); ASSERT_EQ(1, counter.times_called()); - EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types, + EXPECT_TRUE(CompareModelTypeSetToModelTypeStateMap(model_types, records.snapshots[1].source().types)); EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION, records.snapshots[1].source().updates_source); @@ -417,12 +418,12 @@ TEST_F(SyncSchedulerTest, NudgeWithConfigWithBackingOff) { ASSERT_EQ(4U, records.snapshots.size()); - EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types, + EXPECT_TRUE(CompareModelTypeSetToModelTypeStateMap(model_types, records.snapshots[2].source().types)); EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION, records.snapshots[2].source().updates_source); - EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types, + EXPECT_TRUE(CompareModelTypeSetToModelTypeStateMap(model_types, records.snapshots[3].source().types)); EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, records.snapshots[3].source().updates_source); @@ -448,7 +449,7 @@ TEST_F(SyncSchedulerTest, NudgeCoalescing) { ASSERT_EQ(1U, r.snapshots.size()); EXPECT_GE(r.times[0], optimal_time); - EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap( + EXPECT_TRUE(CompareModelTypeSetToModelTypeStateMap( Union(types1, types2), r.snapshots[0].source().types)); EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, r.snapshots[0].source().updates_source); @@ -464,7 +465,7 @@ TEST_F(SyncSchedulerTest, NudgeCoalescing) { RunLoop(); ASSERT_EQ(1U, r2.snapshots.size()); - EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(types3, + EXPECT_TRUE(CompareModelTypeSetToModelTypeStateMap(types3, r2.snapshots[0].source().types)); EXPECT_EQ(GetUpdatesCallerInfo::NOTIFICATION, r2.snapshots[0].source().updates_source); @@ -496,7 +497,7 @@ TEST_F(SyncSchedulerTest, NudgeCoalescingWithDifferentTimings) { // Make sure the sync has happened. ASSERT_EQ(1U, r.snapshots.size()); - EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap( + EXPECT_TRUE(CompareModelTypeSetToModelTypeStateMap( Union(types1, types2), r.snapshots[0].source().types)); // Make sure the sync happened at the right time. @@ -505,23 +506,23 @@ TEST_F(SyncSchedulerTest, NudgeCoalescingWithDifferentTimings) { } // Test nudge scheduling. -TEST_F(SyncSchedulerTest, NudgeWithPayloads) { +TEST_F(SyncSchedulerTest, NudgeWithStates) { StartSyncScheduler(SyncScheduler::NORMAL_MODE); SyncShareRecords records; - ModelTypePayloadMap model_types_with_payloads; - model_types_with_payloads[BOOKMARKS] = "test"; + ModelTypeStateMap type_state_map; + type_state_map[BOOKMARKS].payload = "test"; EXPECT_CALL(*syncer(), SyncShare(_,_,_)) .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), WithArg<0>(RecordSyncShare(&records)))) .RetiresOnSaturation(); - scheduler()->ScheduleNudgeWithPayloadsAsync( - zero(), NUDGE_SOURCE_LOCAL, model_types_with_payloads, FROM_HERE); + scheduler()->ScheduleNudgeWithStatesAsync( + zero(), NUDGE_SOURCE_LOCAL, type_state_map, FROM_HERE); RunLoop(); ASSERT_EQ(1U, records.snapshots.size()); - EXPECT_EQ(model_types_with_payloads, records.snapshots[0].source().types); + EXPECT_THAT(type_state_map, Eq(records.snapshots[0].source().types)); EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, records.snapshots[0].source().updates_source); @@ -529,47 +530,47 @@ TEST_F(SyncSchedulerTest, NudgeWithPayloads) { // Make sure a second, later, nudge is unaffected by first (no coalescing). SyncShareRecords records2; - model_types_with_payloads.erase(BOOKMARKS); - model_types_with_payloads[AUTOFILL] = "test2"; + type_state_map.erase(BOOKMARKS); + type_state_map[AUTOFILL].payload = "test2"; EXPECT_CALL(*syncer(), SyncShare(_,_,_)) .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), WithArg<0>(RecordSyncShare(&records2)))); - scheduler()->ScheduleNudgeWithPayloadsAsync( - zero(), NUDGE_SOURCE_LOCAL, model_types_with_payloads, FROM_HERE); + scheduler()->ScheduleNudgeWithStatesAsync( + zero(), NUDGE_SOURCE_LOCAL, type_state_map, FROM_HERE); RunLoop(); ASSERT_EQ(1U, records2.snapshots.size()); - EXPECT_EQ(model_types_with_payloads, records2.snapshots[0].source().types); + EXPECT_THAT(type_state_map, Eq(records2.snapshots[0].source().types)); EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, records2.snapshots[0].source().updates_source); } // Test that nudges are coalesced. -TEST_F(SyncSchedulerTest, NudgeWithPayloadsCoalescing) { +TEST_F(SyncSchedulerTest, NudgeWithStatesCoalescing) { StartSyncScheduler(SyncScheduler::NORMAL_MODE); SyncShareRecords r; EXPECT_CALL(*syncer(), SyncShare(_,_,_)) .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), WithArg<0>(RecordSyncShare(&r)))); - ModelTypePayloadMap types1, types2, types3; - types1[BOOKMARKS] = "test1"; - types2[AUTOFILL] = "test2"; - types3[THEMES] = "test3"; + ModelTypeStateMap types1, types2, types3; + types1[BOOKMARKS].payload = "test1"; + types2[AUTOFILL].payload = "test2"; + types3[THEMES].payload = "test3"; TimeDelta delay = zero(); TimeTicks optimal_time = TimeTicks::Now() + delay; - scheduler()->ScheduleNudgeWithPayloadsAsync( + scheduler()->ScheduleNudgeWithStatesAsync( delay, NUDGE_SOURCE_UNKNOWN, types1, FROM_HERE); - scheduler()->ScheduleNudgeWithPayloadsAsync( + scheduler()->ScheduleNudgeWithStatesAsync( zero(), NUDGE_SOURCE_LOCAL, types2, FROM_HERE); RunLoop(); ASSERT_EQ(1U, r.snapshots.size()); EXPECT_GE(r.times[0], optimal_time); - ModelTypePayloadMap coalesced_types; - CoalescePayloads(&coalesced_types, types1); - CoalescePayloads(&coalesced_types, types2); - EXPECT_EQ(coalesced_types, r.snapshots[0].source().types); + ModelTypeStateMap coalesced_types; + CoalesceStates(&coalesced_types, types1); + CoalesceStates(&coalesced_types, types2); + EXPECT_THAT(coalesced_types, Eq(r.snapshots[0].source().types)); EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, r.snapshots[0].source().updates_source); @@ -579,12 +580,12 @@ TEST_F(SyncSchedulerTest, NudgeWithPayloadsCoalescing) { EXPECT_CALL(*syncer(), SyncShare(_,_,_)) .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), WithArg<0>(RecordSyncShare(&r2)))); - scheduler()->ScheduleNudgeWithPayloadsAsync( + scheduler()->ScheduleNudgeWithStatesAsync( zero(), NUDGE_SOURCE_NOTIFICATION, types3, FROM_HERE); RunLoop(); ASSERT_EQ(1U, r2.snapshots.size()); - EXPECT_EQ(types3, r2.snapshots[0].source().types); + EXPECT_THAT(types3, Eq(r2.snapshots[0].source().types)); EXPECT_EQ(GetUpdatesCallerInfo::NOTIFICATION, r2.snapshots[0].source().updates_source); } @@ -795,7 +796,7 @@ TEST_F(SyncSchedulerTest, ConfigurationMode) { ASSERT_EQ(1, counter.times_called()); ASSERT_EQ(1U, records.snapshots.size()); - EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(config_types, + EXPECT_TRUE(CompareModelTypeSetToModelTypeStateMap(config_types, records.snapshots[0].source().types)); } @@ -944,15 +945,15 @@ TEST_F(SyncSchedulerTest, BackoffElevation) { const TimeDelta fifth = TimeDelta::FromMilliseconds(5); const TimeDelta sixth = TimeDelta::FromDays(1); - EXPECT_CALL(*delay(), GetDelay(Eq(first))).WillOnce(Return(second)) + EXPECT_CALL(*delay(), GetDelay(first)).WillOnce(Return(second)) .RetiresOnSaturation(); - EXPECT_CALL(*delay(), GetDelay(Eq(second))).WillOnce(Return(third)) + EXPECT_CALL(*delay(), GetDelay(second)).WillOnce(Return(third)) .RetiresOnSaturation(); - EXPECT_CALL(*delay(), GetDelay(Eq(third))).WillOnce(Return(fourth)) + EXPECT_CALL(*delay(), GetDelay(third)).WillOnce(Return(fourth)) .RetiresOnSaturation(); - EXPECT_CALL(*delay(), GetDelay(Eq(fourth))).WillOnce(Return(fifth)) + EXPECT_CALL(*delay(), GetDelay(fourth)).WillOnce(Return(fifth)) .RetiresOnSaturation(); - EXPECT_CALL(*delay(), GetDelay(Eq(fifth))).WillOnce(Return(sixth)); + EXPECT_CALL(*delay(), GetDelay(fifth)).WillOnce(Return(sixth)); StartSyncScheduler(SyncScheduler::NORMAL_MODE); diff --git a/sync/engine/sync_scheduler_whitebox_unittest.cc b/sync/engine/sync_scheduler_whitebox_unittest.cc index afc8c6f..7f4dfdb 100644 --- a/sync/engine/sync_scheduler_whitebox_unittest.cc +++ b/sync/engine/sync_scheduler_whitebox_unittest.cc @@ -155,10 +155,10 @@ TEST_F(SyncSchedulerWhiteboxTest, SaveNudgeWhileTypeThrottled) { context()->throttled_data_type_tracker()->SetUnthrottleTime( types, base::TimeTicks::Now() + base::TimeDelta::FromHours(2)); - ModelTypePayloadMap types_with_payload; - types_with_payload[BOOKMARKS] = ""; + ModelTypeStateMap type_state_map; + type_state_map.insert(std::make_pair(BOOKMARKS, InvalidationState())); - SyncSourceInfo info(GetUpdatesCallerInfo::LOCAL, types_with_payload); + SyncSourceInfo info(GetUpdatesCallerInfo::LOCAL, type_state_map); SyncSession* s = scheduler_->CreateSyncSession(info); // Now schedule a nudge with just bookmarks and the change is local. diff --git a/sync/engine/syncer_unittest.cc b/sync/engine/syncer_unittest.cc index d82197f..506fa3f 100644 --- a/sync/engine/syncer_unittest.cc +++ b/sync/engine/syncer_unittest.cc @@ -178,8 +178,8 @@ class SyncerTest : public testing::Test, std::vector<ModelSafeWorker*> workers; GetModelSafeRoutingInfo(&info); GetWorkers(&workers); - ModelTypePayloadMap types = - ModelSafeRoutingInfoToPayloadMap(info, std::string()); + ModelTypeStateMap types = + ModelSafeRoutingInfoToStateMap(info, std::string()); return new SyncSession(context_.get(), this, sessions::SyncSourceInfo(sync_pb::GetUpdatesCallerInfo::UNKNOWN, types), info, workers); diff --git a/sync/internal_api/debug_info_event_listener.cc b/sync/internal_api/debug_info_event_listener.cc index d88981a..c48b7c9 100644 --- a/sync/internal_api/debug_info_event_listener.cc +++ b/sync/internal_api/debug_info_event_listener.cc @@ -109,9 +109,9 @@ void DebugInfoEventListener::OnNudgeFromDatatype(ModelType datatype) { } void DebugInfoEventListener::OnIncomingNotification( - const ModelTypePayloadMap& type_payloads) { + const ModelTypeStateMap& type_state_map) { sync_pb::DebugEventInfo event_info; - ModelTypeSet types = ModelTypePayloadMapToEnumSet(type_payloads); + ModelTypeSet types = ModelTypeStateMapToSet(type_state_map); for (ModelTypeSet::Iterator it = types.First(); it.Good(); it.Inc()) { event_info.add_datatypes_notified_from_server( diff --git a/sync/internal_api/debug_info_event_listener.h b/sync/internal_api/debug_info_event_listener.h index 158801d..252f64b 100644 --- a/sync/internal_api/debug_info_event_listener.h +++ b/sync/internal_api/debug_info_event_listener.h @@ -60,7 +60,7 @@ class DebugInfoEventListener : public SyncManager::Observer, // Sync manager events. void OnNudgeFromDatatype(ModelType datatype); - void OnIncomingNotification(const ModelTypePayloadMap& type_payloads); + void OnIncomingNotification(const ModelTypeStateMap& type_state_map); // DebugInfoGetter Implementation. virtual void GetAndClearDebugInfo(sync_pb::DebugInfo* debug_info) OVERRIDE; diff --git a/sync/internal_api/js_sync_manager_observer_unittest.cc b/sync/internal_api/js_sync_manager_observer_unittest.cc index 4cde1f6..6d8c9be8 100644 --- a/sync/internal_api/js_sync_manager_observer_unittest.cc +++ b/sync/internal_api/js_sync_manager_observer_unittest.cc @@ -72,7 +72,7 @@ TEST_F(JsSyncManagerObserverTest, OnInitializationComplete) { } TEST_F(JsSyncManagerObserverTest, OnSyncCycleCompleted) { - ModelTypePayloadMap download_progress_markers; + ModelTypeStateMap download_progress_markers; sessions::SyncSessionSnapshot snapshot(sessions::ModelNeutralState(), false, ModelTypeSet(), diff --git a/sync/internal_api/public/base/invalidation_state.h b/sync/internal_api/public/base/invalidation_state.h new file mode 100644 index 0000000..8b79019 --- /dev/null +++ b/sync/internal_api/public/base/invalidation_state.h @@ -0,0 +1,25 @@ +// 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_INVALIDATION_STATE_H_ +#define SYNC_INTERNAL_API_PUBLIC_BASE_INVALIDATION_STATE_H_ + +#include <string> + +namespace syncer { + +// Opaque class that represents an ack handle. +// TODO(dcheng): This is just a refactoring change, so the class is empty for +// the moment. It will be filled once we start implementing 'reminders'. +class AckHandle { +}; + +struct InvalidationState { + std::string payload; + AckHandle ack_handle; +}; + +} // namespace syncer + +#endif // SYNC_INTERNAL_API_PUBLIC_BASE_INVALIDATION_STATE_H_ diff --git a/sync/internal_api/public/base/invalidation_state_test_util.cc b/sync/internal_api/public/base/invalidation_state_test_util.cc new file mode 100644 index 0000000..a27d045 --- /dev/null +++ b/sync/internal_api/public/base/invalidation_state_test_util.cc @@ -0,0 +1,63 @@ +// 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/invalidation_state_test_util.h" + +#include "base/basictypes.h" +#include "sync/internal_api/public/base/invalidation_state.h" + +namespace syncer { + +using ::testing::MakeMatcher; +using ::testing::MatchResultListener; +using ::testing::Matcher; +using ::testing::MatcherInterface; +using ::testing::PrintToString; + +namespace { + +class InvalidationStateEqMatcher + : public MatcherInterface<const InvalidationState&> { + public: + explicit InvalidationStateEqMatcher(const InvalidationState& expected); + + virtual bool MatchAndExplain(const InvalidationState& actual, + MatchResultListener* listener) const; + virtual void DescribeTo(::std::ostream* os) const; + virtual void DescribeNegationTo(::std::ostream* os) const; + + private: + const InvalidationState expected_; + + DISALLOW_COPY_AND_ASSIGN(InvalidationStateEqMatcher); +}; + +InvalidationStateEqMatcher::InvalidationStateEqMatcher( + const InvalidationState& expected) : expected_(expected) { +} + +bool InvalidationStateEqMatcher::MatchAndExplain( + const InvalidationState& actual, MatchResultListener* listener) const { + return expected_.payload == actual.payload; +} + +void InvalidationStateEqMatcher::DescribeTo(::std::ostream* os) const { + *os << " is equal to " << PrintToString(expected_); +} + +void InvalidationStateEqMatcher::DescribeNegationTo(::std::ostream* os) const { + *os << " isn't equal to " << PrintToString(expected_); +} + +} // namespace + +void PrintTo(const InvalidationState& state, ::std::ostream* os) { + *os << "{ payload: " << state.payload << " }"; +} + +Matcher<const InvalidationState&> Eq(const InvalidationState& expected) { + return MakeMatcher(new InvalidationStateEqMatcher(expected)); +} + +} // namespace syncer diff --git a/sync/internal_api/public/base/invalidation_state_test_util.h b/sync/internal_api/public/base/invalidation_state_test_util.h new file mode 100644 index 0000000..77baccb --- /dev/null +++ b/sync/internal_api/public/base/invalidation_state_test_util.h @@ -0,0 +1,23 @@ +// 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_INVALIDATION_STATE_TEST_UTIL_H_ +#define SYNC_INTERNAL_API_PUBLIC_BASE_INVALIDATION_STATE_TEST_UTIL_H_ + +#include <iosfwd> + +#include "testing/gmock/include/gmock/gmock.h" + +namespace syncer { + +struct InvalidationState; + +void PrintTo(const InvalidationState& state, ::std::ostream* os); + +::testing::Matcher<const InvalidationState&> Eq( + const InvalidationState& expected); + +} // namespace syncer + +#endif // SYNC_INTERNAL_API_PUBLIC_BASE_INVALIDATION_STATE_TEST_UTIL_H_ diff --git a/sync/internal_api/public/base/model_type_payload_map.cc b/sync/internal_api/public/base/model_type_payload_map.cc deleted file mode 100644 index 1728130..0000000 --- a/sync/internal_api/public/base/model_type_payload_map.cc +++ /dev/null @@ -1,75 +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_payload_map.h" - -#include <vector> - -#include "base/base64.h" -#include "base/json/json_writer.h" -#include "base/memory/scoped_ptr.h" -#include "base/values.h" - -namespace syncer { - -ModelTypePayloadMap ModelTypePayloadMapFromEnumSet( - ModelTypeSet types, - const std::string& payload) { - ModelTypePayloadMap types_with_payloads; - for (ModelTypeSet::Iterator it = types.First(); it.Good(); it.Inc()) { - types_with_payloads[it.Get()] = payload; - } - return types_with_payloads; -} - -ModelTypeSet ModelTypePayloadMapToEnumSet( - const ModelTypePayloadMap& payload_map) { - ModelTypeSet types; - for (ModelTypePayloadMap::const_iterator it = payload_map.begin(); - it != payload_map.end(); ++it) { - types.Put(it->first); - } - return types; -} - -std::string ModelTypePayloadMapToString( - const ModelTypePayloadMap& type_payloads) { - scoped_ptr<DictionaryValue> value( - ModelTypePayloadMapToValue(type_payloads)); - std::string json; - base::JSONWriter::Write(value.get(), &json); - return json; -} - -DictionaryValue* ModelTypePayloadMapToValue( - const ModelTypePayloadMap& type_payloads) { - DictionaryValue* value = new DictionaryValue(); - for (ModelTypePayloadMap::const_iterator it = type_payloads.begin(); - it != type_payloads.end(); ++it) { - // TODO(akalin): Unpack the value into a protobuf. - std::string base64_marker; - bool encoded = base::Base64Encode(it->second, &base64_marker); - DCHECK(encoded); - value->SetString(ModelTypeToString(it->first), base64_marker); - } - return value; -} - -void CoalescePayloads(ModelTypePayloadMap* original, - const ModelTypePayloadMap& update) { - for (ModelTypePayloadMap::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.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] = i->second; - } - } -} - -} // namespace syncer diff --git a/sync/internal_api/public/base/model_type_payload_map.h b/sync/internal_api/public/base/model_type_payload_map.h deleted file mode 100644 index 66eb7f7..0000000 --- a/sync/internal_api/public/base/model_type_payload_map.h +++ /dev/null @@ -1,53 +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. -// -// Definition of ModelTypePayloadMap and various utility functions. - -#ifndef SYNC_INTERNAL_PUBLIC_API_BASE_MODEL_TYPE_PAYLOAD_MAP_H_ -#define SYNC_INTERNAL_PUBLIC_API_BASE_MODEL_TYPE_PAYLOAD_MAP_H_ - -#include <map> -#include <string> - -#include "sync/base/sync_export.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 container that contains a set of datatypes with possible string -// payloads. -typedef std::map<ModelType, std::string> ModelTypePayloadMap; - -// Helper functions for building ModelTypePayloadMaps. - -// Make a TypePayloadMap from all the types in a ModelTypeSet using a -// default payload. -SYNC_EXPORT ModelTypePayloadMap ModelTypePayloadMapFromEnumSet( - ModelTypeSet model_types, const std::string& payload); - -ModelTypeSet ModelTypePayloadMapToEnumSet( - const ModelTypePayloadMap& payload_map); - -std::string ModelTypePayloadMapToString( - const ModelTypePayloadMap& model_type_payloads); - -// Caller takes ownership of the returned dictionary. -base::DictionaryValue* ModelTypePayloadMapToValue( - const ModelTypePayloadMap& model_type_payloads); - -// Coalesce |update| into |original|, overwriting only when |update| has -// a non-empty payload. -void CoalescePayloads(ModelTypePayloadMap* original, - const ModelTypePayloadMap& update); - -} // namespace syncer - -#endif // SYNC_INTERNAL_PUBLIC_API_BASE_MODEL_TYPE_PAYLOAD_MAP_H_ diff --git a/sync/internal_api/public/base/model_type_payload_map_unittest.cc b/sync/internal_api/public/base/model_type_payload_map_unittest.cc deleted file mode 100644 index 19762eeb..0000000 --- a/sync/internal_api/public/base/model_type_payload_map_unittest.cc +++ /dev/null @@ -1,73 +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_payload_map.h" - -#include <string> - -#include "base/base64.h" -#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 ModelTypePayloadMapTest : public testing::Test {}; - -TEST_F(ModelTypePayloadMapTest, TypePayloadMapToSet) { - ModelTypePayloadMap payloads; - payloads[BOOKMARKS] = "bookmarkpayload"; - payloads[APPS] = ""; - - const ModelTypeSet types(BOOKMARKS, APPS); - EXPECT_TRUE(ModelTypePayloadMapToEnumSet(payloads).Equals(types)); -} - -TEST_F(ModelTypePayloadMapTest, TypePayloadMapToValue) { - ModelTypePayloadMap payloads; - std::string encoded; - payloads[BOOKMARKS] = "bookmarkpayload"; - base::Base64Encode(payloads[BOOKMARKS], &encoded); - payloads[APPS] = ""; - - scoped_ptr<DictionaryValue> value(ModelTypePayloadMapToValue(payloads)); - EXPECT_EQ(2u, value->size()); - ExpectDictStringValue(encoded, *value, "Bookmarks"); - ExpectDictStringValue("", *value, "Apps"); - EXPECT_FALSE(value->HasKey("Preferences")); -} - -TEST_F(ModelTypePayloadMapTest, CoalescePayloads) { - ModelTypePayloadMap original; - std::string empty_payload; - std::string payload1 = "payload1"; - std::string payload2 = "payload2"; - std::string payload3 = "payload3"; - original[BOOKMARKS] = empty_payload; - original[PASSWORDS] = payload1; - original[AUTOFILL] = payload2; - original[THEMES] = payload3; - - ModelTypePayloadMap update; - update[BOOKMARKS] = empty_payload; // Same. - update[PASSWORDS] = empty_payload; // Overwrite with empty. - update[AUTOFILL] = payload1; // Overwrite with non-empty. - update[SESSIONS] = payload2; // New. - // Themes untouched. - - CoalescePayloads(&original, update); - ASSERT_EQ(5U, original.size()); - EXPECT_EQ(empty_payload, original[BOOKMARKS]); - EXPECT_EQ(payload1, original[PASSWORDS]); - EXPECT_EQ(payload1, original[AUTOFILL]); - EXPECT_EQ(payload2, original[SESSIONS]); - EXPECT_EQ(payload3, original[THEMES]); -} - -} // namespace -} // namespace syncer diff --git a/sync/internal_api/public/base/model_type_state_map.cc b/sync/internal_api/public/base/model_type_state_map.cc new file mode 100644 index 0000000..fbdff7d --- /dev/null +++ b/sync/internal_api/public/base/model_type_state_map.cc @@ -0,0 +1,76 @@ +// 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_state_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 { + +ModelTypeStateMap ModelTypeSetToStateMap(ModelTypeSet types, + const std::string& payload) { + ModelTypeStateMap type_state_map; + for (ModelTypeSet::Iterator it = types.First(); it.Good(); it.Inc()) { + // TODO(dcheng): Do we need to set ack_handle? + type_state_map[it.Get()].payload = payload; + } + return type_state_map; +} + +ModelTypeSet ModelTypeStateMapToSet( + const ModelTypeStateMap& type_state_map) { + ModelTypeSet types; + for (ModelTypeStateMap::const_iterator it = type_state_map.begin(); + it != type_state_map.end(); ++it) { + types.Put(it->first); + } + return types; +} + +std::string ModelTypeStateMapToString(const ModelTypeStateMap& type_state_map) { + scoped_ptr<DictionaryValue> value(ModelTypeStateMapToValue(type_state_map)); + std::string json; + base::JSONWriter::Write(value.get(), &json); + return json; +} + +DictionaryValue* ModelTypeStateMapToValue( + const ModelTypeStateMap& type_state_map) { + DictionaryValue* value = new DictionaryValue(); + for (ModelTypeStateMap::const_iterator it = type_state_map.begin(); + it != type_state_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(ModelTypeStateMap* original, + const ModelTypeStateMap& update) { + // 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 (ModelTypeStateMap::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_state_map.h b/sync/internal_api/public/base/model_type_state_map.h new file mode 100644 index 0000000..71b0e65 --- /dev/null +++ b/sync/internal_api/public/base/model_type_state_map.h @@ -0,0 +1,54 @@ +// 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. +// +// Definition of ModelTypeStateMap and various utility functions. + +#ifndef SYNC_INTERNAL_PUBLIC_API_BASE_MODEL_TYPE_STATE_MAP_H_ +#define SYNC_INTERNAL_PUBLIC_API_BASE_MODEL_TYPE_STATE_MAP_H_ + +#include <map> +#include <string> + +#include "sync/base/sync_export.h" +#include "sync/internal_api/public/base/invalidation_state.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 container that contains a set of datatypes with possible string +// payloads. +typedef std::map<ModelType, InvalidationState> ModelTypeStateMap; + +// Helper functions for building ModelTypeStateMaps. + +// Make a TypeStateMap from all the types in a ModelTypeSet using a +// default payload. +SYNC_EXPORT ModelTypeStateMap ModelTypeSetToStateMap( + ModelTypeSet model_types, const std::string& payload); + +ModelTypeSet ModelTypeStateMapToSet( + const ModelTypeStateMap& payload_map); + +std::string ModelTypeStateMapToString( + const ModelTypeStateMap& model_type_payloads); + +// Caller takes ownership of the returned dictionary. +base::DictionaryValue* ModelTypeStateMapToValue( + const ModelTypeStateMap& model_type_payloads); + +// Coalesce |update| into |original|, overwriting only when |update| has +// a non-empty payload. +void CoalesceStates(ModelTypeStateMap* original, + const ModelTypeStateMap& update); + +} // namespace syncer + +#endif // SYNC_INTERNAL_PUBLIC_API_BASE_MODEL_TYPE_STATE_MAP_H_ diff --git a/sync/internal_api/public/base/model_type_state_map_test_util.cc b/sync/internal_api/public/base/model_type_state_map_test_util.cc new file mode 100644 index 0000000..3b975f8 --- /dev/null +++ b/sync/internal_api/public/base/model_type_state_map_test_util.cc @@ -0,0 +1,111 @@ +// 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_state_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 ModelTypeStateMapEqMatcher + : public MatcherInterface<const ModelTypeStateMap&> { + public: + explicit ModelTypeStateMapEqMatcher(const ModelTypeStateMap& expected); + + virtual bool MatchAndExplain(const ModelTypeStateMap& lhs, + MatchResultListener* listener) const; + virtual void DescribeTo(::std::ostream* os) const; + virtual void DescribeNegationTo(::std::ostream* os) const; + + private: + const ModelTypeStateMap expected_; + + DISALLOW_COPY_AND_ASSIGN(ModelTypeStateMapEqMatcher); +}; + +ModelTypeStateMapEqMatcher::ModelTypeStateMapEqMatcher( + const ModelTypeStateMap& expected) : expected_(expected) { +} + +bool ModelTypeStateMapEqMatcher::MatchAndExplain( + const ModelTypeStateMap& actual, MatchResultListener* listener) const { + ModelTypeStateMap expected_only; + ModelTypeStateMap actual_only; + typedef std::pair<ModelType, + std::pair<InvalidationState, InvalidationState> > + 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 (ModelTypeStateMap::const_iterator it = expected_.begin(); + it != expected_.end(); ++it) { + ModelTypeStateMap::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 ModelTypeStateMapEqMatcher::DescribeTo(::std::ostream* os) const { + *os << " is equal to " << PrintToString(expected_); +} + +void ModelTypeStateMapEqMatcher::DescribeNegationTo(::std::ostream* os) const { + *os << " isn't equal to " << PrintToString(expected_); +} + +} // namespace + +Matcher<const ModelTypeStateMap&> Eq(const ModelTypeStateMap& expected) { + return MakeMatcher(new ModelTypeStateMapEqMatcher(expected)); +} + +} // namespace syncer diff --git a/sync/internal_api/public/base/model_type_state_map_test_util.h b/sync/internal_api/public/base/model_type_state_map_test_util.h new file mode 100644 index 0000000..3538816 --- /dev/null +++ b/sync/internal_api/public/base/model_type_state_map_test_util.h @@ -0,0 +1,20 @@ +// 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_state_test_util.h" +#include "sync/internal_api/public/base/model_type_state_map.h" +#include "testing/gmock/include/gmock/gmock.h" + +namespace syncer { + +::testing::Matcher<const ModelTypeStateMap&> Eq( + const ModelTypeStateMap& 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_state_map_unittest.cc b/sync/internal_api/public/base/model_type_state_map_unittest.cc new file mode 100644 index 0000000..1981f3d --- /dev/null +++ b/sync/internal_api/public/base/model_type_state_map_unittest.cc @@ -0,0 +1,70 @@ +// 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_state_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 ModelTypeStateMapTest : public testing::Test {}; + +TEST_F(ModelTypeStateMapTest, TypeStateMapToSet) { + ModelTypeStateMap states; + states[BOOKMARKS].payload = "bookmarkpayload"; + states[APPS].payload = ""; + + const ModelTypeSet types(BOOKMARKS, APPS); + EXPECT_TRUE(ModelTypeStateMapToSet(states).Equals(types)); +} + +TEST_F(ModelTypeStateMapTest, TypeStateMapToValue) { + ModelTypeStateMap states; + states[BOOKMARKS].payload = "bookmarkpayload"; + states[APPS].payload = ""; + + scoped_ptr<DictionaryValue> value(ModelTypeStateMapToValue(states)); + EXPECT_EQ(2u, value->size()); + ExpectDictStringValue(states[BOOKMARKS].payload, *value, "Bookmarks"); + ExpectDictStringValue("", *value, "Apps"); + EXPECT_FALSE(value->HasKey("Preferences")); +} + +TEST_F(ModelTypeStateMapTest, CoalesceStates) { + ModelTypeStateMap 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; + + ModelTypeStateMap 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(&original, update); + 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/engine/model_safe_worker.cc b/sync/internal_api/public/engine/model_safe_worker.cc index cd7eaea..2212a41 100644 --- a/sync/internal_api/public/engine/model_safe_worker.cc +++ b/sync/internal_api/public/engine/model_safe_worker.cc @@ -29,15 +29,15 @@ std::string ModelSafeRoutingInfoToString( return json; } -ModelTypePayloadMap ModelSafeRoutingInfoToPayloadMap( +ModelTypeStateMap ModelSafeRoutingInfoToStateMap( const ModelSafeRoutingInfo& routes, const std::string& payload) { - ModelTypePayloadMap types_with_payloads; + ModelTypeStateMap type_state_map; for (ModelSafeRoutingInfo::const_iterator i = routes.begin(); i != routes.end(); ++i) { - types_with_payloads[i->first] = payload; + type_state_map[i->first].payload = payload; } - return types_with_payloads; + return type_state_map; } ModelTypeSet GetRoutingInfoTypes(const ModelSafeRoutingInfo& routing_info) { diff --git a/sync/internal_api/public/engine/model_safe_worker.h b/sync/internal_api/public/engine/model_safe_worker.h index d67f4b6..d76ddb9 100644 --- a/sync/internal_api/public/engine/model_safe_worker.h +++ b/sync/internal_api/public/engine/model_safe_worker.h @@ -13,7 +13,7 @@ #include "base/memory/ref_counted.h" #include "sync/base/sync_export.h" #include "sync/internal_api/public/base/model_type.h" -#include "sync/internal_api/public/base/model_type_payload_map.h" +#include "sync/internal_api/public/base/model_type_state_map.h" #include "sync/internal_api/public/util/syncer_error.h" namespace base { @@ -80,9 +80,9 @@ base::DictionaryValue* ModelSafeRoutingInfoToValue( SYNC_EXPORT std::string ModelSafeRoutingInfoToString( const ModelSafeRoutingInfo& routing_info); -// Make a ModelTypePayloadMap for all the enabled types in a +// Make a ModelTypeStateMap for all the enabled types in a // ModelSafeRoutingInfo using a default payload. -ModelTypePayloadMap ModelSafeRoutingInfoToPayloadMap( +ModelTypeStateMap ModelSafeRoutingInfoToStateMap( const ModelSafeRoutingInfo& routes, const std::string& payload); 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 5acf460..9c65894 100644 --- a/sync/internal_api/public/engine/model_safe_worker_unittest.cc +++ b/sync/internal_api/public/engine/model_safe_worker_unittest.cc @@ -48,19 +48,19 @@ TEST_F(ModelSafeWorkerTest, GetRoutingInfoTypes) { EXPECT_TRUE(GetRoutingInfoTypes(routing_info).Equals(expected_types)); } -TEST_F(ModelSafeWorkerTest, ModelSafeRoutingInfoToPayloadMap) { +TEST_F(ModelSafeWorkerTest, ModelSafeRoutingInfoToStateMap) { std::string payload = "test"; ModelSafeRoutingInfo routing_info; routing_info[BOOKMARKS] = GROUP_PASSIVE; routing_info[NIGORI] = GROUP_UI; routing_info[PREFERENCES] = GROUP_DB; - ModelTypePayloadMap types_with_payloads = - ModelSafeRoutingInfoToPayloadMap(routing_info, payload); - ASSERT_EQ(routing_info.size(), types_with_payloads.size()); + ModelTypeStateMap type_state_map = + ModelSafeRoutingInfoToStateMap(routing_info, payload); + ASSERT_EQ(routing_info.size(), type_state_map.size()); for (ModelSafeRoutingInfo::iterator iter = routing_info.begin(); iter != routing_info.end(); ++iter) { - EXPECT_EQ(payload, types_with_payloads[iter->first]); + EXPECT_EQ(payload, type_state_map[iter->first].payload); } } diff --git a/sync/internal_api/public/sessions/sync_session_snapshot.cc b/sync/internal_api/public/sessions/sync_session_snapshot.cc index 5e1e4e7..9e7a3b1 100644 --- a/sync/internal_api/public/sessions/sync_session_snapshot.cc +++ b/sync/internal_api/public/sessions/sync_session_snapshot.cc @@ -29,7 +29,7 @@ SyncSessionSnapshot::SyncSessionSnapshot( const ModelNeutralState& model_neutral_state, bool is_share_usable, ModelTypeSet initial_sync_ended, - const ModelTypePayloadMap& download_progress_markers, + const ModelTypeStateMap& download_progress_markers, bool more_to_sync, bool is_silenced, int num_encryption_conflicts, @@ -84,7 +84,7 @@ DictionaryValue* SyncSessionSnapshot::ToValue() const { value->Set("initialSyncEnded", ModelTypeSetToValue(initial_sync_ended_)); value->Set("downloadProgressMarkers", - ModelTypePayloadMapToValue(download_progress_markers_)); + ModelTypeStateMapToValue(download_progress_markers_)); value->SetBoolean("hasMoreToSync", has_more_to_sync_); value->SetBoolean("isSilenced", is_silenced_); // We don't care too much if we lose precision here, also. @@ -123,7 +123,7 @@ ModelTypeSet SyncSessionSnapshot::initial_sync_ended() const { return initial_sync_ended_; } -ModelTypePayloadMap SyncSessionSnapshot::download_progress_markers() const { +ModelTypeStateMap SyncSessionSnapshot::download_progress_markers() const { return download_progress_markers_; } diff --git a/sync/internal_api/public/sessions/sync_session_snapshot.h b/sync/internal_api/public/sessions/sync_session_snapshot.h index d6fb025..74e972b 100644 --- a/sync/internal_api/public/sessions/sync_session_snapshot.h +++ b/sync/internal_api/public/sessions/sync_session_snapshot.h @@ -10,7 +10,7 @@ #include "base/basictypes.h" #include "base/time.h" #include "sync/internal_api/public/base/model_type.h" -#include "sync/internal_api/public/base/model_type_payload_map.h" +#include "sync/internal_api/public/base/model_type_state_map.h" #include "sync/internal_api/public/sessions/model_neutral_state.h" #include "sync/internal_api/public/sessions/sync_source_info.h" @@ -33,7 +33,7 @@ class SyncSessionSnapshot { const ModelNeutralState& model_neutral_state, bool is_share_usable, ModelTypeSet initial_sync_ended, - const ModelTypePayloadMap& download_progress_markers, + const ModelTypeStateMap& download_progress_markers, bool more_to_sync, bool is_silenced, int num_encryption_conflicts, @@ -58,7 +58,7 @@ class SyncSessionSnapshot { int64 num_server_changes_remaining() const; bool is_share_usable() const; ModelTypeSet initial_sync_ended() const; - ModelTypePayloadMap download_progress_markers() const; + ModelTypeStateMap download_progress_markers() const; bool has_more_to_sync() const; bool is_silenced() const; int num_encryption_conflicts() const; @@ -78,7 +78,7 @@ class SyncSessionSnapshot { ModelNeutralState model_neutral_state_; bool is_share_usable_; ModelTypeSet initial_sync_ended_; - ModelTypePayloadMap download_progress_markers_; + ModelTypeStateMap download_progress_markers_; bool has_more_to_sync_; bool is_silenced_; int num_encryption_conflicts_; diff --git a/sync/internal_api/public/sessions/sync_source_info.cc b/sync/internal_api/public/sessions/sync_source_info.cc index 9e15289..8a64c8a 100644 --- a/sync/internal_api/public/sessions/sync_source_info.cc +++ b/sync/internal_api/public/sessions/sync_source_info.cc @@ -13,12 +13,12 @@ namespace sessions { SyncSourceInfo::SyncSourceInfo() : updates_source(sync_pb::GetUpdatesCallerInfo::UNKNOWN) {} -SyncSourceInfo::SyncSourceInfo(const ModelTypePayloadMap& t) +SyncSourceInfo::SyncSourceInfo(const ModelTypeStateMap& t) : updates_source(sync_pb::GetUpdatesCallerInfo::UNKNOWN), types(t) {} SyncSourceInfo::SyncSourceInfo( const sync_pb::GetUpdatesCallerInfo::GetUpdatesSource& u, - const ModelTypePayloadMap& t) + const ModelTypeStateMap& t) : updates_source(u), types(t) {} SyncSourceInfo::~SyncSourceInfo() {} @@ -27,7 +27,7 @@ DictionaryValue* SyncSourceInfo::ToValue() const { DictionaryValue* value = new DictionaryValue(); value->SetString("updatesSource", GetUpdatesSourceString(updates_source)); - value->Set("types", ModelTypePayloadMapToValue(types)); + value->Set("types", ModelTypeStateMapToValue(types)); return value; } diff --git a/sync/internal_api/public/sessions/sync_source_info.h b/sync/internal_api/public/sessions/sync_source_info.h index 390bdb5..619fc57 100644 --- a/sync/internal_api/public/sessions/sync_source_info.h +++ b/sync/internal_api/public/sessions/sync_source_info.h @@ -7,7 +7,7 @@ #include "base/basictypes.h" #include "sync/internal_api/public/base/model_type.h" -#include "sync/internal_api/public/base/model_type_payload_map.h" +#include "sync/internal_api/public/base/model_type_state_map.h" #include "sync/protocol/sync.pb.h" namespace base { @@ -22,17 +22,17 @@ namespace sessions { // specific payloads which should be sent to the server. struct SyncSourceInfo { SyncSourceInfo(); - explicit SyncSourceInfo(const ModelTypePayloadMap& t); + explicit SyncSourceInfo(const ModelTypeStateMap& t); SyncSourceInfo( const sync_pb::GetUpdatesCallerInfo::GetUpdatesSource& u, - const ModelTypePayloadMap& t); + const ModelTypeStateMap& t); ~SyncSourceInfo(); // Caller takes ownership of the returned dictionary. base::DictionaryValue* ToValue() const; sync_pb::GetUpdatesCallerInfo::GetUpdatesSource updates_source; - ModelTypePayloadMap types; + ModelTypeStateMap types; }; } // namespace sessions diff --git a/sync/internal_api/public/test/fake_sync_manager.h b/sync/internal_api/public/test/fake_sync_manager.h index 91a25d1..604429f 100644 --- a/sync/internal_api/public/test/fake_sync_manager.h +++ b/sync/internal_api/public/test/fake_sync_manager.h @@ -54,7 +54,7 @@ class FakeSyncManager : public SyncManager { ModelTypeSet GetAndResetEnabledTypes(); // Posts a method to invalidate the given IDs on the sync thread. - void Invalidate(const ObjectIdPayloadMap& id_payloads, + void Invalidate(const ObjectIdStateMap& id_state_map, IncomingNotificationSource source); // Posts a method to enable notifications on the sync thread. @@ -125,7 +125,7 @@ class FakeSyncManager : public SyncManager { private: void InvalidateOnSyncThread( - const ObjectIdPayloadMap& id_payloads, + const ObjectIdStateMap& id_state_map, IncomingNotificationSource source); void EnableNotificationsOnSyncThread(); void DisableNotificationsOnSyncThread(NotificationsDisabledReason reason); diff --git a/sync/internal_api/sync_manager_impl.cc b/sync/internal_api/sync_manager_impl.cc index 4335fe1..ccf5cea 100644 --- a/sync/internal_api/sync_manager_impl.cc +++ b/sync/internal_api/sync_manager_impl.cc @@ -21,7 +21,7 @@ #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_payload_map.h" +#include "sync/internal_api/public/base/model_type_state_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" @@ -1017,7 +1017,7 @@ void SyncManagerImpl::OnSyncEngineEvent(const SyncEngineEvent& event) { if (is_notifiable_commit) { if (sync_notifier_.get()) { const ModelTypeSet changed_types = - ModelTypePayloadMapToEnumSet(event.snapshot.source().types); + ModelTypeStateMapToSet(event.snapshot.source().types); sync_notifier_->SendNotification(changed_types); } else { DVLOG(1) << "Not sending notification: sync_notifier_ is NULL"; @@ -1259,12 +1259,12 @@ JsArgList SyncManagerImpl::GetChildNodeIds(const JsArgList& args) { } void SyncManagerImpl::UpdateNotificationInfo( - const ModelTypePayloadMap& type_payloads) { - for (ModelTypePayloadMap::const_iterator it = type_payloads.begin(); - it != type_payloads.end(); ++it) { + const ModelTypeStateMap& type_state_map) { + for (ModelTypeStateMap::const_iterator it = type_state_map.begin(); + it != type_state_map.end(); ++it) { NotificationInfo* info = ¬ification_info_map_[it->first]; info->total_count++; - info->payload = it->second; + info->payload = it->second.payload; } } @@ -1278,24 +1278,24 @@ void SyncManagerImpl::OnNotificationsDisabled( } void SyncManagerImpl::OnIncomingNotification( - const ObjectIdPayloadMap& id_payloads, + const ObjectIdStateMap& id_state_map, IncomingNotificationSource source) { DCHECK(thread_checker_.CalledOnValidThread()); - const ModelTypePayloadMap& type_payloads = - ObjectIdPayloadMapToModelTypePayloadMap(id_payloads); + const ModelTypeStateMap& type_state_map = + ObjectIdStateMapToModelTypeStateMap(id_state_map); if (source == LOCAL_NOTIFICATION) { - scheduler_->ScheduleNudgeWithPayloadsAsync( + scheduler_->ScheduleNudgeWithStatesAsync( TimeDelta::FromMilliseconds(kSyncRefreshDelayMsec), NUDGE_SOURCE_LOCAL_REFRESH, - type_payloads, FROM_HERE); - } else if (!type_payloads.empty()) { - scheduler_->ScheduleNudgeWithPayloadsAsync( + type_state_map, FROM_HERE); + } else if (!type_state_map.empty()) { + scheduler_->ScheduleNudgeWithStatesAsync( TimeDelta::FromMilliseconds(kSyncSchedulerDelayMsec), NUDGE_SOURCE_NOTIFICATION, - type_payloads, FROM_HERE); + type_state_map, FROM_HERE); allstatus_.IncrementNotificationsReceived(); - UpdateNotificationInfo(type_payloads); - debug_info_event_listener_.OnIncomingNotification(type_payloads); + UpdateNotificationInfo(type_state_map); + debug_info_event_listener_.OnIncomingNotification(type_state_map); } else { LOG(WARNING) << "Sync received notification without any type information."; } @@ -1304,8 +1304,8 @@ void SyncManagerImpl::OnIncomingNotification( DictionaryValue details; ListValue* changed_types = new ListValue(); details.Set("changedTypes", changed_types); - for (ModelTypePayloadMap::const_iterator it = type_payloads.begin(); - it != type_payloads.end(); ++it) { + for (ModelTypeStateMap::const_iterator it = type_state_map.begin(); + it != type_state_map.end(); ++it) { const std::string& model_type_str = ModelTypeToString(it->first); changed_types->Append(Value::CreateStringValue(model_type_str)); diff --git a/sync/internal_api/sync_manager_impl.h b/sync/internal_api/sync_manager_impl.h index 7b2a6c4..b0ed231 100644 --- a/sync/internal_api/sync_manager_impl.h +++ b/sync/internal_api/sync_manager_impl.h @@ -171,7 +171,7 @@ class SyncManagerImpl : public SyncManager, virtual void OnNotificationsDisabled( NotificationsDisabledReason reason) OVERRIDE; virtual void OnIncomingNotification( - const ObjectIdPayloadMap& id_payloads, + const ObjectIdStateMap& id_state_map, IncomingNotificationSource source) OVERRIDE; // Called only by our NetworkChangeNotifier. @@ -255,7 +255,7 @@ class SyncManagerImpl : public SyncManager, // Called for every notification. This updates the notification statistics // to be displayed in about:sync. void UpdateNotificationInfo( - const ModelTypePayloadMap& type_payloads); + const ModelTypeStateMap& type_state_map); // Checks for server reachabilty and requests a nudge. void OnIPAddressChangedImpl(); diff --git a/sync/internal_api/sync_manager_impl_unittest.cc b/sync/internal_api/sync_manager_impl_unittest.cc index 48b81c1..dc3ea15 100644 --- a/sync/internal_api/sync_manager_impl_unittest.cc +++ b/sync/internal_api/sync_manager_impl_unittest.cc @@ -942,10 +942,10 @@ class SyncManagerTest : public testing::Test, void TriggerOnIncomingNotificationForTest(ModelTypeSet model_types) { DCHECK(sync_manager_.thread_checker_.CalledOnValidThread()); - ModelTypePayloadMap model_types_with_payloads = - ModelTypePayloadMapFromEnumSet(model_types, std::string()); + ModelTypeStateMap type_state_map = + ModelTypeSetToStateMap(model_types, std::string()); sync_manager_.OnIncomingNotification( - ModelTypePayloadMapToObjectIdPayloadMap(model_types_with_payloads), + ModelTypeStateMapToObjectIdStateMap(type_state_map), REMOTE_NOTIFICATION); } diff --git a/sync/internal_api/test/fake_sync_manager.cc b/sync/internal_api/test/fake_sync_manager.cc index 97e729e..6bf55fc 100644 --- a/sync/internal_api/test/fake_sync_manager.cc +++ b/sync/internal_api/test/fake_sync_manager.cc @@ -17,7 +17,7 @@ #include "sync/internal_api/public/internal_components_factory.h" #include "sync/internal_api/public/util/weak_handle.h" #include "sync/notifier/notifications_disabled_reason.h" -#include "sync/notifier/object_id_payload_map.h" +#include "sync/notifier/object_id_state_map.h" #include "sync/notifier/sync_notifier.h" #include "sync/test/fake_sync_encryption_handler.h" @@ -52,12 +52,12 @@ ModelTypeSet FakeSyncManager::GetAndResetEnabledTypes() { return enabled_types; } -void FakeSyncManager::Invalidate(const ObjectIdPayloadMap& id_payloads, +void FakeSyncManager::Invalidate(const ObjectIdStateMap& id_state_map, IncomingNotificationSource source) { if (!sync_task_runner_->PostTask( FROM_HERE, base::Bind(&FakeSyncManager::InvalidateOnSyncThread, - base::Unretained(this), id_payloads, source))) { + base::Unretained(this), id_state_map, source))) { NOTREACHED(); } } @@ -265,10 +265,10 @@ SyncEncryptionHandler* FakeSyncManager::GetEncryptionHandler() { } void FakeSyncManager::InvalidateOnSyncThread( - const ObjectIdPayloadMap& id_payloads, + const ObjectIdStateMap& id_state_map, IncomingNotificationSource source) { DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); - registrar_.DispatchInvalidationsToHandlers(id_payloads, source); + registrar_.DispatchInvalidationsToHandlers(id_state_map, source); } void FakeSyncManager::EnableNotificationsOnSyncThread() { diff --git a/sync/notifier/chrome_invalidation_client.cc b/sync/notifier/chrome_invalidation_client.cc index 6ec4659..e2f406d 100644 --- a/sync/notifier/chrome_invalidation_client.cc +++ b/sync/notifier/chrome_invalidation_client.cc @@ -162,9 +162,9 @@ void ChromeInvalidationClient::Invalidate( if (invalidation.has_payload()) payload = invalidation.payload(); - ObjectIdPayloadMap id_payloads; - id_payloads[id] = payload; - EmitInvalidation(id_payloads); + ObjectIdStateMap id_state_map; + id_state_map[id].payload = payload; + EmitInvalidation(id_state_map); // TODO(akalin): We should really acknowledge only after we get the // updates from the sync server. (see http://crbug.com/78462). client->Acknowledge(ack_handle); @@ -178,9 +178,9 @@ void ChromeInvalidationClient::InvalidateUnknownVersion( DCHECK_EQ(client, invalidation_client_.get()); DVLOG(1) << "InvalidateUnknownVersion"; - ObjectIdPayloadMap id_payloads; - id_payloads[object_id] = std::string(); - EmitInvalidation(id_payloads); + ObjectIdStateMap id_state_map; + id_state_map[object_id].payload = std::string(); + EmitInvalidation(id_state_map); // TODO(akalin): We should really acknowledge only after we get the // updates from the sync server. (see http://crbug.com/78462). client->Acknowledge(ack_handle); @@ -195,21 +195,21 @@ void ChromeInvalidationClient::InvalidateAll( DCHECK_EQ(client, invalidation_client_.get()); DVLOG(1) << "InvalidateAll"; - ObjectIdPayloadMap id_payloads; + ObjectIdStateMap id_state_map; for (ObjectIdSet::const_iterator it = registered_ids_.begin(); it != registered_ids_.end(); ++it) { - id_payloads[*it] = std::string(); + id_state_map[*it].payload = std::string(); } - EmitInvalidation(id_payloads); + EmitInvalidation(id_state_map); // TODO(akalin): We should really acknowledge only after we get the // updates from the sync server. (see http://crbug.com/76482). client->Acknowledge(ack_handle); } void ChromeInvalidationClient::EmitInvalidation( - const ObjectIdPayloadMap& id_payloads) { + const ObjectIdStateMap& id_state_map) { DCHECK(CalledOnValidThread()); - listener_->OnInvalidate(id_payloads); + listener_->OnInvalidate(id_state_map); } void ChromeInvalidationClient::InformRegistrationStatus( diff --git a/sync/notifier/chrome_invalidation_client.h b/sync/notifier/chrome_invalidation_client.h index e05808c..fc6c43d 100644 --- a/sync/notifier/chrome_invalidation_client.h +++ b/sync/notifier/chrome_invalidation_client.h @@ -22,7 +22,7 @@ #include "sync/notifier/chrome_system_resources.h" #include "sync/notifier/invalidation_state_tracker.h" #include "sync/notifier/notifications_disabled_reason.h" -#include "sync/notifier/object_id_payload_map.h" +#include "sync/notifier/object_id_state_map.h" #include "sync/notifier/state_writer.h" namespace buzz { @@ -56,7 +56,7 @@ class ChromeInvalidationClient public: virtual ~Listener(); - virtual void OnInvalidate(const ObjectIdPayloadMap& id_payloads) = 0; + virtual void OnInvalidate(const ObjectIdStateMap& id_state_map) = 0; virtual void OnNotificationsEnabled() = 0; @@ -137,7 +137,7 @@ class ChromeInvalidationClient void EmitStateChange(); - void EmitInvalidation(const ObjectIdPayloadMap& id_payloads); + void EmitInvalidation(const ObjectIdStateMap& id_state_map); // Owned by |chrome_system_resources_|. notifier::PushClient* const push_client_; diff --git a/sync/notifier/chrome_invalidation_client_unittest.cc b/sync/notifier/chrome_invalidation_client_unittest.cc index 1cc9bc5..a7c8f8af 100644 --- a/sync/notifier/chrome_invalidation_client_unittest.cc +++ b/sync/notifier/chrome_invalidation_client_unittest.cc @@ -140,8 +140,8 @@ class FakeListener : public ChromeInvalidationClient::Listener { } std::string GetPayload(const ObjectId& id) const { - ObjectIdPayloadMap::const_iterator it = payloads_.find(id); - return (it == payloads_.end()) ? "" : it->second; + ObjectIdStateMap::const_iterator it = states_.find(id); + return (it == states_.end()) ? "" : it->second.payload; } // NO_NOTIFICATION_ERROR is the enabled state. @@ -151,11 +151,11 @@ class FakeListener : public ChromeInvalidationClient::Listener { // ChromeInvalidationClient::Listener implementation. - virtual void OnInvalidate(const ObjectIdPayloadMap& id_payloads) OVERRIDE { - for (ObjectIdPayloadMap::const_iterator it = id_payloads.begin(); - it != id_payloads.end(); ++it) { + virtual void OnInvalidate(const ObjectIdStateMap& id_state_map) OVERRIDE { + for (ObjectIdStateMap::const_iterator it = id_state_map.begin(); + it != id_state_map.end(); ++it) { ++invalidation_counts_[it->first]; - payloads_[it->first] = it->second; + states_[it->first] = it->second; } } @@ -170,7 +170,7 @@ class FakeListener : public ChromeInvalidationClient::Listener { private: typedef std::map<ObjectId, int, ObjectIdLessThan> ObjectIdCountMap; ObjectIdCountMap invalidation_counts_; - ObjectIdPayloadMap payloads_; + ObjectIdStateMap states_; NotificationsDisabledReason reason_; }; diff --git a/sync/notifier/invalidation_notifier.cc b/sync/notifier/invalidation_notifier.cc index 1b7ac86..f56bbd6 100644 --- a/sync/notifier/invalidation_notifier.cc +++ b/sync/notifier/invalidation_notifier.cc @@ -11,7 +11,6 @@ #include "google/cacheinvalidation/include/invalidation-client-factory.h" #include "jingle/notifier/listener/push_client.h" #include "net/url_request/url_request_context.h" -#include "sync/internal_api/public/base/model_type_payload_map.h" #include "sync/notifier/sync_notifier_observer.h" #include "talk/xmpp/jid.h" #include "talk/xmpp/xmppclientsettings.h" @@ -100,9 +99,9 @@ void InvalidationNotifier::SendNotification(ModelTypeSet changed_types) { // Do nothing. } -void InvalidationNotifier::OnInvalidate(const ObjectIdPayloadMap& id_payloads) { +void InvalidationNotifier::OnInvalidate(const ObjectIdStateMap& id_state_map) { DCHECK(CalledOnValidThread()); - registrar_.DispatchInvalidationsToHandlers(id_payloads, REMOTE_NOTIFICATION); + registrar_.DispatchInvalidationsToHandlers(id_state_map, REMOTE_NOTIFICATION); } void InvalidationNotifier::OnNotificationsEnabled() { diff --git a/sync/notifier/invalidation_notifier.h b/sync/notifier/invalidation_notifier.h index 6cbe44d..91c16c3 100644 --- a/sync/notifier/invalidation_notifier.h +++ b/sync/notifier/invalidation_notifier.h @@ -60,7 +60,7 @@ class InvalidationNotifier virtual void SendNotification(ModelTypeSet changed_types) OVERRIDE; // ChromeInvalidationClient::Listener implementation. - virtual void OnInvalidate(const ObjectIdPayloadMap& id_payloads) OVERRIDE; + virtual void OnInvalidate(const ObjectIdStateMap& id_state_map) OVERRIDE; virtual void OnNotificationsEnabled() OVERRIDE; virtual void OnNotificationsDisabled( NotificationsDisabledReason reason) OVERRIDE; diff --git a/sync/notifier/invalidation_notifier_unittest.cc b/sync/notifier/invalidation_notifier_unittest.cc index 973c26f..bdf88eb 100644 --- a/sync/notifier/invalidation_notifier_unittest.cc +++ b/sync/notifier/invalidation_notifier_unittest.cc @@ -11,11 +11,12 @@ #include "jingle/notifier/listener/fake_push_client.h" #include "net/url_request/url_request_test_util.h" #include "sync/internal_api/public/base/model_type.h" -#include "sync/internal_api/public/base/model_type_payload_map.h" +#include "sync/internal_api/public/base/model_type_state_map.h" #include "sync/internal_api/public/util/weak_handle.h" #include "sync/notifier/fake_invalidation_state_tracker.h" #include "sync/notifier/invalidation_state_tracker.h" #include "sync/notifier/mock_sync_notifier_observer.h" +#include "sync/notifier/object_id_state_map_test_util.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -84,11 +85,11 @@ TEST_F(InvalidationNotifierTest, Basic) { CreateNotifier("fake_state"); const ModelTypeSet models(PREFERENCES, BOOKMARKS, AUTOFILL); - const ModelTypePayloadMap& type_payloads = - ModelTypePayloadMapFromEnumSet(models, "payload"); + const ModelTypeStateMap& type_state_map = + ModelTypeSetToStateMap(models, "payload"); EXPECT_CALL(mock_observer_, OnNotificationsEnabled()); EXPECT_CALL(mock_observer_, OnIncomingNotification( - ModelTypePayloadMapToObjectIdPayloadMap(type_payloads), + ModelTypeStateMapToObjectIdStateMap(type_state_map), REMOTE_NOTIFICATION)); EXPECT_CALL(mock_observer_, OnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR)); @@ -110,7 +111,7 @@ TEST_F(InvalidationNotifierTest, Basic) { invalidation_notifier_->OnNotificationsEnabled(); invalidation_notifier_->OnInvalidate( - ModelTypePayloadMapToObjectIdPayloadMap(type_payloads)); + ModelTypeStateMapToObjectIdStateMap(type_state_map)); invalidation_notifier_->OnNotificationsDisabled( TRANSIENT_NOTIFICATION_ERROR); diff --git a/sync/notifier/invalidation_util.cc b/sync/notifier/invalidation_util.cc index b10e2b4..7307292 100644 --- a/sync/notifier/invalidation_util.cc +++ b/sync/notifier/invalidation_util.cc @@ -4,11 +4,18 @@ #include "sync/notifier/invalidation_util.h" +#include <ostream> #include <sstream> #include "google/cacheinvalidation/include/types.h" #include "google/cacheinvalidation/types.pb.h" +namespace invalidation { +void PrintTo(const invalidation::ObjectId& id, std::ostream* os) { + *os << syncer::ObjectIdToString(id); +} +} // namespace invalidation + namespace syncer { bool ObjectIdLessThan::operator()(const invalidation::ObjectId& lhs, diff --git a/sync/notifier/invalidation_util.h b/sync/notifier/invalidation_util.h index bc43523..2f3198b 100644 --- a/sync/notifier/invalidation_util.h +++ b/sync/notifier/invalidation_util.h @@ -7,6 +7,7 @@ #ifndef SYNC_NOTIFIER_INVALIDATION_UTIL_H_ #define SYNC_NOTIFIER_INVALIDATION_UTIL_H_ +#include <iosfwd> #include <set> #include <string> @@ -17,6 +18,9 @@ namespace invalidation { class Invalidation; class ObjectId; +// Gmock print helper +void PrintTo(const invalidation::ObjectId& id, std::ostream* os); + } // namespace invalidation namespace syncer { diff --git a/sync/notifier/mock_sync_notifier_observer.h b/sync/notifier/mock_sync_notifier_observer.h index fc88c52..6a50ad4 100644 --- a/sync/notifier/mock_sync_notifier_observer.h +++ b/sync/notifier/mock_sync_notifier_observer.h @@ -20,7 +20,7 @@ class MockSyncNotifierObserver : public SyncNotifierObserver { MOCK_METHOD0(OnNotificationsEnabled, void()); MOCK_METHOD1(OnNotificationsDisabled, void(NotificationsDisabledReason)); MOCK_METHOD2(OnIncomingNotification, - void(const ObjectIdPayloadMap&, IncomingNotificationSource)); + void(const ObjectIdStateMap&, IncomingNotificationSource)); }; } // namespace syncer diff --git a/sync/notifier/non_blocking_invalidation_notifier.cc b/sync/notifier/non_blocking_invalidation_notifier.cc index c561c35..89fb19a 100644 --- a/sync/notifier/non_blocking_invalidation_notifier.cc +++ b/sync/notifier/non_blocking_invalidation_notifier.cc @@ -46,7 +46,7 @@ class NonBlockingInvalidationNotifier::Core virtual void OnNotificationsDisabled( NotificationsDisabledReason reason) OVERRIDE; virtual void OnIncomingNotification( - const ObjectIdPayloadMap& id_payloads, + const ObjectIdStateMap& id_state_map, IncomingNotificationSource source) OVERRIDE; private: @@ -139,11 +139,11 @@ void NonBlockingInvalidationNotifier::Core::OnNotificationsDisabled( } void NonBlockingInvalidationNotifier::Core::OnIncomingNotification( - const ObjectIdPayloadMap& id_payloads, IncomingNotificationSource source) { + const ObjectIdStateMap& id_state_map, IncomingNotificationSource source) { DCHECK(network_task_runner_->BelongsToCurrentThread()); delegate_observer_.Call(FROM_HERE, &SyncNotifierObserver::OnIncomingNotification, - id_payloads, + id_state_map, source); } @@ -265,10 +265,10 @@ void NonBlockingInvalidationNotifier::OnNotificationsDisabled( } void NonBlockingInvalidationNotifier::OnIncomingNotification( - const ObjectIdPayloadMap& id_payloads, + const ObjectIdStateMap& id_state_map, IncomingNotificationSource source) { DCHECK(parent_task_runner_->BelongsToCurrentThread()); - registrar_.DispatchInvalidationsToHandlers(id_payloads, source); + registrar_.DispatchInvalidationsToHandlers(id_state_map, source); } } // namespace syncer diff --git a/sync/notifier/non_blocking_invalidation_notifier.h b/sync/notifier/non_blocking_invalidation_notifier.h index 9577297..849c9813 100644 --- a/sync/notifier/non_blocking_invalidation_notifier.h +++ b/sync/notifier/non_blocking_invalidation_notifier.h @@ -61,7 +61,7 @@ class NonBlockingInvalidationNotifier virtual void OnNotificationsDisabled( NotificationsDisabledReason reason) OVERRIDE; virtual void OnIncomingNotification( - const ObjectIdPayloadMap& id_payloads, + const ObjectIdStateMap& id_state_map, IncomingNotificationSource source) OVERRIDE; private: diff --git a/sync/notifier/non_blocking_invalidation_notifier_unittest.cc b/sync/notifier/non_blocking_invalidation_notifier_unittest.cc index f237cdb..1121b4b 100644 --- a/sync/notifier/non_blocking_invalidation_notifier_unittest.cc +++ b/sync/notifier/non_blocking_invalidation_notifier_unittest.cc @@ -12,10 +12,11 @@ #include "jingle/notifier/base/fake_base_task.h" #include "net/url_request/url_request_test_util.h" #include "sync/internal_api/public/base/model_type.h" -#include "sync/internal_api/public/base/model_type_payload_map.h" +#include "sync/internal_api/public/base/model_type_state_map.h" #include "sync/internal_api/public/util/weak_handle.h" #include "sync/notifier/invalidation_state_tracker.h" #include "sync/notifier/mock_sync_notifier_observer.h" +#include "sync/notifier/object_id_state_map_test_util.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -71,11 +72,11 @@ TEST_F(NonBlockingInvalidationNotifierTest, Basic) { InSequence dummy; const ModelTypeSet models(PREFERENCES, BOOKMARKS, AUTOFILL); - const ModelTypePayloadMap& type_payloads = - ModelTypePayloadMapFromEnumSet(models, "payload"); + const ModelTypeStateMap& type_state_map = + ModelTypeSetToStateMap(models, "payload"); EXPECT_CALL(mock_observer_, OnNotificationsEnabled()); EXPECT_CALL(mock_observer_, OnIncomingNotification( - ModelTypePayloadMapToObjectIdPayloadMap(type_payloads), + ModelTypeStateMapToObjectIdStateMap(type_state_map), REMOTE_NOTIFICATION)); EXPECT_CALL(mock_observer_, OnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR)); @@ -91,7 +92,7 @@ TEST_F(NonBlockingInvalidationNotifierTest, Basic) { invalidation_notifier_->OnNotificationsEnabled(); invalidation_notifier_->OnIncomingNotification( - ModelTypePayloadMapToObjectIdPayloadMap(type_payloads), + ModelTypeStateMapToObjectIdStateMap(type_state_map), REMOTE_NOTIFICATION); invalidation_notifier_->OnNotificationsDisabled( TRANSIENT_NOTIFICATION_ERROR); diff --git a/sync/notifier/object_id_payload_map.cc b/sync/notifier/object_id_payload_map.cc deleted file mode 100644 index 7fa1f7c..0000000 --- a/sync/notifier/object_id_payload_map.cc +++ /dev/null @@ -1,59 +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/notifier/object_id_payload_map.h" - -namespace syncer { - -ObjectIdSet ObjectIdPayloadMapToSet( - const ObjectIdPayloadMap& id_payloads) { - ObjectIdSet ids; - for (ObjectIdPayloadMap::const_iterator it = id_payloads.begin(); - it != id_payloads.end(); ++it) { - ids.insert(it->first); - } - return ids; -} - -ObjectIdPayloadMap ObjectIdSetToPayloadMap(ObjectIdSet ids, - const std::string& payload) { - ObjectIdPayloadMap id_payloads; - for (ObjectIdSet::const_iterator it = ids.begin(); it != ids.end(); ++it) { - id_payloads[*it] = payload; - } - return id_payloads; -} - -ModelTypePayloadMap ObjectIdPayloadMapToModelTypePayloadMap( - const ObjectIdPayloadMap& id_payloads) { - ModelTypePayloadMap types_with_payloads; - for (ObjectIdPayloadMap::const_iterator it = id_payloads.begin(); - it != id_payloads.end(); ++it) { - ModelType model_type; - if (!ObjectIdToRealModelType(it->first, &model_type)) { - DLOG(WARNING) << "Invalid object ID: " - << ObjectIdToString(it->first); - continue; - } - types_with_payloads[model_type] = it->second; - } - return types_with_payloads; -} - -ObjectIdPayloadMap ModelTypePayloadMapToObjectIdPayloadMap( - const ModelTypePayloadMap& type_payloads) { - ObjectIdPayloadMap id_payloads; - for (ModelTypePayloadMap::const_iterator it = type_payloads.begin(); - it != type_payloads.end(); ++it) { - invalidation::ObjectId id; - if (!RealModelTypeToObjectId(it->first, &id)) { - DLOG(WARNING) << "Invalid model type " << it->first; - continue; - } - id_payloads[id] = it->second; - } - return id_payloads; -} - -} // namespace syncer diff --git a/sync/notifier/object_id_payload_map.h b/sync/notifier/object_id_payload_map.h deleted file mode 100644 index e0300dc..0000000 --- a/sync/notifier/object_id_payload_map.h +++ /dev/null @@ -1,34 +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_NOTIFIER_OBJECT_ID_PAYLOAD_MAP_H_ -#define SYNC_NOTIFIER_OBJECT_ID_PAYLOAD_MAP_H_ - -#include <map> -#include <string> - -#include "google/cacheinvalidation/include/types.h" -#include "sync/internal_api/public/base/model_type_payload_map.h" -#include "sync/notifier/invalidation_util.h" - -namespace syncer { - -typedef std::map<invalidation::ObjectId, - std::string, - ObjectIdLessThan> ObjectIdPayloadMap; - -// Converts between ObjectIdPayloadMaps and ObjectIdSets. -ObjectIdSet ObjectIdPayloadMapToSet(const ObjectIdPayloadMap& id_payloads); -ObjectIdPayloadMap ObjectIdSetToPayloadMap(ObjectIdSet ids, - const std::string& payload); - -// Converts between ObjectIdPayloadMaps and ModelTypePayloadMaps. -ModelTypePayloadMap ObjectIdPayloadMapToModelTypePayloadMap( - const ObjectIdPayloadMap& id_payloads); -ObjectIdPayloadMap ModelTypePayloadMapToObjectIdPayloadMap( - const ModelTypePayloadMap& type_payloads); - -} // namespace syncer - -#endif // HOME_DCHENG_SRC_CHROMIUM_SRC_SYNC_NOTIFIER_OBJECT_ID_PAYLOAD_MAP_H_ diff --git a/sync/notifier/object_id_state_map.cc b/sync/notifier/object_id_state_map.cc new file mode 100644 index 0000000..2d3b7f7 --- /dev/null +++ b/sync/notifier/object_id_state_map.cc @@ -0,0 +1,59 @@ +// 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/notifier/object_id_state_map.h" + +namespace syncer { + +ObjectIdSet ObjectIdStateMapToSet(const ObjectIdStateMap& id_state_map) { + ObjectIdSet ids; + for (ObjectIdStateMap::const_iterator it = id_state_map.begin(); + it != id_state_map.end(); ++it) { + ids.insert(it->first); + } + return ids; +} + +ObjectIdStateMap ObjectIdSetToStateMap(const ObjectIdSet& ids, + const std::string& payload) { + ObjectIdStateMap id_state_map; + for (ObjectIdSet::const_iterator it = ids.begin(); it != ids.end(); ++it) { + // TODO(dcheng): Do we need to provide a way to set AckHandle? + id_state_map[*it].payload = payload; + } + return id_state_map; +} + +ModelTypeStateMap ObjectIdStateMapToModelTypeStateMap( + const ObjectIdStateMap& id_state_map) { + ModelTypeStateMap type_state_map; + for (ObjectIdStateMap::const_iterator it = id_state_map.begin(); + it != id_state_map.end(); ++it) { + ModelType model_type; + if (!ObjectIdToRealModelType(it->first, &model_type)) { + DLOG(WARNING) << "Invalid object ID: " + << ObjectIdToString(it->first); + continue; + } + type_state_map[model_type] = it->second; + } + return type_state_map; +} + +ObjectIdStateMap ModelTypeStateMapToObjectIdStateMap( + const ModelTypeStateMap& type_state_map) { + ObjectIdStateMap id_state_map; + for (ModelTypeStateMap::const_iterator it = type_state_map.begin(); + it != type_state_map.end(); ++it) { + invalidation::ObjectId id; + if (!RealModelTypeToObjectId(it->first, &id)) { + DLOG(WARNING) << "Invalid model type " << it->first; + continue; + } + id_state_map[id] = it->second; + } + return id_state_map; +} + +} // namespace syncer diff --git a/sync/notifier/object_id_state_map.h b/sync/notifier/object_id_state_map.h new file mode 100644 index 0000000..17f8ceb --- /dev/null +++ b/sync/notifier/object_id_state_map.h @@ -0,0 +1,35 @@ +// 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_NOTIFIER_OBJECT_ID_STATE_MAP_H_ +#define SYNC_NOTIFIER_OBJECT_ID_STATE_MAP_H_ + +#include <map> +#include <string> + +#include "google/cacheinvalidation/include/types.h" +#include "sync/internal_api/public/base/invalidation_state.h" +#include "sync/internal_api/public/base/model_type_state_map.h" +#include "sync/notifier/invalidation_util.h" + +namespace syncer { + +typedef std::map<invalidation::ObjectId, + InvalidationState, + ObjectIdLessThan> ObjectIdStateMap; + +// Converts between ObjectIdStateMaps and ObjectIdSets. +ObjectIdSet ObjectIdStateMapToSet(const ObjectIdStateMap& id_payloads); +ObjectIdStateMap ObjectIdSetToStateMap(const ObjectIdSet& ids, + const std::string& payload); + +// Converts between ObjectIdStateMaps and ModelTypeStateMaps. +ModelTypeStateMap ObjectIdStateMapToModelTypeStateMap( + const ObjectIdStateMap& id_payloads); +ObjectIdStateMap ModelTypeStateMapToObjectIdStateMap( + const ModelTypeStateMap& type_payloads); + +} // namespace syncer + +#endif // HOME_DCHENG_SRC_CHROMIUM_SRC_SYNC_NOTIFIER_OBJECT_ID_STATE_MAP_H_ diff --git a/sync/notifier/object_id_state_map_test_util.cc b/sync/notifier/object_id_state_map_test_util.cc new file mode 100644 index 0000000..58659af --- /dev/null +++ b/sync/notifier/object_id_state_map_test_util.cc @@ -0,0 +1,110 @@ +// 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/notifier/object_id_state_map_test_util.h" + +#include <algorithm> + +#include "base/basictypes.h" + +namespace syncer { + +using ::testing::MakeMatcher; +using ::testing::MatchResultListener; +using ::testing::Matcher; +using ::testing::MatcherInterface; +using ::testing::PrintToString; + +namespace { + +class ObjectIdStateMapEqMatcher + : public MatcherInterface<const ObjectIdStateMap&> { + public: + explicit ObjectIdStateMapEqMatcher(const ObjectIdStateMap& expected); + + virtual bool MatchAndExplain(const ObjectIdStateMap& actual, + MatchResultListener* listener) const; + virtual void DescribeTo(::std::ostream* os) const; + virtual void DescribeNegationTo(::std::ostream* os) const; + + private: + const ObjectIdStateMap expected_; + + DISALLOW_COPY_AND_ASSIGN(ObjectIdStateMapEqMatcher); +}; + +ObjectIdStateMapEqMatcher::ObjectIdStateMapEqMatcher( + const ObjectIdStateMap& expected) : expected_(expected) { +} + +bool ObjectIdStateMapEqMatcher::MatchAndExplain( + const ObjectIdStateMap& actual, MatchResultListener* listener) const { + ObjectIdStateMap expected_only; + ObjectIdStateMap actual_only; + typedef std::pair<invalidation::ObjectId, + std::pair<InvalidationState, InvalidationState> > + 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 (ObjectIdStateMap::const_iterator it = expected_.begin(); + it != expected_.end(); ++it) { + ObjectIdStateMap::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 ObjectIdStateMapEqMatcher::DescribeTo(::std::ostream* os) const { + *os << " is equal to " << PrintToString(expected_); +} + +void ObjectIdStateMapEqMatcher::DescribeNegationTo(::std::ostream* os) const { + *os << " isn't equal to " << PrintToString(expected_); +} + +} // namespace + +Matcher<const ObjectIdStateMap&> Eq(const ObjectIdStateMap& expected) { + return MakeMatcher(new ObjectIdStateMapEqMatcher(expected)); +} + +} // namespace syncer diff --git a/sync/notifier/object_id_state_map_test_util.h b/sync/notifier/object_id_state_map_test_util.h new file mode 100644 index 0000000..7b26b93 --- /dev/null +++ b/sync/notifier/object_id_state_map_test_util.h @@ -0,0 +1,20 @@ +// 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_NOTIFIER_OBJECT_ID_STATE_MAP_TEST_UTILH_ +#define SYNC_NOTIFIER_OBJECT_ID_STATE_MAP_TEST_UTILH_ + +// Convince googletest to use the correct overload for PrintTo(). +#include "sync/internal_api/public/base/invalidation_state_test_util.h" +#include "sync/notifier/object_id_state_map.h" +#include "testing/gmock/include/gmock/gmock.h" + +namespace syncer { + +::testing::Matcher<const ObjectIdStateMap&> Eq( + const ObjectIdStateMap& expected); + +} // namespace syncer + +#endif // SYNC_NOTIFIER_OBJECT_ID_STATE_MAP_TEST_UTILH_ diff --git a/sync/notifier/p2p_notifier.cc b/sync/notifier/p2p_notifier.cc index dab7221..44fa05a 100644 --- a/sync/notifier/p2p_notifier.cc +++ b/sync/notifier/p2p_notifier.cc @@ -11,7 +11,7 @@ #include "base/logging.h" #include "base/values.h" #include "jingle/notifier/listener/push_client.h" -#include "sync/internal_api/public/base/model_type_payload_map.h" +#include "sync/internal_api/public/base/model_type_state_map.h" #include "sync/notifier/invalidation_util.h" #include "sync/notifier/sync_notifier_observer.h" @@ -268,10 +268,10 @@ void P2PNotifier::OnIncomingNotification( DVLOG(1) << "No enabled and changed types -- not emitting notification"; return; } - const ModelTypePayloadMap& type_payloads = ModelTypePayloadMapFromEnumSet( + const ModelTypeStateMap& type_state_map = ModelTypeSetToStateMap( notification_data.GetChangedTypes(), std::string()); registrar_.DispatchInvalidationsToHandlers( - ModelTypePayloadMapToObjectIdPayloadMap(type_payloads), + ModelTypeStateMapToObjectIdStateMap(type_state_map), REMOTE_NOTIFICATION); } diff --git a/sync/notifier/p2p_notifier_unittest.cc b/sync/notifier/p2p_notifier_unittest.cc index 97033ea..9ad6f8a 100644 --- a/sync/notifier/p2p_notifier_unittest.cc +++ b/sync/notifier/p2p_notifier_unittest.cc @@ -8,8 +8,9 @@ #include "jingle/notifier/listener/fake_push_client.h" #include "sync/internal_api/public/base/model_type.h" -#include "sync/internal_api/public/base/model_type_payload_map.h" +#include "sync/internal_api/public/base/model_type_state_map.h" #include "sync/notifier/mock_sync_notifier_observer.h" +#include "sync/notifier/object_id_state_map_test_util.h" #include "testing/gtest/include/gtest/gtest.h" namespace syncer { @@ -35,8 +36,8 @@ class P2PNotifierTest : public testing::Test { p2p_notifier_.UnregisterHandler(&mock_observer_); } - ModelTypePayloadMap MakePayloadMap(ModelTypeSet types) { - return ModelTypePayloadMapFromEnumSet(types, std::string()); + ModelTypeStateMap MakeStateMap(ModelTypeSet types) { + return ModelTypeSetToStateMap(types, std::string()); } // Simulate receiving all the notifications we sent out since last @@ -145,7 +146,8 @@ TEST_F(P2PNotifierTest, NotificationsBasic) { EXPECT_CALL(mock_observer_, OnNotificationsEnabled()); EXPECT_CALL(mock_observer_, OnIncomingNotification( - ModelTypePayloadMapToObjectIdPayloadMap(MakePayloadMap(enabled_types)), + ModelTypeStateMapToObjectIdStateMap(MakeStateMap( + enabled_types)), REMOTE_NOTIFICATION)); p2p_notifier_.UpdateRegisteredIds(&mock_observer_, @@ -191,15 +193,15 @@ TEST_F(P2PNotifierTest, SendNotificationData) { EXPECT_CALL(mock_observer_, OnNotificationsEnabled()); EXPECT_CALL(mock_observer_, OnIncomingNotification( - ModelTypePayloadMapToObjectIdPayloadMap( - MakePayloadMap(enabled_types)), + ModelTypeStateMapToObjectIdStateMap( + MakeStateMap(enabled_types)), REMOTE_NOTIFICATION)); p2p_notifier_.UpdateRegisteredIds(&mock_observer_, ModelTypeSetToObjectIdSet(enabled_types)); - const ModelTypePayloadMap& expected_payload_map = - MakePayloadMap(expected_types); + const ModelTypeStateMap& expected_state_map = + MakeStateMap(expected_types); p2p_notifier_.SetUniqueId("sender"); p2p_notifier_.UpdateCredentials("foo@bar.com", "fake_token"); @@ -218,7 +220,7 @@ TEST_F(P2PNotifierTest, SendNotificationData) { // Should be propagated. Mock::VerifyAndClearExpectations(&mock_observer_); EXPECT_CALL(mock_observer_, OnIncomingNotification( - ModelTypePayloadMapToObjectIdPayloadMap(expected_payload_map), + ModelTypeStateMapToObjectIdStateMap(expected_state_map), REMOTE_NOTIFICATION)); p2p_notifier_.SendNotificationDataForTest( P2PNotificationData("sender", NOTIFY_SELF, changed_types)); @@ -248,7 +250,7 @@ TEST_F(P2PNotifierTest, SendNotificationData) { // Should be propagated. Mock::VerifyAndClearExpectations(&mock_observer_); EXPECT_CALL(mock_observer_, OnIncomingNotification( - ModelTypePayloadMapToObjectIdPayloadMap(expected_payload_map), + ModelTypeStateMapToObjectIdStateMap(expected_state_map), REMOTE_NOTIFICATION)); p2p_notifier_.SendNotificationDataForTest( P2PNotificationData("sender2", NOTIFY_OTHERS, changed_types)); @@ -265,7 +267,7 @@ TEST_F(P2PNotifierTest, SendNotificationData) { // Should be propagated. Mock::VerifyAndClearExpectations(&mock_observer_); EXPECT_CALL(mock_observer_, OnIncomingNotification( - ModelTypePayloadMapToObjectIdPayloadMap(expected_payload_map), + ModelTypeStateMapToObjectIdStateMap(expected_state_map), REMOTE_NOTIFICATION)); p2p_notifier_.SendNotificationDataForTest( P2PNotificationData("sender", NOTIFY_ALL, changed_types)); @@ -275,7 +277,7 @@ TEST_F(P2PNotifierTest, SendNotificationData) { // Should be propagated. Mock::VerifyAndClearExpectations(&mock_observer_); EXPECT_CALL(mock_observer_, OnIncomingNotification( - ModelTypePayloadMapToObjectIdPayloadMap(expected_payload_map), + ModelTypeStateMapToObjectIdStateMap(expected_state_map), REMOTE_NOTIFICATION)); p2p_notifier_.SendNotificationDataForTest( P2PNotificationData("sender2", NOTIFY_ALL, changed_types)); diff --git a/sync/notifier/sync_notifier_factory_unittest.cc b/sync/notifier/sync_notifier_factory_unittest.cc index 50d923b..64c802f 100644 --- a/sync/notifier/sync_notifier_factory_unittest.cc +++ b/sync/notifier/sync_notifier_factory_unittest.cc @@ -15,7 +15,6 @@ #include "jingle/notifier/base/notifier_options.h" #include "net/url_request/url_request_test_util.h" #include "sync/internal_api/public/base/model_type.h" -#include "sync/internal_api/public/base/model_type_payload_map.h" #include "sync/notifier/invalidation_state_tracker.h" #include "sync/notifier/mock_sync_notifier_observer.h" #include "sync/notifier/sync_notifier.h" diff --git a/sync/notifier/sync_notifier_observer.h b/sync/notifier/sync_notifier_observer.h index b79f838..1dd5ea6 100644 --- a/sync/notifier/sync_notifier_observer.h +++ b/sync/notifier/sync_notifier_observer.h @@ -5,7 +5,7 @@ #ifndef SYNC_NOTIFIER_SYNC_NOTIFIER_OBSERVER_H_ #define SYNC_NOTIFIER_SYNC_NOTIFIER_OBSERVER_H_ -#include "sync/notifier/object_id_payload_map.h" +#include "sync/notifier/object_id_state_map.h" #include "sync/notifier/notifications_disabled_reason.h" namespace syncer { @@ -27,10 +27,10 @@ class SyncNotifierObserver { virtual void OnNotificationsDisabled( NotificationsDisabledReason reason) = 0; - // Called when a notification is received. The per-id payloads - // are in |type_payloads| and the source is in |source|. + // Called when a notification is received. The per-id states + // are in |id_state_map| and the source is in |source|. virtual void OnIncomingNotification( - const ObjectIdPayloadMap& id_payloads, + const ObjectIdStateMap& id_state_map, IncomingNotificationSource source) = 0; protected: diff --git a/sync/notifier/sync_notifier_registrar.cc b/sync/notifier/sync_notifier_registrar.cc index 02c00b6..77c394c 100644 --- a/sync/notifier/sync_notifier_registrar.cc +++ b/sync/notifier/sync_notifier_registrar.cc @@ -74,7 +74,7 @@ ObjectIdSet SyncNotifierRegistrar::GetAllRegisteredIds() const { } void SyncNotifierRegistrar::DispatchInvalidationsToHandlers( - const ObjectIdPayloadMap& id_payloads, + const ObjectIdStateMap& id_state_map, IncomingNotificationSource source) { DCHECK(thread_checker_.CalledOnValidThread()); // If we have no handlers, there's nothing to do. @@ -82,10 +82,10 @@ void SyncNotifierRegistrar::DispatchInvalidationsToHandlers( return; } - typedef std::map<SyncNotifierObserver*, ObjectIdPayloadMap> DispatchMap; + typedef std::map<SyncNotifierObserver*, ObjectIdStateMap> DispatchMap; DispatchMap dispatch_map; - for (ObjectIdPayloadMap::const_iterator it = id_payloads.begin(); - it != id_payloads.end(); ++it) { + for (ObjectIdStateMap::const_iterator it = id_state_map.begin(); + it != id_state_map.end(); ++it) { SyncNotifierObserver* const handler = ObjectIdToHandler(it->first); // Filter out invalidations for IDs with no handler. if (handler) diff --git a/sync/notifier/sync_notifier_registrar.h b/sync/notifier/sync_notifier_registrar.h index 949e3ca..4ebdc14 100644 --- a/sync/notifier/sync_notifier_registrar.h +++ b/sync/notifier/sync_notifier_registrar.h @@ -11,7 +11,7 @@ #include "base/observer_list.h" #include "base/threading/thread_checker.h" #include "sync/notifier/invalidation_util.h" -#include "sync/notifier/object_id_payload_map.h" +#include "sync/notifier/object_id_state_map.h" #include "sync/notifier/sync_notifier_observer.h" namespace invalidation { @@ -53,7 +53,7 @@ class SyncNotifierRegistrar { // dispatches the batched invalidations to the corresponding handler. // Invalidations for IDs with no corresponding handler are dropped, as are // invalidations for handlers that are not added. - void DispatchInvalidationsToHandlers(const ObjectIdPayloadMap& id_payloads, + void DispatchInvalidationsToHandlers(const ObjectIdStateMap& id_state_map, IncomingNotificationSource source); // Calls the given handler method for each handler that has registered IDs. diff --git a/sync/notifier/sync_notifier_registrar_unittest.cc b/sync/notifier/sync_notifier_registrar_unittest.cc index e8c1b40..f78ebc9 100644 --- a/sync/notifier/sync_notifier_registrar_unittest.cc +++ b/sync/notifier/sync_notifier_registrar_unittest.cc @@ -4,6 +4,7 @@ #include "google/cacheinvalidation/types.pb.h" #include "sync/notifier/mock_sync_notifier_observer.h" +#include "sync/notifier/object_id_state_map_test_util.h" #include "sync/notifier/sync_notifier_registrar.h" #include "testing/gtest/include/gtest/gtest.h" @@ -40,13 +41,13 @@ TEST_F(SyncNotifierRegistrarTest, Basic) { registrar.RegisterHandler(&handler); - ObjectIdPayloadMap payloads; - payloads[kObjectId1] = "1"; - payloads[kObjectId2] = "2"; - payloads[kObjectId3] = "3"; + ObjectIdStateMap states; + states[kObjectId1].payload = "1"; + states[kObjectId2].payload = "2"; + states[kObjectId3].payload = "3"; // Should be ignored since no IDs are registered to |handler|. - registrar.DispatchInvalidationsToHandlers(payloads, REMOTE_NOTIFICATION); + registrar.DispatchInvalidationsToHandlers(states, REMOTE_NOTIFICATION); Mock::VerifyAndClearExpectations(&handler); @@ -56,14 +57,14 @@ TEST_F(SyncNotifierRegistrarTest, Basic) { registrar.UpdateRegisteredIds(&handler, ids); { - ObjectIdPayloadMap expected_payloads; - expected_payloads[kObjectId1] = "1"; - expected_payloads[kObjectId2] = "2"; - EXPECT_CALL(handler, OnIncomingNotification(expected_payloads, - REMOTE_NOTIFICATION)); + ObjectIdStateMap expected_states; + expected_states[kObjectId1].payload = "1"; + expected_states[kObjectId2].payload = "2"; + EXPECT_CALL(handler, OnIncomingNotification( + expected_states, REMOTE_NOTIFICATION)); } - registrar.DispatchInvalidationsToHandlers(payloads, REMOTE_NOTIFICATION); + registrar.DispatchInvalidationsToHandlers(states, REMOTE_NOTIFICATION); Mock::VerifyAndClearExpectations(&handler); @@ -72,22 +73,22 @@ TEST_F(SyncNotifierRegistrarTest, Basic) { registrar.UpdateRegisteredIds(&handler, ids); { - ObjectIdPayloadMap expected_payloads; - expected_payloads[kObjectId2] = "2"; - expected_payloads[kObjectId3] = "3"; - EXPECT_CALL(handler, OnIncomingNotification(expected_payloads, - REMOTE_NOTIFICATION)); + ObjectIdStateMap expected_states; + expected_states[kObjectId2].payload = "2"; + expected_states[kObjectId3].payload = "3"; + EXPECT_CALL(handler, OnIncomingNotification( + expected_states, REMOTE_NOTIFICATION)); } // Removed object IDs should not be notified, newly-added ones should. - registrar.DispatchInvalidationsToHandlers(payloads, REMOTE_NOTIFICATION); + registrar.DispatchInvalidationsToHandlers(states, REMOTE_NOTIFICATION); Mock::VerifyAndClearExpectations(&handler); registrar.UnregisterHandler(&handler); // Should be ignored since |handler| isn't registered anymore. - registrar.DispatchInvalidationsToHandlers(payloads, REMOTE_NOTIFICATION); + registrar.DispatchInvalidationsToHandlers(states, REMOTE_NOTIFICATION); } // Register handlers and some IDs for those handlers, register a handler with @@ -99,11 +100,11 @@ TEST_F(SyncNotifierRegistrarTest, MultipleHandlers) { StrictMock<MockSyncNotifierObserver> handler1; EXPECT_CALL(handler1, OnNotificationsEnabled()); { - ObjectIdPayloadMap expected_payloads; - expected_payloads[kObjectId1] = "1"; - expected_payloads[kObjectId2] = "2"; - EXPECT_CALL(handler1, OnIncomingNotification(expected_payloads, - REMOTE_NOTIFICATION)); + ObjectIdStateMap expected_states; + expected_states[kObjectId1].payload = "1"; + expected_states[kObjectId2].payload = "2"; + EXPECT_CALL(handler1, OnIncomingNotification( + expected_states, REMOTE_NOTIFICATION)); } EXPECT_CALL(handler1, OnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR)); @@ -111,10 +112,10 @@ TEST_F(SyncNotifierRegistrarTest, MultipleHandlers) { StrictMock<MockSyncNotifierObserver> handler2; EXPECT_CALL(handler2, OnNotificationsEnabled()); { - ObjectIdPayloadMap expected_payloads; - expected_payloads[kObjectId3] = "3"; - EXPECT_CALL(handler2, OnIncomingNotification(expected_payloads, - REMOTE_NOTIFICATION)); + ObjectIdStateMap expected_states; + expected_states[kObjectId3].payload = "3"; + EXPECT_CALL(handler2, OnIncomingNotification( + expected_states, REMOTE_NOTIFICATION)); } EXPECT_CALL(handler2, OnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR)); @@ -158,12 +159,12 @@ TEST_F(SyncNotifierRegistrarTest, MultipleHandlers) { registrar.EmitOnNotificationsEnabled(); { - ObjectIdPayloadMap payloads; - payloads[kObjectId1] = "1"; - payloads[kObjectId2] = "2"; - payloads[kObjectId3] = "3"; - payloads[kObjectId4] = "4"; - registrar.DispatchInvalidationsToHandlers(payloads, REMOTE_NOTIFICATION); + ObjectIdStateMap states; + states[kObjectId1].payload = "1"; + states[kObjectId2].payload = "2"; + states[kObjectId3].payload = "3"; + states[kObjectId4].payload = "4"; + registrar.DispatchInvalidationsToHandlers(states, REMOTE_NOTIFICATION); } registrar.EmitOnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR); } @@ -202,10 +203,10 @@ TEST_F(SyncNotifierRegistrarTest, EmptySetUnregisters) { StrictMock<MockSyncNotifierObserver> handler2; EXPECT_CALL(handler2, OnNotificationsEnabled()); { - ObjectIdPayloadMap expected_payloads; - expected_payloads[kObjectId3] = "3"; - EXPECT_CALL(handler2, OnIncomingNotification(expected_payloads, - REMOTE_NOTIFICATION)); + ObjectIdStateMap expected_states; + expected_states[kObjectId3].payload = "3"; + EXPECT_CALL(handler2, OnIncomingNotification( + expected_states, REMOTE_NOTIFICATION)); } EXPECT_CALL(handler2, OnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR)); @@ -234,12 +235,11 @@ TEST_F(SyncNotifierRegistrarTest, EmptySetUnregisters) { registrar.EmitOnNotificationsEnabled(); { - ObjectIdPayloadMap payloads; - payloads[kObjectId1] = "1"; - payloads[kObjectId2] = "2"; - payloads[kObjectId3] = "3"; - registrar.DispatchInvalidationsToHandlers(payloads, - REMOTE_NOTIFICATION); + ObjectIdStateMap states; + states[kObjectId1].payload = "1"; + states[kObjectId2].payload = "2"; + states[kObjectId3].payload = "3"; + registrar.DispatchInvalidationsToHandlers(states, REMOTE_NOTIFICATION); } registrar.EmitOnNotificationsDisabled(TRANSIENT_NOTIFICATION_ERROR); } diff --git a/sync/sessions/session_state_unittest.cc b/sync/sessions/session_state_unittest.cc index 5685e28..1069e94 100644 --- a/sync/sessions/session_state_unittest.cc +++ b/sync/sessions/session_state_unittest.cc @@ -30,11 +30,11 @@ class SessionStateTest : public testing::Test {}; TEST_F(SessionStateTest, SyncSourceInfoToValue) { sync_pb::GetUpdatesCallerInfo::GetUpdatesSource updates_source = sync_pb::GetUpdatesCallerInfo::PERIODIC; - ModelTypePayloadMap types; - types[PREFERENCES] = "preferencespayload"; - types[EXTENSIONS] = ""; + ModelTypeStateMap types; + types[PREFERENCES].payload = "preferencespayload"; + types[EXTENSIONS].payload = ""; scoped_ptr<DictionaryValue> expected_types_value( - ModelTypePayloadMapToValue(types)); + ModelTypeStateMapToValue(types)); SyncSourceInfo source_info(updates_source, types); @@ -61,11 +61,11 @@ TEST_F(SessionStateTest, SyncSessionSnapshotToValue) { scoped_ptr<ListValue> expected_initial_sync_ended_value( ModelTypeSetToValue(initial_sync_ended)); - ModelTypePayloadMap download_progress_markers; - download_progress_markers[BOOKMARKS] = "test"; - download_progress_markers[APPS] = "apps"; + ModelTypeStateMap download_progress_markers; + download_progress_markers[BOOKMARKS].payload = "test"; + download_progress_markers[APPS].payload = "apps"; scoped_ptr<DictionaryValue> expected_download_progress_markers_value( - ModelTypePayloadMapToValue(download_progress_markers)); + ModelTypeStateMapToValue(download_progress_markers)); const bool kHasMoreToSync = false; const bool kIsSilenced = true; diff --git a/sync/sessions/sync_session.cc b/sync/sessions/sync_session.cc index ee29668..b7bb5ca 100644 --- a/sync/sessions/sync_session.cc +++ b/sync/sessions/sync_session.cc @@ -48,17 +48,17 @@ std::set<ModelSafeGroup> ComputeEnabledGroups( return enabled_groups; } -void PurgeStalePayload(ModelTypePayloadMap* original, - const ModelSafeRoutingInfo& routing_info) { - std::vector<ModelTypePayloadMap::iterator> iterators_to_delete; - for (ModelTypePayloadMap::iterator i = original->begin(); +void PurgeStaleStates(ModelTypeStateMap* original, + const ModelSafeRoutingInfo& routing_info) { + std::vector<ModelTypeStateMap::iterator> iterators_to_delete; + for (ModelTypeStateMap::iterator i = original->begin(); i != original->end(); ++i) { if (routing_info.end() == routing_info.find(i->first)) { iterators_to_delete.push_back(i); } } - for (std::vector<ModelTypePayloadMap::iterator>::iterator + for (std::vector<ModelTypeStateMap::iterator>::iterator it = iterators_to_delete.begin(); it != iterators_to_delete.end(); ++it) { original->erase(*it); @@ -92,8 +92,8 @@ void SyncSession::Coalesce(const SyncSession& session) { } // When we coalesce sessions, the sync update source gets overwritten with the - // most recent, while the type/payload map gets merged. - CoalescePayloads(&source_.types, session.source_.types); + // most recent, while the type/state map gets merged. + CoalesceStates(&source_.types, session.source_.types); source_.updates_source = session.source_.updates_source; std::vector<ModelSafeWorker*> temp; @@ -132,7 +132,7 @@ void SyncSession::RebaseRoutingInfoWithLatest(const SyncSession& session) { routing_info_.swap(temp_routing_info); // Now update the payload map. - PurgeStalePayload(&source_.types, session.routing_info_); + PurgeStaleStates(&source_.types, session.routing_info_); // Now update the workers. std::vector<ModelSafeWorker*> temp; @@ -157,7 +157,7 @@ SyncSessionSnapshot SyncSession::TakeSnapshot() const { bool is_share_useable = true; ModelTypeSet initial_sync_ended; - ModelTypePayloadMap download_progress_markers; + ModelTypeStateMap download_progress_markers; for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) { ModelType type(ModelTypeFromInt(i)); if (routing_info_.count(type) != 0) { @@ -166,7 +166,10 @@ SyncSessionSnapshot SyncSession::TakeSnapshot() const { else is_share_useable = false; } - dir->GetDownloadProgressAsString(type, &download_progress_markers[type]); + // TODO(dcheng): Is this correct? I'm guessing GetDownloadProgressAsString() + // shouldn't care about the ack handle... + dir->GetDownloadProgressAsString(type, + &download_progress_markers[type].payload); } return SyncSessionSnapshot( diff --git a/sync/sessions/sync_session_unittest.cc b/sync/sessions/sync_session_unittest.cc index ae2922d..bc69fe8 100644 --- a/sync/sessions/sync_session_unittest.cc +++ b/sync/sessions/sync_session_unittest.cc @@ -12,6 +12,7 @@ #include "sync/engine/syncer_types.h" #include "sync/engine/throttled_data_type_tracker.h" #include "sync/internal_api/public/base/model_type.h" +#include "sync/internal_api/public/base/model_type_state_map_test_util.h" #include "sync/sessions/session_state.h" #include "sync/sessions/status_controller.h" #include "sync/syncable/syncable_id.h" @@ -272,12 +273,12 @@ TEST_F(SyncSessionTest, ResetTransientState) { TEST_F(SyncSessionTest, Coalesce) { std::vector<ModelSafeWorker*> workers_one, workers_two; ModelSafeRoutingInfo routes_one, routes_two; - ModelTypePayloadMap one_type = - ModelTypePayloadMapFromEnumSet( + ModelTypeStateMap one_type = + ModelTypeSetToStateMap( ParamsMeaningJustOneEnabledType(), std::string()); - ModelTypePayloadMap all_types = - ModelTypePayloadMapFromEnumSet( + ModelTypeStateMap all_types = + ModelTypeSetToStateMap( ParamsMeaningAllEnabledTypes(), std::string()); SyncSourceInfo source_one(sync_pb::GetUpdatesCallerInfo::PERIODIC, one_type); @@ -316,7 +317,7 @@ TEST_F(SyncSessionTest, Coalesce) { EXPECT_EQ(expected_enabled_groups_two, two.GetEnabledGroups()); EXPECT_EQ(two.source().updates_source, one.source().updates_source); - EXPECT_EQ(all_types, one.source().types); + EXPECT_THAT(all_types, Eq(one.source().types)); std::vector<ModelSafeWorker*>::const_iterator it_db = std::find(one.workers().begin(), one.workers().end(), db_worker); std::vector<ModelSafeWorker*>::const_iterator it_ui = @@ -329,12 +330,12 @@ TEST_F(SyncSessionTest, Coalesce) { TEST_F(SyncSessionTest, RebaseRoutingInfoWithLatestRemoveOneType) { std::vector<ModelSafeWorker*> workers_one, workers_two; ModelSafeRoutingInfo routes_one, routes_two; - ModelTypePayloadMap one_type = - ModelTypePayloadMapFromEnumSet( + ModelTypeStateMap one_type = + ModelTypeSetToStateMap( ParamsMeaningJustOneEnabledType(), std::string()); - ModelTypePayloadMap all_types = - ModelTypePayloadMapFromEnumSet( + ModelTypeStateMap all_types = + ModelTypeSetToStateMap( ParamsMeaningAllEnabledTypes(), std::string()); SyncSourceInfo source_one(sync_pb::GetUpdatesCallerInfo::PERIODIC, one_type); @@ -377,7 +378,7 @@ TEST_F(SyncSessionTest, RebaseRoutingInfoWithLatestRemoveOneType) { sync_pb::GetUpdatesCallerInfo::LOCAL); // Make sure the payload is reduced to one. - EXPECT_EQ(one_type, two.source().types); + EXPECT_THAT(one_type, Eq(two.source().types)); // Make sure the workers are udpated. std::vector<ModelSafeWorker*>::const_iterator it_db = @@ -401,8 +402,8 @@ TEST_F(SyncSessionTest, RebaseRoutingInfoWithLatestRemoveOneType) { TEST_F(SyncSessionTest, RebaseRoutingInfoWithLatestWithSameType) { std::vector<ModelSafeWorker*> workers_first, workers_second; ModelSafeRoutingInfo routes_first, routes_second; - ModelTypePayloadMap all_types = - ModelTypePayloadMapFromEnumSet( + ModelTypeStateMap all_types = + ModelTypeSetToStateMap( ParamsMeaningAllEnabledTypes(), std::string()); SyncSourceInfo source_first(sync_pb::GetUpdatesCallerInfo::PERIODIC, @@ -447,7 +448,7 @@ TEST_F(SyncSessionTest, RebaseRoutingInfoWithLatestWithSameType) { sync_pb::GetUpdatesCallerInfo::LOCAL); // Make sure our payload is still the same. - EXPECT_EQ(all_types, second.source().types); + EXPECT_THAT(all_types, Eq(second.source().types)); // Make sure the workers are still the same. std::vector<ModelSafeWorker*>::const_iterator it_passive = @@ -481,23 +482,23 @@ TEST_F(SyncSessionTest, RebaseRoutingInfoWithLatestWithSameType) { } -TEST_F(SyncSessionTest, MakeTypePayloadMapFromBitSet) { +TEST_F(SyncSessionTest, MakeTypeStateMapFromBitSet) { ModelTypeSet types; std::string payload = "test"; - ModelTypePayloadMap types_with_payloads = - ModelTypePayloadMapFromEnumSet(types, payload); - EXPECT_TRUE(types_with_payloads.empty()); + ModelTypeStateMap type_state_map = + ModelTypeSetToStateMap(types, payload); + EXPECT_TRUE(type_state_map.empty()); types.Put(BOOKMARKS); types.Put(PASSWORDS); types.Put(AUTOFILL); payload = "test2"; - types_with_payloads = ModelTypePayloadMapFromEnumSet(types, payload); + type_state_map = ModelTypeSetToStateMap(types, payload); - ASSERT_EQ(3U, types_with_payloads.size()); - EXPECT_EQ(types_with_payloads[BOOKMARKS], payload); - EXPECT_EQ(types_with_payloads[PASSWORDS], payload); - EXPECT_EQ(types_with_payloads[AUTOFILL], payload); + ASSERT_EQ(3U, type_state_map.size()); + EXPECT_EQ(type_state_map[BOOKMARKS].payload, payload); + EXPECT_EQ(type_state_map[PASSWORDS].payload, payload); + EXPECT_EQ(type_state_map[AUTOFILL].payload, payload); } } // namespace diff --git a/sync/sync.gyp b/sync/sync.gyp index 720a28c..415a3be 100644 --- a/sync/sync.gyp +++ b/sync/sync.gyp @@ -41,9 +41,10 @@ 'sources': [ 'base/sync_export.h', 'internal_api/public/base/enum_set.h', + 'internal_api/public/base/invalidation_state.h', 'internal_api/public/base/model_type.h', - 'internal_api/public/base/model_type_payload_map.cc', - 'internal_api/public/base/model_type_payload_map.h', + 'internal_api/public/base/model_type_state_map.cc', + 'internal_api/public/base/model_type_state_map.h', 'internal_api/public/engine/model_safe_worker.cc', 'internal_api/public/engine/model_safe_worker.h', 'internal_api/public/engine/passive_model_worker.cc', @@ -256,8 +257,8 @@ 'notifier/invalidation_util.h', 'notifier/notifications_disabled_reason.cc', 'notifier/notifications_disabled_reason.h', - 'notifier/object_id_payload_map.cc', - 'notifier/object_id_payload_map.h', + 'notifier/object_id_state_map.cc', + 'notifier/object_id_state_map.h', 'notifier/sync_notifier.h', 'notifier/sync_notifier_factory.cc', 'notifier/sync_notifier_factory.h', @@ -416,6 +417,10 @@ 'sync', ], 'sources': [ + 'internal_api/public/base/invalidation_state_test_util.cc', + 'internal_api/public/base/invalidation_state_test_util.h', + 'internal_api/public/base/model_type_state_map_test_util.cc', + 'internal_api/public/base/model_type_state_map_test_util.h', 'internal_api/public/base/model_type_test_util.cc', 'internal_api/public/base/model_type_test_util.h', 'js/js_test_util.cc', @@ -477,6 +482,8 @@ 'notifier/fake_invalidation_state_tracker.h', 'notifier/mock_sync_notifier_observer.cc', 'notifier/mock_sync_notifier_observer.h', + 'notifier/object_id_state_map_test_util.cc', + 'notifier/object_id_state_map_test_util.h', ], }, @@ -570,7 +577,7 @@ ], 'sources': [ 'internal_api/public/base/enum_set_unittest.cc', - 'internal_api/public/base/model_type_payload_map_unittest.cc', + 'internal_api/public/base/model_type_state_map_unittest.cc', 'internal_api/public/engine/model_safe_worker_unittest.cc', 'internal_api/public/util/immutable_unittest.cc', 'engine/apply_updates_command_unittest.cc', diff --git a/sync/test/engine/fake_sync_scheduler.cc b/sync/test/engine/fake_sync_scheduler.cc index 2327949..fee1595 100644 --- a/sync/test/engine/fake_sync_scheduler.cc +++ b/sync/test/engine/fake_sync_scheduler.cc @@ -25,9 +25,9 @@ void FakeSyncScheduler::ScheduleNudgeAsync( const tracked_objects::Location& nudge_location) { } -void FakeSyncScheduler::ScheduleNudgeWithPayloadsAsync( +void FakeSyncScheduler::ScheduleNudgeWithStatesAsync( const base::TimeDelta& delay, NudgeSource source, - const ModelTypePayloadMap& types_with_payloads, + const ModelTypeStateMap& types_with_payloads, const tracked_objects::Location& nudge_location) { } diff --git a/sync/test/engine/fake_sync_scheduler.h b/sync/test/engine/fake_sync_scheduler.h index 4c2fbba..40ebd41 100644 --- a/sync/test/engine/fake_sync_scheduler.h +++ b/sync/test/engine/fake_sync_scheduler.h @@ -26,9 +26,9 @@ class FakeSyncScheduler : public SyncScheduler { NudgeSource source, ModelTypeSet types, const tracked_objects::Location& nudge_location) OVERRIDE; - virtual void ScheduleNudgeWithPayloadsAsync( + virtual void ScheduleNudgeWithStatesAsync( const base::TimeDelta& delay, NudgeSource source, - const ModelTypePayloadMap& types_with_payloads, + const ModelTypeStateMap& type_state_map, const tracked_objects::Location& nudge_location) OVERRIDE; virtual bool ScheduleConfiguration( const ConfigurationParams& params) OVERRIDE; diff --git a/sync/test/engine/mock_connection_manager.cc b/sync/test/engine/mock_connection_manager.cc index 3739bf3..0d4041b 100644 --- a/sync/test/engine/mock_connection_manager.cc +++ b/sync/test/engine/mock_connection_manager.cc @@ -408,8 +408,8 @@ void MockConnectionManager::ProcessGetUpdates( EXPECT_EQ(expected_filter_.Has(model_type), (progress_marker != NULL)) << "Syncer requested_types differs from test expectation."; if (progress_marker) { - EXPECT_EQ((expected_payloads_.count(model_type) > 0 ? - expected_payloads_[model_type] : + EXPECT_EQ((expected_states_.count(model_type) > 0 ? + expected_states_[model_type].payload : std::string()), progress_marker->notification_hint()); } diff --git a/sync/test/engine/mock_connection_manager.h b/sync/test/engine/mock_connection_manager.h index 5aabe7f..7c5271c 100644 --- a/sync/test/engine/mock_connection_manager.h +++ b/sync/test/engine/mock_connection_manager.h @@ -17,7 +17,7 @@ #include "base/memory/scoped_vector.h" #include "sync/engine/net/server_connection_manager.h" #include "sync/internal_api/public/base/model_type.h" -#include "sync/internal_api/public/base/model_type_payload_map.h" +#include "sync/internal_api/public/base/model_type_state_map.h" #include "sync/protocol/sync.pb.h" namespace syncer { @@ -188,8 +188,8 @@ class MockConnectionManager : public ServerConnectionManager { expected_filter_ = expected_filter; } - void ExpectGetUpdatesRequestPayloads(const ModelTypePayloadMap& payloads) { - expected_payloads_ = payloads; + void ExpectGetUpdatesRequestStates(const ModelTypeStateMap& states) { + expected_states_ = states; } void SetServerReachable(); @@ -338,7 +338,7 @@ class MockConnectionManager : public ServerConnectionManager { ModelTypeSet expected_filter_; - ModelTypePayloadMap expected_payloads_; + ModelTypeStateMap expected_states_; int num_get_updates_requests_; diff --git a/sync/test/engine/syncer_command_test.h b/sync/test/engine/syncer_command_test.h index 803ef18..8e1aa14 100644 --- a/sync/test/engine/syncer_command_test.h +++ b/sync/test/engine/syncer_command_test.h @@ -98,10 +98,10 @@ class SyncerCommandTestBase : public testing::Test, sessions::SyncSessionContext* context() const { return context_.get(); } sessions::SyncSession::Delegate* delegate() { return this; } - // Lazily create a session requesting all datatypes with no payload. + // Lazily create a session requesting all datatypes with no state. sessions::SyncSession* session() { - ModelTypePayloadMap types = - ModelSafeRoutingInfoToPayloadMap(routing_info_, std::string()); + ModelTypeStateMap types = + ModelSafeRoutingInfoToStateMap(routing_info_, std::string()); return session(sessions::SyncSourceInfo(types)); } diff --git a/sync/tools/sync_listen_notifications.cc b/sync/tools/sync_listen_notifications.cc index 6d8adb0..ef5ef19 100644 --- a/sync/tools/sync_listen_notifications.cc +++ b/sync/tools/sync_listen_notifications.cc @@ -24,7 +24,7 @@ #include "net/base/transport_security_state.h" #include "net/url_request/url_request_test_util.h" #include "sync/internal_api/public/base/model_type.h" -#include "sync/internal_api/public/base/model_type_payload_map.h" +#include "sync/internal_api/public/base/model_type_state_map.h" #include "sync/notifier/invalidation_state_tracker.h" #include "sync/notifier/invalidation_util.h" #include "sync/notifier/sync_notifier.h" @@ -65,16 +65,16 @@ class NotificationPrinter : public SyncNotifierObserver { } virtual void OnIncomingNotification( - const ObjectIdPayloadMap& id_payloads, + const ObjectIdStateMap& id_state_map, IncomingNotificationSource source) OVERRIDE { - const ModelTypePayloadMap& type_payloads = - ObjectIdPayloadMapToModelTypePayloadMap(id_payloads); - for (ModelTypePayloadMap::const_iterator it = - type_payloads.begin(); it != type_payloads.end(); ++it) { + const ModelTypeStateMap& type_state_map = + ObjectIdStateMapToModelTypeStateMap(id_state_map); + for (ModelTypeStateMap::const_iterator it = type_state_map.begin(); + it != type_state_map.end(); ++it) { LOG(INFO) << (source == REMOTE_NOTIFICATION ? "Remote" : "Local") << " Notification: type = " << ModelTypeToString(it->first) - << ", payload = " << it->second; + << ", payload = " << it->second.payload; } } |