Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(700)

Unified Diff: chrome/browser/sync/profile_sync_service.cc

Issue 332923002: [sync] Add backup time in synced device info so that server can flag device (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: check db on DB thread Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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();
+}
« no previous file with comments | « chrome/browser/sync/profile_sync_service.h ('k') | chrome/browser/sync/test/integration/single_client_backup_rollback_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698