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..86f3ddc12b0f36bfbd2a6dad74745ce6bf53978f 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,10 @@ 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. |
+ // |done_callback| is called on the sync thread. |
+ void DoAssociateNigori(const base::Closure& done_callback); |
// The shutdown order is a bit complicated: |
// 1) From |sync_thread_|, invoke the syncapi Shutdown call to do |
@@ -737,8 +742,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 at the PSS, then make the encryption handler |
tim (not reviewing)
2012/08/14 02:32:20
Which value? The result of the whole expression b
Nicolas Zea
2012/08/14 23:24:51
Comment updated, you're right, it's better to cach
|
+ // NonThreadSafe and only accessible from the sync thread. |
return IsNigoriEnabled() && |
- core_->sync_manager()->IsUsingExplicitPassphrase(); |
+ core_->sync_manager()->GetEncryptionHandler()-> |
+ IsUsingExplicitPassphrase(); |
} |
bool SyncBackendHost::IsCryptographerReady( |
@@ -993,6 +1001,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 +1135,32 @@ void SyncBackendHost::Core::DoStartSyncing( |
sync_manager_->StartSyncingNormally(routing_info); |
} |
+void SyncBackendHost::Core::DoAssociateNigori( |
+ const base::Closure& done_callback) { |
+ DCHECK_EQ(MessageLoop::current(), sync_loop_); |
+ sync_manager_->GetEncryptionHandler()->AddObserver(this); |
+ sync_manager_->GetEncryptionHandler()->ReloadNigori(); |
+ done_callback.Run(); |
tim (not reviewing)
2012/08/14 02:32:20
I think you can remove all the done_callback plumb
Nicolas Zea
2012/08/14 23:24:51
Done.
|
+} |
+ |
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( |
@@ -1310,16 +1325,16 @@ void SyncBackendHost::HandleInitializationCompletedOnFrontendLoop( |
weak_ptr_factory_.GetWeakPtr())); |
break; |
case DOWNLOADING_NIGORI: |
- initialization_state_ = REFRESHING_NIGORI; |
+ initialization_state_ = ASSOCIATING_NIGORI; |
// Triggers OnEncryptedTypesChanged() and OnEncryptionComplete() |
// if necessary. |
- RefreshNigori( |
+ AssociateNigori( |
base::Bind( |
&SyncBackendHost:: |
HandleInitializationCompletedOnFrontendLoop, |
weak_ptr_factory_.GetWeakPtr(), js_backend, true)); |
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 |
@@ -1413,6 +1428,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; |
} |
@@ -1503,14 +1519,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)); |
} |