| 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 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
| 14 #include "base/callback.h" | 14 #include "base/callback.h" |
| 15 #include "base/command_line.h" | 15 #include "base/command_line.h" |
| 16 #include "base/compiler_specific.h" | 16 #include "base/compiler_specific.h" |
| 17 #include "base/files/file_util.h" | 17 #include "base/files/file_util.h" |
| 18 #include "base/logging.h" | 18 #include "base/logging.h" |
| 19 #include "base/memory/ref_counted.h" | 19 #include "base/memory/ref_counted.h" |
| 20 #include "base/message_loop/message_loop.h" | |
| 21 #include "base/metrics/histogram.h" | 20 #include "base/metrics/histogram.h" |
| 22 #include "base/profiler/scoped_tracker.h" | 21 #include "base/profiler/scoped_tracker.h" |
| 22 #include "base/single_thread_task_runner.h" |
| 23 #include "base/strings/string16.h" | 23 #include "base/strings/string16.h" |
| 24 #include "base/strings/stringprintf.h" | 24 #include "base/strings/stringprintf.h" |
| 25 #include "base/thread_task_runner_handle.h" | 25 #include "base/thread_task_runner_handle.h" |
| 26 #include "base/threading/thread_restrictions.h" | 26 #include "base/threading/thread_restrictions.h" |
| 27 #include "build/build_config.h" | 27 #include "build/build_config.h" |
| 28 #include "chrome/browser/browser_process.h" | 28 #include "chrome/browser/browser_process.h" |
| 29 #include "chrome/browser/browsing_data/browsing_data_helper.h" | 29 #include "chrome/browser/browsing_data/browsing_data_helper.h" |
| 30 #include "chrome/browser/chrome_notification_types.h" | 30 #include "chrome/browser/chrome_notification_types.h" |
| 31 #include "chrome/browser/defaults.h" | 31 #include "chrome/browser/defaults.h" |
| 32 #include "chrome/browser/invalidation/profile_invalidation_provider_factory.h" | 32 #include "chrome/browser/invalidation/profile_invalidation_provider_factory.h" |
| (...skipping 787 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 820 | 820 |
| 821 if (sync_thread_) | 821 if (sync_thread_) |
| 822 sync_thread_->Stop(); | 822 sync_thread_->Stop(); |
| 823 } | 823 } |
| 824 | 824 |
| 825 void ProfileSyncService::ShutdownImpl(syncer::ShutdownReason reason) { | 825 void ProfileSyncService::ShutdownImpl(syncer::ShutdownReason reason) { |
| 826 if (!backend_) { | 826 if (!backend_) { |
| 827 if (reason == syncer::ShutdownReason::DISABLE_SYNC && sync_thread_) { | 827 if (reason == syncer::ShutdownReason::DISABLE_SYNC && sync_thread_) { |
| 828 // If the backend is already shut down when a DISABLE_SYNC happens, | 828 // If the backend is already shut down when a DISABLE_SYNC happens, |
| 829 // the data directory needs to be cleaned up here. | 829 // the data directory needs to be cleaned up here. |
| 830 sync_thread_->message_loop()->PostTask(FROM_HERE, | 830 sync_thread_->task_runner()->PostTask( |
| 831 base::Bind(&DeleteSyncDataFolder, directory_path_)); | 831 FROM_HERE, base::Bind(&DeleteSyncDataFolder, directory_path_)); |
| 832 } | 832 } |
| 833 return; | 833 return; |
| 834 } | 834 } |
| 835 | 835 |
| 836 if (reason == syncer::ShutdownReason::STOP_SYNC | 836 if (reason == syncer::ShutdownReason::STOP_SYNC |
| 837 || reason == syncer::ShutdownReason::DISABLE_SYNC) { | 837 || reason == syncer::ShutdownReason::DISABLE_SYNC) { |
| 838 RemoveClientFromServer(); | 838 RemoveClientFromServer(); |
| 839 } | 839 } |
| 840 | 840 |
| 841 non_blocking_data_type_manager_.DisconnectSyncBackend(); | 841 non_blocking_data_type_manager_.DisconnectSyncBackend(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 882 | 882 |
| 883 // Don't let backup block sync regardless backup succeeded or not. | 883 // Don't let backup block sync regardless backup succeeded or not. |
| 884 if (backend_mode_ == BACKUP) | 884 if (backend_mode_ == BACKUP) |
| 885 backup_finished_ = true; | 885 backup_finished_ = true; |
| 886 | 886 |
| 887 // Sync could be blocked by rollback/backup. Post task to check whether sync | 887 // Sync could be blocked by rollback/backup. Post task to check whether sync |
| 888 // should start after shutting down rollback/backup backend. | 888 // should start after shutting down rollback/backup backend. |
| 889 if ((backend_mode_ == ROLLBACK || backend_mode_ == BACKUP) && | 889 if ((backend_mode_ == ROLLBACK || backend_mode_ == BACKUP) && |
| 890 reason != syncer::SWITCH_MODE_SYNC && | 890 reason != syncer::SWITCH_MODE_SYNC && |
| 891 reason != syncer::BROWSER_SHUTDOWN) { | 891 reason != syncer::BROWSER_SHUTDOWN) { |
| 892 base::MessageLoop::current()->PostTask( | 892 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 893 FROM_HERE, base::Bind(&ProfileSyncService::TryStartSyncAfterBackup, | 893 FROM_HERE, base::Bind(&ProfileSyncService::TryStartSyncAfterBackup, |
| 894 startup_controller_weak_factory_.GetWeakPtr())); | 894 startup_controller_weak_factory_.GetWeakPtr())); |
| 895 } | 895 } |
| 896 | 896 |
| 897 // Clear various flags. | 897 // Clear various flags. |
| 898 backend_mode_ = IDLE; | 898 backend_mode_ = IDLE; |
| 899 expect_sync_configuration_aborted_ = false; | 899 expect_sync_configuration_aborted_ = false; |
| 900 is_auth_in_progress_ = false; | 900 is_auth_in_progress_ = false; |
| 901 backend_initialized_ = false; | 901 backend_initialized_ = false; |
| 902 cached_passphrase_.clear(); | 902 cached_passphrase_.clear(); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 982 UMA_HISTOGRAM_ENUMERATION(kSyncUnrecoverableErrorHistogram, | 982 UMA_HISTOGRAM_ENUMERATION(kSyncUnrecoverableErrorHistogram, |
| 983 unrecoverable_error_reason_, | 983 unrecoverable_error_reason_, |
| 984 ERROR_REASON_LIMIT); | 984 ERROR_REASON_LIMIT); |
| 985 std::string location; | 985 std::string location; |
| 986 from_here.Write(true, true, &location); | 986 from_here.Write(true, true, &location); |
| 987 LOG(ERROR) | 987 LOG(ERROR) |
| 988 << "Unrecoverable error detected at " << location | 988 << "Unrecoverable error detected at " << location |
| 989 << " -- ProfileSyncService unusable: " << message; | 989 << " -- ProfileSyncService unusable: " << message; |
| 990 | 990 |
| 991 // Shut all data types down. | 991 // Shut all data types down. |
| 992 base::MessageLoop::current()->PostTask(FROM_HERE, | 992 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 993 base::Bind(&ProfileSyncService::ShutdownImpl, | 993 FROM_HERE, |
| 994 weak_factory_.GetWeakPtr(), | 994 base::Bind( |
| 995 delete_sync_database ? | 995 &ProfileSyncService::ShutdownImpl, weak_factory_.GetWeakPtr(), |
| 996 syncer::DISABLE_SYNC : syncer::STOP_SYNC)); | 996 delete_sync_database ? syncer::DISABLE_SYNC : syncer::STOP_SYNC)); |
| 997 } | 997 } |
| 998 | 998 |
| 999 void ProfileSyncService::ReenableDatatype(syncer::ModelType type) { | 999 void ProfileSyncService::ReenableDatatype(syncer::ModelType type) { |
| 1000 if (!backend_initialized_) | 1000 if (!backend_initialized_) |
| 1001 return; | 1001 return; |
| 1002 directory_data_type_manager_->ReenableType(type); | 1002 directory_data_type_manager_->ReenableType(type); |
| 1003 } | 1003 } |
| 1004 | 1004 |
| 1005 void ProfileSyncService::UpdateBackendInitUMA(bool success) { | 1005 void ProfileSyncService::UpdateBackendInitUMA(bool success) { |
| 1006 if (backend_mode_ != SYNC) | 1006 if (backend_mode_ != SYNC) |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1132 ConfigureDataTypeManager(); | 1132 ConfigureDataTypeManager(); |
| 1133 else | 1133 else |
| 1134 PostBackendInitialization(); | 1134 PostBackendInitialization(); |
| 1135 } | 1135 } |
| 1136 | 1136 |
| 1137 void ProfileSyncService::OnSyncCycleCompleted() { | 1137 void ProfileSyncService::OnSyncCycleCompleted() { |
| 1138 UpdateLastSyncedTime(); | 1138 UpdateLastSyncedTime(); |
| 1139 if (IsDataTypeControllerRunning(syncer::SESSIONS)) { | 1139 if (IsDataTypeControllerRunning(syncer::SESSIONS)) { |
| 1140 // Trigger garbage collection of old sessions now that we've downloaded | 1140 // Trigger garbage collection of old sessions now that we've downloaded |
| 1141 // any new session data. | 1141 // any new session data. |
| 1142 base::MessageLoop::current()->PostTask(FROM_HERE, base::Bind( | 1142 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 1143 &SessionsSyncManager::DoGarbageCollection, | 1143 FROM_HERE, base::Bind(&SessionsSyncManager::DoGarbageCollection, |
| 1144 base::AsWeakPtr(sessions_sync_manager_.get()))); | 1144 base::AsWeakPtr(sessions_sync_manager_.get()))); |
| 1145 } | 1145 } |
| 1146 DVLOG(2) << "Notifying observers sync cycle completed"; | 1146 DVLOG(2) << "Notifying observers sync cycle completed"; |
| 1147 NotifySyncCycleCompleted(); | 1147 NotifySyncCycleCompleted(); |
| 1148 } | 1148 } |
| 1149 | 1149 |
| 1150 void ProfileSyncService::OnExperimentsChanged( | 1150 void ProfileSyncService::OnExperimentsChanged( |
| 1151 const syncer::Experiments& experiments) { | 1151 const syncer::Experiments& experiments) { |
| 1152 if (current_experiments_.Matches(experiments)) | 1152 if (current_experiments_.Matches(experiments)) |
| 1153 return; | 1153 return; |
| 1154 | 1154 |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1419 | 1419 |
| 1420 if (backend_mode_ != SYNC) { | 1420 if (backend_mode_ != SYNC) { |
| 1421 if (configure_status_ == DataTypeManager::OK) { | 1421 if (configure_status_ == DataTypeManager::OK) { |
| 1422 StartSyncingWithServer(); | 1422 StartSyncingWithServer(); |
| 1423 | 1423 |
| 1424 // Backup is done after models are associated. | 1424 // Backup is done after models are associated. |
| 1425 if (backend_mode_ == BACKUP) | 1425 if (backend_mode_ == BACKUP) |
| 1426 backup_finished_ = true; | 1426 backup_finished_ = true; |
| 1427 | 1427 |
| 1428 // Asynchronously check whether sync needs to start. | 1428 // Asynchronously check whether sync needs to start. |
| 1429 base::MessageLoop::current()->PostTask( | 1429 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 1430 FROM_HERE, base::Bind(&ProfileSyncService::TryStartSyncAfterBackup, | 1430 FROM_HERE, base::Bind(&ProfileSyncService::TryStartSyncAfterBackup, |
| 1431 startup_controller_weak_factory_.GetWeakPtr())); | 1431 startup_controller_weak_factory_.GetWeakPtr())); |
| 1432 } else if (!expect_sync_configuration_aborted_) { | 1432 } else if (!expect_sync_configuration_aborted_) { |
| 1433 DVLOG(1) << "Backup/rollback backend failed to configure."; | 1433 DVLOG(1) << "Backup/rollback backend failed to configure."; |
| 1434 ShutdownImpl(syncer::STOP_SYNC); | 1434 ShutdownImpl(syncer::STOP_SYNC); |
| 1435 } | 1435 } |
| 1436 | 1436 |
| 1437 return; | 1437 return; |
| 1438 } | 1438 } |
| 1439 | 1439 |
| (...skipping 1198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2638 #if defined(ENABLE_PRE_SYNC_BACKUP) | 2638 #if defined(ENABLE_PRE_SYNC_BACKUP) |
| 2639 const base::Time last_synced_time = sync_prefs_.GetLastSyncedTime(); | 2639 const base::Time last_synced_time = sync_prefs_.GetLastSyncedTime(); |
| 2640 // Check backup once a day. | 2640 // Check backup once a day. |
| 2641 if (!last_backup_time_ && | 2641 if (!last_backup_time_ && |
| 2642 (last_synced_time.is_null() || | 2642 (last_synced_time.is_null() || |
| 2643 base::Time::Now() - last_synced_time >= | 2643 base::Time::Now() - last_synced_time >= |
| 2644 base::TimeDelta::FromDays(1))) { | 2644 base::TimeDelta::FromDays(1))) { |
| 2645 // If sync thread is set, need to serialize check on sync thread after | 2645 // If sync thread is set, need to serialize check on sync thread after |
| 2646 // closing backup DB. | 2646 // closing backup DB. |
| 2647 if (sync_thread_) { | 2647 if (sync_thread_) { |
| 2648 sync_thread_->message_loop_proxy()->PostTask( | 2648 sync_thread_->task_runner()->PostTask( |
| 2649 FROM_HERE, | 2649 FROM_HERE, |
| 2650 base::Bind(syncer::CheckSyncDbLastModifiedTime, | 2650 base::Bind(syncer::CheckSyncDbLastModifiedTime, |
| 2651 profile_->GetPath().Append(kSyncBackupDataFolderName), | 2651 profile_->GetPath().Append(kSyncBackupDataFolderName), |
| 2652 base::ThreadTaskRunnerHandle::Get(), | 2652 base::ThreadTaskRunnerHandle::Get(), |
| 2653 base::Bind(&ProfileSyncService::CheckSyncBackupCallback, | 2653 base::Bind(&ProfileSyncService::CheckSyncBackupCallback, |
| 2654 weak_factory_.GetWeakPtr()))); | 2654 weak_factory_.GetWeakPtr()))); |
| 2655 } else { | 2655 } else { |
| 2656 content::BrowserThread::PostTask( | 2656 content::BrowserThread::PostTask( |
| 2657 content::BrowserThread::FILE, FROM_HERE, | 2657 content::BrowserThread::FILE, FROM_HERE, |
| 2658 base::Bind(syncer::CheckSyncDbLastModifiedTime, | 2658 base::Bind(syncer::CheckSyncDbLastModifiedTime, |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2749 } else { | 2749 } else { |
| 2750 UMA_HISTOGRAM_COUNTS("Sync.MemoryPressureWarningBeforeCleanShutdown", | 2750 UMA_HISTOGRAM_COUNTS("Sync.MemoryPressureWarningBeforeCleanShutdown", |
| 2751 warning_received); | 2751 warning_received); |
| 2752 } | 2752 } |
| 2753 } | 2753 } |
| 2754 sync_prefs_.SetMemoryPressureWarningCount(0); | 2754 sync_prefs_.SetMemoryPressureWarningCount(0); |
| 2755 // Will set to true during a clean shutdown, so crash or something else will | 2755 // Will set to true during a clean shutdown, so crash or something else will |
| 2756 // remain this as false. | 2756 // remain this as false. |
| 2757 sync_prefs_.SetCleanShutdown(false); | 2757 sync_prefs_.SetCleanShutdown(false); |
| 2758 } | 2758 } |
| OLD | NEW |