| 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 "components/sync/core_impl/sync_manager_impl.h" | 5 #include "components/sync/core_impl/sync_manager_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 767 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 778 } | 778 } |
| 779 | 779 |
| 780 void SyncManagerImpl::RequestNudgeForDataTypes( | 780 void SyncManagerImpl::RequestNudgeForDataTypes( |
| 781 const tracked_objects::Location& nudge_location, | 781 const tracked_objects::Location& nudge_location, |
| 782 ModelTypeSet types) { | 782 ModelTypeSet types) { |
| 783 debug_info_event_listener_.OnNudgeFromDatatype(types.First().Get()); | 783 debug_info_event_listener_.OnNudgeFromDatatype(types.First().Get()); |
| 784 | 784 |
| 785 scheduler_->ScheduleLocalNudge(types, nudge_location); | 785 scheduler_->ScheduleLocalNudge(types, nudge_location); |
| 786 } | 786 } |
| 787 | 787 |
| 788 void SyncManagerImpl::NudgeForInitialDownload(syncer::ModelType type) { | 788 void SyncManagerImpl::NudgeForInitialDownload(ModelType type) { |
| 789 DCHECK(thread_checker_.CalledOnValidThread()); | 789 DCHECK(thread_checker_.CalledOnValidThread()); |
| 790 scheduler_->ScheduleInitialSyncNudge(type); | 790 scheduler_->ScheduleInitialSyncNudge(type); |
| 791 } | 791 } |
| 792 | 792 |
| 793 void SyncManagerImpl::NudgeForCommit(syncer::ModelType type) { | 793 void SyncManagerImpl::NudgeForCommit(ModelType type) { |
| 794 DCHECK(thread_checker_.CalledOnValidThread()); | 794 DCHECK(thread_checker_.CalledOnValidThread()); |
| 795 RequestNudgeForDataTypes(FROM_HERE, ModelTypeSet(type)); | 795 RequestNudgeForDataTypes(FROM_HERE, ModelTypeSet(type)); |
| 796 } | 796 } |
| 797 | 797 |
| 798 void SyncManagerImpl::NudgeForRefresh(syncer::ModelType type) { | 798 void SyncManagerImpl::NudgeForRefresh(ModelType type) { |
| 799 DCHECK(thread_checker_.CalledOnValidThread()); | 799 DCHECK(thread_checker_.CalledOnValidThread()); |
| 800 RefreshTypes(ModelTypeSet(type)); | 800 RefreshTypes(ModelTypeSet(type)); |
| 801 } | 801 } |
| 802 | 802 |
| 803 void SyncManagerImpl::OnSyncCycleEvent(const SyncCycleEvent& event) { | 803 void SyncManagerImpl::OnSyncCycleEvent(const SyncCycleEvent& event) { |
| 804 DCHECK(thread_checker_.CalledOnValidThread()); | 804 DCHECK(thread_checker_.CalledOnValidThread()); |
| 805 // Only send an event if this is due to a cycle ending and this cycle | 805 // Only send an event if this is due to a cycle ending and this cycle |
| 806 // concludes a canonical "sync" process; that is, based on what is known | 806 // concludes a canonical "sync" process; that is, based on what is known |
| 807 // locally we are "all happy" and up to date. There may be new changes on | 807 // locally we are "all happy" and up to date. There may be new changes on |
| 808 // the server, but we'll get them on a subsequent sync. | 808 // the server, but we'll get them on a subsequent sync. |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 850 | 850 |
| 851 void SyncManagerImpl::SetInvalidatorEnabled(bool invalidator_enabled) { | 851 void SyncManagerImpl::SetInvalidatorEnabled(bool invalidator_enabled) { |
| 852 DCHECK(thread_checker_.CalledOnValidThread()); | 852 DCHECK(thread_checker_.CalledOnValidThread()); |
| 853 | 853 |
| 854 DVLOG(1) << "Invalidator enabled state is now: " << invalidator_enabled; | 854 DVLOG(1) << "Invalidator enabled state is now: " << invalidator_enabled; |
| 855 allstatus_.SetNotificationsEnabled(invalidator_enabled); | 855 allstatus_.SetNotificationsEnabled(invalidator_enabled); |
| 856 scheduler_->SetNotificationsEnabled(invalidator_enabled); | 856 scheduler_->SetNotificationsEnabled(invalidator_enabled); |
| 857 } | 857 } |
| 858 | 858 |
| 859 void SyncManagerImpl::OnIncomingInvalidation( | 859 void SyncManagerImpl::OnIncomingInvalidation( |
| 860 syncer::ModelType type, | 860 ModelType type, |
| 861 std::unique_ptr<InvalidationInterface> invalidation) { | 861 std::unique_ptr<InvalidationInterface> invalidation) { |
| 862 DCHECK(thread_checker_.CalledOnValidThread()); | 862 DCHECK(thread_checker_.CalledOnValidThread()); |
| 863 | 863 |
| 864 allstatus_.IncrementNotificationsReceived(); | 864 allstatus_.IncrementNotificationsReceived(); |
| 865 scheduler_->ScheduleInvalidationNudge(type, std::move(invalidation), | 865 scheduler_->ScheduleInvalidationNudge(type, std::move(invalidation), |
| 866 FROM_HERE); | 866 FROM_HERE); |
| 867 } | 867 } |
| 868 | 868 |
| 869 void SyncManagerImpl::RefreshTypes(ModelTypeSet types) { | 869 void SyncManagerImpl::RefreshTypes(ModelTypeSet types) { |
| 870 DCHECK(thread_checker_.CalledOnValidThread()); | 870 DCHECK(thread_checker_.CalledOnValidThread()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 881 | 881 |
| 882 void SyncManagerImpl::SaveChanges() { | 882 void SyncManagerImpl::SaveChanges() { |
| 883 directory()->SaveChanges(); | 883 directory()->SaveChanges(); |
| 884 } | 884 } |
| 885 | 885 |
| 886 UserShare* SyncManagerImpl::GetUserShare() { | 886 UserShare* SyncManagerImpl::GetUserShare() { |
| 887 DCHECK(initialized_); | 887 DCHECK(initialized_); |
| 888 return &share_; | 888 return &share_; |
| 889 } | 889 } |
| 890 | 890 |
| 891 std::unique_ptr<syncer_v2::ModelTypeConnector> | 891 std::unique_ptr<ModelTypeConnector> |
| 892 SyncManagerImpl::GetModelTypeConnectorProxy() { | 892 SyncManagerImpl::GetModelTypeConnectorProxy() { |
| 893 DCHECK(initialized_); | 893 DCHECK(initialized_); |
| 894 return base::MakeUnique<syncer_v2::ModelTypeConnectorProxy>( | 894 return base::MakeUnique<ModelTypeConnectorProxy>( |
| 895 base::ThreadTaskRunnerHandle::Get(), model_type_registry_->AsWeakPtr()); | 895 base::ThreadTaskRunnerHandle::Get(), model_type_registry_->AsWeakPtr()); |
| 896 } | 896 } |
| 897 | 897 |
| 898 const std::string SyncManagerImpl::cache_guid() { | 898 const std::string SyncManagerImpl::cache_guid() { |
| 899 DCHECK(initialized_); | 899 DCHECK(initialized_); |
| 900 return directory()->cache_guid(); | 900 return directory()->cache_guid(); |
| 901 } | 901 } |
| 902 | 902 |
| 903 bool SyncManagerImpl::ReceivedExperiment(Experiments* experiments) { | 903 bool SyncManagerImpl::ReceivedExperiment(Experiments* experiments) { |
| 904 ReadTransaction trans(FROM_HERE, GetUserShare()); | 904 ReadTransaction trans(FROM_HERE, GetUserShare()); |
| 905 ReadNode nigori_node(&trans); | 905 ReadNode nigori_node(&trans); |
| 906 if (nigori_node.InitTypeRoot(NIGORI) != BaseNode::INIT_OK) { | 906 if (nigori_node.InitTypeRoot(NIGORI) != BaseNode::INIT_OK) { |
| 907 DVLOG(1) << "Couldn't find Nigori node."; | 907 DVLOG(1) << "Couldn't find Nigori node."; |
| 908 return false; | 908 return false; |
| 909 } | 909 } |
| 910 bool found_experiment = false; | 910 bool found_experiment = false; |
| 911 | 911 |
| 912 ReadNode favicon_sync_node(&trans); | 912 ReadNode favicon_sync_node(&trans); |
| 913 if (favicon_sync_node.InitByClientTagLookup( | 913 if (favicon_sync_node.InitByClientTagLookup(EXPERIMENTS, kFaviconSyncTag) == |
| 914 syncer::EXPERIMENTS, syncer::kFaviconSyncTag) == BaseNode::INIT_OK) { | 914 BaseNode::INIT_OK) { |
| 915 experiments->favicon_sync_limit = | 915 experiments->favicon_sync_limit = |
| 916 favicon_sync_node.GetExperimentsSpecifics() | 916 favicon_sync_node.GetExperimentsSpecifics() |
| 917 .favicon_sync() | 917 .favicon_sync() |
| 918 .favicon_sync_limit(); | 918 .favicon_sync_limit(); |
| 919 found_experiment = true; | 919 found_experiment = true; |
| 920 } | 920 } |
| 921 | 921 |
| 922 ReadNode pre_commit_update_avoidance_node(&trans); | 922 ReadNode pre_commit_update_avoidance_node(&trans); |
| 923 if (pre_commit_update_avoidance_node.InitByClientTagLookup( | 923 if (pre_commit_update_avoidance_node.InitByClientTagLookup( |
| 924 syncer::EXPERIMENTS, syncer::kPreCommitUpdateAvoidanceTag) == | 924 EXPERIMENTS, kPreCommitUpdateAvoidanceTag) == BaseNode::INIT_OK) { |
| 925 BaseNode::INIT_OK) { | |
| 926 cycle_context_->set_server_enabled_pre_commit_update_avoidance( | 925 cycle_context_->set_server_enabled_pre_commit_update_avoidance( |
| 927 pre_commit_update_avoidance_node.GetExperimentsSpecifics() | 926 pre_commit_update_avoidance_node.GetExperimentsSpecifics() |
| 928 .pre_commit_update_avoidance() | 927 .pre_commit_update_avoidance() |
| 929 .enabled()); | 928 .enabled()); |
| 930 // We don't bother setting found_experiment. The frontend doesn't need to | 929 // We don't bother setting found_experiment. The frontend doesn't need to |
| 931 // know about this. | 930 // know about this. |
| 932 } | 931 } |
| 933 | 932 |
| 934 ReadNode gcm_invalidations_node(&trans); | 933 ReadNode gcm_invalidations_node(&trans); |
| 935 if (gcm_invalidations_node.InitByClientTagLookup( | 934 if (gcm_invalidations_node.InitByClientTagLookup( |
| 936 syncer::EXPERIMENTS, syncer::kGCMInvalidationsTag) == | 935 EXPERIMENTS, kGCMInvalidationsTag) == BaseNode::INIT_OK) { |
| 937 BaseNode::INIT_OK) { | |
| 938 const sync_pb::GcmInvalidationsFlags& gcm_invalidations = | 936 const sync_pb::GcmInvalidationsFlags& gcm_invalidations = |
| 939 gcm_invalidations_node.GetExperimentsSpecifics().gcm_invalidations(); | 937 gcm_invalidations_node.GetExperimentsSpecifics().gcm_invalidations(); |
| 940 if (gcm_invalidations.has_enabled()) { | 938 if (gcm_invalidations.has_enabled()) { |
| 941 experiments->gcm_invalidations_enabled = gcm_invalidations.enabled(); | 939 experiments->gcm_invalidations_enabled = gcm_invalidations.enabled(); |
| 942 found_experiment = true; | 940 found_experiment = true; |
| 943 } | 941 } |
| 944 } | 942 } |
| 945 | 943 |
| 946 return found_experiment; | 944 return found_experiment; |
| 947 } | 945 } |
| 948 | 946 |
| 949 bool SyncManagerImpl::HasUnsyncedItems() { | 947 bool SyncManagerImpl::HasUnsyncedItems() { |
| 950 ReadTransaction trans(FROM_HERE, GetUserShare()); | 948 ReadTransaction trans(FROM_HERE, GetUserShare()); |
| 951 return (trans.GetWrappedTrans()->directory()->unsynced_entity_count() != 0); | 949 return (trans.GetWrappedTrans()->directory()->unsynced_entity_count() != 0); |
| 952 } | 950 } |
| 953 | 951 |
| 954 SyncEncryptionHandler* SyncManagerImpl::GetEncryptionHandler() { | 952 SyncEncryptionHandler* SyncManagerImpl::GetEncryptionHandler() { |
| 955 return sync_encryption_handler_.get(); | 953 return sync_encryption_handler_.get(); |
| 956 } | 954 } |
| 957 | 955 |
| 958 std::vector<std::unique_ptr<ProtocolEvent>> | 956 std::vector<std::unique_ptr<ProtocolEvent>> |
| 959 SyncManagerImpl::GetBufferedProtocolEvents() { | 957 SyncManagerImpl::GetBufferedProtocolEvents() { |
| 960 return protocol_event_buffer_.GetBufferedProtocolEvents(); | 958 return protocol_event_buffer_.GetBufferedProtocolEvents(); |
| 961 } | 959 } |
| 962 | 960 |
| 963 void SyncManagerImpl::RegisterDirectoryTypeDebugInfoObserver( | 961 void SyncManagerImpl::RegisterDirectoryTypeDebugInfoObserver( |
| 964 syncer::TypeDebugInfoObserver* observer) { | 962 TypeDebugInfoObserver* observer) { |
| 965 model_type_registry_->RegisterDirectoryTypeDebugInfoObserver(observer); | 963 model_type_registry_->RegisterDirectoryTypeDebugInfoObserver(observer); |
| 966 } | 964 } |
| 967 | 965 |
| 968 void SyncManagerImpl::UnregisterDirectoryTypeDebugInfoObserver( | 966 void SyncManagerImpl::UnregisterDirectoryTypeDebugInfoObserver( |
| 969 syncer::TypeDebugInfoObserver* observer) { | 967 TypeDebugInfoObserver* observer) { |
| 970 model_type_registry_->UnregisterDirectoryTypeDebugInfoObserver(observer); | 968 model_type_registry_->UnregisterDirectoryTypeDebugInfoObserver(observer); |
| 971 } | 969 } |
| 972 | 970 |
| 973 bool SyncManagerImpl::HasDirectoryTypeDebugInfoObserver( | 971 bool SyncManagerImpl::HasDirectoryTypeDebugInfoObserver( |
| 974 syncer::TypeDebugInfoObserver* observer) { | 972 TypeDebugInfoObserver* observer) { |
| 975 return model_type_registry_->HasDirectoryTypeDebugInfoObserver(observer); | 973 return model_type_registry_->HasDirectoryTypeDebugInfoObserver(observer); |
| 976 } | 974 } |
| 977 | 975 |
| 978 void SyncManagerImpl::RequestEmitDebugInfo() { | 976 void SyncManagerImpl::RequestEmitDebugInfo() { |
| 979 model_type_registry_->RequestEmitDebugInfo(); | 977 model_type_registry_->RequestEmitDebugInfo(); |
| 980 } | 978 } |
| 981 | 979 |
| 982 void SyncManagerImpl::ClearServerData(const ClearServerDataCallback& callback) { | 980 void SyncManagerImpl::ClearServerData(const ClearServerDataCallback& callback) { |
| 983 DCHECK(thread_checker_.CalledOnValidThread()); | 981 DCHECK(thread_checker_.CalledOnValidThread()); |
| 984 scheduler_->Start(SyncScheduler::CLEAR_SERVER_DATA_MODE, base::Time()); | 982 scheduler_->Start(SyncScheduler::CLEAR_SERVER_DATA_MODE, base::Time()); |
| 985 ClearParams params(callback); | 983 ClearParams params(callback); |
| 986 scheduler_->ScheduleClearServerData(params); | 984 scheduler_->ScheduleClearServerData(params); |
| 987 } | 985 } |
| 988 | 986 |
| 989 void SyncManagerImpl::OnCookieJarChanged(bool account_mismatch, | 987 void SyncManagerImpl::OnCookieJarChanged(bool account_mismatch, |
| 990 bool empty_jar) { | 988 bool empty_jar) { |
| 991 DCHECK(thread_checker_.CalledOnValidThread()); | 989 DCHECK(thread_checker_.CalledOnValidThread()); |
| 992 cycle_context_->set_cookie_jar_mismatch(account_mismatch); | 990 cycle_context_->set_cookie_jar_mismatch(account_mismatch); |
| 993 cycle_context_->set_cookie_jar_empty(empty_jar); | 991 cycle_context_->set_cookie_jar_empty(empty_jar); |
| 994 } | 992 } |
| 995 | 993 |
| 996 } // namespace syncer | 994 } // namespace syncer |
| OLD | NEW |