OLD | NEW |
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 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 | 303 |
304 RegisterAuthNotifications(); | 304 RegisterAuthNotifications(); |
305 | 305 |
306 if (!HasSyncSetupCompleted() || signin_->GetEffectiveUsername().empty()) { | 306 if (!HasSyncSetupCompleted() || signin_->GetEffectiveUsername().empty()) { |
307 // Clean up in case of previous crash / setup abort / signout. | 307 // Clean up in case of previous crash / setup abort / signout. |
308 DisableForUser(); | 308 DisableForUser(); |
309 } | 309 } |
310 | 310 |
311 TrySyncDatatypePrefRecovery(); | 311 TrySyncDatatypePrefRecovery(); |
312 | 312 |
313 last_synced_time_ = sync_prefs_.GetLastSyncedTime(); | |
314 | |
315 #if defined(OS_CHROMEOS) | 313 #if defined(OS_CHROMEOS) |
316 std::string bootstrap_token = sync_prefs_.GetEncryptionBootstrapToken(); | 314 std::string bootstrap_token = sync_prefs_.GetEncryptionBootstrapToken(); |
317 if (bootstrap_token.empty()) { | 315 if (bootstrap_token.empty()) { |
318 sync_prefs_.SetEncryptionBootstrapToken( | 316 sync_prefs_.SetEncryptionBootstrapToken( |
319 sync_prefs_.GetSpareBootstrapToken()); | 317 sync_prefs_.GetSpareBootstrapToken()); |
320 } | 318 } |
321 #endif | 319 #endif |
322 | 320 |
323 #if !defined(OS_ANDROID) | 321 #if !defined(OS_ANDROID) |
324 DCHECK(sync_error_controller_ == NULL) | 322 DCHECK(sync_error_controller_ == NULL) |
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
902 | 900 |
903 bool ProfileSyncService::HasSyncSetupCompleted() const { | 901 bool ProfileSyncService::HasSyncSetupCompleted() const { |
904 return sync_prefs_.HasSyncSetupCompleted(); | 902 return sync_prefs_.HasSyncSetupCompleted(); |
905 } | 903 } |
906 | 904 |
907 void ProfileSyncService::SetSyncSetupCompleted() { | 905 void ProfileSyncService::SetSyncSetupCompleted() { |
908 sync_prefs_.SetSyncSetupCompleted(); | 906 sync_prefs_.SetSyncSetupCompleted(); |
909 } | 907 } |
910 | 908 |
911 void ProfileSyncService::UpdateLastSyncedTime() { | 909 void ProfileSyncService::UpdateLastSyncedTime() { |
912 last_synced_time_ = base::Time::Now(); | 910 sync_prefs_.SetLastSyncedTime(base::Time::Now()); |
913 sync_prefs_.SetLastSyncedTime(last_synced_time_); | |
914 } | 911 } |
915 | 912 |
916 void ProfileSyncService::NotifyObservers() { | 913 void ProfileSyncService::NotifyObservers() { |
917 FOR_EACH_OBSERVER(ProfileSyncServiceBase::Observer, observers_, | 914 FOR_EACH_OBSERVER(ProfileSyncServiceBase::Observer, observers_, |
918 OnStateChanged()); | 915 OnStateChanged()); |
919 } | 916 } |
920 | 917 |
921 void ProfileSyncService::NotifySyncCycleCompleted() { | 918 void ProfileSyncService::NotifySyncCycleCompleted() { |
922 FOR_EACH_OBSERVER(ProfileSyncServiceBase::Observer, observers_, | 919 FOR_EACH_OBSERVER(ProfileSyncServiceBase::Observer, observers_, |
923 OnSyncCycleCompleted()); | 920 OnSyncCycleCompleted()); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1027 if (type_debug_info_observers_.might_have_observers()) { | 1024 if (type_debug_info_observers_.might_have_observers()) { |
1028 backend_->EnableDirectoryTypeDebugInfoForwarding(); | 1025 backend_->EnableDirectoryTypeDebugInfoForwarding(); |
1029 } | 1026 } |
1030 | 1027 |
1031 // If we have a cached passphrase use it to decrypt/encrypt data now that the | 1028 // If we have a cached passphrase use it to decrypt/encrypt data now that the |
1032 // backend is initialized. We want to call this before notifying observers in | 1029 // backend is initialized. We want to call this before notifying observers in |
1033 // case this operation affects the "passphrase required" status. | 1030 // case this operation affects the "passphrase required" status. |
1034 ConsumeCachedPassphraseIfPossible(); | 1031 ConsumeCachedPassphraseIfPossible(); |
1035 | 1032 |
1036 // The very first time the backend initializes is effectively the first time | 1033 // The very first time the backend initializes is effectively the first time |
1037 // we can say we successfully "synced". last_synced_time_ will only be null | 1034 // we can say we successfully "synced". LastSyncedTime will only be null in |
1038 // in this case, because the pref wasn't restored on StartUp. | 1035 // this case, because the pref wasn't restored on StartUp. |
1039 if (last_synced_time_.is_null()) { | 1036 if (sync_prefs_.GetLastSyncedTime().is_null()) { |
1040 UpdateLastSyncedTime(); | 1037 UpdateLastSyncedTime(); |
1041 } | 1038 } |
1042 | 1039 |
1043 if (startup_controller_.auto_start_enabled() && !FirstSetupInProgress()) { | 1040 if (startup_controller_.auto_start_enabled() && !FirstSetupInProgress()) { |
1044 // Backend is initialized but we're not in sync setup, so this must be an | 1041 // Backend is initialized but we're not in sync setup, so this must be an |
1045 // autostart - mark our sync setup as completed and we'll start syncing | 1042 // autostart - mark our sync setup as completed and we'll start syncing |
1046 // below. | 1043 // below. |
1047 SetSyncSetupCompleted(); | 1044 SetSyncSetupCompleted(); |
1048 } | 1045 } |
1049 | 1046 |
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1699 } | 1696 } |
1700 | 1697 |
1701 bool ProfileSyncService::IsPassphraseRequiredForDecryption() const { | 1698 bool ProfileSyncService::IsPassphraseRequiredForDecryption() const { |
1702 // If there is an encrypted datatype enabled and we don't have the proper | 1699 // If there is an encrypted datatype enabled and we don't have the proper |
1703 // passphrase, we must prompt the user for a passphrase. The only way for the | 1700 // passphrase, we must prompt the user for a passphrase. The only way for the |
1704 // user to avoid entering their passphrase is to disable the encrypted types. | 1701 // user to avoid entering their passphrase is to disable the encrypted types. |
1705 return IsEncryptedDatatypeEnabled() && IsPassphraseRequired(); | 1702 return IsEncryptedDatatypeEnabled() && IsPassphraseRequired(); |
1706 } | 1703 } |
1707 | 1704 |
1708 base::string16 ProfileSyncService::GetLastSyncedTimeString() const { | 1705 base::string16 ProfileSyncService::GetLastSyncedTimeString() const { |
1709 if (last_synced_time_.is_null()) | 1706 const base::Time last_synced_time = sync_prefs_.GetLastSyncedTime(); |
| 1707 if (last_synced_time.is_null()) |
1710 return l10n_util::GetStringUTF16(IDS_SYNC_TIME_NEVER); | 1708 return l10n_util::GetStringUTF16(IDS_SYNC_TIME_NEVER); |
1711 | 1709 |
1712 base::TimeDelta last_synced = base::Time::Now() - last_synced_time_; | 1710 base::TimeDelta time_since_last_sync = base::Time::Now() - last_synced_time; |
1713 | 1711 |
1714 if (last_synced < base::TimeDelta::FromMinutes(1)) | 1712 if (time_since_last_sync < base::TimeDelta::FromMinutes(1)) |
1715 return l10n_util::GetStringUTF16(IDS_SYNC_TIME_JUST_NOW); | 1713 return l10n_util::GetStringUTF16(IDS_SYNC_TIME_JUST_NOW); |
1716 | 1714 |
1717 return ui::TimeFormat::Simple(ui::TimeFormat::FORMAT_ELAPSED, | 1715 return ui::TimeFormat::Simple(ui::TimeFormat::FORMAT_ELAPSED, |
1718 ui::TimeFormat::LENGTH_SHORT, last_synced); | 1716 ui::TimeFormat::LENGTH_SHORT, |
| 1717 time_since_last_sync); |
1719 } | 1718 } |
1720 | 1719 |
1721 void ProfileSyncService::UpdateSelectedTypesHistogram( | 1720 void ProfileSyncService::UpdateSelectedTypesHistogram( |
1722 bool sync_everything, const syncer::ModelTypeSet chosen_types) const { | 1721 bool sync_everything, const syncer::ModelTypeSet chosen_types) const { |
1723 if (!HasSyncSetupCompleted() || | 1722 if (!HasSyncSetupCompleted() || |
1724 sync_everything != sync_prefs_.HasKeepEverythingSynced()) { | 1723 sync_everything != sync_prefs_.HasKeepEverythingSynced()) { |
1725 UMA_HISTOGRAM_BOOLEAN("Sync.SyncEverything", sync_everything); | 1724 UMA_HISTOGRAM_BOOLEAN("Sync.SyncEverything", sync_everything); |
1726 } | 1725 } |
1727 | 1726 |
1728 // Only log the data types that are shown in the sync settings ui. | 1727 // Only log the data types that are shown in the sync settings ui. |
(...skipping 950 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2679 } | 2678 } |
2680 } | 2679 } |
2681 } | 2680 } |
2682 return result; | 2681 return result; |
2683 } | 2682 } |
2684 | 2683 |
2685 void ProfileSyncService::CheckSyncBackupIfNeeded() { | 2684 void ProfileSyncService::CheckSyncBackupIfNeeded() { |
2686 DCHECK_EQ(backend_mode_, SYNC); | 2685 DCHECK_EQ(backend_mode_, SYNC); |
2687 | 2686 |
2688 #if defined(ENABLE_PRE_SYNC_BACKUP) | 2687 #if defined(ENABLE_PRE_SYNC_BACKUP) |
| 2688 const base::Time last_synced_time = sync_prefs_.GetLastSyncedTime(); |
2689 // Check backup once a day. | 2689 // Check backup once a day. |
2690 if (!last_backup_time_ && | 2690 if (!last_backup_time_ && |
2691 (last_synced_time_.is_null() || | 2691 (last_synced_time.is_null() || |
2692 base::Time::Now() - last_synced_time_ >= | 2692 base::Time::Now() - last_synced_time >= |
2693 base::TimeDelta::FromDays(1))) { | 2693 base::TimeDelta::FromDays(1))) { |
2694 // If sync thread is set, need to serialize check on sync thread after | 2694 // If sync thread is set, need to serialize check on sync thread after |
2695 // closing backup DB. | 2695 // closing backup DB. |
2696 if (sync_thread_) { | 2696 if (sync_thread_) { |
2697 sync_thread_->message_loop_proxy()->PostTask( | 2697 sync_thread_->message_loop_proxy()->PostTask( |
2698 FROM_HERE, | 2698 FROM_HERE, |
2699 base::Bind(syncer::CheckSyncDbLastModifiedTime, | 2699 base::Bind(syncer::CheckSyncDbLastModifiedTime, |
2700 profile_->GetPath().Append(kSyncBackupDataFolderName), | 2700 profile_->GetPath().Append(kSyncBackupDataFolderName), |
2701 base::MessageLoopProxy::current(), | 2701 base::MessageLoopProxy::current(), |
2702 base::Bind(&ProfileSyncService::CheckSyncBackupCallback, | 2702 base::Bind(&ProfileSyncService::CheckSyncBackupCallback, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2735 true)); | 2735 true)); |
2736 } | 2736 } |
2737 | 2737 |
2738 bool ProfileSyncService::NeedBackup() const { | 2738 bool ProfileSyncService::NeedBackup() const { |
2739 return need_backup_; | 2739 return need_backup_; |
2740 } | 2740 } |
2741 | 2741 |
2742 base::Time ProfileSyncService::GetDeviceBackupTimeForTesting() const { | 2742 base::Time ProfileSyncService::GetDeviceBackupTimeForTesting() const { |
2743 return device_info_sync_service_->GetLocalDeviceBackupTime(); | 2743 return device_info_sync_service_->GetLocalDeviceBackupTime(); |
2744 } | 2744 } |
OLD | NEW |