| Index: chrome/browser/sync/profile_sync_service.cc
|
| diff --git a/chrome/browser/sync/profile_sync_service.cc b/chrome/browser/sync/profile_sync_service.cc
|
| index cd24db0e80278c188cf754857b136e9bfc390a6c..9102c4a62d51312741e7a309db759d630d387df7 100644
|
| --- a/chrome/browser/sync/profile_sync_service.cc
|
| +++ b/chrome/browser/sync/profile_sync_service.cc
|
| @@ -76,6 +76,7 @@
|
| #include "components/sync_driver/pref_names.h"
|
| #include "components/sync_driver/system_encryptor.h"
|
| #include "components/sync_driver/user_selectable_sync_type.h"
|
| +#include "content/public/browser/browser_thread.h"
|
| #include "content/public/browser/notification_details.h"
|
| #include "content/public/browser/notification_service.h"
|
| #include "content/public/browser/notification_source.h"
|
| @@ -90,6 +91,7 @@
|
| #include "sync/internal_api/public/sync_context_proxy.h"
|
| #include "sync/internal_api/public/sync_encryption_handler.h"
|
| #include "sync/internal_api/public/util/experiments.h"
|
| +#include "sync/internal_api/public/util/sync_db_util.h"
|
| #include "sync/internal_api/public/util/sync_string_conversions.h"
|
| #include "sync/js/js_event_details.h"
|
| #include "sync/util/cryptographer.h"
|
| @@ -658,6 +660,8 @@ void ProfileSyncService::StartUpSlowBackendComponents(
|
|
|
| if (backend_mode_ == ROLLBACK)
|
| ClearBrowsingDataSinceFirstSync();
|
| + else if (backend_mode_ == SYNC)
|
| + CheckSyncBackupIfNeeded();
|
|
|
| base::FilePath sync_folder = backend_mode_ == SYNC ?
|
| base::FilePath(kSyncDataFolderName) :
|
| @@ -1022,6 +1026,13 @@ void ProfileSyncService::PostBackendInitialization() {
|
| // Never get here for backup / restore.
|
| DCHECK_EQ(backend_mode_, SYNC);
|
|
|
| + if (last_backup_time_) {
|
| + browser_sync::SyncedDeviceTracker* device_tracker =
|
| + backend_->GetSyncedDeviceTracker();
|
| + if (device_tracker)
|
| + device_tracker->UpdateLocalDeviceBackupTime(*last_backup_time_);
|
| + }
|
| +
|
| if (protocol_event_observers_.might_have_observers()) {
|
| backend_->RequestBufferedProtocolEventsAndEnableForwarding();
|
| }
|
| @@ -2597,3 +2608,50 @@ void ProfileSyncService::StartStopBackupForTesting() {
|
| else
|
| backup_rollback_controller_.Start(base::TimeDelta());
|
| }
|
| +
|
| +void ProfileSyncService::CheckSyncBackupIfNeeded() {
|
| + DCHECK_EQ(backend_mode_, SYNC);
|
| +
|
| +#if defined(ENABLE_PRE_SYNC_BACKUP)
|
| + // Check backup once a day.
|
| + if (!last_backup_time_ &&
|
| + (last_synced_time_.is_null() ||
|
| + base::Time::Now() - last_synced_time_ >=
|
| + base::TimeDelta::FromDays(1))) {
|
| + // If sync thread is set, need to serialize check on sync thread after
|
| + // closing backup DB.
|
| + if (sync_thread_) {
|
| + sync_thread_->message_loop_proxy()->PostTask(
|
| + FROM_HERE,
|
| + base::Bind(syncer::CheckSyncDbLastModifiedTime,
|
| + profile_->GetPath().Append(kSyncBackupDataFolderName),
|
| + base::MessageLoopProxy::current(),
|
| + base::Bind(&ProfileSyncService::CheckSyncBackupCallback,
|
| + weak_factory_.GetWeakPtr())));
|
| + } else {
|
| + content::BrowserThread::PostTask(
|
| + content::BrowserThread::FILE, FROM_HERE,
|
| + base::Bind(syncer::CheckSyncDbLastModifiedTime,
|
| + profile_->GetPath().Append(kSyncBackupDataFolderName),
|
| + base::MessageLoopProxy::current(),
|
| + base::Bind(&ProfileSyncService::CheckSyncBackupCallback,
|
| + weak_factory_.GetWeakPtr())));
|
| + }
|
| + }
|
| +#endif
|
| +}
|
| +
|
| +void ProfileSyncService::CheckSyncBackupCallback(base::Time backup_time) {
|
| + last_backup_time_.reset(new base::Time(backup_time));
|
| +
|
| + if (HasSyncingBackend() && backend_initialized_) {
|
| + browser_sync::SyncedDeviceTracker* device_tracker =
|
| + backend_->GetSyncedDeviceTracker();
|
| + if (device_tracker)
|
| + device_tracker->UpdateLocalDeviceBackupTime(*last_backup_time_);
|
| + }
|
| +}
|
| +
|
| +base::Time ProfileSyncService::GetDeviceBackupTimeForTesting() const {
|
| + return backend_->GetSyncedDeviceTracker()->GetLocalDeviceBackupTime();
|
| +}
|
|
|