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

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: Fix tests 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..b4bd2a8f8affbae1029410e508add48bc5640aba 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(); }
tim (not reviewing) 2012/08/12 23:31:20 Can we avoid exposing this? The only reason we ex
Nicolas Zea 2012/08/13 22:56:38 Done.
+
private:
friend class base::RefCountedThreadSafe<SyncBackendHost::Core>;
friend class SyncBackendHostForProfileSyncTest;
@@ -245,6 +254,11 @@ class SyncBackendHost::Core
// The top-level syncapi entry point. Lives on the sync thread.
scoped_ptr<syncer::SyncManager> sync_manager_;
+ // The nigori change processor. For now it's just a wrapper around
+ // the SyncEncryptionHandler, but eventually it will handle all nigori
+ // update and conflict events.
+ scoped_ptr<NigoriChangeProcessor> nigori_processor_;
+
DISALLOW_COPY_AND_ASSIGN(Core);
};
@@ -737,8 +751,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
+ // NonThreadSafe and only accessible from the sync thread.
return IsNigoriEnabled() &&
- core_->sync_manager()->IsUsingExplicitPassphrase();
+ core_->sync_manager()->GetEncryptionHandler()->
+ IsUsingExplicitPassphrase();
}
bool SyncBackendHost::IsCryptographerReady(
@@ -993,6 +1010,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 +1144,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 +1282,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 +1340,7 @@ void SyncBackendHost::HandleInitializationCompletedOnFrontendLoop(
initialization_state_ = REFRESHING_NIGORI;
// Triggers OnEncryptedTypesChanged() and OnEncryptionComplete()
// if necessary.
- RefreshNigori(
+ AssociateNigori(
base::Bind(
&SyncBackendHost::
HandleInitializationCompletedOnFrontendLoop,
@@ -1413,6 +1440,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 +1531,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));
}

Powered by Google App Engine
This is Rietveld 408576698