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

Unified 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 2 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 side-by-side diff with in-line comments
Download patch
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..3a2f2141cd79d0886d7f5339a87b5da37fda70a4 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.
+ void DoAssociateNigori(
+ const syncer::WeakHandle<syncer::JsBackend>& js_backend);
// 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 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(
@@ -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,35 @@ void SyncBackendHost::Core::DoStartSyncing(
sync_manager_->StartSyncingNormally(routing_info);
}
+void SyncBackendHost::Core::DoAssociateNigori(
+ const syncer::WeakHandle<syncer::JsBackend>& js_backend) {
+ DCHECK_EQ(MessageLoop::current(), sync_loop_);
+ sync_manager_->GetEncryptionHandler()->AddObserver(this);
+ sync_manager_->GetEncryptionHandler()->Init();
+ host_.Call(FROM_HERE,
+ &SyncBackendHost::HandleInitializationCompletedOnFrontendLoop,
+ js_backend,
+ 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(
@@ -1310,16 +1328,12 @@ 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(
- base::Bind(
- &SyncBackendHost::
- HandleInitializationCompletedOnFrontendLoop,
- weak_ptr_factory_.GetWeakPtr(), js_backend, true));
+ AssociateNigori(js_backend);
tim (not reviewing) 2012/08/15 00:23:30 Can we cache js_backend somewhere in this class to
Nicolas Zea 2012/08/15 01:08:29 Done.
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 +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;
}
@@ -1503,15 +1518,14 @@ void PostClosure(MessageLoop* message_loop,
} // namespace
-void SyncBackendHost::RefreshNigori(const base::Closure& done_callback) {
+void SyncBackendHost::AssociateNigori(
+ const syncer::WeakHandle<syncer::JsBackend>& js_backend) {
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,
+ js_backend,
+ core_.get()));
}
#undef SDVLOG

Powered by Google App Engine
This is Rietveld 408576698