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

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

Issue 10817023: [Sync] Pass the correct set of enabled types to the sync notifier (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 // operations. 117 // operations.
118 // 118 //
119 // Called to perform initialization of the syncapi on behalf of 119 // Called to perform initialization of the syncapi on behalf of
120 // SyncBackendHost::Initialize. 120 // SyncBackendHost::Initialize.
121 void DoInitialize(const DoInitializeOptions& options); 121 void DoInitialize(const DoInitializeOptions& options);
122 122
123 // Called to perform credential update on behalf of 123 // Called to perform credential update on behalf of
124 // SyncBackendHost::UpdateCredentials 124 // SyncBackendHost::UpdateCredentials
125 void DoUpdateCredentials(const syncer::SyncCredentials& credentials); 125 void DoUpdateCredentials(const syncer::SyncCredentials& credentials);
126 126
127 // Called when the user disables or enables a sync type.
128 void DoUpdateEnabledTypes(const syncer::ModelTypeSet& enabled_types);
129
130 // Called to tell the syncapi to start syncing (generally after 127 // Called to tell the syncapi to start syncing (generally after
131 // initialization and authentication). 128 // initialization and authentication).
132 void DoStartSyncing(const syncer::ModelSafeRoutingInfo& routing_info); 129 void DoStartSyncing(const syncer::ModelSafeRoutingInfo& routing_info);
133 130
134 // Called to set the passphrase for encryption. 131 // Called to set the passphrase for encryption.
135 void DoSetEncryptionPassphrase(const std::string& passphrase, 132 void DoSetEncryptionPassphrase(const std::string& passphrase,
136 bool is_explicit); 133 bool is_explicit);
137 134
138 // Called to decrypt the pending keys. 135 // Called to decrypt the pending keys.
139 void DoSetDecryptionPassphrase(const std::string& passphrase); 136 void DoSetDecryptionPassphrase(const std::string& passphrase);
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 syncer::WeakHandle<SyncBackendHost> host_; 211 syncer::WeakHandle<SyncBackendHost> host_;
215 212
216 // The loop where all the sync backend operations happen. 213 // The loop where all the sync backend operations happen.
217 // Non-NULL only between calls to DoInitialize() and DoShutdown(). 214 // Non-NULL only between calls to DoInitialize() and DoShutdown().
218 MessageLoop* sync_loop_; 215 MessageLoop* sync_loop_;
219 216
220 // Our parent's registrar (not owned). Non-NULL only between 217 // Our parent's registrar (not owned). Non-NULL only between
221 // calls to DoInitialize() and DoShutdown(). 218 // calls to DoInitialize() and DoShutdown().
222 SyncBackendRegistrar* registrar_; 219 SyncBackendRegistrar* registrar_;
223 220
221 // Our parent's notification bridge (not owned). Non-NULL only
222 // between calls to DoInitialize() and DoShutdown().
223 ChromeSyncNotificationBridge* chrome_sync_notification_bridge_;
224
224 // The timer used to periodically call SaveChanges. 225 // The timer used to periodically call SaveChanges.
225 scoped_ptr<base::RepeatingTimer<Core> > save_changes_timer_; 226 scoped_ptr<base::RepeatingTimer<Core> > save_changes_timer_;
226 227
227 // Our encryptor, which uses Chrome's encryption functions. 228 // Our encryptor, which uses Chrome's encryption functions.
228 ChromeEncryptor encryptor_; 229 ChromeEncryptor encryptor_;
229 230
230 // The top-level syncapi entry point. Lives on the sync thread. 231 // The top-level syncapi entry point. Lives on the sync thread.
231 scoped_ptr<syncer::SyncManager> sync_manager_; 232 scoped_ptr<syncer::SyncManager> sync_manager_;
232 233
233 DISALLOW_COPY_AND_ASSIGN(Core); 234 DISALLOW_COPY_AND_ASSIGN(Core);
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 sync_notifier_factory_( 312 sync_notifier_factory_(
312 ParseNotifierOptions(*CommandLine::ForCurrentProcess(), 313 ParseNotifierOptions(*CommandLine::ForCurrentProcess(),
313 profile_->GetRequestContext()), 314 profile_->GetRequestContext()),
314 content::GetUserAgent(GURL()), 315 content::GetUserAgent(GURL()),
315 base::WeakPtr<syncer::InvalidationStateTracker>()), 316 base::WeakPtr<syncer::InvalidationStateTracker>()),
316 frontend_(NULL) { 317 frontend_(NULL) {
317 } 318 }
318 319
319 SyncBackendHost::~SyncBackendHost() { 320 SyncBackendHost::~SyncBackendHost() {
320 DCHECK(!core_ && !frontend_) << "Must call Shutdown before destructor."; 321 DCHECK(!core_ && !frontend_) << "Must call Shutdown before destructor.";
322 DCHECK(!chrome_sync_notification_bridge_.get());
321 DCHECK(!registrar_.get()); 323 DCHECK(!registrar_.get());
322 } 324 }
323 325
324 namespace { 326 namespace {
325 327
326 // Helper to construct a user agent string (ASCII) suitable for use by 328 // Helper to construct a user agent string (ASCII) suitable for use by
327 // the syncapi for any HTTP communication. This string is used by the sync 329 // the syncapi for any HTTP communication. This string is used by the sync
328 // backend for classifying client types when calculating statistics. 330 // backend for classifying client types when calculating statistics.
329 std::string MakeUserAgentForSyncApi() { 331 std::string MakeUserAgentForSyncApi() {
330 std::string user_agent; 332 std::string user_agent;
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
738 base::Bind(&SyncBackendHost::Core::DoConfigureSyncer, 740 base::Bind(&SyncBackendHost::Core::DoConfigureSyncer,
739 core_.get(), 741 core_.get(),
740 reason, 742 reason,
741 types_to_config, 743 types_to_config,
742 routing_info, 744 routing_info,
743 ready_task, 745 ready_task,
744 retry_callback)); 746 retry_callback));
745 } 747 }
746 748
747 void SyncBackendHost::FinishConfigureDataTypesOnFrontendLoop( 749 void SyncBackendHost::FinishConfigureDataTypesOnFrontendLoop(
748 syncer::ModelTypeSet types_to_configure, 750 syncer::ModelTypeSet failed_configuration_types,
749 syncer::ModelTypeSet configured_types,
750 const base::Callback<void(syncer::ModelTypeSet)>& ready_task) { 751 const base::Callback<void(syncer::ModelTypeSet)>& ready_task) {
751 const syncer::ModelTypeSet failed_configuration_types = 752 if (!frontend_)
752 Difference(types_to_configure, configured_types); 753 return;
753 SDVLOG(1) 754 DCHECK_EQ(MessageLoop::current(), frontend_loop_);
754 << "Added types: "
755 << syncer::ModelTypeSetToString(types_to_configure)
756 << ", configured types: "
757 << syncer::ModelTypeSetToString(configured_types)
758 << ", failed configuration types: "
759 << syncer::ModelTypeSetToString(failed_configuration_types);
760
761 // Update |chrome_sync_notification_bridge_|'s enabled types here as it has
762 // to happen on the UI thread.
763 chrome_sync_notification_bridge_->UpdateEnabledTypes(configured_types);
764
765 // Notify SyncManager (especially the notification listener) about new types.
766 sync_thread_.message_loop()->PostTask(FROM_HERE,
767 base::Bind(&SyncBackendHost::Core::DoUpdateEnabledTypes, core_.get(),
768 configured_types));
769
770 if (!ready_task.is_null()) 755 if (!ready_task.is_null())
771 ready_task.Run(failed_configuration_types); 756 ready_task.Run(failed_configuration_types);
772 } 757 }
773 758
774 SyncBackendHost::DoInitializeOptions::DoInitializeOptions( 759 SyncBackendHost::DoInitializeOptions::DoInitializeOptions(
775 MessageLoop* sync_loop, 760 MessageLoop* sync_loop,
776 SyncBackendRegistrar* registrar, 761 SyncBackendRegistrar* registrar,
777 const syncer::ModelSafeRoutingInfo& routing_info, 762 const syncer::ModelSafeRoutingInfo& routing_info,
778 const std::vector<syncer::ModelSafeWorker*>& workers, 763 const std::vector<syncer::ModelSafeWorker*>& workers,
779 syncer::ExtensionsActivityMonitor* extensions_activity_monitor, 764 syncer::ExtensionsActivityMonitor* extensions_activity_monitor,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
812 797
813 SyncBackendHost::DoInitializeOptions::~DoInitializeOptions() {} 798 SyncBackendHost::DoInitializeOptions::~DoInitializeOptions() {}
814 799
815 SyncBackendHost::Core::Core(const std::string& name, 800 SyncBackendHost::Core::Core(const std::string& name,
816 const FilePath& sync_data_folder_path, 801 const FilePath& sync_data_folder_path,
817 const base::WeakPtr<SyncBackendHost>& backend) 802 const base::WeakPtr<SyncBackendHost>& backend)
818 : name_(name), 803 : name_(name),
819 sync_data_folder_path_(sync_data_folder_path), 804 sync_data_folder_path_(sync_data_folder_path),
820 host_(backend), 805 host_(backend),
821 sync_loop_(NULL), 806 sync_loop_(NULL),
822 registrar_(NULL) { 807 registrar_(NULL),
808 chrome_sync_notification_bridge_(NULL) {
823 DCHECK(backend.get()); 809 DCHECK(backend.get());
824 } 810 }
825 811
826 SyncBackendHost::Core::~Core() { 812 SyncBackendHost::Core::~Core() {
827 DCHECK(!sync_manager_.get()); 813 DCHECK(!sync_manager_.get());
828 DCHECK(!sync_loop_); 814 DCHECK(!sync_loop_);
829 } 815 }
830 816
831 void SyncBackendHost::Core::OnSyncCycleCompleted( 817 void SyncBackendHost::Core::OnSyncCycleCompleted(
832 const SyncSessionSnapshot& snapshot) { 818 const SyncSessionSnapshot& snapshot) {
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
961 947
962 // Make sure that the directory exists before initializing the backend. 948 // Make sure that the directory exists before initializing the backend.
963 // If it already exists, this will do no harm. 949 // If it already exists, this will do no harm.
964 bool success = file_util::CreateDirectory(sync_data_folder_path_); 950 bool success = file_util::CreateDirectory(sync_data_folder_path_);
965 DCHECK(success); 951 DCHECK(success);
966 952
967 DCHECK(!registrar_); 953 DCHECK(!registrar_);
968 registrar_ = options.registrar; 954 registrar_ = options.registrar;
969 DCHECK(registrar_); 955 DCHECK(registrar_);
970 956
957 DCHECK(!chrome_sync_notification_bridge_);
958 chrome_sync_notification_bridge_ = options.chrome_sync_notification_bridge;
959 DCHECK(chrome_sync_notification_bridge_);
960
971 sync_manager_ = options.sync_manager_factory->CreateSyncManager(name_); 961 sync_manager_ = options.sync_manager_factory->CreateSyncManager(name_);
972 sync_manager_->AddObserver(this); 962 sync_manager_->AddObserver(this);
973 success = sync_manager_->Init( 963 success = sync_manager_->Init(
974 sync_data_folder_path_, 964 sync_data_folder_path_,
975 options.event_handler, 965 options.event_handler,
976 options.service_url.host() + options.service_url.path(), 966 options.service_url.host() + options.service_url.path(),
977 options.service_url.EffectiveIntPort(), 967 options.service_url.EffectiveIntPort(),
978 options.service_url.SchemeIsSecure(), 968 options.service_url.SchemeIsSecure(),
979 BrowserThread::GetBlockingPool(), 969 BrowserThread::GetBlockingPool(),
980 options.make_http_bridge_factory_fn.Run().Pass(), 970 options.make_http_bridge_factory_fn.Run().Pass(),
(...skipping 24 matching lines...) Expand all
1005 sync_manager_->ThrowUnrecoverableError(); 995 sync_manager_->ThrowUnrecoverableError();
1006 } 996 }
1007 } 997 }
1008 998
1009 void SyncBackendHost::Core::DoUpdateCredentials( 999 void SyncBackendHost::Core::DoUpdateCredentials(
1010 const SyncCredentials& credentials) { 1000 const SyncCredentials& credentials) {
1011 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1001 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1012 sync_manager_->UpdateCredentials(credentials); 1002 sync_manager_->UpdateCredentials(credentials);
1013 } 1003 }
1014 1004
1015 void SyncBackendHost::Core::DoUpdateEnabledTypes(
1016 const syncer::ModelTypeSet& enabled_types) {
1017 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1018 sync_manager_->UpdateEnabledTypes(enabled_types);
1019 }
1020
1021 void SyncBackendHost::Core::DoStartSyncing( 1005 void SyncBackendHost::Core::DoStartSyncing(
1022 const syncer::ModelSafeRoutingInfo& routing_info) { 1006 const syncer::ModelSafeRoutingInfo& routing_info) {
1023 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1007 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1024 sync_manager_->StartSyncingNormally(routing_info); 1008 sync_manager_->StartSyncingNormally(routing_info);
1025 } 1009 }
1026 1010
1027 void SyncBackendHost::Core::DoSetEncryptionPassphrase( 1011 void SyncBackendHost::Core::DoSetEncryptionPassphrase(
1028 const std::string& passphrase, 1012 const std::string& passphrase,
1029 bool is_explicit) { 1013 bool is_explicit) {
1030 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1014 DCHECK_EQ(MessageLoop::current(), sync_loop_);
(...skipping 27 matching lines...) Expand all
1058 1042
1059 void SyncBackendHost::Core::DoShutdown(bool sync_disabled) { 1043 void SyncBackendHost::Core::DoShutdown(bool sync_disabled) {
1060 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1044 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1061 if (!sync_manager_.get()) 1045 if (!sync_manager_.get())
1062 return; 1046 return;
1063 1047
1064 save_changes_timer_.reset(); 1048 save_changes_timer_.reset();
1065 sync_manager_->ShutdownOnSyncThread(); 1049 sync_manager_->ShutdownOnSyncThread();
1066 sync_manager_->RemoveObserver(this); 1050 sync_manager_->RemoveObserver(this);
1067 sync_manager_.reset(); 1051 sync_manager_.reset();
1052 chrome_sync_notification_bridge_ = NULL;
1068 registrar_ = NULL; 1053 registrar_ = NULL;
1069 1054
1070 if (sync_disabled) 1055 if (sync_disabled)
1071 DeleteSyncDataFolder(); 1056 DeleteSyncDataFolder();
1072 1057
1073 sync_loop_ = NULL; 1058 sync_loop_ = NULL;
1074 1059
1075 host_.Reset(); 1060 host_.Reset();
1076 } 1061 }
1077 1062
(...skipping 14 matching lines...) Expand all
1092 ready_task), 1077 ready_task),
1093 base::Bind(&SyncBackendHost::Core::DoRetryConfiguration, 1078 base::Bind(&SyncBackendHost::Core::DoRetryConfiguration,
1094 this, 1079 this,
1095 retry_callback)); 1080 retry_callback));
1096 } 1081 }
1097 1082
1098 void SyncBackendHost::Core::DoFinishConfigureDataTypes( 1083 void SyncBackendHost::Core::DoFinishConfigureDataTypes(
1099 syncer::ModelTypeSet types_to_config, 1084 syncer::ModelTypeSet types_to_config,
1100 const base::Callback<void(syncer::ModelTypeSet)>& ready_task) { 1085 const base::Callback<void(syncer::ModelTypeSet)>& ready_task) {
1101 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1086 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1102 syncer::ModelTypeSet configured_types = 1087
1103 sync_manager_->InitialSyncEndedTypes(); 1088 // Update the enabled types for the bridge and sync manager.
1104 configured_types.RetainAll(types_to_config); 1089 syncer::ModelSafeRoutingInfo routing_info;
1090 registrar_->GetModelSafeRoutingInfo(&routing_info);
1091 const syncer::ModelTypeSet enabled_types = GetRoutingInfoTypes(routing_info);
1092 chrome_sync_notification_bridge_->UpdateEnabledTypes(enabled_types);
1093 sync_manager_->UpdateEnabledTypes(enabled_types);
1094
1095 const syncer::ModelTypeSet failed_configuration_types =
1096 Difference(types_to_config, sync_manager_->InitialSyncEndedTypes());
1105 host_.Call(FROM_HERE, 1097 host_.Call(FROM_HERE,
1106 &SyncBackendHost::FinishConfigureDataTypesOnFrontendLoop, 1098 &SyncBackendHost::FinishConfigureDataTypesOnFrontendLoop,
1107 types_to_config, 1099 failed_configuration_types,
1108 configured_types,
1109 ready_task); 1100 ready_task);
1110 } 1101 }
1111 1102
1112 void SyncBackendHost::Core::DoRetryConfiguration( 1103 void SyncBackendHost::Core::DoRetryConfiguration(
1113 const base::Closure& retry_callback) { 1104 const base::Closure& retry_callback) {
1114 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1105 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1115 host_.Call(FROM_HERE, 1106 host_.Call(FROM_HERE,
1116 &SyncBackendHost::RetryConfigurationOnFrontendLoop, 1107 &SyncBackendHost::RetryConfigurationOnFrontendLoop,
1117 retry_callback); 1108 retry_callback);
1118 } 1109 }
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
1375 FROM_HERE, 1366 FROM_HERE,
1376 base::Bind(&SyncBackendHost::Core::DoRefreshNigori, 1367 base::Bind(&SyncBackendHost::Core::DoRefreshNigori,
1377 core_.get(), sync_thread_done_callback)); 1368 core_.get(), sync_thread_done_callback));
1378 } 1369 }
1379 1370
1380 #undef SDVLOG 1371 #undef SDVLOG
1381 1372
1382 #undef SLOG 1373 #undef SLOG
1383 1374
1384 } // namespace browser_sync 1375 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698