| 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..9e3b137dcf9c60c47b6093dd977852ca1543eca9 100644
|
| --- a/chrome/browser/sync/glue/sync_backend_host.cc
|
| +++ b/chrome/browser/sync/glue/sync_backend_host.cc
|
| @@ -27,6 +27,7 @@
|
| #include "chrome/browser/sync/glue/change_processor.h"
|
| #include "chrome/browser/sync/glue/chrome_encryptor.h"
|
| #include "chrome/browser/sync/glue/chrome_sync_notification_bridge.h"
|
| +#include "chrome/browser/sync/glue/nigori_change_processor.h"
|
| #include "chrome/browser/sync/glue/sync_backend_registrar.h"
|
| #include "chrome/browser/sync/invalidations/invalidator_storage.h"
|
| #include "chrome/browser/sync/sync_prefs.h"
|
| @@ -78,6 +79,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 +98,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;
|
| @@ -183,6 +189,7 @@ class SyncBackendHost::Core
|
| const base::Callback<void(syncer::ModelTypeSet)>& ready_task);
|
| void DoRetryConfiguration(
|
| const base::Closure& retry_callback);
|
| + void DoAssociateNigori(const base::Closure& done_callback);
|
|
|
| // Set the base request context to use when making HTTP calls.
|
| // This method will add a reference to the context to persist it
|
| @@ -195,6 +202,8 @@ class SyncBackendHost::Core
|
| // sync databases), as well as shutdown when you're no longer syncing.
|
| void DeleteSyncDataFolder();
|
|
|
| + NigoriChangeProcessor* nigori_processor() { return nigori_processor_.get(); }
|
| +
|
| private:
|
| friend class base::RefCountedThreadSafe<SyncBackendHost::Core>;
|
| friend class SyncBackendHostForProfileSyncTest;
|
| @@ -245,6 +254,10 @@ class SyncBackendHost::Core
|
| // The top-level syncapi entry point. Lives on the sync thread.
|
| scoped_ptr<syncer::SyncManager> sync_manager_;
|
|
|
| + // The nigori change processor. Handles all nigori/sync encryption
|
| + // functionality.
|
| + scoped_ptr<NigoriChangeProcessor> nigori_processor_;
|
| +
|
| DISALLOW_COPY_AND_ASSIGN(Core);
|
| };
|
|
|
| @@ -737,8 +750,10 @@ 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.
|
| - return IsNigoriEnabled() &&
|
| - core_->sync_manager()->IsUsingExplicitPassphrase();
|
| + // TODO(zea): cache this value at the PSS, then make the encryption handler
|
| + // NonThreadSafe and only accessible from the sync thread.
|
| + return IsNigoriEnabled() && core_->sync_manager()->GetEncryptionHandler()->
|
| + IsUsingExplicitPassphrase();
|
| }
|
|
|
| bool SyncBackendHost::IsCryptographerReady(
|
| @@ -993,6 +1008,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 +1142,35 @@ void SyncBackendHost::Core::DoStartSyncing(
|
| sync_manager_->StartSyncingNormally(routing_info);
|
| }
|
|
|
| +void SyncBackendHost::Core::DoAssociateNigori(
|
| + const base::Closure& done_callback) {
|
| + DCHECK_EQ(MessageLoop::current(), sync_loop_);
|
| + syncer::SyncEncryptionHandler* encryption_handler =
|
| + sync_manager_->GetEncryptionHandler();
|
| + nigori_processor_.reset(new NigoriChangeProcessor(encryption_handler));
|
| + encryption_handler->AddObserver(this);
|
| + nigori_processor_->AssociateModels(sync_manager_->GetUserShare());
|
| + done_callback.Run();
|
| +}
|
| +
|
| 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(
|
| @@ -1255,7 +1280,7 @@ void SyncBackendHost::Core::SaveChanges() {
|
| void SyncBackendHost::AddExperimentalTypes() {
|
| CHECK(initialized());
|
| syncer::Experiments experiments;
|
| - if (core_->sync_manager()->ReceivedExperiment(&experiments))
|
| + if (core_->nigori_processor()->ReceivedExperiments(&experiments))
|
| frontend_->OnExperimentsChanged(experiments);
|
| }
|
|
|
| @@ -1313,7 +1338,7 @@ void SyncBackendHost::HandleInitializationCompletedOnFrontendLoop(
|
| initialization_state_ = REFRESHING_NIGORI;
|
| // Triggers OnEncryptedTypesChanged() and OnEncryptionComplete()
|
| // if necessary.
|
| - RefreshNigori(
|
| + AssociateNigori(
|
| base::Bind(
|
| &SyncBackendHost::
|
| HandleInitializationCompletedOnFrontendLoop,
|
| @@ -1503,14 +1528,15 @@ void PostClosure(MessageLoop* message_loop,
|
|
|
| } // namespace
|
|
|
| -void SyncBackendHost::RefreshNigori(const base::Closure& done_callback) {
|
| +void SyncBackendHost::AssociateNigori(
|
| + const base::Closure& done_callback) {
|
| 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,
|
| + base::Bind(&SyncBackendHost::Core::DoAssociateNigori,
|
| core_.get(), sync_thread_done_callback));
|
| }
|
|
|
|
|