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

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

Issue 10827266: [Sync] Add SyncEncryptionHandler (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 71
72 // Helper macros to log with the syncer thread name; useful when there 72 // Helper macros to log with the syncer thread name; useful when there
73 // are multiple syncers involved. 73 // are multiple syncers involved.
74 74
75 #define SLOG(severity) LOG(severity) << name_ << ": " 75 #define SLOG(severity) LOG(severity) << name_ << ": "
76 76
77 #define SDVLOG(verbose_level) DVLOG(verbose_level) << name_ << ": " 77 #define SDVLOG(verbose_level) DVLOG(verbose_level) << name_ << ": "
78 78
79 class SyncBackendHost::Core 79 class SyncBackendHost::Core
80 : public base::RefCountedThreadSafe<SyncBackendHost::Core>, 80 : public base::RefCountedThreadSafe<SyncBackendHost::Core>,
81 public syncer::SyncEncryptionHandler::Observer,
81 public syncer::SyncManager::Observer, 82 public syncer::SyncManager::Observer,
82 public syncer::SyncNotifierObserver { 83 public syncer::SyncNotifierObserver {
83 public: 84 public:
84 Core(const std::string& name, 85 Core(const std::string& name,
85 const FilePath& sync_data_folder_path, 86 const FilePath& sync_data_folder_path,
86 const base::WeakPtr<SyncBackendHost>& backend); 87 const base::WeakPtr<SyncBackendHost>& backend);
87 88
88 // SyncManager::Observer implementation. The Core just acts like an air 89 // SyncManager::Observer implementation. The Core just acts like an air
89 // traffic controller here, forwarding incoming messages to appropriate 90 // traffic controller here, forwarding incoming messages to appropriate
90 // landing threads. 91 // landing threads.
91 virtual void OnSyncCycleCompleted( 92 virtual void OnSyncCycleCompleted(
92 const syncer::sessions::SyncSessionSnapshot& snapshot) OVERRIDE; 93 const syncer::sessions::SyncSessionSnapshot& snapshot) OVERRIDE;
93 virtual void OnInitializationComplete( 94 virtual void OnInitializationComplete(
94 const syncer::WeakHandle<syncer::JsBackend>& js_backend, 95 const syncer::WeakHandle<syncer::JsBackend>& js_backend,
95 bool success, 96 bool success,
96 syncer::ModelTypeSet restored_types) OVERRIDE; 97 syncer::ModelTypeSet restored_types) OVERRIDE;
97 virtual void OnConnectionStatusChange( 98 virtual void OnConnectionStatusChange(
98 syncer::ConnectionStatus status) OVERRIDE; 99 syncer::ConnectionStatus status) OVERRIDE;
100 virtual void OnStopSyncingPermanently() OVERRIDE;
101 virtual void OnUpdatedToken(const std::string& token) OVERRIDE;
102 virtual void OnActionableError(
103 const syncer::SyncProtocolError& sync_error) OVERRIDE;
104
105 // SyncEncryptionHandler::Observer implementation.
99 virtual void OnPassphraseRequired( 106 virtual void OnPassphraseRequired(
100 syncer::PassphraseRequiredReason reason, 107 syncer::PassphraseRequiredReason reason,
101 const sync_pb::EncryptedData& pending_keys) OVERRIDE; 108 const sync_pb::EncryptedData& pending_keys) OVERRIDE;
102 virtual void OnPassphraseAccepted() OVERRIDE; 109 virtual void OnPassphraseAccepted() OVERRIDE;
103 virtual void OnBootstrapTokenUpdated( 110 virtual void OnBootstrapTokenUpdated(
104 const std::string& bootstrap_token) OVERRIDE; 111 const std::string& bootstrap_token) OVERRIDE;
105 virtual void OnStopSyncingPermanently() OVERRIDE;
106 virtual void OnUpdatedToken(const std::string& token) OVERRIDE;
107 virtual void OnEncryptedTypesChanged( 112 virtual void OnEncryptedTypesChanged(
108 syncer::ModelTypeSet encrypted_types, 113 syncer::ModelTypeSet encrypted_types,
109 bool encrypt_everything) OVERRIDE; 114 bool encrypt_everything) OVERRIDE;
110 virtual void OnEncryptionComplete() OVERRIDE; 115 virtual void OnEncryptionComplete() OVERRIDE;
111 virtual void OnActionableError( 116 virtual void OnCryptographerStateChanged(
112 const syncer::SyncProtocolError& sync_error) OVERRIDE; 117 syncer::Cryptographer* cryptographer) OVERRIDE;
113 118
114 // syncer::SyncNotifierObserver implementation. 119 // syncer::SyncNotifierObserver implementation.
115 virtual void OnNotificationsEnabled() OVERRIDE; 120 virtual void OnNotificationsEnabled() OVERRIDE;
116 virtual void OnNotificationsDisabled( 121 virtual void OnNotificationsDisabled(
117 syncer::NotificationsDisabledReason reason) OVERRIDE; 122 syncer::NotificationsDisabledReason reason) OVERRIDE;
118 virtual void OnIncomingNotification( 123 virtual void OnIncomingNotification(
119 const syncer::ObjectIdPayloadMap& id_payloads, 124 const syncer::ObjectIdPayloadMap& id_payloads,
120 syncer::IncomingNotificationSource source) OVERRIDE; 125 syncer::IncomingNotificationSource source) OVERRIDE;
121 126
122 // Note: 127 // Note:
(...skipping 23 matching lines...) Expand all
146 void DoSetEncryptionPassphrase(const std::string& passphrase, 151 void DoSetEncryptionPassphrase(const std::string& passphrase,
147 bool is_explicit); 152 bool is_explicit);
148 153
149 // Called to decrypt the pending keys. 154 // Called to decrypt the pending keys.
150 void DoSetDecryptionPassphrase(const std::string& passphrase); 155 void DoSetDecryptionPassphrase(const std::string& passphrase);
151 156
152 // Called to turn on encryption of all sync data as well as 157 // Called to turn on encryption of all sync data as well as
153 // reencrypt everything. 158 // reencrypt everything.
154 void DoEnableEncryptEverything(); 159 void DoEnableEncryptEverything();
155 160
156 // Called to refresh encryption with the most recent passphrase 161 // Called to load sync encryption state and re-encrypt any types
157 // and set of encrypted types. Also adds device information to the nigori 162 // needing encryption as necessary.
158 // node. |done_callback| is called on the sync thread. 163 void DoAssociateNigori();
159 void DoRefreshNigori(const base::Closure& done_callback);
160 164
161 // The shutdown order is a bit complicated: 165 // The shutdown order is a bit complicated:
162 // 1) From |sync_thread_|, invoke the syncapi Shutdown call to do 166 // 1) From |sync_thread_|, invoke the syncapi Shutdown call to do
163 // a final SaveChanges, and close sqlite handles. 167 // a final SaveChanges, and close sqlite handles.
164 // 2) Then, from |frontend_loop_|, halt the sync_thread_ (which is 168 // 2) Then, from |frontend_loop_|, halt the sync_thread_ (which is
165 // a blocking call). This causes syncapi thread-exit handlers 169 // a blocking call). This causes syncapi thread-exit handlers
166 // to run and make use of cached pointers to various components 170 // to run and make use of cached pointers to various components
167 // owned implicitly by us. 171 // owned implicitly by us.
168 // 3) Destroy this Core. That will delete syncapi components in a 172 // 3) Destroy this Core. That will delete syncapi components in a
169 // safe order because the thread that was using them has exited 173 // safe order because the thread that was using them has exited
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 { 635 {
632 base::ThreadRestrictions::ScopedAllowIO allow_io; 636 base::ThreadRestrictions::ScopedAllowIO allow_io;
633 sync_thread_.Stop(); 637 sync_thread_.Stop();
634 } 638 }
635 base::TimeDelta stop_sync_thread_time = base::Time::Now() - 639 base::TimeDelta stop_sync_thread_time = base::Time::Now() -
636 stop_thread_start_time; 640 stop_thread_start_time;
637 UMA_HISTOGRAM_TIMES("Sync.Shutdown.StopSyncThreadTime", 641 UMA_HISTOGRAM_TIMES("Sync.Shutdown.StopSyncThreadTime",
638 stop_sync_thread_time); 642 stop_sync_thread_time);
639 643
640 registrar_.reset(); 644 registrar_.reset();
645 js_backend_.Reset();
641 chrome_sync_notification_bridge_.reset(); 646 chrome_sync_notification_bridge_.reset();
642 core_ = NULL; // Releases reference to core_. 647 core_ = NULL; // Releases reference to core_.
643 } 648 }
644 649
645 void SyncBackendHost::ConfigureDataTypes( 650 void SyncBackendHost::ConfigureDataTypes(
646 syncer::ConfigureReason reason, 651 syncer::ConfigureReason reason,
647 syncer::ModelTypeSet types_to_add, 652 syncer::ModelTypeSet types_to_add,
648 syncer::ModelTypeSet types_to_remove, 653 syncer::ModelTypeSet types_to_remove,
649 const base::Callback<void(syncer::ModelTypeSet)>& ready_task, 654 const base::Callback<void(syncer::ModelTypeSet)>& ready_task,
650 const base::Callback<void()>& retry_callback) { 655 const base::Callback<void()>& retry_callback) {
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
750 755
751 bool SyncBackendHost::IsNigoriEnabled() const { 756 bool SyncBackendHost::IsNigoriEnabled() const {
752 return registrar_.get() && registrar_->IsNigoriEnabled(); 757 return registrar_.get() && registrar_->IsNigoriEnabled();
753 } 758 }
754 759
755 bool SyncBackendHost::IsUsingExplicitPassphrase() { 760 bool SyncBackendHost::IsUsingExplicitPassphrase() {
756 // This should only be called once the nigori node has been downloaded, as 761 // This should only be called once the nigori node has been downloaded, as
757 // otherwise we have no idea what kind of passphrase we are using. This will 762 // otherwise we have no idea what kind of passphrase we are using. This will
758 // NOTREACH in sync_manager and return false if we fail to load the nigori 763 // NOTREACH in sync_manager and return false if we fail to load the nigori
759 // node. 764 // node.
765 // TODO(zea): cache this value here, then make the encryption handler
766 // NonThreadSafe and only accessible from the sync thread.
760 return IsNigoriEnabled() && 767 return IsNigoriEnabled() &&
761 core_->sync_manager()->IsUsingExplicitPassphrase(); 768 core_->sync_manager()->GetEncryptionHandler()->
769 IsUsingExplicitPassphrase();
762 } 770 }
763 771
764 bool SyncBackendHost::IsCryptographerReady( 772 bool SyncBackendHost::IsCryptographerReady(
765 const syncer::BaseTransaction* trans) const { 773 const syncer::BaseTransaction* trans) const {
766 return initialized() && trans->GetCryptographer()->is_ready(); 774 return initialized() && trans->GetCryptographer()->is_ready();
767 } 775 }
768 776
769 void SyncBackendHost::GetModelSafeRoutingInfo( 777 void SyncBackendHost::GetModelSafeRoutingInfo(
770 syncer::ModelSafeRoutingInfo* out) const { 778 syncer::ModelSafeRoutingInfo* out) const {
771 if (initialized()) { 779 if (initialized()) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
804 return; 812 return;
805 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 813 DCHECK_EQ(MessageLoop::current(), frontend_loop_);
806 if (!ready_task.is_null()) 814 if (!ready_task.is_null())
807 ready_task.Run(failed_configuration_types); 815 ready_task.Run(failed_configuration_types);
808 } 816 }
809 817
810 void SyncBackendHost::HandleSyncManagerInitializationOnFrontendLoop( 818 void SyncBackendHost::HandleSyncManagerInitializationOnFrontendLoop(
811 const syncer::WeakHandle<syncer::JsBackend>& js_backend, bool success, 819 const syncer::WeakHandle<syncer::JsBackend>& js_backend, bool success,
812 syncer::ModelTypeSet restored_types) { 820 syncer::ModelTypeSet restored_types) {
813 registrar_->SetInitialTypes(restored_types); 821 registrar_->SetInitialTypes(restored_types);
814 HandleInitializationCompletedOnFrontendLoop(js_backend, success); 822 DCHECK(!js_backend_.IsInitialized());
823 js_backend_ = js_backend;
824 HandleInitializationCompletedOnFrontendLoop(success);
815 } 825 }
816 826
817 SyncBackendHost::DoInitializeOptions::DoInitializeOptions( 827 SyncBackendHost::DoInitializeOptions::DoInitializeOptions(
818 MessageLoop* sync_loop, 828 MessageLoop* sync_loop,
819 SyncBackendRegistrar* registrar, 829 SyncBackendRegistrar* registrar,
820 const syncer::ModelSafeRoutingInfo& routing_info, 830 const syncer::ModelSafeRoutingInfo& routing_info,
821 const std::vector<syncer::ModelSafeWorker*>& workers, 831 const std::vector<syncer::ModelSafeWorker*>& workers,
822 syncer::ExtensionsActivityMonitor* extensions_activity_monitor, 832 syncer::ExtensionsActivityMonitor* extensions_activity_monitor,
823 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler, 833 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler,
824 const GURL& service_url, 834 const GURL& service_url,
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
1003 void SyncBackendHost::Core::OnEncryptionComplete() { 1013 void SyncBackendHost::Core::OnEncryptionComplete() {
1004 if (!sync_loop_) 1014 if (!sync_loop_)
1005 return; 1015 return;
1006 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1016 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1007 // NOTE: We're in a transaction. 1017 // NOTE: We're in a transaction.
1008 host_.Call( 1018 host_.Call(
1009 FROM_HERE, 1019 FROM_HERE,
1010 &SyncBackendHost::NotifyEncryptionComplete); 1020 &SyncBackendHost::NotifyEncryptionComplete);
1011 } 1021 }
1012 1022
1023 void SyncBackendHost::Core::OnCryptographerStateChanged(
1024 syncer::Cryptographer* cryptographer) {
1025 // Do nothing.
1026 }
1027
1013 void SyncBackendHost::Core::OnActionableError( 1028 void SyncBackendHost::Core::OnActionableError(
1014 const syncer::SyncProtocolError& sync_error) { 1029 const syncer::SyncProtocolError& sync_error) {
1015 if (!sync_loop_) 1030 if (!sync_loop_)
1016 return; 1031 return;
1017 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1032 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1018 host_.Call( 1033 host_.Call(
1019 FROM_HERE, 1034 FROM_HERE,
1020 &SyncBackendHost::HandleActionableErrorEventOnFrontendLoop, 1035 &SyncBackendHost::HandleActionableErrorEventOnFrontendLoop,
1021 sync_error); 1036 sync_error);
1022 } 1037 }
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
1139 sync_manager_->UpdateRegisteredInvalidationIds(this, ids); 1154 sync_manager_->UpdateRegisteredInvalidationIds(this, ids);
1140 } 1155 }
1141 } 1156 }
1142 1157
1143 void SyncBackendHost::Core::DoStartSyncing( 1158 void SyncBackendHost::Core::DoStartSyncing(
1144 const syncer::ModelSafeRoutingInfo& routing_info) { 1159 const syncer::ModelSafeRoutingInfo& routing_info) {
1145 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1160 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1146 sync_manager_->StartSyncingNormally(routing_info); 1161 sync_manager_->StartSyncingNormally(routing_info);
1147 } 1162 }
1148 1163
1164 void SyncBackendHost::Core::DoAssociateNigori() {
1165 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1166 sync_manager_->GetEncryptionHandler()->AddObserver(this);
1167 sync_manager_->GetEncryptionHandler()->Init();
1168 host_.Call(FROM_HERE,
1169 &SyncBackendHost::HandleInitializationCompletedOnFrontendLoop,
1170 true);
1171 }
1172
1149 void SyncBackendHost::Core::DoSetEncryptionPassphrase( 1173 void SyncBackendHost::Core::DoSetEncryptionPassphrase(
1150 const std::string& passphrase, 1174 const std::string& passphrase,
1151 bool is_explicit) { 1175 bool is_explicit) {
1152 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1176 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1153 sync_manager_->SetEncryptionPassphrase(passphrase, is_explicit); 1177 sync_manager_->GetEncryptionHandler()->SetEncryptionPassphrase(
1178 passphrase, is_explicit);
1154 } 1179 }
1155 1180
1156 void SyncBackendHost::Core::DoSetDecryptionPassphrase( 1181 void SyncBackendHost::Core::DoSetDecryptionPassphrase(
1157 const std::string& passphrase) { 1182 const std::string& passphrase) {
1158 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1183 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1159 sync_manager_->SetDecryptionPassphrase(passphrase); 1184 sync_manager_->GetEncryptionHandler()->SetDecryptionPassphrase(
1185 passphrase);
1160 } 1186 }
1161 1187
1162 void SyncBackendHost::Core::DoEnableEncryptEverything() { 1188 void SyncBackendHost::Core::DoEnableEncryptEverything() {
1163 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1189 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1164 sync_manager_->EnableEncryptEverything(); 1190 sync_manager_->GetEncryptionHandler()->EnableEncryptEverything();
1165 }
1166
1167 void SyncBackendHost::Core::DoRefreshNigori(
1168 const base::Closure& done_callback) {
1169 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1170 chrome::VersionInfo version_info;
1171 sync_manager_->RefreshNigori(version_info.CreateVersionString(),
1172 done_callback);
1173 } 1191 }
1174 1192
1175 void SyncBackendHost::Core::DoStopSyncManagerForShutdown( 1193 void SyncBackendHost::Core::DoStopSyncManagerForShutdown(
1176 const base::Closure& closure) { 1194 const base::Closure& closure) {
1177 if (sync_manager_.get()) { 1195 if (sync_manager_.get()) {
1178 sync_manager_->StopSyncingForShutdown(closure); 1196 sync_manager_->StopSyncingForShutdown(closure);
1179 } else { 1197 } else {
1180 sync_loop_->PostTask(FROM_HERE, closure); 1198 sync_loop_->PostTask(FROM_HERE, closure);
1181 } 1199 }
1182 } 1200 }
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
1292 1310
1293 void SyncBackendHost::OnNigoriDownloadRetry() { 1311 void SyncBackendHost::OnNigoriDownloadRetry() {
1294 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 1312 DCHECK_EQ(MessageLoop::current(), frontend_loop_);
1295 if (!frontend_) 1313 if (!frontend_)
1296 return; 1314 return;
1297 1315
1298 frontend_->OnSyncConfigureRetry(); 1316 frontend_->OnSyncConfigureRetry();
1299 } 1317 }
1300 1318
1301 void SyncBackendHost::HandleInitializationCompletedOnFrontendLoop( 1319 void SyncBackendHost::HandleInitializationCompletedOnFrontendLoop(
1302 const syncer::WeakHandle<syncer::JsBackend>& js_backend, bool success) { 1320 bool success) {
1303 DCHECK_NE(initialization_state_, NOT_ATTEMPTED); 1321 DCHECK_NE(initialization_state_, NOT_ATTEMPTED);
1304 if (!frontend_) 1322 if (!frontend_)
1305 return; 1323 return;
1306 1324
1307 // We've at least created the sync manager at this point, but if that is all 1325 // We've at least created the sync manager at this point, but if that is all
1308 // we've done we're just beginning the initialization process. 1326 // we've done we're just beginning the initialization process.
1309 if (initialization_state_ == CREATING_SYNC_MANAGER) 1327 if (initialization_state_ == CREATING_SYNC_MANAGER)
1310 initialization_state_ = NOT_INITIALIZED; 1328 initialization_state_ = NOT_INITIALIZED;
1311 1329
1312 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 1330 DCHECK_EQ(MessageLoop::current(), frontend_loop_);
1313 if (!success) { 1331 if (!success) {
1332 js_backend_.Reset();
1314 initialization_state_ = NOT_INITIALIZED; 1333 initialization_state_ = NOT_INITIALIZED;
1315 frontend_->OnBackendInitialized( 1334 frontend_->OnBackendInitialized(
1316 syncer::WeakHandle<syncer::JsBackend>(), false); 1335 syncer::WeakHandle<syncer::JsBackend>(), false);
1317 return; 1336 return;
1318 } 1337 }
1319 1338
1320 // Run initialization state machine. 1339 // Run initialization state machine.
1321 switch (initialization_state_) { 1340 switch (initialization_state_) {
1322 case NOT_INITIALIZED: 1341 case NOT_INITIALIZED:
1323 // This configuration should result in a download request if the nigori 1342 // This configuration should result in a download request if the nigori
1324 // type's initial_sync_ended bit is unset. If the download request 1343 // type's initial_sync_ended bit is unset. If the download request
1325 // contains progress markers, there is a risk that the server will try to 1344 // contains progress markers, there is a risk that the server will try to
1326 // trigger migration. That would be disastrous, so we must rely on the 1345 // trigger migration. That would be disastrous, so we must rely on the
1327 // sync manager to ensure that this type never has both progress markers 1346 // sync manager to ensure that this type never has both progress markers
1328 // and !initial_sync_ended. 1347 // and !initial_sync_ended.
1329 initialization_state_ = DOWNLOADING_NIGORI; 1348 initialization_state_ = DOWNLOADING_NIGORI;
1330 ConfigureDataTypes( 1349 ConfigureDataTypes(
1331 syncer::CONFIGURE_REASON_NEW_CLIENT, 1350 syncer::CONFIGURE_REASON_NEW_CLIENT,
1332 syncer::ModelTypeSet(syncer::NIGORI), 1351 syncer::ModelTypeSet(syncer::NIGORI),
1333 syncer::ModelTypeSet(), 1352 syncer::ModelTypeSet(),
1334 // Calls back into this function. 1353 // Calls back into this function.
1335 base::Bind( 1354 base::Bind(
1336 &SyncBackendHost:: 1355 &SyncBackendHost::
1337 HandleNigoriConfigurationCompletedOnFrontendLoop, 1356 HandleNigoriConfigurationCompletedOnFrontendLoop,
1338 weak_ptr_factory_.GetWeakPtr(), js_backend), 1357 weak_ptr_factory_.GetWeakPtr()),
1339 base::Bind(&SyncBackendHost::OnNigoriDownloadRetry, 1358 base::Bind(&SyncBackendHost::OnNigoriDownloadRetry,
1340 weak_ptr_factory_.GetWeakPtr())); 1359 weak_ptr_factory_.GetWeakPtr()));
1341 break; 1360 break;
1342 case DOWNLOADING_NIGORI: 1361 case DOWNLOADING_NIGORI:
1343 initialization_state_ = REFRESHING_NIGORI; 1362 initialization_state_ = ASSOCIATING_NIGORI;
1344 // Triggers OnEncryptedTypesChanged() and OnEncryptionComplete() 1363 // Triggers OnEncryptedTypesChanged() and OnEncryptionComplete()
1345 // if necessary. 1364 // if necessary.
1346 RefreshNigori( 1365 sync_thread_.message_loop()->PostTask(
1347 base::Bind( 1366 FROM_HERE,
1348 &SyncBackendHost:: 1367 base::Bind(&SyncBackendHost::Core::DoAssociateNigori,
1349 HandleInitializationCompletedOnFrontendLoop, 1368 core_.get()));
1350 weak_ptr_factory_.GetWeakPtr(), js_backend, true));
1351 break; 1369 break;
1352 case REFRESHING_NIGORI: 1370 case ASSOCIATING_NIGORI:
1353 initialization_state_ = INITIALIZED; 1371 initialization_state_ = INITIALIZED;
1354 // Now that we've downloaded the nigori node, we can see if there are any 1372 // Now that we've downloaded the nigori node, we can see if there are any
1355 // experimental types to enable. This should be done before we inform 1373 // experimental types to enable. This should be done before we inform
1356 // the frontend to ensure they're visible in the customize screen. 1374 // the frontend to ensure they're visible in the customize screen.
1357 AddExperimentalTypes(); 1375 AddExperimentalTypes();
1358 frontend_->OnBackendInitialized(js_backend, true); 1376 frontend_->OnBackendInitialized(js_backend_, true);
1377 js_backend_.Reset();
1359 break; 1378 break;
1360 default: 1379 default:
1361 NOTREACHED(); 1380 NOTREACHED();
1362 } 1381 }
1363 } 1382 }
1364 1383
1365 void SyncBackendHost::HandleSyncCycleCompletedOnFrontendLoop( 1384 void SyncBackendHost::HandleSyncCycleCompletedOnFrontendLoop(
1366 const SyncSessionSnapshot& snapshot) { 1385 const SyncSessionSnapshot& snapshot) {
1367 if (!frontend_) 1386 if (!frontend_)
1368 return; 1387 return;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1436 } 1455 }
1437 1456
1438 bool SyncBackendHost::CheckPassphraseAgainstCachedPendingKeys( 1457 bool SyncBackendHost::CheckPassphraseAgainstCachedPendingKeys(
1439 const std::string& passphrase) const { 1458 const std::string& passphrase) const {
1440 DCHECK(cached_pending_keys_.has_blob()); 1459 DCHECK(cached_pending_keys_.has_blob());
1441 DCHECK(!passphrase.empty()); 1460 DCHECK(!passphrase.empty());
1442 syncer::Nigori nigori; 1461 syncer::Nigori nigori;
1443 nigori.InitByDerivation("localhost", "dummy", passphrase); 1462 nigori.InitByDerivation("localhost", "dummy", passphrase);
1444 std::string plaintext; 1463 std::string plaintext;
1445 bool result = nigori.Decrypt(cached_pending_keys_.blob(), &plaintext); 1464 bool result = nigori.Decrypt(cached_pending_keys_.blob(), &plaintext);
1465 DVLOG_IF(1, result) << "Passphrase failed to decrypt pending keys.";
1446 return result; 1466 return result;
1447 } 1467 }
1448 1468
1449 void SyncBackendHost::NotifyPassphraseRequired( 1469 void SyncBackendHost::NotifyPassphraseRequired(
1450 syncer::PassphraseRequiredReason reason, 1470 syncer::PassphraseRequiredReason reason,
1451 sync_pb::EncryptedData pending_keys) { 1471 sync_pb::EncryptedData pending_keys) {
1452 if (!frontend_) 1472 if (!frontend_)
1453 return; 1473 return;
1454 1474
1455 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 1475 DCHECK_EQ(MessageLoop::current(), frontend_loop_);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1509 syncer::ConnectionStatus status) { 1529 syncer::ConnectionStatus status) {
1510 if (!frontend_) 1530 if (!frontend_)
1511 return; 1531 return;
1512 1532
1513 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 1533 DCHECK_EQ(MessageLoop::current(), frontend_loop_);
1514 1534
1515 frontend_->OnConnectionStatusChange(status); 1535 frontend_->OnConnectionStatusChange(status);
1516 } 1536 }
1517 1537
1518 void SyncBackendHost::HandleNigoriConfigurationCompletedOnFrontendLoop( 1538 void SyncBackendHost::HandleNigoriConfigurationCompletedOnFrontendLoop(
1519 const syncer::WeakHandle<syncer::JsBackend>& js_backend,
1520 const syncer::ModelTypeSet failed_configuration_types) { 1539 const syncer::ModelTypeSet failed_configuration_types) {
1521 HandleInitializationCompletedOnFrontendLoop( 1540 HandleInitializationCompletedOnFrontendLoop(
1522 js_backend, failed_configuration_types.Empty()); 1541 failed_configuration_types.Empty());
1523 }
1524
1525 namespace {
1526
1527 // Needed because MessageLoop::PostTask is overloaded.
1528 void PostClosure(MessageLoop* message_loop,
1529 const tracked_objects::Location& from_here,
1530 const base::Closure& callback) {
1531 message_loop->PostTask(from_here, callback);
1532 }
1533
1534 } // namespace
1535
1536 void SyncBackendHost::RefreshNigori(const base::Closure& done_callback) {
1537 DCHECK_EQ(MessageLoop::current(), frontend_loop_);
1538 base::Closure sync_thread_done_callback =
1539 base::Bind(&PostClosure,
1540 MessageLoop::current(), FROM_HERE, done_callback);
1541 sync_thread_.message_loop()->PostTask(
1542 FROM_HERE,
1543 base::Bind(&SyncBackendHost::Core::DoRefreshNigori,
1544 core_.get(), sync_thread_done_callback));
1545 } 1542 }
1546 1543
1547 #undef SDVLOG 1544 #undef SDVLOG
1548 1545
1549 #undef SLOG 1546 #undef SLOG
1550 1547
1551 } // namespace browser_sync 1548 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/glue/sync_backend_host.h ('k') | chrome/browser/sync/profile_sync_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698