| 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 "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> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
| 15 #include "base/file_path.h" | 15 #include "base/file_path.h" |
| 16 #include "base/file_util.h" | 16 #include "base/file_util.h" |
| 17 #include "base/location.h" | 17 #include "base/location.h" |
| 18 #include "base/metrics/histogram.h" | 18 #include "base/metrics/histogram.h" |
| 19 #include "base/threading/sequenced_worker_pool.h" | 19 #include "base/threading/sequenced_worker_pool.h" |
| 20 #include "base/threading/thread_restrictions.h" | 20 #include "base/threading/thread_restrictions.h" |
| 21 #include "base/timer.h" | 21 #include "base/timer.h" |
| 22 #include "base/tracked_objects.h" | 22 #include "base/tracked_objects.h" |
| 23 #include "base/utf_string_conversions.h" | 23 #include "base/utf_string_conversions.h" |
| 24 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
| 25 #include "chrome/browser/signin/token_service.h" | 25 #include "chrome/browser/signin/token_service.h" |
| 26 #include "chrome/browser/sync/glue/bridged_sync_notifier.h" | 26 #include "chrome/browser/sync/glue/bridged_sync_notifier.h" |
| 27 #include "chrome/browser/sync/glue/change_processor.h" | 27 #include "chrome/browser/sync/glue/change_processor.h" |
| 28 #include "chrome/browser/sync/glue/chrome_encryptor.h" | 28 #include "chrome/browser/sync/glue/chrome_encryptor.h" |
| 29 #include "chrome/browser/sync/glue/chrome_sync_notification_bridge.h" | 29 #include "chrome/browser/sync/glue/chrome_sync_notification_bridge.h" |
| 30 #include "chrome/browser/sync/glue/nigori_change_processor.h" |
| 30 #include "chrome/browser/sync/glue/sync_backend_registrar.h" | 31 #include "chrome/browser/sync/glue/sync_backend_registrar.h" |
| 31 #include "chrome/browser/sync/invalidations/invalidator_storage.h" | 32 #include "chrome/browser/sync/invalidations/invalidator_storage.h" |
| 32 #include "chrome/browser/sync/sync_prefs.h" | 33 #include "chrome/browser/sync/sync_prefs.h" |
| 33 #include "chrome/common/chrome_notification_types.h" | 34 #include "chrome/common/chrome_notification_types.h" |
| 34 #include "chrome/common/chrome_switches.h" | 35 #include "chrome/common/chrome_switches.h" |
| 35 #include "chrome/common/chrome_version_info.h" | 36 #include "chrome/common/chrome_version_info.h" |
| 36 #include "chrome/common/net/gaia/gaia_constants.h" | 37 #include "chrome/common/net/gaia/gaia_constants.h" |
| 37 #include "content/public/browser/browser_thread.h" | 38 #include "content/public/browser/browser_thread.h" |
| 38 #include "content/public/browser/notification_service.h" | 39 #include "content/public/browser/notification_service.h" |
| 39 #include "content/public/common/content_client.h" | 40 #include "content/public/common/content_client.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 | 72 |
| 72 // Helper macros to log with the syncer thread name; useful when there | 73 // Helper macros to log with the syncer thread name; useful when there |
| 73 // are multiple syncers involved. | 74 // are multiple syncers involved. |
| 74 | 75 |
| 75 #define SLOG(severity) LOG(severity) << name_ << ": " | 76 #define SLOG(severity) LOG(severity) << name_ << ": " |
| 76 | 77 |
| 77 #define SDVLOG(verbose_level) DVLOG(verbose_level) << name_ << ": " | 78 #define SDVLOG(verbose_level) DVLOG(verbose_level) << name_ << ": " |
| 78 | 79 |
| 79 class SyncBackendHost::Core | 80 class SyncBackendHost::Core |
| 80 : public base::RefCountedThreadSafe<SyncBackendHost::Core>, | 81 : public base::RefCountedThreadSafe<SyncBackendHost::Core>, |
| 82 public syncer::SyncEncryptionHandler::Observer, |
| 81 public syncer::SyncManager::Observer, | 83 public syncer::SyncManager::Observer, |
| 82 public syncer::SyncNotifierObserver { | 84 public syncer::SyncNotifierObserver { |
| 83 public: | 85 public: |
| 84 Core(const std::string& name, | 86 Core(const std::string& name, |
| 85 const FilePath& sync_data_folder_path, | 87 const FilePath& sync_data_folder_path, |
| 86 const base::WeakPtr<SyncBackendHost>& backend); | 88 const base::WeakPtr<SyncBackendHost>& backend); |
| 87 | 89 |
| 88 // SyncManager::Observer implementation. The Core just acts like an air | 90 // SyncManager::Observer implementation. The Core just acts like an air |
| 89 // traffic controller here, forwarding incoming messages to appropriate | 91 // traffic controller here, forwarding incoming messages to appropriate |
| 90 // landing threads. | 92 // landing threads. |
| 91 virtual void OnSyncCycleCompleted( | 93 virtual void OnSyncCycleCompleted( |
| 92 const syncer::sessions::SyncSessionSnapshot& snapshot) OVERRIDE; | 94 const syncer::sessions::SyncSessionSnapshot& snapshot) OVERRIDE; |
| 93 virtual void OnInitializationComplete( | 95 virtual void OnInitializationComplete( |
| 94 const syncer::WeakHandle<syncer::JsBackend>& js_backend, | 96 const syncer::WeakHandle<syncer::JsBackend>& js_backend, |
| 95 bool success, | 97 bool success, |
| 96 syncer::ModelTypeSet restored_types) OVERRIDE; | 98 syncer::ModelTypeSet restored_types) OVERRIDE; |
| 97 virtual void OnConnectionStatusChange( | 99 virtual void OnConnectionStatusChange( |
| 98 syncer::ConnectionStatus status) OVERRIDE; | 100 syncer::ConnectionStatus status) OVERRIDE; |
| 101 virtual void OnStopSyncingPermanently() OVERRIDE; |
| 102 virtual void OnUpdatedToken(const std::string& token) OVERRIDE; |
| 103 virtual void OnActionableError( |
| 104 const syncer::SyncProtocolError& sync_error) OVERRIDE; |
| 105 |
| 106 // SyncEncryptionHandler::Observer implementation. |
| 99 virtual void OnPassphraseRequired( | 107 virtual void OnPassphraseRequired( |
| 100 syncer::PassphraseRequiredReason reason, | 108 syncer::PassphraseRequiredReason reason, |
| 101 const sync_pb::EncryptedData& pending_keys) OVERRIDE; | 109 const sync_pb::EncryptedData& pending_keys) OVERRIDE; |
| 102 virtual void OnPassphraseAccepted() OVERRIDE; | 110 virtual void OnPassphraseAccepted() OVERRIDE; |
| 103 virtual void OnBootstrapTokenUpdated( | 111 virtual void OnBootstrapTokenUpdated( |
| 104 const std::string& bootstrap_token) OVERRIDE; | 112 const std::string& bootstrap_token) OVERRIDE; |
| 105 virtual void OnStopSyncingPermanently() OVERRIDE; | |
| 106 virtual void OnUpdatedToken(const std::string& token) OVERRIDE; | |
| 107 virtual void OnEncryptedTypesChanged( | 113 virtual void OnEncryptedTypesChanged( |
| 108 syncer::ModelTypeSet encrypted_types, | 114 syncer::ModelTypeSet encrypted_types, |
| 109 bool encrypt_everything) OVERRIDE; | 115 bool encrypt_everything) OVERRIDE; |
| 110 virtual void OnEncryptionComplete() OVERRIDE; | 116 virtual void OnEncryptionComplete() OVERRIDE; |
| 111 virtual void OnActionableError( | 117 virtual void OnCryptographerStateChanged( |
| 112 const syncer::SyncProtocolError& sync_error) OVERRIDE; | 118 syncer::Cryptographer* cryptographer) OVERRIDE; |
| 113 | 119 |
| 114 // syncer::SyncNotifierObserver implementation. | 120 // syncer::SyncNotifierObserver implementation. |
| 115 virtual void OnNotificationsEnabled() OVERRIDE; | 121 virtual void OnNotificationsEnabled() OVERRIDE; |
| 116 virtual void OnNotificationsDisabled( | 122 virtual void OnNotificationsDisabled( |
| 117 syncer::NotificationsDisabledReason reason) OVERRIDE; | 123 syncer::NotificationsDisabledReason reason) OVERRIDE; |
| 118 virtual void OnIncomingNotification( | 124 virtual void OnIncomingNotification( |
| 119 const syncer::ObjectIdPayloadMap& id_payloads, | 125 const syncer::ObjectIdPayloadMap& id_payloads, |
| 120 syncer::IncomingNotificationSource source) OVERRIDE; | 126 syncer::IncomingNotificationSource source) OVERRIDE; |
| 121 | 127 |
| 122 // Note: | 128 // Note: |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 syncer::ConfigureReason reason, | 182 syncer::ConfigureReason reason, |
| 177 syncer::ModelTypeSet types_to_config, | 183 syncer::ModelTypeSet types_to_config, |
| 178 const syncer::ModelSafeRoutingInfo routing_info, | 184 const syncer::ModelSafeRoutingInfo routing_info, |
| 179 const base::Callback<void(syncer::ModelTypeSet)>& ready_task, | 185 const base::Callback<void(syncer::ModelTypeSet)>& ready_task, |
| 180 const base::Closure& retry_callback); | 186 const base::Closure& retry_callback); |
| 181 void DoFinishConfigureDataTypes( | 187 void DoFinishConfigureDataTypes( |
| 182 syncer::ModelTypeSet types_to_config, | 188 syncer::ModelTypeSet types_to_config, |
| 183 const base::Callback<void(syncer::ModelTypeSet)>& ready_task); | 189 const base::Callback<void(syncer::ModelTypeSet)>& ready_task); |
| 184 void DoRetryConfiguration( | 190 void DoRetryConfiguration( |
| 185 const base::Closure& retry_callback); | 191 const base::Closure& retry_callback); |
| 192 void DoAssociateNigori(const base::Closure& done_callback); |
| 186 | 193 |
| 187 // Set the base request context to use when making HTTP calls. | 194 // Set the base request context to use when making HTTP calls. |
| 188 // This method will add a reference to the context to persist it | 195 // This method will add a reference to the context to persist it |
| 189 // on the IO thread. Must be removed from IO thread. | 196 // on the IO thread. Must be removed from IO thread. |
| 190 | 197 |
| 191 syncer::SyncManager* sync_manager() { return sync_manager_.get(); } | 198 syncer::SyncManager* sync_manager() { return sync_manager_.get(); } |
| 192 | 199 |
| 193 // Delete the sync data folder to cleanup backend data. Happens the first | 200 // Delete the sync data folder to cleanup backend data. Happens the first |
| 194 // time sync is enabled for a user (to prevent accidentally reusing old | 201 // time sync is enabled for a user (to prevent accidentally reusing old |
| 195 // sync databases), as well as shutdown when you're no longer syncing. | 202 // sync databases), as well as shutdown when you're no longer syncing. |
| 196 void DeleteSyncDataFolder(); | 203 void DeleteSyncDataFolder(); |
| 197 | 204 |
| 205 NigoriChangeProcessor* nigori_processor() { return nigori_processor_.get(); } |
| 206 |
| 198 private: | 207 private: |
| 199 friend class base::RefCountedThreadSafe<SyncBackendHost::Core>; | 208 friend class base::RefCountedThreadSafe<SyncBackendHost::Core>; |
| 200 friend class SyncBackendHostForProfileSyncTest; | 209 friend class SyncBackendHostForProfileSyncTest; |
| 201 | 210 |
| 202 virtual ~Core(); | 211 virtual ~Core(); |
| 203 | 212 |
| 204 // Invoked when initialization of syncapi is complete and we can start | 213 // Invoked when initialization of syncapi is complete and we can start |
| 205 // our timer. | 214 // our timer. |
| 206 // This must be called from the thread on which SaveChanges is intended to | 215 // This must be called from the thread on which SaveChanges is intended to |
| 207 // be run on; the host's |sync_thread_|. | 216 // be run on; the host's |sync_thread_|. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 238 | 247 |
| 239 // The timer used to periodically call SaveChanges. | 248 // The timer used to periodically call SaveChanges. |
| 240 scoped_ptr<base::RepeatingTimer<Core> > save_changes_timer_; | 249 scoped_ptr<base::RepeatingTimer<Core> > save_changes_timer_; |
| 241 | 250 |
| 242 // Our encryptor, which uses Chrome's encryption functions. | 251 // Our encryptor, which uses Chrome's encryption functions. |
| 243 ChromeEncryptor encryptor_; | 252 ChromeEncryptor encryptor_; |
| 244 | 253 |
| 245 // The top-level syncapi entry point. Lives on the sync thread. | 254 // The top-level syncapi entry point. Lives on the sync thread. |
| 246 scoped_ptr<syncer::SyncManager> sync_manager_; | 255 scoped_ptr<syncer::SyncManager> sync_manager_; |
| 247 | 256 |
| 257 // The nigori change processor. Handles all nigori/sync encryption |
| 258 // functionality. |
| 259 scoped_ptr<NigoriChangeProcessor> nigori_processor_; |
| 260 |
| 248 DISALLOW_COPY_AND_ASSIGN(Core); | 261 DISALLOW_COPY_AND_ASSIGN(Core); |
| 249 }; | 262 }; |
| 250 | 263 |
| 251 namespace { | 264 namespace { |
| 252 | 265 |
| 253 // Parses the given command line for notifier options. | 266 // Parses the given command line for notifier options. |
| 254 notifier::NotifierOptions ParseNotifierOptions( | 267 notifier::NotifierOptions ParseNotifierOptions( |
| 255 const CommandLine& command_line, | 268 const CommandLine& command_line, |
| 256 const scoped_refptr<net::URLRequestContextGetter>& | 269 const scoped_refptr<net::URLRequestContextGetter>& |
| 257 request_context_getter) { | 270 request_context_getter) { |
| (...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 730 | 743 |
| 731 bool SyncBackendHost::IsNigoriEnabled() const { | 744 bool SyncBackendHost::IsNigoriEnabled() const { |
| 732 return registrar_.get() && registrar_->IsNigoriEnabled(); | 745 return registrar_.get() && registrar_->IsNigoriEnabled(); |
| 733 } | 746 } |
| 734 | 747 |
| 735 bool SyncBackendHost::IsUsingExplicitPassphrase() { | 748 bool SyncBackendHost::IsUsingExplicitPassphrase() { |
| 736 // This should only be called once the nigori node has been downloaded, as | 749 // This should only be called once the nigori node has been downloaded, as |
| 737 // otherwise we have no idea what kind of passphrase we are using. This will | 750 // otherwise we have no idea what kind of passphrase we are using. This will |
| 738 // NOTREACH in sync_manager and return false if we fail to load the nigori | 751 // NOTREACH in sync_manager and return false if we fail to load the nigori |
| 739 // node. | 752 // node. |
| 740 return IsNigoriEnabled() && | 753 // TODO(zea): cache this value at the PSS, then make the encryption handler |
| 741 core_->sync_manager()->IsUsingExplicitPassphrase(); | 754 // NonThreadSafe and only accessible from the sync thread. |
| 755 return IsNigoriEnabled() && core_->sync_manager()->GetEncryptionHandler()-> |
| 756 IsUsingExplicitPassphrase(); |
| 742 } | 757 } |
| 743 | 758 |
| 744 bool SyncBackendHost::IsCryptographerReady( | 759 bool SyncBackendHost::IsCryptographerReady( |
| 745 const syncer::BaseTransaction* trans) const { | 760 const syncer::BaseTransaction* trans) const { |
| 746 return initialized() && trans->GetCryptographer()->is_ready(); | 761 return initialized() && trans->GetCryptographer()->is_ready(); |
| 747 } | 762 } |
| 748 | 763 |
| 749 void SyncBackendHost::GetModelSafeRoutingInfo( | 764 void SyncBackendHost::GetModelSafeRoutingInfo( |
| 750 syncer::ModelSafeRoutingInfo* out) const { | 765 syncer::ModelSafeRoutingInfo* out) const { |
| 751 if (initialized()) { | 766 if (initialized()) { |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 986 void SyncBackendHost::Core::OnEncryptionComplete() { | 1001 void SyncBackendHost::Core::OnEncryptionComplete() { |
| 987 if (!sync_loop_) | 1002 if (!sync_loop_) |
| 988 return; | 1003 return; |
| 989 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1004 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 990 // NOTE: We're in a transaction. | 1005 // NOTE: We're in a transaction. |
| 991 host_.Call( | 1006 host_.Call( |
| 992 FROM_HERE, | 1007 FROM_HERE, |
| 993 &SyncBackendHost::NotifyEncryptionComplete); | 1008 &SyncBackendHost::NotifyEncryptionComplete); |
| 994 } | 1009 } |
| 995 | 1010 |
| 1011 void SyncBackendHost::Core::OnCryptographerStateChanged( |
| 1012 syncer::Cryptographer* cryptographer) { |
| 1013 // Do nothing. |
| 1014 } |
| 1015 |
| 996 void SyncBackendHost::Core::OnActionableError( | 1016 void SyncBackendHost::Core::OnActionableError( |
| 997 const syncer::SyncProtocolError& sync_error) { | 1017 const syncer::SyncProtocolError& sync_error) { |
| 998 if (!sync_loop_) | 1018 if (!sync_loop_) |
| 999 return; | 1019 return; |
| 1000 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1020 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1001 host_.Call( | 1021 host_.Call( |
| 1002 FROM_HERE, | 1022 FROM_HERE, |
| 1003 &SyncBackendHost::HandleActionableErrorEventOnFrontendLoop, | 1023 &SyncBackendHost::HandleActionableErrorEventOnFrontendLoop, |
| 1004 sync_error); | 1024 sync_error); |
| 1005 } | 1025 } |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1115 sync_manager_->UpdateRegisteredInvalidationIds(this, ids); | 1135 sync_manager_->UpdateRegisteredInvalidationIds(this, ids); |
| 1116 } | 1136 } |
| 1117 } | 1137 } |
| 1118 | 1138 |
| 1119 void SyncBackendHost::Core::DoStartSyncing( | 1139 void SyncBackendHost::Core::DoStartSyncing( |
| 1120 const syncer::ModelSafeRoutingInfo& routing_info) { | 1140 const syncer::ModelSafeRoutingInfo& routing_info) { |
| 1121 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1141 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1122 sync_manager_->StartSyncingNormally(routing_info); | 1142 sync_manager_->StartSyncingNormally(routing_info); |
| 1123 } | 1143 } |
| 1124 | 1144 |
| 1145 void SyncBackendHost::Core::DoAssociateNigori( |
| 1146 const base::Closure& done_callback) { |
| 1147 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1148 syncer::SyncEncryptionHandler* encryption_handler = |
| 1149 sync_manager_->GetEncryptionHandler(); |
| 1150 nigori_processor_.reset(new NigoriChangeProcessor(encryption_handler)); |
| 1151 encryption_handler->AddObserver(this); |
| 1152 nigori_processor_->AssociateModels(sync_manager_->GetUserShare()); |
| 1153 done_callback.Run(); |
| 1154 } |
| 1155 |
| 1125 void SyncBackendHost::Core::DoSetEncryptionPassphrase( | 1156 void SyncBackendHost::Core::DoSetEncryptionPassphrase( |
| 1126 const std::string& passphrase, | 1157 const std::string& passphrase, |
| 1127 bool is_explicit) { | 1158 bool is_explicit) { |
| 1128 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1159 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1129 sync_manager_->SetEncryptionPassphrase(passphrase, is_explicit); | 1160 sync_manager_->GetEncryptionHandler()->SetEncryptionPassphrase( |
| 1161 passphrase, is_explicit); |
| 1130 } | 1162 } |
| 1131 | 1163 |
| 1132 void SyncBackendHost::Core::DoSetDecryptionPassphrase( | 1164 void SyncBackendHost::Core::DoSetDecryptionPassphrase( |
| 1133 const std::string& passphrase) { | 1165 const std::string& passphrase) { |
| 1134 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1166 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1135 sync_manager_->SetDecryptionPassphrase(passphrase); | 1167 sync_manager_->GetEncryptionHandler()->SetDecryptionPassphrase( |
| 1168 passphrase); |
| 1136 } | 1169 } |
| 1137 | 1170 |
| 1138 void SyncBackendHost::Core::DoEnableEncryptEverything() { | 1171 void SyncBackendHost::Core::DoEnableEncryptEverything() { |
| 1139 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1172 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1140 sync_manager_->EnableEncryptEverything(); | 1173 sync_manager_->GetEncryptionHandler()->EnableEncryptEverything(); |
| 1141 } | |
| 1142 | |
| 1143 void SyncBackendHost::Core::DoRefreshNigori( | |
| 1144 const base::Closure& done_callback) { | |
| 1145 DCHECK_EQ(MessageLoop::current(), sync_loop_); | |
| 1146 chrome::VersionInfo version_info; | |
| 1147 sync_manager_->RefreshNigori(version_info.CreateVersionString(), | |
| 1148 done_callback); | |
| 1149 } | 1174 } |
| 1150 | 1175 |
| 1151 void SyncBackendHost::Core::DoStopSyncManagerForShutdown( | 1176 void SyncBackendHost::Core::DoStopSyncManagerForShutdown( |
| 1152 const base::Closure& closure) { | 1177 const base::Closure& closure) { |
| 1153 if (sync_manager_.get()) { | 1178 if (sync_manager_.get()) { |
| 1154 sync_manager_->StopSyncingForShutdown(closure); | 1179 sync_manager_->StopSyncingForShutdown(closure); |
| 1155 } else { | 1180 } else { |
| 1156 sync_loop_->PostTask(FROM_HERE, closure); | 1181 sync_loop_->PostTask(FROM_HERE, closure); |
| 1157 } | 1182 } |
| 1158 } | 1183 } |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1248 } | 1273 } |
| 1249 | 1274 |
| 1250 void SyncBackendHost::Core::SaveChanges() { | 1275 void SyncBackendHost::Core::SaveChanges() { |
| 1251 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1276 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| 1252 sync_manager_->SaveChanges(); | 1277 sync_manager_->SaveChanges(); |
| 1253 } | 1278 } |
| 1254 | 1279 |
| 1255 void SyncBackendHost::AddExperimentalTypes() { | 1280 void SyncBackendHost::AddExperimentalTypes() { |
| 1256 CHECK(initialized()); | 1281 CHECK(initialized()); |
| 1257 syncer::Experiments experiments; | 1282 syncer::Experiments experiments; |
| 1258 if (core_->sync_manager()->ReceivedExperiment(&experiments)) | 1283 if (core_->nigori_processor()->ReceivedExperiments(&experiments)) |
| 1259 frontend_->OnExperimentsChanged(experiments); | 1284 frontend_->OnExperimentsChanged(experiments); |
| 1260 } | 1285 } |
| 1261 | 1286 |
| 1262 void SyncBackendHost::OnNigoriDownloadRetry() { | 1287 void SyncBackendHost::OnNigoriDownloadRetry() { |
| 1263 DCHECK_EQ(MessageLoop::current(), frontend_loop_); | 1288 DCHECK_EQ(MessageLoop::current(), frontend_loop_); |
| 1264 if (!frontend_) | 1289 if (!frontend_) |
| 1265 return; | 1290 return; |
| 1266 | 1291 |
| 1267 frontend_->OnSyncConfigureRetry(); | 1292 frontend_->OnSyncConfigureRetry(); |
| 1268 } | 1293 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1306 &SyncBackendHost:: | 1331 &SyncBackendHost:: |
| 1307 HandleNigoriConfigurationCompletedOnFrontendLoop, | 1332 HandleNigoriConfigurationCompletedOnFrontendLoop, |
| 1308 weak_ptr_factory_.GetWeakPtr(), js_backend), | 1333 weak_ptr_factory_.GetWeakPtr(), js_backend), |
| 1309 base::Bind(&SyncBackendHost::OnNigoriDownloadRetry, | 1334 base::Bind(&SyncBackendHost::OnNigoriDownloadRetry, |
| 1310 weak_ptr_factory_.GetWeakPtr())); | 1335 weak_ptr_factory_.GetWeakPtr())); |
| 1311 break; | 1336 break; |
| 1312 case DOWNLOADING_NIGORI: | 1337 case DOWNLOADING_NIGORI: |
| 1313 initialization_state_ = REFRESHING_NIGORI; | 1338 initialization_state_ = REFRESHING_NIGORI; |
| 1314 // Triggers OnEncryptedTypesChanged() and OnEncryptionComplete() | 1339 // Triggers OnEncryptedTypesChanged() and OnEncryptionComplete() |
| 1315 // if necessary. | 1340 // if necessary. |
| 1316 RefreshNigori( | 1341 AssociateNigori( |
| 1317 base::Bind( | 1342 base::Bind( |
| 1318 &SyncBackendHost:: | 1343 &SyncBackendHost:: |
| 1319 HandleInitializationCompletedOnFrontendLoop, | 1344 HandleInitializationCompletedOnFrontendLoop, |
| 1320 weak_ptr_factory_.GetWeakPtr(), js_backend, true)); | 1345 weak_ptr_factory_.GetWeakPtr(), js_backend, true)); |
| 1321 break; | 1346 break; |
| 1322 case REFRESHING_NIGORI: | 1347 case REFRESHING_NIGORI: |
| 1323 initialization_state_ = INITIALIZED; | 1348 initialization_state_ = INITIALIZED; |
| 1324 // Now that we've downloaded the nigori node, we can see if there are any | 1349 // Now that we've downloaded the nigori node, we can see if there are any |
| 1325 // experimental types to enable. This should be done before we inform | 1350 // experimental types to enable. This should be done before we inform |
| 1326 // the frontend to ensure they're visible in the customize screen. | 1351 // the frontend to ensure they're visible in the customize screen. |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1496 | 1521 |
| 1497 // Needed because MessageLoop::PostTask is overloaded. | 1522 // Needed because MessageLoop::PostTask is overloaded. |
| 1498 void PostClosure(MessageLoop* message_loop, | 1523 void PostClosure(MessageLoop* message_loop, |
| 1499 const tracked_objects::Location& from_here, | 1524 const tracked_objects::Location& from_here, |
| 1500 const base::Closure& callback) { | 1525 const base::Closure& callback) { |
| 1501 message_loop->PostTask(from_here, callback); | 1526 message_loop->PostTask(from_here, callback); |
| 1502 } | 1527 } |
| 1503 | 1528 |
| 1504 } // namespace | 1529 } // namespace |
| 1505 | 1530 |
| 1506 void SyncBackendHost::RefreshNigori(const base::Closure& done_callback) { | 1531 void SyncBackendHost::AssociateNigori( |
| 1532 const base::Closure& done_callback) { |
| 1507 DCHECK_EQ(MessageLoop::current(), frontend_loop_); | 1533 DCHECK_EQ(MessageLoop::current(), frontend_loop_); |
| 1508 base::Closure sync_thread_done_callback = | 1534 base::Closure sync_thread_done_callback = |
| 1509 base::Bind(&PostClosure, | 1535 base::Bind(&PostClosure, |
| 1510 MessageLoop::current(), FROM_HERE, done_callback); | 1536 MessageLoop::current(), FROM_HERE, done_callback); |
| 1511 sync_thread_.message_loop()->PostTask( | 1537 sync_thread_.message_loop()->PostTask( |
| 1512 FROM_HERE, | 1538 FROM_HERE, |
| 1513 base::Bind(&SyncBackendHost::Core::DoRefreshNigori, | 1539 base::Bind(&SyncBackendHost::Core::DoAssociateNigori, |
| 1514 core_.get(), sync_thread_done_callback)); | 1540 core_.get(), sync_thread_done_callback)); |
| 1515 } | 1541 } |
| 1516 | 1542 |
| 1517 #undef SDVLOG | 1543 #undef SDVLOG |
| 1518 | 1544 |
| 1519 #undef SLOG | 1545 #undef SLOG |
| 1520 | 1546 |
| 1521 } // namespace browser_sync | 1547 } // namespace browser_sync |
| OLD | NEW |