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(); } | |
tim (not reviewing)
2012/08/12 23:31:20
Can we avoid exposing this? The only reason we ex
Nicolas Zea
2012/08/13 22:56:38
Done.
| |
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. For now it's just a wrapper around | |
258 // the SyncEncryptionHandler, but eventually it will handle all nigori | |
259 // update and conflict events. | |
260 scoped_ptr<NigoriChangeProcessor> nigori_processor_; | |
261 | |
248 DISALLOW_COPY_AND_ASSIGN(Core); | 262 DISALLOW_COPY_AND_ASSIGN(Core); |
249 }; | 263 }; |
250 | 264 |
251 namespace { | 265 namespace { |
252 | 266 |
253 // Parses the given command line for notifier options. | 267 // Parses the given command line for notifier options. |
254 notifier::NotifierOptions ParseNotifierOptions( | 268 notifier::NotifierOptions ParseNotifierOptions( |
255 const CommandLine& command_line, | 269 const CommandLine& command_line, |
256 const scoped_refptr<net::URLRequestContextGetter>& | 270 const scoped_refptr<net::URLRequestContextGetter>& |
257 request_context_getter) { | 271 request_context_getter) { |
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
730 | 744 |
731 bool SyncBackendHost::IsNigoriEnabled() const { | 745 bool SyncBackendHost::IsNigoriEnabled() const { |
732 return registrar_.get() && registrar_->IsNigoriEnabled(); | 746 return registrar_.get() && registrar_->IsNigoriEnabled(); |
733 } | 747 } |
734 | 748 |
735 bool SyncBackendHost::IsUsingExplicitPassphrase() { | 749 bool SyncBackendHost::IsUsingExplicitPassphrase() { |
736 // This should only be called once the nigori node has been downloaded, as | 750 // 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 | 751 // 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 | 752 // NOTREACH in sync_manager and return false if we fail to load the nigori |
739 // node. | 753 // node. |
754 // TODO(zea): cache this value at the PSS, then make the encryption handler | |
755 // NonThreadSafe and only accessible from the sync thread. | |
740 return IsNigoriEnabled() && | 756 return IsNigoriEnabled() && |
741 core_->sync_manager()->IsUsingExplicitPassphrase(); | 757 core_->sync_manager()->GetEncryptionHandler()-> |
758 IsUsingExplicitPassphrase(); | |
742 } | 759 } |
743 | 760 |
744 bool SyncBackendHost::IsCryptographerReady( | 761 bool SyncBackendHost::IsCryptographerReady( |
745 const syncer::BaseTransaction* trans) const { | 762 const syncer::BaseTransaction* trans) const { |
746 return initialized() && trans->GetCryptographer()->is_ready(); | 763 return initialized() && trans->GetCryptographer()->is_ready(); |
747 } | 764 } |
748 | 765 |
749 void SyncBackendHost::GetModelSafeRoutingInfo( | 766 void SyncBackendHost::GetModelSafeRoutingInfo( |
750 syncer::ModelSafeRoutingInfo* out) const { | 767 syncer::ModelSafeRoutingInfo* out) const { |
751 if (initialized()) { | 768 if (initialized()) { |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
986 void SyncBackendHost::Core::OnEncryptionComplete() { | 1003 void SyncBackendHost::Core::OnEncryptionComplete() { |
987 if (!sync_loop_) | 1004 if (!sync_loop_) |
988 return; | 1005 return; |
989 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1006 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
990 // NOTE: We're in a transaction. | 1007 // NOTE: We're in a transaction. |
991 host_.Call( | 1008 host_.Call( |
992 FROM_HERE, | 1009 FROM_HERE, |
993 &SyncBackendHost::NotifyEncryptionComplete); | 1010 &SyncBackendHost::NotifyEncryptionComplete); |
994 } | 1011 } |
995 | 1012 |
1013 void SyncBackendHost::Core::OnCryptographerStateChanged( | |
1014 syncer::Cryptographer* cryptographer) { | |
1015 // Do nothing. | |
1016 } | |
1017 | |
996 void SyncBackendHost::Core::OnActionableError( | 1018 void SyncBackendHost::Core::OnActionableError( |
997 const syncer::SyncProtocolError& sync_error) { | 1019 const syncer::SyncProtocolError& sync_error) { |
998 if (!sync_loop_) | 1020 if (!sync_loop_) |
999 return; | 1021 return; |
1000 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1022 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
1001 host_.Call( | 1023 host_.Call( |
1002 FROM_HERE, | 1024 FROM_HERE, |
1003 &SyncBackendHost::HandleActionableErrorEventOnFrontendLoop, | 1025 &SyncBackendHost::HandleActionableErrorEventOnFrontendLoop, |
1004 sync_error); | 1026 sync_error); |
1005 } | 1027 } |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1115 sync_manager_->UpdateRegisteredInvalidationIds(this, ids); | 1137 sync_manager_->UpdateRegisteredInvalidationIds(this, ids); |
1116 } | 1138 } |
1117 } | 1139 } |
1118 | 1140 |
1119 void SyncBackendHost::Core::DoStartSyncing( | 1141 void SyncBackendHost::Core::DoStartSyncing( |
1120 const syncer::ModelSafeRoutingInfo& routing_info) { | 1142 const syncer::ModelSafeRoutingInfo& routing_info) { |
1121 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1143 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
1122 sync_manager_->StartSyncingNormally(routing_info); | 1144 sync_manager_->StartSyncingNormally(routing_info); |
1123 } | 1145 } |
1124 | 1146 |
1147 void SyncBackendHost::Core::DoAssociateNigori( | |
1148 const base::Closure& done_callback) { | |
1149 DCHECK_EQ(MessageLoop::current(), sync_loop_); | |
1150 syncer::SyncEncryptionHandler* encryption_handler = | |
1151 sync_manager_->GetEncryptionHandler(); | |
1152 nigori_processor_.reset(new NigoriChangeProcessor(encryption_handler)); | |
1153 encryption_handler->AddObserver(this); | |
1154 nigori_processor_->AssociateModels(sync_manager_->GetUserShare()); | |
1155 done_callback.Run(); | |
1156 } | |
1157 | |
1125 void SyncBackendHost::Core::DoSetEncryptionPassphrase( | 1158 void SyncBackendHost::Core::DoSetEncryptionPassphrase( |
1126 const std::string& passphrase, | 1159 const std::string& passphrase, |
1127 bool is_explicit) { | 1160 bool is_explicit) { |
1128 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1161 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
1129 sync_manager_->SetEncryptionPassphrase(passphrase, is_explicit); | 1162 sync_manager_->GetEncryptionHandler()->SetEncryptionPassphrase( |
1163 passphrase, is_explicit); | |
1130 } | 1164 } |
1131 | 1165 |
1132 void SyncBackendHost::Core::DoSetDecryptionPassphrase( | 1166 void SyncBackendHost::Core::DoSetDecryptionPassphrase( |
1133 const std::string& passphrase) { | 1167 const std::string& passphrase) { |
1134 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1168 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
1135 sync_manager_->SetDecryptionPassphrase(passphrase); | 1169 sync_manager_->GetEncryptionHandler()->SetDecryptionPassphrase( |
1170 passphrase); | |
1136 } | 1171 } |
1137 | 1172 |
1138 void SyncBackendHost::Core::DoEnableEncryptEverything() { | 1173 void SyncBackendHost::Core::DoEnableEncryptEverything() { |
1139 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1174 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
1140 sync_manager_->EnableEncryptEverything(); | 1175 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 } | 1176 } |
1150 | 1177 |
1151 void SyncBackendHost::Core::DoStopSyncManagerForShutdown( | 1178 void SyncBackendHost::Core::DoStopSyncManagerForShutdown( |
1152 const base::Closure& closure) { | 1179 const base::Closure& closure) { |
1153 if (sync_manager_.get()) { | 1180 if (sync_manager_.get()) { |
1154 sync_manager_->StopSyncingForShutdown(closure); | 1181 sync_manager_->StopSyncingForShutdown(closure); |
1155 } else { | 1182 } else { |
1156 sync_loop_->PostTask(FROM_HERE, closure); | 1183 sync_loop_->PostTask(FROM_HERE, closure); |
1157 } | 1184 } |
1158 } | 1185 } |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1248 } | 1275 } |
1249 | 1276 |
1250 void SyncBackendHost::Core::SaveChanges() { | 1277 void SyncBackendHost::Core::SaveChanges() { |
1251 DCHECK_EQ(MessageLoop::current(), sync_loop_); | 1278 DCHECK_EQ(MessageLoop::current(), sync_loop_); |
1252 sync_manager_->SaveChanges(); | 1279 sync_manager_->SaveChanges(); |
1253 } | 1280 } |
1254 | 1281 |
1255 void SyncBackendHost::AddExperimentalTypes() { | 1282 void SyncBackendHost::AddExperimentalTypes() { |
1256 CHECK(initialized()); | 1283 CHECK(initialized()); |
1257 syncer::Experiments experiments; | 1284 syncer::Experiments experiments; |
1258 if (core_->sync_manager()->ReceivedExperiment(&experiments)) | 1285 if (core_->nigori_processor()->ReceivedExperiments(&experiments)) |
1259 frontend_->OnExperimentsChanged(experiments); | 1286 frontend_->OnExperimentsChanged(experiments); |
1260 } | 1287 } |
1261 | 1288 |
1262 void SyncBackendHost::OnNigoriDownloadRetry() { | 1289 void SyncBackendHost::OnNigoriDownloadRetry() { |
1263 DCHECK_EQ(MessageLoop::current(), frontend_loop_); | 1290 DCHECK_EQ(MessageLoop::current(), frontend_loop_); |
1264 if (!frontend_) | 1291 if (!frontend_) |
1265 return; | 1292 return; |
1266 | 1293 |
1267 frontend_->OnSyncConfigureRetry(); | 1294 frontend_->OnSyncConfigureRetry(); |
1268 } | 1295 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1306 &SyncBackendHost:: | 1333 &SyncBackendHost:: |
1307 HandleNigoriConfigurationCompletedOnFrontendLoop, | 1334 HandleNigoriConfigurationCompletedOnFrontendLoop, |
1308 weak_ptr_factory_.GetWeakPtr(), js_backend), | 1335 weak_ptr_factory_.GetWeakPtr(), js_backend), |
1309 base::Bind(&SyncBackendHost::OnNigoriDownloadRetry, | 1336 base::Bind(&SyncBackendHost::OnNigoriDownloadRetry, |
1310 weak_ptr_factory_.GetWeakPtr())); | 1337 weak_ptr_factory_.GetWeakPtr())); |
1311 break; | 1338 break; |
1312 case DOWNLOADING_NIGORI: | 1339 case DOWNLOADING_NIGORI: |
1313 initialization_state_ = REFRESHING_NIGORI; | 1340 initialization_state_ = REFRESHING_NIGORI; |
1314 // Triggers OnEncryptedTypesChanged() and OnEncryptionComplete() | 1341 // Triggers OnEncryptedTypesChanged() and OnEncryptionComplete() |
1315 // if necessary. | 1342 // if necessary. |
1316 RefreshNigori( | 1343 AssociateNigori( |
1317 base::Bind( | 1344 base::Bind( |
1318 &SyncBackendHost:: | 1345 &SyncBackendHost:: |
1319 HandleInitializationCompletedOnFrontendLoop, | 1346 HandleInitializationCompletedOnFrontendLoop, |
1320 weak_ptr_factory_.GetWeakPtr(), js_backend, true)); | 1347 weak_ptr_factory_.GetWeakPtr(), js_backend, true)); |
1321 break; | 1348 break; |
1322 case REFRESHING_NIGORI: | 1349 case REFRESHING_NIGORI: |
1323 initialization_state_ = INITIALIZED; | 1350 initialization_state_ = INITIALIZED; |
1324 // Now that we've downloaded the nigori node, we can see if there are any | 1351 // 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 | 1352 // experimental types to enable. This should be done before we inform |
1326 // the frontend to ensure they're visible in the customize screen. | 1353 // the frontend to ensure they're visible in the customize screen. |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1406 } | 1433 } |
1407 | 1434 |
1408 bool SyncBackendHost::CheckPassphraseAgainstCachedPendingKeys( | 1435 bool SyncBackendHost::CheckPassphraseAgainstCachedPendingKeys( |
1409 const std::string& passphrase) const { | 1436 const std::string& passphrase) const { |
1410 DCHECK(cached_pending_keys_.has_blob()); | 1437 DCHECK(cached_pending_keys_.has_blob()); |
1411 DCHECK(!passphrase.empty()); | 1438 DCHECK(!passphrase.empty()); |
1412 syncer::Nigori nigori; | 1439 syncer::Nigori nigori; |
1413 nigori.InitByDerivation("localhost", "dummy", passphrase); | 1440 nigori.InitByDerivation("localhost", "dummy", passphrase); |
1414 std::string plaintext; | 1441 std::string plaintext; |
1415 bool result = nigori.Decrypt(cached_pending_keys_.blob(), &plaintext); | 1442 bool result = nigori.Decrypt(cached_pending_keys_.blob(), &plaintext); |
1443 DVLOG_IF(1, result) << "Passphrase failed to decrypt pending keys."; | |
1416 return result; | 1444 return result; |
1417 } | 1445 } |
1418 | 1446 |
1419 void SyncBackendHost::NotifyPassphraseRequired( | 1447 void SyncBackendHost::NotifyPassphraseRequired( |
1420 syncer::PassphraseRequiredReason reason, | 1448 syncer::PassphraseRequiredReason reason, |
1421 sync_pb::EncryptedData pending_keys) { | 1449 sync_pb::EncryptedData pending_keys) { |
1422 if (!frontend_) | 1450 if (!frontend_) |
1423 return; | 1451 return; |
1424 | 1452 |
1425 DCHECK_EQ(MessageLoop::current(), frontend_loop_); | 1453 DCHECK_EQ(MessageLoop::current(), frontend_loop_); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1496 | 1524 |
1497 // Needed because MessageLoop::PostTask is overloaded. | 1525 // Needed because MessageLoop::PostTask is overloaded. |
1498 void PostClosure(MessageLoop* message_loop, | 1526 void PostClosure(MessageLoop* message_loop, |
1499 const tracked_objects::Location& from_here, | 1527 const tracked_objects::Location& from_here, |
1500 const base::Closure& callback) { | 1528 const base::Closure& callback) { |
1501 message_loop->PostTask(from_here, callback); | 1529 message_loop->PostTask(from_here, callback); |
1502 } | 1530 } |
1503 | 1531 |
1504 } // namespace | 1532 } // namespace |
1505 | 1533 |
1506 void SyncBackendHost::RefreshNigori(const base::Closure& done_callback) { | 1534 void SyncBackendHost::AssociateNigori( |
1535 const base::Closure& done_callback) { | |
1507 DCHECK_EQ(MessageLoop::current(), frontend_loop_); | 1536 DCHECK_EQ(MessageLoop::current(), frontend_loop_); |
1508 base::Closure sync_thread_done_callback = | 1537 base::Closure sync_thread_done_callback = |
1509 base::Bind(&PostClosure, | 1538 base::Bind(&PostClosure, |
1510 MessageLoop::current(), FROM_HERE, done_callback); | 1539 MessageLoop::current(), FROM_HERE, done_callback); |
1511 sync_thread_.message_loop()->PostTask( | 1540 sync_thread_.message_loop()->PostTask( |
1512 FROM_HERE, | 1541 FROM_HERE, |
1513 base::Bind(&SyncBackendHost::Core::DoRefreshNigori, | 1542 base::Bind(&SyncBackendHost::Core::DoAssociateNigori, |
1514 core_.get(), sync_thread_done_callback)); | 1543 core_.get(), sync_thread_done_callback)); |
1515 } | 1544 } |
1516 | 1545 |
1517 #undef SDVLOG | 1546 #undef SDVLOG |
1518 | 1547 |
1519 #undef SLOG | 1548 #undef SLOG |
1520 | 1549 |
1521 } // namespace browser_sync | 1550 } // namespace browser_sync |
OLD | NEW |