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

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

Issue 17552014: [Sync] Have SBH tell SyncManager which types to purge (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Self review Created 7 years, 6 months 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) 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 "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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 using syncer::SyncCredentials; 78 using syncer::SyncCredentials;
79 79
80 namespace { 80 namespace {
81 81
82 // Helper struct to handle currying params to 82 // Helper struct to handle currying params to
83 // SyncBackendHost::Core::DoConfigureSyncer. 83 // SyncBackendHost::Core::DoConfigureSyncer.
84 struct DoConfigureSyncerTypes { 84 struct DoConfigureSyncerTypes {
85 DoConfigureSyncerTypes() {} 85 DoConfigureSyncerTypes() {}
86 ~DoConfigureSyncerTypes() {} 86 ~DoConfigureSyncerTypes() {}
87 syncer::ModelTypeSet to_download; 87 syncer::ModelTypeSet to_download;
88 syncer::ModelTypeSet to_purge;
88 syncer::ModelTypeSet to_journal; 89 syncer::ModelTypeSet to_journal;
89 syncer::ModelTypeSet to_unapply; 90 syncer::ModelTypeSet to_unapply;
90 syncer::ModelTypeSet to_ignore;
91 }; 91 };
92 92
93 } // namespace 93 } // namespace
94 94
95 // Helper macros to log with the syncer thread name; useful when there 95 // Helper macros to log with the syncer thread name; useful when there
96 // are multiple syncers involved. 96 // are multiple syncers involved.
97 97
98 #define SLOG(severity) LOG(severity) << name_ << ": " 98 #define SLOG(severity) LOG(severity) << name_ << ": "
99 99
100 #define SDVLOG(verbose_level) DVLOG(verbose_level) << name_ << ": " 100 #define SDVLOG(verbose_level) DVLOG(verbose_level) << name_ << ": "
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after
710 // must ask the syncer to download them. Any newly supported datatypes will 710 // must ask the syncer to download them. Any newly supported datatypes will
711 // not have been in that routing info list, so they will be among the types 711 // not have been in that routing info list, so they will be among the types
712 // downloaded if they are enabled. 712 // downloaded if they are enabled.
713 // 713 //
714 // The SyncBackendRegistrar's state was initially derived from the types 714 // The SyncBackendRegistrar's state was initially derived from the types
715 // detected to have been downloaded in the database. Afterwards it is 715 // detected to have been downloaded in the database. Afterwards it is
716 // modified only by this function. We expect it to remain in sync with the 716 // modified only by this function. We expect it to remain in sync with the
717 // backend because configuration requests are never aborted; they are retried 717 // backend because configuration requests are never aborted; they are retried
718 // until they succeed or the backend is shut down. 718 // until they succeed or the backend is shut down.
719 719
720 syncer::ModelTypeSet previous_types = registrar_->GetLastConfiguredTypes();
721
720 syncer::ModelTypeSet disabled_types = 722 syncer::ModelTypeSet disabled_types =
721 GetDataTypesInState(DISABLED, config_state_map); 723 GetDataTypesInState(DISABLED, config_state_map);
722 syncer::ModelTypeSet fatal_types = 724 syncer::ModelTypeSet fatal_types =
723 GetDataTypesInState(FATAL, config_state_map); 725 GetDataTypesInState(FATAL, config_state_map);
724 syncer::ModelTypeSet crypto_types = 726 syncer::ModelTypeSet crypto_types =
725 GetDataTypesInState(CRYPTO, config_state_map); 727 GetDataTypesInState(CRYPTO, config_state_map);
726 disabled_types.PutAll(fatal_types); 728 disabled_types.PutAll(fatal_types);
727 disabled_types.PutAll(crypto_types); 729 disabled_types.PutAll(crypto_types);
728 syncer::ModelTypeSet types_to_download = registrar_->ConfigureDataTypes( 730 syncer::ModelTypeSet types_to_download = registrar_->ConfigureDataTypes(
729 GetDataTypesInState(CONFIGURE_ACTIVE, config_state_map), 731 GetDataTypesInState(CONFIGURE_ACTIVE, config_state_map),
730 disabled_types); 732 disabled_types);
731 syncer::ModelTypeSet inactive_types =
732 GetDataTypesInState(CONFIGURE_INACTIVE, config_state_map);
733 types_to_download.RemoveAll(syncer::ProxyTypes()); 733 types_to_download.RemoveAll(syncer::ProxyTypes());
734 if (!types_to_download.Empty()) 734 if (!types_to_download.Empty())
735 types_to_download.Put(syncer::NIGORI); 735 types_to_download.Put(syncer::NIGORI);
736 736
737 // TODO(sync): crbug.com/137550. 737 // TODO(sync): crbug.com/137550.
738 // It's dangerous to configure types that have progress markers. Types with 738 // It's dangerous to configure types that have progress markers. Types with
739 // progress markers can trigger a MIGRATION_DONE response. We are not 739 // progress markers can trigger a MIGRATION_DONE response. We are not
740 // prepared to handle a migration during a configure, so we must ensure that 740 // prepared to handle a migration during a configure, so we must ensure that
741 // all our types_to_download actually contain no data before we sync them. 741 // all our types_to_download actually contain no data before we sync them.
742 // 742 //
743 // One common way to end up in this situation used to be types which 743 // One common way to end up in this situation used to be types which
744 // downloaded some or all of their data but have not applied it yet. We avoid 744 // downloaded some or all of their data but have not applied it yet. We avoid
745 // problems with those types by purging the data of any such partially synced 745 // problems with those types by purging the data of any such partially synced
746 // types soon after we load the directory. 746 // types soon after we load the directory.
747 // 747 //
748 // Another possible scenario is that we have newly supported or newly enabled 748 // Another possible scenario is that we have newly supported or newly enabled
749 // data types being downloaded here but the nigori type, which is always 749 // data types being downloaded here but the nigori type, which is always
750 // included in any GetUpdates request, requires migration. The server has 750 // included in any GetUpdates request, requires migration. The server has
751 // code to detect this scenario based on the configure reason, the fact that 751 // code to detect this scenario based on the configure reason, the fact that
752 // the nigori type is the only requested type which requires migration, and 752 // the nigori type is the only requested type which requires migration, and
753 // that the requested types list includes at least one non-nigori type. It 753 // that the requested types list includes at least one non-nigori type. It
754 // will not send a MIGRATION_DONE response in that case. We still need to be 754 // will not send a MIGRATION_DONE response in that case. We still need to be
755 // careful to not send progress markers for non-nigori types, though. If a 755 // careful to not send progress markers for non-nigori types, though. If a
756 // non-nigori type in the request requires migration, a MIGRATION_DONE 756 // non-nigori type in the request requires migration, a MIGRATION_DONE
757 // response will be sent. 757 // response will be sent.
758 758
759 syncer::ModelSafeRoutingInfo routing_info; 759 syncer::ModelSafeRoutingInfo routing_info;
760 registrar_->GetModelSafeRoutingInfo(&routing_info); 760 registrar_->GetModelSafeRoutingInfo(&routing_info);
761 761
762 syncer::ModelTypeSet current_types = registrar_->GetLastConfiguredTypes();
763 syncer::ModelTypeSet types_to_purge =
764 syncer::Difference(previous_types, current_types);
765 syncer::ModelTypeSet inactive_types =
766 GetDataTypesInState(CONFIGURE_INACTIVE, config_state_map);
767 types_to_purge.RemoveAll(inactive_types);
768 DCHECK(types_to_purge.HasAll(fatal_types));
769 DCHECK(types_to_purge.HasAll(crypto_types));
770
762 SDVLOG(1) << "Types " 771 SDVLOG(1) << "Types "
763 << syncer::ModelTypeSetToString(types_to_download) 772 << syncer::ModelTypeSetToString(types_to_download)
764 << " added; calling DoConfigureSyncer"; 773 << " added; calling DoConfigureSyncer";
765 // Divide up the types into their corresponding actions (each is mutually 774 // Divide up the types into their corresponding actions (each is mutually
766 // exclusive): 775 // exclusive):
767 // - Types which have just been added to the routing info (types_to_download): 776 // - Types which have just been added to the routing info (types_to_download):
768 // are downloaded. 777 // are downloaded.
769 // - Types which have encountered a fatal error (fatal_types) are deleted 778 // - Types which have encountered a fatal error (fatal_types) are deleted
770 // from the directory and journaled in the delete journal. 779 // from the directory and journaled in the delete journal.
771 // - Types which have encountered a cryptographer error (crypto_types) are 780 // - Types which have encountered a cryptographer error (crypto_types) are
772 // unapplied (local state is purged but sync state is not). 781 // unapplied (local state is purged but sync state is not).
773 // - All other types not in the routing info (types just disabled) are deleted 782 // - All other types not in the routing info (types just disabled) are deleted
774 // from the directory. 783 // from the directory.
775 // - Everything else (enabled types and already disabled types) is not 784 // - Everything else (enabled types and already disabled types) is not
776 // touched. 785 // touched.
777 RequestConfigureSyncer(reason, 786 RequestConfigureSyncer(reason,
778 types_to_download, 787 types_to_download,
788 types_to_purge,
779 fatal_types, 789 fatal_types,
780 crypto_types, 790 crypto_types,
781 inactive_types, 791 inactive_types,
782 routing_info, 792 routing_info,
783 ready_task, 793 ready_task,
784 retry_callback); 794 retry_callback);
785 } 795 }
786 796
787 void SyncBackendHost::EnableEncryptEverything() { 797 void SyncBackendHost::EnableEncryptEverything() {
788 sync_thread_.message_loop()->PostTask(FROM_HERE, 798 sync_thread_.message_loop()->PostTask(FROM_HERE,
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
852 } 862 }
853 863
854 void SyncBackendHost::InitCore(const DoInitializeOptions& options) { 864 void SyncBackendHost::InitCore(const DoInitializeOptions& options) {
855 sync_thread_.message_loop()->PostTask(FROM_HERE, 865 sync_thread_.message_loop()->PostTask(FROM_HERE,
856 base::Bind(&SyncBackendHost::Core::DoInitialize, core_.get(), options)); 866 base::Bind(&SyncBackendHost::Core::DoInitialize, core_.get(), options));
857 } 867 }
858 868
859 void SyncBackendHost::RequestConfigureSyncer( 869 void SyncBackendHost::RequestConfigureSyncer(
860 syncer::ConfigureReason reason, 870 syncer::ConfigureReason reason,
861 syncer::ModelTypeSet to_download, 871 syncer::ModelTypeSet to_download,
872 syncer::ModelTypeSet to_purge,
862 syncer::ModelTypeSet to_journal, 873 syncer::ModelTypeSet to_journal,
863 syncer::ModelTypeSet to_unapply, 874 syncer::ModelTypeSet to_unapply,
864 syncer::ModelTypeSet to_ignore, 875 syncer::ModelTypeSet to_ignore,
865 const syncer::ModelSafeRoutingInfo& routing_info, 876 const syncer::ModelSafeRoutingInfo& routing_info,
866 const base::Callback<void(syncer::ModelTypeSet, 877 const base::Callback<void(syncer::ModelTypeSet,
867 syncer::ModelTypeSet)>& ready_task, 878 syncer::ModelTypeSet)>& ready_task,
868 const base::Closure& retry_callback) { 879 const base::Closure& retry_callback) {
869 DoConfigureSyncerTypes config_types; 880 DoConfigureSyncerTypes config_types;
870 config_types.to_download = to_download; 881 config_types.to_download = to_download;
882 config_types.to_purge = to_purge;
871 config_types.to_journal = to_journal; 883 config_types.to_journal = to_journal;
872 config_types.to_unapply = to_unapply; 884 config_types.to_unapply = to_unapply;
873 config_types.to_ignore = to_ignore;
874 sync_thread_.message_loop()->PostTask(FROM_HERE, 885 sync_thread_.message_loop()->PostTask(FROM_HERE,
875 base::Bind(&SyncBackendHost::Core::DoConfigureSyncer, 886 base::Bind(&SyncBackendHost::Core::DoConfigureSyncer,
876 core_.get(), 887 core_.get(),
877 reason, 888 reason,
878 config_types, 889 config_types,
879 routing_info, 890 routing_info,
880 ready_task, 891 ready_task,
881 retry_callback)); 892 retry_callback));
882 } 893 }
883 894
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
1021 void SyncBackendHost::Core::DoDownloadControlTypes( 1032 void SyncBackendHost::Core::DoDownloadControlTypes(
1022 syncer::ConfigureReason reason) { 1033 syncer::ConfigureReason reason) {
1023 syncer::ModelTypeSet new_control_types = registrar_->ConfigureDataTypes( 1034 syncer::ModelTypeSet new_control_types = registrar_->ConfigureDataTypes(
1024 syncer::ControlTypes(), syncer::ModelTypeSet()); 1035 syncer::ControlTypes(), syncer::ModelTypeSet());
1025 syncer::ModelSafeRoutingInfo routing_info; 1036 syncer::ModelSafeRoutingInfo routing_info;
1026 registrar_->GetModelSafeRoutingInfo(&routing_info); 1037 registrar_->GetModelSafeRoutingInfo(&routing_info);
1027 SDVLOG(1) << "Control Types " 1038 SDVLOG(1) << "Control Types "
1028 << syncer::ModelTypeSetToString(new_control_types) 1039 << syncer::ModelTypeSetToString(new_control_types)
1029 << " added; calling ConfigureSyncer"; 1040 << " added; calling ConfigureSyncer";
1030 1041
1042 syncer::ModelTypeSet types_to_purge =
1043 syncer::Difference(syncer::ModelTypeSet::All(),
1044 GetRoutingInfoTypes(routing_info));
1045
1031 sync_manager_->ConfigureSyncer( 1046 sync_manager_->ConfigureSyncer(
1032 reason, 1047 reason,
1033 new_control_types, 1048 new_control_types,
1034 syncer::ModelTypeSet(), 1049 types_to_purge,
1035 syncer::ModelTypeSet(), 1050 syncer::ModelTypeSet(),
1036 syncer::ModelTypeSet(), 1051 syncer::ModelTypeSet(),
1037 routing_info, 1052 routing_info,
1038 base::Bind(&SyncBackendHost::Core::DoInitialProcessControlTypes, 1053 base::Bind(&SyncBackendHost::Core::DoInitialProcessControlTypes,
1039 this), 1054 this),
1040 base::Bind(&SyncBackendHost::Core::OnControlTypesDownloadRetry, 1055 base::Bind(&SyncBackendHost::Core::OnControlTypesDownloadRetry,
1041 this)); 1056 this));
1042 } 1057 }
1043 1058
1044 void SyncBackendHost::Core::DoRefreshTypes(syncer::ModelTypeSet types) { 1059 void SyncBackendHost::Core::DoRefreshTypes(syncer::ModelTypeSet types) {
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
1444 syncer::ConfigureReason reason, 1459 syncer::ConfigureReason reason,
1445 const DoConfigureSyncerTypes& config_types, 1460 const DoConfigureSyncerTypes& config_types,
1446 const syncer::ModelSafeRoutingInfo routing_info, 1461 const syncer::ModelSafeRoutingInfo routing_info,
1447 const base::Callback<void(syncer::ModelTypeSet, 1462 const base::Callback<void(syncer::ModelTypeSet,
1448 syncer::ModelTypeSet)>& ready_task, 1463 syncer::ModelTypeSet)>& ready_task,
1449 const base::Closure& retry_callback) { 1464 const base::Closure& retry_callback) {
1450 DCHECK_EQ(base::MessageLoop::current(), sync_loop_); 1465 DCHECK_EQ(base::MessageLoop::current(), sync_loop_);
1451 sync_manager_->ConfigureSyncer( 1466 sync_manager_->ConfigureSyncer(
1452 reason, 1467 reason,
1453 config_types.to_download, 1468 config_types.to_download,
1469 config_types.to_purge,
1454 config_types.to_journal, 1470 config_types.to_journal,
1455 config_types.to_unapply, 1471 config_types.to_unapply,
1456 config_types.to_ignore,
1457 routing_info, 1472 routing_info,
1458 base::Bind(&SyncBackendHost::Core::DoFinishConfigureDataTypes, 1473 base::Bind(&SyncBackendHost::Core::DoFinishConfigureDataTypes,
1459 this, 1474 this,
1460 config_types.to_download, 1475 config_types.to_download,
1461 ready_task), 1476 ready_task),
1462 base::Bind(&SyncBackendHost::Core::DoRetryConfiguration, 1477 base::Bind(&SyncBackendHost::Core::DoRetryConfiguration,
1463 this, 1478 this,
1464 retry_callback)); 1479 retry_callback));
1465 } 1480 }
1466 1481
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
1720 DVLOG(1) << "Connection status changed: " 1735 DVLOG(1) << "Connection status changed: "
1721 << syncer::ConnectionStatusToString(status); 1736 << syncer::ConnectionStatusToString(status);
1722 frontend_->OnConnectionStatusChange(status); 1737 frontend_->OnConnectionStatusChange(status);
1723 } 1738 }
1724 1739
1725 #undef SDVLOG 1740 #undef SDVLOG
1726 1741
1727 #undef SLOG 1742 #undef SLOG
1728 1743
1729 } // namespace browser_sync 1744 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698