From b1133ac9da61c61238ddc112099cc9fbd883853e Mon Sep 17 00:00:00 2001 From: zea Date: Thu, 14 May 2015 19:23:10 -0700 Subject: Reland [Sync] Refactoring polling to be reliable. This is a reland of https://codereview.chromium.org/1132013004/ Polling is now an important component of sync health, as it can sometimes be the only time we'll query for certain datatypes. As such, the following has changed: - Polls that fail will be retried (with backoff). - As such, the logic to force a poll after an auth error isn't needed anymore - The last successful poll time will be persisted in the sync prefs. - On startup, schedule the first poll for last_poll_time + poll_interval (or Now(), whichever is latest). - Receiving a new poll interval from the server will update the poll timer - The poll timer is now a one shot timer, and only restarts on success - Some code cleanup to make the above more straightforward BUG=482154 Review URL: https://codereview.chromium.org/1144543004 Cr-Commit-Position: refs/heads/master@{#330024} --- components/sync_driver/sync_prefs.cc | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'components/sync_driver/sync_prefs.cc') diff --git a/components/sync_driver/sync_prefs.cc b/components/sync_driver/sync_prefs.cc index 89f5320..82106ee 100644 --- a/components/sync_driver/sync_prefs.cc +++ b/components/sync_driver/sync_prefs.cc @@ -38,6 +38,7 @@ void SyncPrefs::RegisterProfilePrefs( registry->RegisterBooleanPref(prefs::kSyncHasSetupCompleted, false); registry->RegisterBooleanPref(prefs::kSyncSuppressStart, false); registry->RegisterInt64Pref(prefs::kSyncLastSyncedTime, 0); + registry->RegisterInt64Pref(prefs::kSyncLastPollTime, 0); registry->RegisterInt64Pref(prefs::kSyncFirstSyncTime, 0); // All datatypes are on by default, but this gets set explicitly @@ -97,6 +98,7 @@ void SyncPrefs::RemoveSyncPrefObserver(SyncPrefObserver* sync_pref_observer) { void SyncPrefs::ClearPreferences() { DCHECK(CalledOnValidThread()); pref_service_->ClearPref(prefs::kSyncLastSyncedTime); + pref_service_->ClearPref(prefs::kSyncLastPollTime); pref_service_->ClearPref(prefs::kSyncHasSetupCompleted); pref_service_->ClearPref(prefs::kSyncEncryptionBootstrapToken); pref_service_->ClearPref(prefs::kSyncKeystoreEncryptionBootstrapToken); @@ -148,6 +150,17 @@ void SyncPrefs::SetLastSyncedTime(base::Time time) { pref_service_->SetInt64(prefs::kSyncLastSyncedTime, time.ToInternalValue()); } +base::Time SyncPrefs::GetLastPollTime() const { + DCHECK(CalledOnValidThread()); + return base::Time::FromInternalValue( + pref_service_->GetInt64(prefs::kSyncLastSyncedTime)); +} + +void SyncPrefs::SetLastPollTime(base::Time time) { + DCHECK(CalledOnValidThread()); + pref_service_->SetInt64(prefs::kSyncLastPollTime, time.ToInternalValue()); +} + bool SyncPrefs::HasKeepEverythingSynced() const { DCHECK(CalledOnValidThread()); return pref_service_->GetBoolean(prefs::kSyncKeepEverythingSynced); -- cgit v1.1