Chromium Code Reviews| 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 8d814985d9a2f9dc815376783ccf4767379a432e..2eafef7332aff882c0e3d6a727c510e9c3b99efb 100644 |
| --- a/chrome/browser/sync/profile_sync_service.cc |
| +++ b/chrome/browser/sync/profile_sync_service.cc |
| @@ -87,6 +87,7 @@ |
| #include "sync/internal_api/public/sync_core_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" |
| @@ -680,6 +681,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) : |
| @@ -1021,6 +1024,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(); |
| } |
| @@ -2553,3 +2563,41 @@ void ProfileSyncService::SetClearingBrowseringDataForTesting( |
| base::Callback<void(Profile*, base::Time, base::Time)> c) { |
| clear_browsing_data_ = c; |
| } |
| + |
| +void ProfileSyncService::CheckSyncBackupIfNeeded() { |
| + DCHECK_EQ(backend_mode_, SYNC); |
| + |
| +#if defined(OS_WIN) || defined(OS_MACOSX) || (defined(OS_LINUX) && !defined(OS_CHROMEOS)) |
|
Nicolas Zea
2014/06/13 22:36:41
I wonder if it's better to pull out these platform
haitaol1
2014/06/13 23:28:25
Will do in follow-up cl.
On 2014/06/13 22:36:41,
|
| + // Check backup once a day. |
| + if (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. |
|
Nicolas Zea
2014/06/13 22:36:41
Why do we need to serialize on the sync thread in
haitaol1
2014/06/13 23:28:25
Check will fail if sync DB is still opened by back
Nicolas Zea
2014/06/13 23:48:52
If the backup is running, why not have it do this
haitaol1
2014/06/16 17:35:28
Backup may or may not be running at the time. If i
|
| + base::TaskRunner* check_task_runner = sync_thread_ ? |
| + sync_thread_->message_loop_proxy().get() : |
| + profile_->GetIOTaskRunner().get(); |
| + check_task_runner->PostTask( |
| + 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()) { |
| + 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(); |
| +} |