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

Side by Side Diff: chrome/browser/sync/profile_sync_service.cc

Issue 660023003: [Sync] Fix bug where DeviceInfo is missing a backup timestamp (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge with master. Created 6 years, 1 month 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/sync/profile_sync_service.h" 5 #include "chrome/browser/sync/profile_sync_service.h"
6 6
7 #include <cstddef> 7 #include <cstddef>
8 #include <map> 8 #include <map>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 304
305 RegisterAuthNotifications(); 305 RegisterAuthNotifications();
306 306
307 if (!HasSyncSetupCompleted() || signin_->GetEffectiveUsername().empty()) { 307 if (!HasSyncSetupCompleted() || signin_->GetEffectiveUsername().empty()) {
308 // Clean up in case of previous crash / setup abort / signout. 308 // Clean up in case of previous crash / setup abort / signout.
309 DisableForUser(); 309 DisableForUser();
310 } 310 }
311 311
312 TrySyncDatatypePrefRecovery(); 312 TrySyncDatatypePrefRecovery();
313 313
314 last_synced_time_ = sync_prefs_.GetLastSyncedTime();
315
316 #if defined(OS_CHROMEOS) 314 #if defined(OS_CHROMEOS)
317 std::string bootstrap_token = sync_prefs_.GetEncryptionBootstrapToken(); 315 std::string bootstrap_token = sync_prefs_.GetEncryptionBootstrapToken();
318 if (bootstrap_token.empty()) { 316 if (bootstrap_token.empty()) {
319 sync_prefs_.SetEncryptionBootstrapToken( 317 sync_prefs_.SetEncryptionBootstrapToken(
320 sync_prefs_.GetSpareBootstrapToken()); 318 sync_prefs_.GetSpareBootstrapToken());
321 } 319 }
322 #endif 320 #endif
323 321
324 #if !defined(OS_ANDROID) 322 #if !defined(OS_ANDROID)
325 DCHECK(sync_error_controller_ == NULL) 323 DCHECK(sync_error_controller_ == NULL)
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after
897 895
898 bool ProfileSyncService::HasSyncSetupCompleted() const { 896 bool ProfileSyncService::HasSyncSetupCompleted() const {
899 return sync_prefs_.HasSyncSetupCompleted(); 897 return sync_prefs_.HasSyncSetupCompleted();
900 } 898 }
901 899
902 void ProfileSyncService::SetSyncSetupCompleted() { 900 void ProfileSyncService::SetSyncSetupCompleted() {
903 sync_prefs_.SetSyncSetupCompleted(); 901 sync_prefs_.SetSyncSetupCompleted();
904 } 902 }
905 903
906 void ProfileSyncService::UpdateLastSyncedTime() { 904 void ProfileSyncService::UpdateLastSyncedTime() {
907 last_synced_time_ = base::Time::Now(); 905 sync_prefs_.SetLastSyncedTime(base::Time::Now());
908 sync_prefs_.SetLastSyncedTime(last_synced_time_);
909 } 906 }
910 907
911 void ProfileSyncService::NotifyObservers() { 908 void ProfileSyncService::NotifyObservers() {
912 FOR_EACH_OBSERVER(ProfileSyncServiceBase::Observer, observers_, 909 FOR_EACH_OBSERVER(ProfileSyncServiceBase::Observer, observers_,
913 OnStateChanged()); 910 OnStateChanged());
914 } 911 }
915 912
916 void ProfileSyncService::NotifySyncCycleCompleted() { 913 void ProfileSyncService::NotifySyncCycleCompleted() {
917 FOR_EACH_OBSERVER(ProfileSyncServiceBase::Observer, observers_, 914 FOR_EACH_OBSERVER(ProfileSyncServiceBase::Observer, observers_,
918 OnSyncCycleCompleted()); 915 OnSyncCycleCompleted());
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1021 if (type_debug_info_observers_.might_have_observers()) { 1018 if (type_debug_info_observers_.might_have_observers()) {
1022 backend_->EnableDirectoryTypeDebugInfoForwarding(); 1019 backend_->EnableDirectoryTypeDebugInfoForwarding();
1023 } 1020 }
1024 1021
1025 // If we have a cached passphrase use it to decrypt/encrypt data now that the 1022 // If we have a cached passphrase use it to decrypt/encrypt data now that the
1026 // backend is initialized. We want to call this before notifying observers in 1023 // backend is initialized. We want to call this before notifying observers in
1027 // case this operation affects the "passphrase required" status. 1024 // case this operation affects the "passphrase required" status.
1028 ConsumeCachedPassphraseIfPossible(); 1025 ConsumeCachedPassphraseIfPossible();
1029 1026
1030 // The very first time the backend initializes is effectively the first time 1027 // The very first time the backend initializes is effectively the first time
1031 // we can say we successfully "synced". last_synced_time_ will only be null 1028 // we can say we successfully "synced". LastSyncedTime will only be null in
1032 // in this case, because the pref wasn't restored on StartUp. 1029 // this case, because the pref wasn't restored on StartUp.
1033 if (last_synced_time_.is_null()) { 1030 if (sync_prefs_.GetLastSyncedTime().is_null()) {
1034 UpdateLastSyncedTime(); 1031 UpdateLastSyncedTime();
1035 } 1032 }
1036 1033
1037 if (startup_controller_.auto_start_enabled() && !FirstSetupInProgress()) { 1034 if (startup_controller_.auto_start_enabled() && !FirstSetupInProgress()) {
1038 // Backend is initialized but we're not in sync setup, so this must be an 1035 // Backend is initialized but we're not in sync setup, so this must be an
1039 // autostart - mark our sync setup as completed and we'll start syncing 1036 // autostart - mark our sync setup as completed and we'll start syncing
1040 // below. 1037 // below.
1041 SetSyncSetupCompleted(); 1038 SetSyncSetupCompleted();
1042 } 1039 }
1043 1040
(...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after
1700 } 1697 }
1701 1698
1702 bool ProfileSyncService::IsPassphraseRequiredForDecryption() const { 1699 bool ProfileSyncService::IsPassphraseRequiredForDecryption() const {
1703 // If there is an encrypted datatype enabled and we don't have the proper 1700 // If there is an encrypted datatype enabled and we don't have the proper
1704 // passphrase, we must prompt the user for a passphrase. The only way for the 1701 // passphrase, we must prompt the user for a passphrase. The only way for the
1705 // user to avoid entering their passphrase is to disable the encrypted types. 1702 // user to avoid entering their passphrase is to disable the encrypted types.
1706 return IsEncryptedDatatypeEnabled() && IsPassphraseRequired(); 1703 return IsEncryptedDatatypeEnabled() && IsPassphraseRequired();
1707 } 1704 }
1708 1705
1709 base::string16 ProfileSyncService::GetLastSyncedTimeString() const { 1706 base::string16 ProfileSyncService::GetLastSyncedTimeString() const {
1710 if (last_synced_time_.is_null()) 1707 const base::Time last_synced_time = sync_prefs_.GetLastSyncedTime();
1708 if (last_synced_time.is_null())
1711 return l10n_util::GetStringUTF16(IDS_SYNC_TIME_NEVER); 1709 return l10n_util::GetStringUTF16(IDS_SYNC_TIME_NEVER);
1712 1710
1713 base::TimeDelta last_synced = base::Time::Now() - last_synced_time_; 1711 base::TimeDelta time_since_last_sync = base::Time::Now() - last_synced_time;
1714 1712
1715 if (last_synced < base::TimeDelta::FromMinutes(1)) 1713 if (time_since_last_sync < base::TimeDelta::FromMinutes(1))
1716 return l10n_util::GetStringUTF16(IDS_SYNC_TIME_JUST_NOW); 1714 return l10n_util::GetStringUTF16(IDS_SYNC_TIME_JUST_NOW);
1717 1715
1718 return ui::TimeFormat::Simple(ui::TimeFormat::FORMAT_ELAPSED, 1716 return ui::TimeFormat::Simple(ui::TimeFormat::FORMAT_ELAPSED,
1719 ui::TimeFormat::LENGTH_SHORT, last_synced); 1717 ui::TimeFormat::LENGTH_SHORT,
1718 time_since_last_sync);
1720 } 1719 }
1721 1720
1722 void ProfileSyncService::UpdateSelectedTypesHistogram( 1721 void ProfileSyncService::UpdateSelectedTypesHistogram(
1723 bool sync_everything, const syncer::ModelTypeSet chosen_types) const { 1722 bool sync_everything, const syncer::ModelTypeSet chosen_types) const {
1724 if (!HasSyncSetupCompleted() || 1723 if (!HasSyncSetupCompleted() ||
1725 sync_everything != sync_prefs_.HasKeepEverythingSynced()) { 1724 sync_everything != sync_prefs_.HasKeepEverythingSynced()) {
1726 UMA_HISTOGRAM_BOOLEAN("Sync.SyncEverything", sync_everything); 1725 UMA_HISTOGRAM_BOOLEAN("Sync.SyncEverything", sync_everything);
1727 } 1726 }
1728 1727
1729 // Only log the data types that are shown in the sync settings ui. 1728 // Only log the data types that are shown in the sync settings ui.
(...skipping 936 matching lines...) Expand 10 before | Expand all | Expand 10 after
2666 } 2665 }
2667 } 2666 }
2668 } 2667 }
2669 return result; 2668 return result;
2670 } 2669 }
2671 2670
2672 void ProfileSyncService::CheckSyncBackupIfNeeded() { 2671 void ProfileSyncService::CheckSyncBackupIfNeeded() {
2673 DCHECK_EQ(backend_mode_, SYNC); 2672 DCHECK_EQ(backend_mode_, SYNC);
2674 2673
2675 #if defined(ENABLE_PRE_SYNC_BACKUP) 2674 #if defined(ENABLE_PRE_SYNC_BACKUP)
2675 const base::Time last_synced_time = sync_prefs_.GetLastSyncedTime();
2676 // Check backup once a day. 2676 // Check backup once a day.
2677 if (!last_backup_time_ && 2677 if (!last_backup_time_ &&
2678 (last_synced_time_.is_null() || 2678 (last_synced_time.is_null() ||
2679 base::Time::Now() - last_synced_time_ >= 2679 base::Time::Now() - last_synced_time >=
2680 base::TimeDelta::FromDays(1))) { 2680 base::TimeDelta::FromDays(1))) {
2681 // If sync thread is set, need to serialize check on sync thread after 2681 // If sync thread is set, need to serialize check on sync thread after
2682 // closing backup DB. 2682 // closing backup DB.
2683 if (sync_thread_) { 2683 if (sync_thread_) {
2684 sync_thread_->message_loop_proxy()->PostTask( 2684 sync_thread_->message_loop_proxy()->PostTask(
2685 FROM_HERE, 2685 FROM_HERE,
2686 base::Bind(syncer::CheckSyncDbLastModifiedTime, 2686 base::Bind(syncer::CheckSyncDbLastModifiedTime,
2687 profile_->GetPath().Append(kSyncBackupDataFolderName), 2687 profile_->GetPath().Append(kSyncBackupDataFolderName),
2688 base::MessageLoopProxy::current(), 2688 base::MessageLoopProxy::current(),
2689 base::Bind(&ProfileSyncService::CheckSyncBackupCallback, 2689 base::Bind(&ProfileSyncService::CheckSyncBackupCallback,
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
2729 base::Time ProfileSyncService::GetDeviceBackupTimeForTesting() const { 2729 base::Time ProfileSyncService::GetDeviceBackupTimeForTesting() const {
2730 return device_info_sync_service_->GetLocalDeviceBackupTime(); 2730 return device_info_sync_service_->GetLocalDeviceBackupTime();
2731 } 2731 }
2732 2732
2733 void ProfileSyncService::FlushDirectory() const { 2733 void ProfileSyncService::FlushDirectory() const {
2734 // backend_initialized_ implies backend_ isn't NULL and the manager exists. 2734 // backend_initialized_ implies backend_ isn't NULL and the manager exists.
2735 // If sync is not initialized yet, we fail silently. 2735 // If sync is not initialized yet, we fail silently.
2736 if (backend_initialized_) 2736 if (backend_initialized_)
2737 backend_->FlushDirectory(); 2737 backend_->FlushDirectory();
2738 } 2738 }
OLDNEW
« no previous file with comments | « chrome/browser/sync/profile_sync_service.h ('k') | chrome/browser/sync/profile_sync_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698