diff options
author | tim@chromium.org <tim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-03 19:41:30 +0000 |
---|---|---|
committer | tim@chromium.org <tim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-03 19:41:30 +0000 |
commit | 5d26cf9520236ea4a9258abe5ca65b98861e2e70 (patch) | |
tree | c706e1c6a6bed48840b0f0f90a819cb1bfd4d787 | |
parent | aa938666082034e7671c298ed27e6bfff7dd18b4 (diff) | |
download | chromium_src-5d26cf9520236ea4a9258abe5ca65b98861e2e70.zip chromium_src-5d26cf9520236ea4a9258abe5ca65b98861e2e70.tar.gz chromium_src-5d26cf9520236ea4a9258abe5ca65b98861e2e70.tar.bz2 |
sync: add a SyncSessionJobPurpose for clearing private data.
Removes the nudge source which wasn't used server-side.
BUG=71616,26339
TEST=SyncerThread2Test
Review URL: http://codereview.chromium.org/6286067
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@73647 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/sync/engine/nudge_source.h | 3 | ||||
-rw-r--r-- | chrome/browser/sync/engine/syncer.cc | 28 | ||||
-rw-r--r-- | chrome/browser/sync/engine/syncer.h | 17 | ||||
-rw-r--r-- | chrome/browser/sync/engine/syncer_thread2.cc | 61 | ||||
-rw-r--r-- | chrome/browser/sync/engine/syncer_thread2.h | 13 | ||||
-rw-r--r-- | chrome/browser/sync/engine/syncer_thread2_unittest.cc | 91 | ||||
-rw-r--r-- | chrome/browser/sync/sessions/test_util.cc | 12 | ||||
-rw-r--r-- | chrome/browser/sync/sessions/test_util.h | 13 |
8 files changed, 169 insertions, 69 deletions
diff --git a/chrome/browser/sync/engine/nudge_source.h b/chrome/browser/sync/engine/nudge_source.h index 6a75ad1..3e3b3ae 100644 --- a/chrome/browser/sync/engine/nudge_source.h +++ b/chrome/browser/sync/engine/nudge_source.h @@ -18,9 +18,6 @@ enum NudgeSource { NUDGE_SOURCE_LOCAL, // A previous sync cycle did not fully complete (e.g. HTTP error). NUDGE_SOURCE_CONTINUATION, - // A nudge corresponding to the user invoking a function in the UI to clear - // their entire account and stop syncing (globally). - NUDGE_SOURCE_CLEAR_PRIVATE_DATA, }; } // namespace s3 diff --git a/chrome/browser/sync/engine/syncer.cc b/chrome/browser/sync/engine/syncer.cc index b436c66..9ca668e 100644 --- a/chrome/browser/sync/engine/syncer.cc +++ b/chrome/browser/sync/engine/syncer.cc @@ -70,6 +70,7 @@ void Syncer::RequestEarlyExit() { early_exit_requested_ = true; } +// TODO(tim): Deprecated. void Syncer::SyncShare(sessions::SyncSession* session) { ScopedDirLookup dir(session->context()->directory_manager(), session->context()->account_name()); @@ -82,17 +83,6 @@ void Syncer::SyncShare(sessions::SyncSession* session) { SyncShare(session, CLEAR_PRIVATE_DATA, SYNCER_END); return; } else { - // This isn't perfect, as we can end up bundling extensions activity - // intended for the next session into the current one. We could do a - // test-and-reset as with the source, but note that also falls short if - // the commit request fails (e.g. due to lost connection), as we will - // fall all the way back to the syncer thread main loop in that case, and - // wind up creating a new session when a connection is established, losing - // the records set here on the original attempt. This should provide us - // with the right data "most of the time", and we're only using this for - // analysis purposes, so Law of Large Numbers FTW. - session->context()->extensions_monitor()->GetAndClearRecords( - session->mutable_extensions_activity()); SyncShare(session, SYNCER_BEGIN, SYNCER_END); } } @@ -100,6 +90,11 @@ void Syncer::SyncShare(sessions::SyncSession* session) { void Syncer::SyncShare(sessions::SyncSession* session, const SyncerStep first_step, const SyncerStep last_step) { + ScopedDirLookup dir(session->context()->directory_manager(), + session->context()->account_name()); + // The directory must be good here. + CHECK(dir.good()); + ScopedSessionContextConflictResolver scoped(session->context(), &resolver_); SyncerStep current_step = first_step; @@ -109,6 +104,17 @@ void Syncer::SyncShare(sessions::SyncSession* session, switch (current_step) { case SYNCER_BEGIN: VLOG(1) << "Syncer Begin"; + // This isn't perfect, as we can end up bundling extensions activity + // intended for the next session into the current one. We could do a + // test-and-reset as with the source, but note that also falls short if + // the commit request fails (e.g. due to lost connection), as we will + // fall all the way back to the syncer thread main loop in that case, + // creating a new session when a connection is established, losing the + // records set here on the original attempt. This should provide us + // with the right data "most of the time", and we're only using this + // for analysis purposes, so Law of Large Numbers FTW. + session->context()->extensions_monitor()->GetAndClearRecords( + session->mutable_extensions_activity()); next_step = CLEANUP_DISABLED_TYPES; break; case CLEANUP_DISABLED_TYPES: { diff --git a/chrome/browser/sync/engine/syncer.h b/chrome/browser/sync/engine/syncer.h index bbcbb3b..b9deb23 100644 --- a/chrome/browser/sync/engine/syncer.h +++ b/chrome/browser/sync/engine/syncer.h @@ -56,7 +56,7 @@ enum SyncerStep { BUILD_AND_PROCESS_CONFLICT_SETS, RESOLVE_CONFLICTS, APPLY_UPDATES_TO_RESOLVE_CONFLICTS, - CLEAR_PRIVATE_DATA, + CLEAR_PRIVATE_DATA, // TODO(tim): Rename 'private' to 'user'. SYNCER_END }; @@ -84,23 +84,22 @@ class Syncer { bool ExitRequested(); void RequestEarlyExit(); + // TODO(tim): Deprecated. // Cause one sync cycle to occur. Like a good parent, it is the caller's // responsibility to clean up after the syncer when it finishes a sync share // operation and honor server mandated throttles. virtual void SyncShare(sessions::SyncSession* session); + // Like SyncShare() above, but |first_step| and |last_step| are provided to + // perform a partial sync cycle, stopping after |last_step| is performed. + virtual void SyncShare(sessions::SyncSession* session, + SyncerStep first_step, + SyncerStep last_step); + private: // Implements the PROCESS_CLIENT_COMMAND syncer step. void ProcessClientCommand(sessions::SyncSession *session); - // This is the bottom-most SyncShare variant, and does not cause transient - // state to be reset in session. - // Like SyncShare(), but |first_step| and |last_step| are provided to perform - // a partial sync cycle, stopping after |last_step| is performed. - void SyncShare(sessions::SyncSession* session, - SyncerStep first_step, - SyncerStep last_step); - bool early_exit_requested_; base::Lock early_exit_requested_lock_; diff --git a/chrome/browser/sync/engine/syncer_thread2.cc b/chrome/browser/sync/engine/syncer_thread2.cc index c8aa18a..be49a39 100644 --- a/chrome/browser/sync/engine/syncer_thread2.cc +++ b/chrome/browser/sync/engine/syncer_thread2.cc @@ -102,6 +102,8 @@ bool SyncerThread::ShouldRunJob(SyncSessionJobPurpose purpose, // Check wait interval. if (wait_interval_.get()) { + // TODO(tim): Consider different handling for CLEAR_USER_DATA (i.e. permit + // when throttled). if (wait_interval_->mode == WaitInterval::THROTTLED) return false; @@ -121,7 +123,7 @@ bool SyncerThread::ShouldRunJob(SyncSessionJobPurpose purpose, return false; break; case NORMAL_MODE: - if (purpose != POLL && purpose != NUDGE) + if (purpose == CONFIGURATION) return false; break; default: @@ -158,10 +160,10 @@ GetUpdatesCallerInfo::GetUpdatesSource GetUpdatesFromNudgeSource( return GetUpdatesCallerInfo::LOCAL; case NUDGE_SOURCE_CONTINUATION: return GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION; - case NUDGE_SOURCE_CLEAR_PRIVATE_DATA: - return GetUpdatesCallerInfo::CLEAR_PRIVATE_DATA; case NUDGE_SOURCE_UNKNOWN: + return GetUpdatesCallerInfo::UNKNOWN; default: + NOTREACHED(); return GetUpdatesCallerInfo::UNKNOWN; } } @@ -176,6 +178,15 @@ struct WorkerGroupIs { }; } // namespace +void SyncerThread::ScheduleClearUserData() { + if (!thread_.IsRunning()) { + NOTREACHED(); + return; + } + thread_.message_loop()->PostTask(FROM_HERE, NewRunnableMethod( + this, &SyncerThread::ScheduleClearUserDataImpl)); +} + void SyncerThread::ScheduleNudge(const TimeDelta& delay, NudgeSource source, const ModelTypeBitSet& types) { if (!thread_.IsRunning()) { @@ -202,12 +213,18 @@ void SyncerThread::ScheduleNudgeWithPayloads(const TimeDelta& delay, types_with_payloads)); } +void SyncerThread::ScheduleClearUserDataImpl() { + DCHECK_EQ(MessageLoop::current(), thread_.message_loop()); + SyncSession* session = new SyncSession(session_context_.get(), this, + SyncSourceInfo(), ModelSafeRoutingInfo(), + std::vector<ModelSafeWorker*>()); + ScheduleSyncSessionJob(TimeDelta::FromSeconds(0), CLEAR_USER_DATA, session); +} + void SyncerThread::ScheduleNudgeImpl(const TimeDelta& delay, NudgeSource source, const TypePayloadMap& types_with_payloads) { DCHECK_EQ(MessageLoop::current(), thread_.message_loop()); TimeTicks rough_start = TimeTicks::Now() + delay; - if (!ShouldRunJob(NUDGE, rough_start)) - return; // Note we currently nudge for all types regardless of the ones incurring // the nudge. Doing different would throw off some syncer commands like @@ -308,6 +325,26 @@ void SyncerThread::ScheduleSyncSessionJob(const base::TimeDelta& delay, &SyncerThread::DoSyncSessionJob, job), delay.InMilliseconds()); } +void SyncerThread::SetSyncerStepsForPurpose(SyncSessionJobPurpose purpose, + SyncerStep* start, SyncerStep* end) { + *end = SYNCER_END; + switch (purpose) { + case CONFIGURATION: + *start = DOWNLOAD_UPDATES; + *end = APPLY_UPDATES; + return; + case CLEAR_USER_DATA: + *start = CLEAR_PRIVATE_DATA; + return; + case NUDGE: + case POLL: + *start = SYNCER_BEGIN; + return; + default: + NOTREACHED(); + } +} + void SyncerThread::DoSyncSessionJob(const SyncSessionJob& job) { DCHECK_EQ(MessageLoop::current(), thread_.message_loop()); @@ -316,17 +353,19 @@ void SyncerThread::DoSyncSessionJob(const SyncSessionJob& job) { if (pending_nudge_->session != job.session) return; // Another nudge must have been scheduled in in the meantime. pending_nudge_.reset(); - } else if (job.purpose == CONFIGURATION) { - NOTIMPLEMENTED() << "TODO(tim): SyncShare [DOWNLOAD_UPDATES,APPLY_UPDATES]"; } + SyncerStep begin(SYNCER_BEGIN); + SyncerStep end(SYNCER_END); + SetSyncerStepsForPurpose(job.purpose, &begin, &end); + bool has_more_to_sync = true; bool did_job = false; while (ShouldRunJob(job.purpose, job.scheduled_start) && has_more_to_sync) { VLOG(1) << "SyncerThread: Calling SyncShare."; did_job = true; // Synchronously perform the sync session from this thread. - syncer_->SyncShare(job.session.get()); + syncer_->SyncShare(job.session.get(), begin, end); has_more_to_sync = job.session->HasMoreToSync(); if (has_more_to_sync) job.session->ResetTransientState(); @@ -375,7 +414,11 @@ void SyncerThread::ScheduleNextSync(const SyncSessionJob& old_job) { // TODO(tim): Old impl had special code if notifications disabled. Needed? if (!work_to_do) { - wait_interval_.reset(); // Success implies backoff relief. + // Success implies backoff relief. Note that if this was a "one-off" job + // (i.e. purpose == CLEAR_USER_DATA), if there was work_to_do before it + // ran this wont have changed, as jobs like this don't run a full sync + // cycle. So we don't need special code here. + wait_interval_.reset(); return; } diff --git a/chrome/browser/sync/engine/syncer_thread2.h b/chrome/browser/sync/engine/syncer_thread2.h index afa1814..a9848ff 100644 --- a/chrome/browser/sync/engine/syncer_thread2.h +++ b/chrome/browser/sync/engine/syncer_thread2.h @@ -16,13 +16,13 @@ #include "base/timer.h" #include "chrome/browser/sync/engine/nudge_source.h" #include "chrome/browser/sync/engine/polling_constants.h" +#include "chrome/browser/sync/engine/syncer.h" #include "chrome/browser/sync/sessions/sync_session.h" #include "chrome/browser/sync/sessions/sync_session_context.h" namespace browser_sync { struct ServerConnectionEvent; -class Syncer; namespace s3 { @@ -65,6 +65,7 @@ class SyncerThread : public sessions::SyncSession::Delegate { const sessions::TypePayloadMap& types_with_payloads); void ScheduleConfig(const base::TimeDelta& delay, const syncable::ModelTypeBitSet& types); + void ScheduleClearUserData(); // Change status of notifications in the SyncSessionContext. void set_notifications_enabled(bool notifications_enabled); @@ -97,6 +98,9 @@ class SyncerThread : public sessions::SyncSession::Delegate { // A nudge task can come from a variety of components needing to force // a sync. The source is inferable from |session.source()|. NUDGE, + // The user invoked a function in the UI to clear their entire account + // and stop syncing (globally). + CLEAR_USER_DATA, // Typically used for fetching updates for a subset of the enabled types // during initial sync or reconfiguration. We don't run all steps of // the sync cycle for these (e.g. CleanupDisabledTypes is skipped). @@ -153,6 +157,7 @@ class SyncerThread : public sessions::SyncSession::Delegate { void ScheduleConfigImpl(const base::TimeDelta& delay, const ModelSafeRoutingInfo& routing_info, const std::vector<ModelSafeWorker*>& workers); + void ScheduleClearUserDataImpl(); // Returns true if the client is currently in exponential backoff. bool IsBackingOff() const; @@ -171,6 +176,12 @@ class SyncerThread : public sessions::SyncSession::Delegate { // Creates a session for a poll and performs the sync. void PollTimerCallback(); + // Assign |start| and |end| to appropriate SyncerStep values for the + // specified |purpose|. + void SetSyncerStepsForPurpose(SyncSessionJobPurpose purpose, + SyncerStep* start, + SyncerStep* end); + base::Thread thread_; // Modifiable versions of kDefaultLongPollIntervalSeconds which can be diff --git a/chrome/browser/sync/engine/syncer_thread2_unittest.cc b/chrome/browser/sync/engine/syncer_thread2_unittest.cc index 3b2742c..1268593 100644 --- a/chrome/browser/sync/engine/syncer_thread2_unittest.cc +++ b/chrome/browser/sync/engine/syncer_thread2_unittest.cc @@ -32,7 +32,8 @@ using sync_pb::GetUpdatesCallerInfo; class MockSyncer : public Syncer { public: - MOCK_METHOD1(SyncShare, void(sessions::SyncSession*)); + MOCK_METHOD3(SyncShare, void(sessions::SyncSession*, SyncerStep, + SyncerStep)); }; namespace s3 { @@ -183,7 +184,7 @@ TEST_F(SyncerThread2Test, Nudge) { syncable::ModelTypeBitSet model_types; model_types[syncable::BOOKMARKS] = true; - EXPECT_CALL(*syncer(), SyncShare(_)) + EXPECT_CALL(*syncer(), SyncShare(_,_,_)) .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), WithArg<0>(RecordSyncShare(&records, 1U, &done)))) .RetiresOnSaturation(); @@ -200,7 +201,7 @@ TEST_F(SyncerThread2Test, Nudge) { SyncShareRecords records2; model_types[syncable::BOOKMARKS] = false; model_types[syncable::AUTOFILL] = true; - EXPECT_CALL(*syncer(), SyncShare(_)) + EXPECT_CALL(*syncer(), SyncShare(_,_,_)) .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), WithArg<0>(RecordSyncShare(&records2, 1U, &done)))); syncer_thread()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, model_types); @@ -218,7 +219,7 @@ TEST_F(SyncerThread2Test, NudgeCoalescing) { syncer_thread()->Start(SyncerThread::NORMAL_MODE); base::WaitableEvent done(false, false); SyncShareRecords r; - EXPECT_CALL(*syncer(), SyncShare(_)) + EXPECT_CALL(*syncer(), SyncShare(_,_,_)) .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), WithArg<0>(RecordSyncShare(&r, 1U, &done)))); syncable::ModelTypeBitSet types1, types2, types3; @@ -240,7 +241,7 @@ TEST_F(SyncerThread2Test, NudgeCoalescing) { r.snapshots[0]->source.updates_source); SyncShareRecords r2; - EXPECT_CALL(*syncer(), SyncShare(_)) + EXPECT_CALL(*syncer(), SyncShare(_,_,_)) .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), WithArg<0>(RecordSyncShare(&r2, 1U, &done)))); syncer_thread()->ScheduleNudge(zero(), NUDGE_SOURCE_NOTIFICATION, types3); @@ -260,7 +261,7 @@ TEST_F(SyncerThread2Test, NudgeWithPayloads) { sessions::TypePayloadMap model_types_with_payloads; model_types_with_payloads[syncable::BOOKMARKS] = "test"; - EXPECT_CALL(*syncer(), SyncShare(_)) + EXPECT_CALL(*syncer(), SyncShare(_,_,_)) .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), WithArg<0>(RecordSyncShare(&records, 1U, &done)))) .RetiresOnSaturation(); @@ -277,7 +278,7 @@ TEST_F(SyncerThread2Test, NudgeWithPayloads) { SyncShareRecords records2; model_types_with_payloads.erase(syncable::BOOKMARKS); model_types_with_payloads[syncable::AUTOFILL] = "test2"; - EXPECT_CALL(*syncer(), SyncShare(_)) + EXPECT_CALL(*syncer(), SyncShare(_,_,_)) .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), WithArg<0>(RecordSyncShare(&records2, 1U, &done)))); syncer_thread()->ScheduleNudgeWithPayloads(zero(), NUDGE_SOURCE_LOCAL, @@ -295,7 +296,7 @@ TEST_F(SyncerThread2Test, NudgeWithPayloadsCoalescing) { syncer_thread()->Start(SyncerThread::NORMAL_MODE); base::WaitableEvent done(false, false); SyncShareRecords r; - EXPECT_CALL(*syncer(), SyncShare(_)) + EXPECT_CALL(*syncer(), SyncShare(_,_,_)) .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), WithArg<0>(RecordSyncShare(&r, 1U, &done)))); sessions::TypePayloadMap types1, types2, types3; @@ -323,7 +324,7 @@ TEST_F(SyncerThread2Test, NudgeWithPayloadsCoalescing) { r.snapshots[0]->source.updates_source); SyncShareRecords r2; - EXPECT_CALL(*syncer(), SyncShare(_)) + EXPECT_CALL(*syncer(), SyncShare(_,_,_)) .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), WithArg<0>(RecordSyncShare(&r2, 1U, &done)))); syncer_thread()->ScheduleNudgeWithPayloads(zero(), NUDGE_SOURCE_NOTIFICATION, @@ -341,7 +342,7 @@ TEST_F(SyncerThread2Test, Polling) { base::WaitableEvent done(false, false); TimeDelta poll_interval(TimeDelta::FromMilliseconds(30)); syncer_thread()->OnReceivedLongPollIntervalUpdate(poll_interval); - EXPECT_CALL(*syncer(), SyncShare(_)).Times(AtLeast(kMinNumSamples)) + EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(AtLeast(kMinNumSamples)) .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess), WithArg<0>(RecordSyncShare(&records, kMinNumSamples, &done)))); @@ -360,7 +361,7 @@ TEST_F(SyncerThread2Test, PollNotificationsDisabled) { TimeDelta poll_interval(TimeDelta::FromMilliseconds(30)); syncer_thread()->OnReceivedShortPollIntervalUpdate(poll_interval); syncer_thread()->set_notifications_enabled(false); - EXPECT_CALL(*syncer(), SyncShare(_)).Times(AtLeast(kMinNumSamples)) + EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(AtLeast(kMinNumSamples)) .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess), WithArg<0>(RecordSyncShare(&records, kMinNumSamples, &done)))); @@ -379,7 +380,7 @@ TEST_F(SyncerThread2Test, PollIntervalUpdate) { TimeDelta poll1(TimeDelta::FromMilliseconds(120)); TimeDelta poll2(TimeDelta::FromMilliseconds(30)); syncer_thread()->OnReceivedLongPollIntervalUpdate(poll1); - EXPECT_CALL(*syncer(), SyncShare(_)).Times(AtLeast(kMinNumSamples)) + EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(AtLeast(kMinNumSamples)) .WillOnce(WithArg<0>( sessions::test_util::SimulatePollIntervalUpdate(poll2))) .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess), @@ -397,7 +398,7 @@ TEST_F(SyncerThread2Test, PollIntervalUpdate) { TEST_F(SyncerThread2Test, HasMoreToSync) { syncer_thread()->Start(SyncerThread::NORMAL_MODE); base::WaitableEvent done(false, false); - EXPECT_CALL(*syncer(), SyncShare(_)) + EXPECT_CALL(*syncer(), SyncShare(_,_,_)) .WillOnce(Invoke(sessions::test_util::SimulateHasMoreToSync)) .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), SignalEvent(&done))); @@ -415,7 +416,7 @@ TEST_F(SyncerThread2Test, ThrottlingDoesThrottle) { TimeDelta poll(TimeDelta::FromMilliseconds(5)); TimeDelta throttle(TimeDelta::FromMinutes(10)); syncer_thread()->OnReceivedLongPollIntervalUpdate(poll); - EXPECT_CALL(*syncer(), SyncShare(_)) + EXPECT_CALL(*syncer(), SyncShare(_,_,_)) .WillOnce(WithArg<0>(sessions::test_util::SimulateThrottled(throttle))); syncer_thread()->Start(SyncerThread::NORMAL_MODE); @@ -436,10 +437,10 @@ TEST_F(SyncerThread2Test, ThrottlingExpires) { syncer_thread()->OnReceivedLongPollIntervalUpdate(poll); ::testing::InSequence seq; - EXPECT_CALL(*syncer(), SyncShare(_)) + EXPECT_CALL(*syncer(), SyncShare(_,_,_)) .WillOnce(WithArg<0>(sessions::test_util::SimulateThrottled(throttle1))) .RetiresOnSaturation(); - EXPECT_CALL(*syncer(), SyncShare(_)) + EXPECT_CALL(*syncer(), SyncShare(_,_,_)) .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess), WithArg<0>(RecordSyncShare(&records, kMinNumSamples, &done)))); @@ -456,7 +457,7 @@ TEST_F(SyncerThread2Test, ConfigurationMode) { TimeDelta poll(TimeDelta::FromMilliseconds(15)); base::WaitableEvent done(false, false); syncer_thread()->OnReceivedLongPollIntervalUpdate(poll); - EXPECT_CALL(*syncer(), SyncShare(_)).Times(0); + EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(0); syncer_thread()->Start(SyncerThread::CONFIGURATION_MODE); syncable::ModelTypeBitSet nudge_types; nudge_types[syncable::AUTOFILL] = true; @@ -476,35 +477,35 @@ TEST_F(SyncerThread2Test, BackoffTriggers) { base::WaitableEvent done(false, false); UseMockDelayProvider(); - EXPECT_CALL(*syncer(), SyncShare(_)) + EXPECT_CALL(*syncer(), SyncShare(_,_,_)) .WillOnce(Invoke(sessions::test_util::SimulateDownloadUpdatesFailed)) .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), SignalEvent(&done))); EXPECT_FALSE(GetBackoffAndResetTest(&done)); // Note GetBackoffAndResetTest clears mocks and re-instantiates the syncer. - EXPECT_CALL(*syncer(), SyncShare(_)) + EXPECT_CALL(*syncer(), SyncShare(_,_,_)) .WillOnce(Invoke(sessions::test_util::SimulateCommitFailed)) .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), SignalEvent(&done))); EXPECT_FALSE(GetBackoffAndResetTest(&done)); - EXPECT_CALL(*syncer(), SyncShare(_)) + EXPECT_CALL(*syncer(), SyncShare(_,_,_)) .WillOnce(Invoke(sessions::test_util::SimulateDownloadUpdatesFailed)) .WillRepeatedly(DoAll(Invoke( sessions::test_util::SimulateDownloadUpdatesFailed), SignalEvent(&done))); EXPECT_TRUE(GetBackoffAndResetTest(&done)); - EXPECT_CALL(*syncer(), SyncShare(_)) + EXPECT_CALL(*syncer(), SyncShare(_,_,_)) .WillOnce(Invoke(sessions::test_util::SimulateCommitFailed)) .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), SignalEvent(&done))); EXPECT_TRUE(GetBackoffAndResetTest(&done)); - EXPECT_CALL(*syncer(), SyncShare(_)) + EXPECT_CALL(*syncer(), SyncShare(_,_,_)) .WillOnce(Invoke(sessions::test_util::SimulateDownloadUpdatesFailed)) .WillOnce(Invoke(sessions::test_util::SimulateDownloadUpdatesFailed)) .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess), SignalEvent(&done))); EXPECT_FALSE(GetBackoffAndResetTest(&done)); - EXPECT_CALL(*syncer(), SyncShare(_)) + EXPECT_CALL(*syncer(), SyncShare(_,_,_)) .WillOnce(Invoke(sessions::test_util::SimulateCommitFailed)) .WillOnce(Invoke(sessions::test_util::SimulateCommitFailed)) .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess), @@ -522,7 +523,7 @@ TEST_F(SyncerThread2Test, BackoffDropsJobs) { syncer_thread()->OnReceivedLongPollIntervalUpdate(poll); UseMockDelayProvider(); - EXPECT_CALL(*syncer(), SyncShare(_)).Times(2) + EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(2) .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), RecordSyncShareAndPostSignal(&r, 2U, this, &done))); EXPECT_CALL(*delay(), GetDelay(_)) @@ -539,7 +540,7 @@ TEST_F(SyncerThread2Test, BackoffDropsJobs) { EXPECT_EQ(GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION, r.snapshots[1]->source.updates_source); - EXPECT_CALL(*syncer(), SyncShare(_)).Times(1) + EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(1) .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), RecordSyncShareAndPostSignal(&r, 1U, this, &done))); @@ -555,7 +556,7 @@ TEST_F(SyncerThread2Test, BackoffDropsJobs) { EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, r.snapshots[2]->source.updates_source); - EXPECT_CALL(*syncer(), SyncShare(_)).Times(0); + EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(0); EXPECT_CALL(*delay(), GetDelay(_)).Times(0); syncer_thread()->Start(SyncerThread::CONFIGURATION_MODE); @@ -582,7 +583,7 @@ TEST_F(SyncerThread2Test, BackoffElevation) { const TimeDelta fourth = TimeDelta::FromMilliseconds(30); const TimeDelta fifth = TimeDelta::FromDays(1); - EXPECT_CALL(*syncer(), SyncShare(_)).Times(kMinNumSamples) + EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(kMinNumSamples) .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), RecordSyncShareAndPostSignal(&r, kMinNumSamples, this, &done))); @@ -613,7 +614,7 @@ TEST_F(SyncerThread2Test, BackoffRelief) { const TimeDelta backoff = TimeDelta::FromMilliseconds(100); - EXPECT_CALL(*syncer(), SyncShare(_)) + EXPECT_CALL(*syncer(), SyncShare(_,_,_)) .WillOnce(Invoke(sessions::test_util::SimulateCommitFailed)) .WillOnce(Invoke(sessions::test_util::SimulateCommitFailed)) .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess), @@ -655,6 +656,40 @@ TEST_F(SyncerThread2Test, GetRecommendedDelay) { TimeDelta::FromSeconds(kMaxBackoffSeconds + 1))); } +// Test that appropriate syncer steps are requested for each job type. +TEST_F(SyncerThread2Test, SyncerSteps) { + // Nudges. + base::WaitableEvent done(false, false); + EXPECT_CALL(*syncer(), SyncShare(_, SYNCER_BEGIN, SYNCER_END)) + .Times(1); + syncer_thread()->Start(SyncerThread::NORMAL_MODE); + syncer_thread()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, ModelTypeBitSet()); + FlushLastTask(&done); + syncer_thread()->Stop(); + Mock::VerifyAndClearExpectations(syncer()); + + // ClearUserData. + EXPECT_CALL(*syncer(), SyncShare(_, CLEAR_PRIVATE_DATA, SYNCER_END)) + .Times(1); + syncer_thread()->Start(SyncerThread::NORMAL_MODE); + syncer_thread()->ScheduleClearUserData(); + FlushLastTask(&done); + syncer_thread()->Stop(); + Mock::VerifyAndClearExpectations(syncer()); + + // Poll. + EXPECT_CALL(*syncer(), SyncShare(_, SYNCER_BEGIN, SYNCER_END)) + .Times(AtLeast(1)) + .WillRepeatedly(SignalEvent(&done)); + const TimeDelta poll(TimeDelta::FromMilliseconds(10)); + syncer_thread()->OnReceivedLongPollIntervalUpdate(poll); + syncer_thread()->Start(SyncerThread::NORMAL_MODE); + done.TimedWait(timeout()); + syncer_thread()->Stop(); + Mock::VerifyAndClearExpectations(syncer()); + done.Reset(); +} + // Test config tasks don't run during normal mode. // TODO(tim): Implement this test and then the functionality! TEST_F(SyncerThread2Test, DISABLED_NoConfigDuringNormal) { diff --git a/chrome/browser/sync/sessions/test_util.cc b/chrome/browser/sync/sessions/test_util.cc index d6fdef5..6f69de6 100644 --- a/chrome/browser/sync/sessions/test_util.cc +++ b/chrome/browser/sync/sessions/test_util.cc @@ -8,19 +8,22 @@ namespace browser_sync { namespace sessions { namespace test_util { -void SimulateHasMoreToSync(sessions::SyncSession* session) { +void SimulateHasMoreToSync(sessions::SyncSession* session, + SyncerStep begin, SyncerStep end) { session->status_controller()->update_conflicts_resolved(true); ASSERT_TRUE(session->HasMoreToSync()); } -void SimulateDownloadUpdatesFailed(sessions::SyncSession* session) { +void SimulateDownloadUpdatesFailed(sessions::SyncSession* session, + SyncerStep begin, SyncerStep end) { // Note that a non-zero value of changes_remaining once a session has // completed implies that the Syncer was unable to exhaust this count during // the GetUpdates cycle. This is an indication that an error occurred. session->status_controller()->set_num_server_changes_remaining(1); } -void SimulateCommitFailed(sessions::SyncSession* session) { +void SimulateCommitFailed(sessions::SyncSession* session, + SyncerStep begin, SyncerStep end) { // Note that a non-zero number of unsynced handles once a session has // completed implies that the Syncer was unable to make forward progress // during a commit, indicating an error occurred. @@ -30,7 +33,8 @@ void SimulateCommitFailed(sessions::SyncSession* session) { session->status_controller()->set_unsynced_handles(handles); } -void SimulateSuccess(sessions::SyncSession* session) { +void SimulateSuccess(sessions::SyncSession* session, + SyncerStep begin, SyncerStep end) { if (session->HasMoreToSync()) { ADD_FAILURE() << "Shouldn't have more to sync"; } diff --git a/chrome/browser/sync/sessions/test_util.h b/chrome/browser/sync/sessions/test_util.h index 420cf3f..12a0119 100644 --- a/chrome/browser/sync/sessions/test_util.h +++ b/chrome/browser/sync/sessions/test_util.h @@ -7,6 +7,7 @@ #define CHROME_BROWSER_SYNC_SESSIONS_TEST_UTIL_H_ #pragma once +#include "chrome/browser/sync/engine/syncer.h" #include "chrome/browser/sync/sessions/sync_session.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/gmock/include/gmock/gmock.h" @@ -15,10 +16,14 @@ namespace browser_sync { namespace sessions { namespace test_util { -void SimulateHasMoreToSync(sessions::SyncSession* session); -void SimulateDownloadUpdatesFailed(sessions::SyncSession* session); -void SimulateCommitFailed(sessions::SyncSession* session); -void SimulateSuccess(sessions::SyncSession* session); +void SimulateHasMoreToSync(sessions::SyncSession* session, + SyncerStep begin, SyncerStep end); +void SimulateDownloadUpdatesFailed(sessions::SyncSession* session, + SyncerStep begin, SyncerStep end); +void SimulateCommitFailed(sessions::SyncSession* session, + SyncerStep begin, SyncerStep end); +void SimulateSuccess(sessions::SyncSession* session, + SyncerStep begin, SyncerStep end); void SimulateThrottledImpl(sessions::SyncSession* session, const base::TimeDelta& delta); void SimulatePollIntervalUpdateImpl(sessions::SyncSession* session, |