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

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: Address comments 3 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 560 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 734
731 bool SyncBackendHost::IsNigoriEnabled() const { 735 bool SyncBackendHost::IsNigoriEnabled() const {
732 return registrar_.get() && registrar_->IsNigoriEnabled(); 736 return registrar_.get() && registrar_->IsNigoriEnabled();
733 } 737 }
734 738
735 bool SyncBackendHost::IsUsingExplicitPassphrase() { 739 bool SyncBackendHost::IsUsingExplicitPassphrase() {
736 // This should only be called once the nigori node has been downloaded, as 740 // 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 741 // 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 742 // NOTREACH in sync_manager and return false if we fail to load the nigori
739 // node. 743 // node.
744 // TODO(zea): cache this value here, then make the encryption handler
745 // NonThreadSafe and only accessible from the sync thread.
740 return IsNigoriEnabled() && 746 return IsNigoriEnabled() &&
741 core_->sync_manager()->IsUsingExplicitPassphrase(); 747 core_->sync_manager()->GetEncryptionHandler()->
748 IsUsingExplicitPassphrase();
742 } 749 }
743 750
744 bool SyncBackendHost::IsCryptographerReady( 751 bool SyncBackendHost::IsCryptographerReady(
745 const syncer::BaseTransaction* trans) const { 752 const syncer::BaseTransaction* trans) const {
746 return initialized() && trans->GetCryptographer()->is_ready(); 753 return initialized() && trans->GetCryptographer()->is_ready();
747 } 754 }
748 755
749 void SyncBackendHost::GetModelSafeRoutingInfo( 756 void SyncBackendHost::GetModelSafeRoutingInfo(
750 syncer::ModelSafeRoutingInfo* out) const { 757 syncer::ModelSafeRoutingInfo* out) const {
751 if (initialized()) { 758 if (initialized()) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 return; 791 return;
785 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 792 DCHECK_EQ(MessageLoop::current(), frontend_loop_);
786 if (!ready_task.is_null()) 793 if (!ready_task.is_null())
787 ready_task.Run(failed_configuration_types); 794 ready_task.Run(failed_configuration_types);
788 } 795 }
789 796
790 void SyncBackendHost::HandleSyncManagerInitializationOnFrontendLoop( 797 void SyncBackendHost::HandleSyncManagerInitializationOnFrontendLoop(
791 const syncer::WeakHandle<syncer::JsBackend>& js_backend, bool success, 798 const syncer::WeakHandle<syncer::JsBackend>& js_backend, bool success,
792 syncer::ModelTypeSet restored_types) { 799 syncer::ModelTypeSet restored_types) {
793 registrar_->SetInitialTypes(restored_types); 800 registrar_->SetInitialTypes(restored_types);
794 HandleInitializationCompletedOnFrontendLoop(js_backend, success); 801 DCHECK(!js_backend_.IsInitialized());
802 js_backend_ = js_backend;
803 HandleInitializationCompletedOnFrontendLoop(success);
795 } 804 }
796 805
797 SyncBackendHost::DoInitializeOptions::DoInitializeOptions( 806 SyncBackendHost::DoInitializeOptions::DoInitializeOptions(
798 MessageLoop* sync_loop, 807 MessageLoop* sync_loop,
799 SyncBackendRegistrar* registrar, 808 SyncBackendRegistrar* registrar,
800 const syncer::ModelSafeRoutingInfo& routing_info, 809 const syncer::ModelSafeRoutingInfo& routing_info,
801 const std::vector<syncer::ModelSafeWorker*>& workers, 810 const std::vector<syncer::ModelSafeWorker*>& workers,
802 syncer::ExtensionsActivityMonitor* extensions_activity_monitor, 811 syncer::ExtensionsActivityMonitor* extensions_activity_monitor,
803 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler, 812 const syncer::WeakHandle<syncer::JsEventHandler>& event_handler,
804 const GURL& service_url, 813 const GURL& service_url,
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
986 void SyncBackendHost::Core::OnEncryptionComplete() { 995 void SyncBackendHost::Core::OnEncryptionComplete() {
987 if (!sync_loop_) 996 if (!sync_loop_)
988 return; 997 return;
989 DCHECK_EQ(MessageLoop::current(), sync_loop_); 998 DCHECK_EQ(MessageLoop::current(), sync_loop_);
990 // NOTE: We're in a transaction. 999 // NOTE: We're in a transaction.
991 host_.Call( 1000 host_.Call(
992 FROM_HERE, 1001 FROM_HERE,
993 &SyncBackendHost::NotifyEncryptionComplete); 1002 &SyncBackendHost::NotifyEncryptionComplete);
994 } 1003 }
995 1004
1005 void SyncBackendHost::Core::OnCryptographerStateChanged(
1006 syncer::Cryptographer* cryptographer) {
1007 // Do nothing.
1008 }
1009
996 void SyncBackendHost::Core::OnActionableError( 1010 void SyncBackendHost::Core::OnActionableError(
997 const syncer::SyncProtocolError& sync_error) { 1011 const syncer::SyncProtocolError& sync_error) {
998 if (!sync_loop_) 1012 if (!sync_loop_)
999 return; 1013 return;
1000 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1014 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1001 host_.Call( 1015 host_.Call(
1002 FROM_HERE, 1016 FROM_HERE,
1003 &SyncBackendHost::HandleActionableErrorEventOnFrontendLoop, 1017 &SyncBackendHost::HandleActionableErrorEventOnFrontendLoop,
1004 sync_error); 1018 sync_error);
1005 } 1019 }
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
1115 sync_manager_->UpdateRegisteredInvalidationIds(this, ids); 1129 sync_manager_->UpdateRegisteredInvalidationIds(this, ids);
1116 } 1130 }
1117 } 1131 }
1118 1132
1119 void SyncBackendHost::Core::DoStartSyncing( 1133 void SyncBackendHost::Core::DoStartSyncing(
1120 const syncer::ModelSafeRoutingInfo& routing_info) { 1134 const syncer::ModelSafeRoutingInfo& routing_info) {
1121 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1135 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1122 sync_manager_->StartSyncingNormally(routing_info); 1136 sync_manager_->StartSyncingNormally(routing_info);
1123 } 1137 }
1124 1138
1139 void SyncBackendHost::Core::DoAssociateNigori() {
1140 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1141 sync_manager_->GetEncryptionHandler()->AddObserver(this);
1142 sync_manager_->GetEncryptionHandler()->Init();
1143 host_.Call(FROM_HERE,
1144 &SyncBackendHost::HandleInitializationCompletedOnFrontendLoop,
1145 true);
1146 }
1147
1125 void SyncBackendHost::Core::DoSetEncryptionPassphrase( 1148 void SyncBackendHost::Core::DoSetEncryptionPassphrase(
1126 const std::string& passphrase, 1149 const std::string& passphrase,
1127 bool is_explicit) { 1150 bool is_explicit) {
1128 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1151 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1129 sync_manager_->SetEncryptionPassphrase(passphrase, is_explicit); 1152 sync_manager_->GetEncryptionHandler()->SetEncryptionPassphrase(
1153 passphrase, is_explicit);
1130 } 1154 }
1131 1155
1132 void SyncBackendHost::Core::DoSetDecryptionPassphrase( 1156 void SyncBackendHost::Core::DoSetDecryptionPassphrase(
1133 const std::string& passphrase) { 1157 const std::string& passphrase) {
1134 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1158 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1135 sync_manager_->SetDecryptionPassphrase(passphrase); 1159 sync_manager_->GetEncryptionHandler()->SetDecryptionPassphrase(
1160 passphrase);
1136 } 1161 }
1137 1162
1138 void SyncBackendHost::Core::DoEnableEncryptEverything() { 1163 void SyncBackendHost::Core::DoEnableEncryptEverything() {
1139 DCHECK_EQ(MessageLoop::current(), sync_loop_); 1164 DCHECK_EQ(MessageLoop::current(), sync_loop_);
1140 sync_manager_->EnableEncryptEverything(); 1165 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 } 1166 }
1150 1167
1151 void SyncBackendHost::Core::DoStopSyncManagerForShutdown( 1168 void SyncBackendHost::Core::DoStopSyncManagerForShutdown(
1152 const base::Closure& closure) { 1169 const base::Closure& closure) {
1153 if (sync_manager_.get()) { 1170 if (sync_manager_.get()) {
1154 sync_manager_->StopSyncingForShutdown(closure); 1171 sync_manager_->StopSyncingForShutdown(closure);
1155 } else { 1172 } else {
1156 sync_loop_->PostTask(FROM_HERE, closure); 1173 sync_loop_->PostTask(FROM_HERE, closure);
1157 } 1174 }
1158 } 1175 }
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1261 1278
1262 void SyncBackendHost::OnNigoriDownloadRetry() { 1279 void SyncBackendHost::OnNigoriDownloadRetry() {
1263 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 1280 DCHECK_EQ(MessageLoop::current(), frontend_loop_);
1264 if (!frontend_) 1281 if (!frontend_)
1265 return; 1282 return;
1266 1283
1267 frontend_->OnSyncConfigureRetry(); 1284 frontend_->OnSyncConfigureRetry();
1268 } 1285 }
1269 1286
1270 void SyncBackendHost::HandleInitializationCompletedOnFrontendLoop( 1287 void SyncBackendHost::HandleInitializationCompletedOnFrontendLoop(
1271 const syncer::WeakHandle<syncer::JsBackend>& js_backend, bool success) { 1288 bool success) {
1272 DCHECK_NE(NOT_ATTEMPTED, initialization_state_); 1289 DCHECK_NE(NOT_ATTEMPTED, initialization_state_);
1290 DCHECK(js_backend_.IsInitialized());
1273 if (!frontend_) 1291 if (!frontend_)
1274 return; 1292 return;
1275 1293
1276 // We've at least created the sync manager at this point, but if that is all 1294 // We've at least created the sync manager at this point, but if that is all
1277 // we've done we're just beginning the initialization process. 1295 // we've done we're just beginning the initialization process.
1278 if (initialization_state_ == CREATING_SYNC_MANAGER) 1296 if (initialization_state_ == CREATING_SYNC_MANAGER)
1279 initialization_state_ = NOT_INITIALIZED; 1297 initialization_state_ = NOT_INITIALIZED;
1280 1298
1281 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 1299 DCHECK_EQ(MessageLoop::current(), frontend_loop_);
1282 if (!success) { 1300 if (!success) {
(...skipping 15 matching lines...) Expand all
1298 initialization_state_ = DOWNLOADING_NIGORI; 1316 initialization_state_ = DOWNLOADING_NIGORI;
1299 ConfigureDataTypes( 1317 ConfigureDataTypes(
1300 syncer::CONFIGURE_REASON_NEW_CLIENT, 1318 syncer::CONFIGURE_REASON_NEW_CLIENT,
1301 syncer::ModelTypeSet(), 1319 syncer::ModelTypeSet(),
1302 syncer::ModelTypeSet(), 1320 syncer::ModelTypeSet(),
1303 WITH_NIGORI, 1321 WITH_NIGORI,
1304 // Calls back into this function. 1322 // Calls back into this function.
1305 base::Bind( 1323 base::Bind(
1306 &SyncBackendHost:: 1324 &SyncBackendHost::
1307 HandleNigoriConfigurationCompletedOnFrontendLoop, 1325 HandleNigoriConfigurationCompletedOnFrontendLoop,
1308 weak_ptr_factory_.GetWeakPtr(), js_backend), 1326 weak_ptr_factory_.GetWeakPtr()),
1309 base::Bind(&SyncBackendHost::OnNigoriDownloadRetry, 1327 base::Bind(&SyncBackendHost::OnNigoriDownloadRetry,
1310 weak_ptr_factory_.GetWeakPtr())); 1328 weak_ptr_factory_.GetWeakPtr()));
1311 break; 1329 break;
1312 case DOWNLOADING_NIGORI: 1330 case DOWNLOADING_NIGORI:
1313 initialization_state_ = REFRESHING_NIGORI; 1331 initialization_state_ = ASSOCIATING_NIGORI;
1314 // Triggers OnEncryptedTypesChanged() and OnEncryptionComplete() 1332 // Triggers OnEncryptedTypesChanged() and OnEncryptionComplete()
1315 // if necessary. 1333 // if necessary.
1316 RefreshNigori( 1334 AssociateNigori();
1317 base::Bind(
1318 &SyncBackendHost::
1319 HandleInitializationCompletedOnFrontendLoop,
1320 weak_ptr_factory_.GetWeakPtr(), js_backend, true));
1321 break; 1335 break;
1322 case REFRESHING_NIGORI: 1336 case ASSOCIATING_NIGORI:
1323 initialization_state_ = INITIALIZED; 1337 initialization_state_ = INITIALIZED;
1324 // Now that we've downloaded the nigori node, we can see if there are any 1338 // 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 1339 // experimental types to enable. This should be done before we inform
1326 // the frontend to ensure they're visible in the customize screen. 1340 // the frontend to ensure they're visible in the customize screen.
1327 AddExperimentalTypes(); 1341 AddExperimentalTypes();
1328 frontend_->OnBackendInitialized(js_backend, true); 1342 frontend_->OnBackendInitialized(js_backend_, true);
tim (not reviewing) 2012/08/15 01:39:02 Can / should we reset the member variable here?
Nicolas Zea 2012/08/15 20:56:49 Done. Also reset in shutdown now. I went ahead and
1329 break; 1343 break;
1330 default: 1344 default:
1331 NOTREACHED(); 1345 NOTREACHED();
1332 } 1346 }
1333 } 1347 }
1334 1348
1335 void SyncBackendHost::HandleSyncCycleCompletedOnFrontendLoop( 1349 void SyncBackendHost::HandleSyncCycleCompletedOnFrontendLoop(
1336 const SyncSessionSnapshot& snapshot) { 1350 const SyncSessionSnapshot& snapshot) {
1337 if (!frontend_) 1351 if (!frontend_)
1338 return; 1352 return;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1406 } 1420 }
1407 1421
1408 bool SyncBackendHost::CheckPassphraseAgainstCachedPendingKeys( 1422 bool SyncBackendHost::CheckPassphraseAgainstCachedPendingKeys(
1409 const std::string& passphrase) const { 1423 const std::string& passphrase) const {
1410 DCHECK(cached_pending_keys_.has_blob()); 1424 DCHECK(cached_pending_keys_.has_blob());
1411 DCHECK(!passphrase.empty()); 1425 DCHECK(!passphrase.empty());
1412 syncer::Nigori nigori; 1426 syncer::Nigori nigori;
1413 nigori.InitByDerivation("localhost", "dummy", passphrase); 1427 nigori.InitByDerivation("localhost", "dummy", passphrase);
1414 std::string plaintext; 1428 std::string plaintext;
1415 bool result = nigori.Decrypt(cached_pending_keys_.blob(), &plaintext); 1429 bool result = nigori.Decrypt(cached_pending_keys_.blob(), &plaintext);
1430 DVLOG_IF(1, result) << "Passphrase failed to decrypt pending keys.";
1416 return result; 1431 return result;
1417 } 1432 }
1418 1433
1419 void SyncBackendHost::NotifyPassphraseRequired( 1434 void SyncBackendHost::NotifyPassphraseRequired(
1420 syncer::PassphraseRequiredReason reason, 1435 syncer::PassphraseRequiredReason reason,
1421 sync_pb::EncryptedData pending_keys) { 1436 sync_pb::EncryptedData pending_keys) {
1422 if (!frontend_) 1437 if (!frontend_)
1423 return; 1438 return;
1424 1439
1425 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 1440 DCHECK_EQ(MessageLoop::current(), frontend_loop_);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1479 syncer::ConnectionStatus status) { 1494 syncer::ConnectionStatus status) {
1480 if (!frontend_) 1495 if (!frontend_)
1481 return; 1496 return;
1482 1497
1483 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 1498 DCHECK_EQ(MessageLoop::current(), frontend_loop_);
1484 1499
1485 frontend_->OnConnectionStatusChange(status); 1500 frontend_->OnConnectionStatusChange(status);
1486 } 1501 }
1487 1502
1488 void SyncBackendHost::HandleNigoriConfigurationCompletedOnFrontendLoop( 1503 void SyncBackendHost::HandleNigoriConfigurationCompletedOnFrontendLoop(
1489 const syncer::WeakHandle<syncer::JsBackend>& js_backend,
1490 const syncer::ModelTypeSet failed_configuration_types) { 1504 const syncer::ModelTypeSet failed_configuration_types) {
1491 HandleInitializationCompletedOnFrontendLoop( 1505 HandleInitializationCompletedOnFrontendLoop(
1492 js_backend, failed_configuration_types.Empty()); 1506 failed_configuration_types.Empty());
1493 } 1507 }
1494 1508
1495 namespace { 1509 void SyncBackendHost::AssociateNigori() {
tim (not reviewing) 2012/08/15 01:39:02 Okay, after all that, I think we should now just i
Nicolas Zea 2012/08/15 20:56:49 Done.
1496
1497 // Needed because MessageLoop::PostTask is overloaded.
1498 void PostClosure(MessageLoop* message_loop,
1499 const tracked_objects::Location& from_here,
1500 const base::Closure& callback) {
1501 message_loop->PostTask(from_here, callback);
1502 }
1503
1504 } // namespace
1505
1506 void SyncBackendHost::RefreshNigori(const base::Closure& done_callback) {
1507 DCHECK_EQ(MessageLoop::current(), frontend_loop_); 1510 DCHECK_EQ(MessageLoop::current(), frontend_loop_);
1508 base::Closure sync_thread_done_callback =
1509 base::Bind(&PostClosure,
1510 MessageLoop::current(), FROM_HERE, done_callback);
1511 sync_thread_.message_loop()->PostTask( 1511 sync_thread_.message_loop()->PostTask(
1512 FROM_HERE, 1512 FROM_HERE,
1513 base::Bind(&SyncBackendHost::Core::DoRefreshNigori, 1513 base::Bind(&SyncBackendHost::Core::DoAssociateNigori,
1514 core_.get(), sync_thread_done_callback)); 1514 core_.get()));
1515 } 1515 }
1516 1516
1517 #undef SDVLOG 1517 #undef SDVLOG
1518 1518
1519 #undef SLOG 1519 #undef SLOG
1520 1520
1521 } // namespace browser_sync 1521 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698