Chromium Code Reviews| Index: chrome/browser/sync/glue/sync_backend_host.cc |
| diff --git a/chrome/browser/sync/glue/sync_backend_host.cc b/chrome/browser/sync/glue/sync_backend_host.cc |
| index eb2659de110f3426aef31f0a3d019705c3ad4b83..62eef3489de0e2a87cc6edfbef5aca850263c619 100644 |
| --- a/chrome/browser/sync/glue/sync_backend_host.cc |
| +++ b/chrome/browser/sync/glue/sync_backend_host.cc |
| @@ -78,6 +78,7 @@ using syncer::SyncCredentials; |
| class SyncBackendHost::Core |
| : public base::RefCountedThreadSafe<SyncBackendHost::Core>, |
| + public syncer::SyncEncryptionHandler::Observer, |
| public syncer::SyncManager::Observer, |
| public syncer::SyncNotifierObserver { |
| public: |
| @@ -96,20 +97,24 @@ class SyncBackendHost::Core |
| syncer::ModelTypeSet restored_types) OVERRIDE; |
| virtual void OnConnectionStatusChange( |
| syncer::ConnectionStatus status) OVERRIDE; |
| + virtual void OnStopSyncingPermanently() OVERRIDE; |
| + virtual void OnUpdatedToken(const std::string& token) OVERRIDE; |
| + virtual void OnActionableError( |
| + const syncer::SyncProtocolError& sync_error) OVERRIDE; |
| + |
| + // SyncEncryptionHandler::Observer implementation. |
| virtual void OnPassphraseRequired( |
| syncer::PassphraseRequiredReason reason, |
| const sync_pb::EncryptedData& pending_keys) OVERRIDE; |
| virtual void OnPassphraseAccepted() OVERRIDE; |
| virtual void OnBootstrapTokenUpdated( |
| const std::string& bootstrap_token) OVERRIDE; |
| - virtual void OnStopSyncingPermanently() OVERRIDE; |
| - virtual void OnUpdatedToken(const std::string& token) OVERRIDE; |
| virtual void OnEncryptedTypesChanged( |
| syncer::ModelTypeSet encrypted_types, |
| bool encrypt_everything) OVERRIDE; |
| virtual void OnEncryptionComplete() OVERRIDE; |
| - virtual void OnActionableError( |
| - const syncer::SyncProtocolError& sync_error) OVERRIDE; |
| + virtual void OnCryptographerStateChanged( |
| + syncer::Cryptographer* cryptographer) OVERRIDE; |
| // syncer::SyncNotifierObserver implementation. |
| virtual void OnNotificationsEnabled() OVERRIDE; |
| @@ -153,10 +158,9 @@ class SyncBackendHost::Core |
| // reencrypt everything. |
| void DoEnableEncryptEverything(); |
| - // Called to refresh encryption with the most recent passphrase |
| - // and set of encrypted types. Also adds device information to the nigori |
| - // node. |done_callback| is called on the sync thread. |
| - void DoRefreshNigori(const base::Closure& done_callback); |
| + // Called to load sync encryption state and re-encrypt any types |
| + // needing encryption as necessary. |
| + void DoAssociateNigori(); |
| // The shutdown order is a bit complicated: |
| // 1) From |sync_thread_|, invoke the syncapi Shutdown call to do |
| @@ -737,8 +741,11 @@ bool SyncBackendHost::IsUsingExplicitPassphrase() { |
| // otherwise we have no idea what kind of passphrase we are using. This will |
| // NOTREACH in sync_manager and return false if we fail to load the nigori |
| // node. |
| + // TODO(zea): cache this value here, then make the encryption handler |
| + // NonThreadSafe and only accessible from the sync thread. |
| return IsNigoriEnabled() && |
| - core_->sync_manager()->IsUsingExplicitPassphrase(); |
| + core_->sync_manager()->GetEncryptionHandler()-> |
| + IsUsingExplicitPassphrase(); |
| } |
| bool SyncBackendHost::IsCryptographerReady( |
| @@ -791,7 +798,9 @@ void SyncBackendHost::HandleSyncManagerInitializationOnFrontendLoop( |
| const syncer::WeakHandle<syncer::JsBackend>& js_backend, bool success, |
| syncer::ModelTypeSet restored_types) { |
| registrar_->SetInitialTypes(restored_types); |
| - HandleInitializationCompletedOnFrontendLoop(js_backend, success); |
| + DCHECK(!js_backend_.IsInitialized()); |
| + js_backend_ = js_backend; |
| + HandleInitializationCompletedOnFrontendLoop(success); |
| } |
| SyncBackendHost::DoInitializeOptions::DoInitializeOptions( |
| @@ -993,6 +1002,11 @@ void SyncBackendHost::Core::OnEncryptionComplete() { |
| &SyncBackendHost::NotifyEncryptionComplete); |
| } |
| +void SyncBackendHost::Core::OnCryptographerStateChanged( |
| + syncer::Cryptographer* cryptographer) { |
| + // Do nothing. |
| +} |
| + |
| void SyncBackendHost::Core::OnActionableError( |
| const syncer::SyncProtocolError& sync_error) { |
| if (!sync_loop_) |
| @@ -1122,30 +1136,33 @@ void SyncBackendHost::Core::DoStartSyncing( |
| sync_manager_->StartSyncingNormally(routing_info); |
| } |
| +void SyncBackendHost::Core::DoAssociateNigori() { |
| + DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| + sync_manager_->GetEncryptionHandler()->AddObserver(this); |
| + sync_manager_->GetEncryptionHandler()->Init(); |
| + host_.Call(FROM_HERE, |
| + &SyncBackendHost::HandleInitializationCompletedOnFrontendLoop, |
| + true); |
| +} |
| + |
| void SyncBackendHost::Core::DoSetEncryptionPassphrase( |
| const std::string& passphrase, |
| bool is_explicit) { |
| DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| - sync_manager_->SetEncryptionPassphrase(passphrase, is_explicit); |
| + sync_manager_->GetEncryptionHandler()->SetEncryptionPassphrase( |
| + passphrase, is_explicit); |
| } |
| void SyncBackendHost::Core::DoSetDecryptionPassphrase( |
| const std::string& passphrase) { |
| DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| - sync_manager_->SetDecryptionPassphrase(passphrase); |
| + sync_manager_->GetEncryptionHandler()->SetDecryptionPassphrase( |
| + passphrase); |
| } |
| void SyncBackendHost::Core::DoEnableEncryptEverything() { |
| DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| - sync_manager_->EnableEncryptEverything(); |
| -} |
| - |
| -void SyncBackendHost::Core::DoRefreshNigori( |
| - const base::Closure& done_callback) { |
| - DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| - chrome::VersionInfo version_info; |
| - sync_manager_->RefreshNigori(version_info.CreateVersionString(), |
| - done_callback); |
| + sync_manager_->GetEncryptionHandler()->EnableEncryptEverything(); |
| } |
| void SyncBackendHost::Core::DoStopSyncManagerForShutdown( |
| @@ -1268,8 +1285,9 @@ void SyncBackendHost::OnNigoriDownloadRetry() { |
| } |
| void SyncBackendHost::HandleInitializationCompletedOnFrontendLoop( |
| - const syncer::WeakHandle<syncer::JsBackend>& js_backend, bool success) { |
| + bool success) { |
| DCHECK_NE(NOT_ATTEMPTED, initialization_state_); |
| + DCHECK(js_backend_.IsInitialized()); |
| if (!frontend_) |
| return; |
| @@ -1305,27 +1323,23 @@ void SyncBackendHost::HandleInitializationCompletedOnFrontendLoop( |
| base::Bind( |
| &SyncBackendHost:: |
| HandleNigoriConfigurationCompletedOnFrontendLoop, |
| - weak_ptr_factory_.GetWeakPtr(), js_backend), |
| + weak_ptr_factory_.GetWeakPtr()), |
| base::Bind(&SyncBackendHost::OnNigoriDownloadRetry, |
| weak_ptr_factory_.GetWeakPtr())); |
| break; |
| case DOWNLOADING_NIGORI: |
| - initialization_state_ = REFRESHING_NIGORI; |
| + initialization_state_ = ASSOCIATING_NIGORI; |
| // Triggers OnEncryptedTypesChanged() and OnEncryptionComplete() |
| // if necessary. |
| - RefreshNigori( |
| - base::Bind( |
| - &SyncBackendHost:: |
| - HandleInitializationCompletedOnFrontendLoop, |
| - weak_ptr_factory_.GetWeakPtr(), js_backend, true)); |
| + AssociateNigori(); |
| break; |
| - case REFRESHING_NIGORI: |
| + case ASSOCIATING_NIGORI: |
| initialization_state_ = INITIALIZED; |
| // Now that we've downloaded the nigori node, we can see if there are any |
| // experimental types to enable. This should be done before we inform |
| // the frontend to ensure they're visible in the customize screen. |
| AddExperimentalTypes(); |
| - frontend_->OnBackendInitialized(js_backend, true); |
| + 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
|
| break; |
| default: |
| NOTREACHED(); |
| @@ -1413,6 +1427,7 @@ bool SyncBackendHost::CheckPassphraseAgainstCachedPendingKeys( |
| nigori.InitByDerivation("localhost", "dummy", passphrase); |
| std::string plaintext; |
| bool result = nigori.Decrypt(cached_pending_keys_.blob(), &plaintext); |
| + DVLOG_IF(1, result) << "Passphrase failed to decrypt pending keys."; |
| return result; |
| } |
| @@ -1486,32 +1501,17 @@ void SyncBackendHost::HandleConnectionStatusChangeOnFrontendLoop( |
| } |
| void SyncBackendHost::HandleNigoriConfigurationCompletedOnFrontendLoop( |
| - const syncer::WeakHandle<syncer::JsBackend>& js_backend, |
| const syncer::ModelTypeSet failed_configuration_types) { |
| HandleInitializationCompletedOnFrontendLoop( |
| - js_backend, failed_configuration_types.Empty()); |
| + failed_configuration_types.Empty()); |
| } |
| -namespace { |
| - |
| -// Needed because MessageLoop::PostTask is overloaded. |
| -void PostClosure(MessageLoop* message_loop, |
| - const tracked_objects::Location& from_here, |
| - const base::Closure& callback) { |
| - message_loop->PostTask(from_here, callback); |
| -} |
| - |
| -} // namespace |
| - |
| -void SyncBackendHost::RefreshNigori(const base::Closure& done_callback) { |
| +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.
|
| DCHECK_EQ(MessageLoop::current(), frontend_loop_); |
| - base::Closure sync_thread_done_callback = |
| - base::Bind(&PostClosure, |
| - MessageLoop::current(), FROM_HERE, done_callback); |
| sync_thread_.message_loop()->PostTask( |
| FROM_HERE, |
| - base::Bind(&SyncBackendHost::Core::DoRefreshNigori, |
| - core_.get(), sync_thread_done_callback)); |
| + base::Bind(&SyncBackendHost::Core::DoAssociateNigori, |
| + core_.get())); |
| } |
| #undef SDVLOG |