Chromium Code Reviews| 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 "sync/internal_api/sync_manager_impl.h" | 5 #include "sync/internal_api/sync_manager_impl.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 195 // We do not verify the tokens given. After this call, the tokens are set | 195 // We do not verify the tokens given. After this call, the tokens are set |
| 196 // and the sync DB is open. True if successful, false if something | 196 // and the sync DB is open. True if successful, false if something |
| 197 // went wrong. | 197 // went wrong. |
| 198 bool SignIn(const SyncCredentials& credentials); | 198 bool SignIn(const SyncCredentials& credentials); |
| 199 | 199 |
| 200 // Purge from the directory those types with non-empty progress markers | 200 // Purge from the directory those types with non-empty progress markers |
| 201 // but without initial synced ended set. | 201 // but without initial synced ended set. |
| 202 // Returns false if an error occurred, true otherwise. | 202 // Returns false if an error occurred, true otherwise. |
| 203 bool PurgePartiallySyncedTypes(); | 203 bool PurgePartiallySyncedTypes(); |
| 204 | 204 |
| 205 // Purges all disabled types. | |
| 206 // Warning: this is expensive as it will iterate over all entries in the | |
| 207 // directory. Only call if absolutely necessary. | |
| 208 bool CleanupDisabledTypes(); | |
| 209 | |
| 205 // Update tokens that we're using in Sync. Email must stay the same. | 210 // Update tokens that we're using in Sync. Email must stay the same. |
| 206 void UpdateCredentials(const SyncCredentials& credentials); | 211 void UpdateCredentials(const SyncCredentials& credentials); |
| 207 | 212 |
| 208 // Called when the user disables or enables a sync type. | 213 // Called when the user disables or enables a sync type. |
| 209 void UpdateEnabledTypes(const ModelTypeSet& enabled_types); | 214 void UpdateEnabledTypes(const ModelTypeSet& enabled_types); |
| 210 | 215 |
| 211 // Tell the sync engine to start the syncing process. | 216 // Tell the sync engine to start the syncing process. |
| 212 void StartSyncingNormally( | 217 void StartSyncingNormally( |
| 213 const syncer::ModelSafeRoutingInfo& routing_info); | 218 const syncer::ModelSafeRoutingInfo& routing_info); |
| 214 | 219 |
| (...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 822 void SyncManagerImpl::ConfigureSyncer( | 827 void SyncManagerImpl::ConfigureSyncer( |
| 823 ConfigureReason reason, | 828 ConfigureReason reason, |
| 824 const syncer::ModelTypeSet& types_to_config, | 829 const syncer::ModelTypeSet& types_to_config, |
| 825 const syncer::ModelSafeRoutingInfo& new_routing_info, | 830 const syncer::ModelSafeRoutingInfo& new_routing_info, |
| 826 const base::Closure& ready_task, | 831 const base::Closure& ready_task, |
| 827 const base::Closure& retry_task) { | 832 const base::Closure& retry_task) { |
| 828 DCHECK(thread_checker_.CalledOnValidThread()); | 833 DCHECK(thread_checker_.CalledOnValidThread()); |
| 829 DCHECK(!ready_task.is_null()); | 834 DCHECK(!ready_task.is_null()); |
| 830 DCHECK(!retry_task.is_null()); | 835 DCHECK(!retry_task.is_null()); |
| 831 | 836 |
| 837 // Cleanup disabled types if necessary. | |
| 838 // Note: tests might not have a session context. | |
| 839 if (data_->session_context()) { | |
| 840 ModelTypeSet disabled_types = | |
| 841 Difference( | |
|
tim (not reviewing)
2012/07/19 22:05:59
nit: I'd move Difference( up one line
Nicolas Zea
2012/07/20 22:07:01
Done.
| |
| 842 GetRoutingInfoTypes(data_->session_context()->routing_info()), | |
| 843 GetRoutingInfoTypes(new_routing_info)); | |
| 844 if (!disabled_types.Empty()) { | |
| 845 DVLOG(1) << "Purging disabled types: " | |
| 846 << ModelTypeSetToString(disabled_types); | |
| 847 data_->directory()->PurgeEntriesWithTypeIn(disabled_types); | |
|
tim (not reviewing)
2012/07/19 22:05:59
We should probably bail / callback / use a bigger
Nicolas Zea
2012/07/20 22:07:01
Done.
| |
| 848 } | |
| 849 } | |
| 850 | |
| 832 // TODO(zea): set this based on whether cryptographer has keystore | 851 // TODO(zea): set this based on whether cryptographer has keystore |
| 833 // encryption key or not (requires opening a transaction). crbug.com/129665. | 852 // encryption key or not (requires opening a transaction). crbug.com/129665. |
| 834 ConfigurationParams::KeystoreKeyStatus keystore_key_status = | 853 ConfigurationParams::KeystoreKeyStatus keystore_key_status = |
| 835 ConfigurationParams::KEYSTORE_KEY_UNNECESSARY; | 854 ConfigurationParams::KEYSTORE_KEY_UNNECESSARY; |
| 836 | 855 |
| 837 ConfigurationParams params(GetSourceFromReason(reason), | 856 ConfigurationParams params(GetSourceFromReason(reason), |
| 838 types_to_config, | 857 types_to_config, |
| 839 new_routing_info, | 858 new_routing_info, |
| 840 keystore_key_status, | 859 keystore_key_status, |
| 841 ready_task); | 860 ready_task); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 961 // re-downloaded during any configuration. But, it's possible for a datatype | 980 // re-downloaded during any configuration. But, it's possible for a datatype |
| 962 // to have a progress marker but not have initial sync ended yet, making | 981 // to have a progress marker but not have initial sync ended yet, making |
| 963 // it a candidate for migration. This is a problem, as the DataTypeManager | 982 // it a candidate for migration. This is a problem, as the DataTypeManager |
| 964 // does not support a migration while it's already in the middle of a | 983 // does not support a migration while it's already in the middle of a |
| 965 // configuration. As a result, any partially synced datatype can stall the | 984 // configuration. As a result, any partially synced datatype can stall the |
| 966 // DTM, waiting for the configuration to complete, which it never will due | 985 // DTM, waiting for the configuration to complete, which it never will due |
| 967 // to the migration error. In addition, a partially synced nigori will | 986 // to the migration error. In addition, a partially synced nigori will |
| 968 // trigger the migration logic before the backend is initialized, resulting | 987 // trigger the migration logic before the backend is initialized, resulting |
| 969 // in crashes. We therefore detect and purge any partially synced types as | 988 // in crashes. We therefore detect and purge any partially synced types as |
| 970 // part of initialization. | 989 // part of initialization. |
| 971 if (!PurgePartiallySyncedTypes()) | 990 // |
| 991 // Similarly, a type may have been disabled previously, but we didn't | |
| 992 // manage to purge. Ensure we cleanup any disabled types before starting up. | |
| 993 // | |
| 994 // Note: If either of these methods fail, we have directory corruption and | |
| 995 // cannot continue. | |
| 996 if (!PurgePartiallySyncedTypes() || !CleanupDisabledTypes()) | |
| 972 success = false; | 997 success = false; |
| 973 | 998 |
| 974 // Cryptographer should only be accessed while holding a | 999 // Cryptographer should only be accessed while holding a |
| 975 // transaction. Grabbing the user share for the transaction | 1000 // transaction. Grabbing the user share for the transaction |
| 976 // checks the initialization state, so this must come after | 1001 // checks the initialization state, so this must come after |
| 977 // |initialized_| is set to true. | 1002 // |initialized_| is set to true. |
| 978 ReadTransaction trans(FROM_HERE, GetUserShare()); | 1003 ReadTransaction trans(FROM_HERE, GetUserShare()); |
| 979 trans.GetCryptographer()->Bootstrap(restored_key_for_bootstrapping); | 1004 trans.GetCryptographer()->Bootstrap(restored_key_for_bootstrapping); |
| 980 trans.GetCryptographer()->AddObserver(this); | 1005 trans.GetCryptographer()->AddObserver(this); |
| 981 } | 1006 } |
| 982 | 1007 |
| 983 // Notify that initialization is complete. Note: This should be the last to | 1008 // Notify that initialization is complete. Note: This should be the last to |
| 984 // execute if |signed_in| is false. Reason being in that case we would | 1009 // execute if |signed_in| is false. Reason being in that case we would |
| 985 // post a task to shutdown sync. But if this function posts any other tasks | 1010 // post a task to shutdown sync. But if this function posts any other tasks |
| 986 // on the UI thread and if shutdown wins then that tasks would execute on | 1011 // on the UI thread and if shutdown wins then that tasks would execute on |
| 987 // a freed pointer. This is because UI thread is not shut down. | 1012 // a freed pointer. This is because UI thread is not shut down. |
| 988 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, | 1013 FOR_EACH_OBSERVER(SyncManager::Observer, observers_, |
| 989 OnInitializationComplete( | 1014 OnInitializationComplete( |
| 990 MakeWeakHandle(weak_ptr_factory_.GetWeakPtr()), | 1015 MakeWeakHandle(weak_ptr_factory_.GetWeakPtr()), |
| 991 success)); | 1016 success)); |
| 992 | 1017 |
| 993 if (!success && testing_mode_ == NON_TEST) | 1018 if (!success && testing_mode_ == NON_TEST) |
| 994 return false; | 1019 return false; |
| 995 | 1020 |
| 996 sync_notifier_->AddObserver(this); | 1021 sync_notifier_->AddObserver(this); |
| 997 | 1022 |
| 998 return success; | 1023 return success; |
| 999 } | 1024 } |
| 1000 | 1025 |
| 1026 bool SyncManagerImpl::SyncInternal::CleanupDisabledTypes() { | |
| 1027 if (testing_mode_ != NON_TEST) | |
| 1028 return true; | |
| 1029 | |
| 1030 ModelTypeSet enabled_types = GetRoutingInfoTypes( | |
| 1031 session_context()->routing_info()); | |
| 1032 ModelTypeSet disabled_types = Difference(ModelTypeSet::All(), | |
| 1033 enabled_types); | |
| 1034 if (disabled_types.Empty()) | |
| 1035 return true; | |
| 1036 | |
| 1037 DVLOG(1) << "Purging disabled types " | |
| 1038 << ModelTypeSetToString(disabled_types); | |
| 1039 return directory()->PurgeEntriesWithTypeIn(disabled_types); | |
| 1040 } | |
| 1041 | |
| 1042 | |
| 1001 void SyncManagerImpl::SyncInternal::UpdateCryptographerAndNigori( | 1043 void SyncManagerImpl::SyncInternal::UpdateCryptographerAndNigori( |
| 1002 const std::string& chrome_version, | 1044 const std::string& chrome_version, |
| 1003 const base::Closure& done_callback) { | 1045 const base::Closure& done_callback) { |
| 1004 DCHECK(initialized_); | 1046 DCHECK(initialized_); |
| 1005 syncer::GetSessionName( | 1047 syncer::GetSessionName( |
| 1006 blocking_task_runner_, | 1048 blocking_task_runner_, |
| 1007 base::Bind( | 1049 base::Bind( |
| 1008 &SyncManagerImpl::SyncInternal::UpdateCryptographerAndNigoriCallback, | 1050 &SyncManagerImpl::SyncInternal::UpdateCryptographerAndNigoriCallback, |
| 1009 weak_ptr_factory_.GetWeakPtr(), | 1051 weak_ptr_factory_.GetWeakPtr(), |
| 1010 chrome_version, | 1052 chrome_version, |
| (...skipping 1482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2493 int SyncManagerImpl::GetDefaultNudgeDelay() { | 2535 int SyncManagerImpl::GetDefaultNudgeDelay() { |
| 2494 return kDefaultNudgeDelayMilliseconds; | 2536 return kDefaultNudgeDelayMilliseconds; |
| 2495 } | 2537 } |
| 2496 | 2538 |
| 2497 // static. | 2539 // static. |
| 2498 int SyncManagerImpl::GetPreferencesNudgeDelay() { | 2540 int SyncManagerImpl::GetPreferencesNudgeDelay() { |
| 2499 return kPreferencesNudgeDelayMilliseconds; | 2541 return kPreferencesNudgeDelayMilliseconds; |
| 2500 } | 2542 } |
| 2501 | 2543 |
| 2502 } // namespace syncer | 2544 } // namespace syncer |
| OLD | NEW |