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

Side by Side Diff: chrome/browser/sync/glue/sync_backend_host.cc

Issue 8786014: [Sync] Convert sessions/ directory to ModelEnumSet (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync to head Created 9 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #include "chrome/browser/sync/glue/sync_backend_host.h" 7 #include "chrome/browser/sync/glue/sync_backend_host.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <map> 10 #include <map>
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 243
244 registrar_.reset(); 244 registrar_.reset();
245 frontend_ = NULL; 245 frontend_ = NULL;
246 core_ = NULL; // Releases reference to core_. 246 core_ = NULL; // Releases reference to core_.
247 } 247 }
248 248
249 void SyncBackendHost::ConfigureDataTypes( 249 void SyncBackendHost::ConfigureDataTypes(
250 const syncable::ModelTypeSet& types_to_add, 250 const syncable::ModelTypeSet& types_to_add,
251 const syncable::ModelTypeSet& types_to_remove, 251 const syncable::ModelTypeSet& types_to_remove,
252 sync_api::ConfigureReason reason, 252 sync_api::ConfigureReason reason,
253 base::Callback<void(const syncable::ModelTypeSet&)> ready_task, 253 base::Callback<void(syncable::ModelEnumSet)> ready_task,
254 bool enable_nigori) { 254 bool enable_nigori) {
255 syncable::ModelTypeSet types_to_add_with_nigori = types_to_add; 255 syncable::ModelTypeSet types_to_add_with_nigori = types_to_add;
256 syncable::ModelTypeSet types_to_remove_with_nigori = types_to_remove; 256 syncable::ModelTypeSet types_to_remove_with_nigori = types_to_remove;
257 if (enable_nigori) { 257 if (enable_nigori) {
258 types_to_add_with_nigori.insert(syncable::NIGORI); 258 types_to_add_with_nigori.insert(syncable::NIGORI);
259 types_to_remove_with_nigori.erase(syncable::NIGORI); 259 types_to_remove_with_nigori.erase(syncable::NIGORI);
260 } else { 260 } else {
261 types_to_add_with_nigori.erase(syncable::NIGORI); 261 types_to_add_with_nigori.erase(syncable::NIGORI);
262 types_to_remove_with_nigori.insert(syncable::NIGORI); 262 types_to_remove_with_nigori.insert(syncable::NIGORI);
263 } 263 }
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 void SyncBackendHost::Core::HandleInitializationCompletedOnFrontendLoop( 713 void SyncBackendHost::Core::HandleInitializationCompletedOnFrontendLoop(
714 const WeakHandle<JsBackend>& js_backend, 714 const WeakHandle<JsBackend>& js_backend,
715 bool success) { 715 bool success) {
716 if (!host_) 716 if (!host_)
717 return; 717 return;
718 host_->HandleInitializationCompletedOnFrontendLoop(js_backend, success); 718 host_->HandleInitializationCompletedOnFrontendLoop(js_backend, success);
719 } 719 }
720 720
721 void SyncBackendHost::Core::HandleNigoriConfigurationCompletedOnFrontendLoop( 721 void SyncBackendHost::Core::HandleNigoriConfigurationCompletedOnFrontendLoop(
722 const WeakHandle<JsBackend>& js_backend, 722 const WeakHandle<JsBackend>& js_backend,
723 const syncable::ModelTypeSet& failed_configuration_types) { 723 const syncable::ModelEnumSet failed_configuration_types) {
724 if (!host_) 724 if (!host_)
725 return; 725 return;
726 host_->HandleInitializationCompletedOnFrontendLoop( 726 host_->HandleInitializationCompletedOnFrontendLoop(
727 js_backend, failed_configuration_types.empty()); 727 js_backend, failed_configuration_types.Empty());
728 } 728 }
729 729
730 void SyncBackendHost::Core::StartSavingChanges() { 730 void SyncBackendHost::Core::StartSavingChanges() {
731 // We may already be shut down. 731 // We may already be shut down.
732 if (!sync_loop_) 732 if (!sync_loop_)
733 return; 733 return;
734 DCHECK_EQ(MessageLoop::current(), sync_loop_); 734 DCHECK_EQ(MessageLoop::current(), sync_loop_);
735 save_changes_timer_.Start(FROM_HERE, 735 save_changes_timer_.Start(FROM_HERE,
736 base::TimeDelta::FromSeconds(kSaveChangesIntervalSeconds), 736 base::TimeDelta::FromSeconds(kSaveChangesIntervalSeconds),
737 this, &Core::SaveChanges); 737 this, &Core::SaveChanges);
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
813 void SyncBackendHost::Core::HandleSyncCycleCompletedOnFrontendLoop( 813 void SyncBackendHost::Core::HandleSyncCycleCompletedOnFrontendLoop(
814 SyncSessionSnapshot* snapshot) { 814 SyncSessionSnapshot* snapshot) {
815 if (!host_ || !host_->frontend_) 815 if (!host_ || !host_->frontend_)
816 return; 816 return;
817 DCHECK_EQ(MessageLoop::current(), host_->frontend_loop_); 817 DCHECK_EQ(MessageLoop::current(), host_->frontend_loop_);
818 818
819 host_->last_snapshot_.reset(snapshot); 819 host_->last_snapshot_.reset(snapshot);
820 820
821 SVLOG(1) << "Got snapshot " << snapshot->ToString(); 821 SVLOG(1) << "Got snapshot " << snapshot->ToString();
822 822
823 const syncable::ModelTypeSet& to_migrate = 823 const syncable::ModelEnumSet to_migrate =
824 snapshot->syncer_status.types_needing_local_migration; 824 snapshot->syncer_status.types_needing_local_migration;
825 if (!to_migrate.empty()) 825 if (!to_migrate.Empty())
826 host_->frontend_->OnMigrationNeededForTypes(to_migrate); 826 host_->frontend_->OnMigrationNeededForTypes(
827 syncable::ModelEnumSetToSet(to_migrate));
827 828
828 // Process any changes to the datatypes we're syncing. 829 // Process any changes to the datatypes we're syncing.
829 // TODO(sync): add support for removing types. 830 // TODO(sync): add support for removing types.
830 if (host_->initialized()) 831 if (host_->initialized())
831 host_->AddExperimentalTypes(); 832 host_->AddExperimentalTypes();
832 833
833 // If we are waiting for a configuration change, check here to see 834 // If we are waiting for a configuration change, check here to see
834 // if this sync cycle has initialized all of the types we've been 835 // if this sync cycle has initialized all of the types we've been
835 // waiting for. 836 // waiting for.
836 if (host_->pending_download_state_.get()) { 837 if (host_->pending_download_state_.get()) {
837 scoped_ptr<PendingConfigureDataTypesState> state( 838 scoped_ptr<PendingConfigureDataTypesState> state(
838 host_->pending_download_state_.release()); 839 host_->pending_download_state_.release());
839 DCHECK( 840 const syncable::ModelEnumSet types_to_add =
840 std::includes(state->types_to_add.begin(), state->types_to_add.end(), 841 syncable::ModelTypeSetToEnumSet(state->types_to_add);
841 state->added_types.begin(), state->added_types.end())); 842 const syncable::ModelEnumSet added_types =
842 syncable::ModelTypeSet initial_sync_ended = 843 syncable::ModelTypeSetToEnumSet(state->added_types);
843 syncable::ModelTypeBitSetToSet(snapshot->initial_sync_ended); 844 DCHECK(types_to_add.HasAll(added_types));
844 syncable::ModelTypeSet failed_configuration_types; 845 const syncable::ModelEnumSet initial_sync_ended =
845 std::set_difference( 846 snapshot->initial_sync_ended;
846 state->added_types.begin(), state->added_types.end(), 847 const syncable::ModelEnumSet failed_configuration_types =
847 initial_sync_ended.begin(), initial_sync_ended.end(), 848 Difference(added_types, initial_sync_ended);
848 std::inserter(failed_configuration_types,
849 failed_configuration_types.end()));
850 SVLOG(1) 849 SVLOG(1)
851 << "Added types: " 850 << "Added types: "
852 << syncable::ModelTypeSetToString(state->added_types) 851 << syncable::ModelEnumSetToString(added_types)
853 << ", configured types: " 852 << ", configured types: "
854 << syncable::ModelTypeSetToString(initial_sync_ended) 853 << syncable::ModelEnumSetToString(initial_sync_ended)
855 << ", failed configuration types: " 854 << ", failed configuration types: "
856 << syncable::ModelTypeSetToString(failed_configuration_types); 855 << syncable::ModelEnumSetToString(failed_configuration_types);
857 state->ready_task.Run(failed_configuration_types); 856 state->ready_task.Run(failed_configuration_types);
858 if (!failed_configuration_types.empty()) 857 if (!failed_configuration_types.Empty())
859 return; 858 return;
860 } 859 }
861 860
862 if (host_->initialized()) 861 if (host_->initialized())
863 host_->frontend_->OnSyncCycleCompleted(); 862 host_->frontend_->OnSyncCycleCompleted();
864 } 863 }
865 864
866 void SyncBackendHost::Core::HandleStopSyncingPermanentlyOnFrontendLoop() { 865 void SyncBackendHost::Core::HandleStopSyncingPermanentlyOnFrontendLoop() {
867 if (!host_ || !host_->frontend_) 866 if (!host_ || !host_->frontend_)
868 return; 867 return;
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
999 pending_config_mode_state_->added_types = 998 pending_config_mode_state_->added_types =
1000 sync_api::GetTypesWithEmptyProgressMarkerToken(enabled_types, 999 sync_api::GetTypesWithEmptyProgressMarkerToken(enabled_types,
1001 GetUserShare()); 1000 GetUserShare());
1002 } 1001 }
1003 1002
1004 // If we've added types, we always want to request a nudge/config (even if 1003 // If we've added types, we always want to request a nudge/config (even if
1005 // the initial sync is ended), in case we could not decrypt the data. 1004 // the initial sync is ended), in case we could not decrypt the data.
1006 if (pending_config_mode_state_->added_types.empty()) { 1005 if (pending_config_mode_state_->added_types.empty()) {
1007 SVLOG(1) << "No new types added; calling ready_task directly"; 1006 SVLOG(1) << "No new types added; calling ready_task directly";
1008 // No new types - just notify the caller that the types are available. 1007 // No new types - just notify the caller that the types are available.
1009 const syncable::ModelTypeSet failed_configuration_types; 1008 const syncable::ModelEnumSet failed_configuration_types;
1010 pending_config_mode_state_->ready_task.Run(failed_configuration_types); 1009 pending_config_mode_state_->ready_task.Run(failed_configuration_types);
1011 } else { 1010 } else {
1012 pending_download_state_.reset(pending_config_mode_state_.release()); 1011 pending_download_state_.reset(pending_config_mode_state_.release());
1013 1012
1014 // Always configure nigori if it's enabled. 1013 // Always configure nigori if it's enabled.
1015 syncable::ModelTypeSet types_to_config = 1014 syncable::ModelTypeSet types_to_config =
1016 pending_download_state_->added_types; 1015 pending_download_state_->added_types;
1017 if (IsNigoriEnabled()) { 1016 if (IsNigoriEnabled()) {
1018 // Note: Nigori is the only type that gets added with a nonempty 1017 // Note: Nigori is the only type that gets added with a nonempty
1019 // progress marker during config. If the server returns a migration 1018 // progress marker during config. If the server returns a migration
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1076 FROM_HERE, 1075 FROM_HERE,
1077 base::Bind(&SyncBackendHost::Core::DoRefreshEncryption, 1076 base::Bind(&SyncBackendHost::Core::DoRefreshEncryption,
1078 core_.get(), sync_thread_done_callback)); 1077 core_.get(), sync_thread_done_callback));
1079 } 1078 }
1080 1079
1081 #undef SVLOG 1080 #undef SVLOG
1082 1081
1083 #undef SLOG 1082 #undef SLOG
1084 1083
1085 } // namespace browser_sync 1084 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/sync_backend_host.h ('k') | chrome/browser/sync/glue/sync_backend_host_mock.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698