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

Unified Diff: sync/test/fake_sync_encryption_handler.cc

Issue 10827266: [Sync] Add SyncEncryptionHandler (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix 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
« no previous file with comments | « sync/test/fake_sync_encryption_handler.h ('k') | sync/util/DEPS » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sync/test/fake_sync_encryption_handler.cc
diff --git a/sync/test/fake_sync_encryption_handler.cc b/sync/test/fake_sync_encryption_handler.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b4908622540a7a1b343e7f8ce8086613b226ba43
--- /dev/null
+++ b/sync/test/fake_sync_encryption_handler.cc
@@ -0,0 +1,106 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "sync/test/fake_sync_encryption_handler.h"
+
+#include "sync/protocol/nigori_specifics.pb.h"
+#include "sync/syncable/nigori_util.h"
+#include "sync/util/cryptographer.h"
+
+namespace syncer {
+
+FakeSyncEncryptionHandler::FakeSyncEncryptionHandler()
+ : encrypted_types_(SensitiveTypes()),
+ encrypt_everything_(false),
+ explicit_passphrase_(false),
+ cryptographer_(NULL) {
+}
+FakeSyncEncryptionHandler::~FakeSyncEncryptionHandler() {}
+
+void FakeSyncEncryptionHandler::Init() {
+ // Do nothing.
+}
+
+void FakeSyncEncryptionHandler::ApplyNigoriUpdate(
+ const sync_pb::NigoriSpecifics& nigori,
+ syncable::BaseTransaction* const trans) {
+ if (nigori.encrypt_everything())
+ EnableEncryptEverything();
+ if (nigori.using_explicit_passphrase())
+ explicit_passphrase_ = true;
+
+ if (!cryptographer_)
+ return;
+
+ if (cryptographer_->CanDecrypt(nigori.encrypted()))
+ cryptographer_->InstallKeys(nigori.encrypted());
+ else
+ cryptographer_->SetPendingKeys(nigori.encrypted());
+
+ if (cryptographer_->has_pending_keys()) {
+ DVLOG(1) << "OnPassPhraseRequired Sent";
+ sync_pb::EncryptedData pending_keys = cryptographer_->GetPendingKeys();
+ FOR_EACH_OBSERVER(SyncEncryptionHandler::Observer, observers_,
+ OnPassphraseRequired(REASON_DECRYPTION,
+ pending_keys));
+ } else if (!cryptographer_->is_ready()) {
+ DVLOG(1) << "OnPassphraseRequired sent because cryptographer is not "
+ << "ready";
+ FOR_EACH_OBSERVER(SyncEncryptionHandler::Observer, observers_,
+ OnPassphraseRequired(REASON_ENCRYPTION,
+ sync_pb::EncryptedData()));
+ }
+}
+
+void FakeSyncEncryptionHandler::UpdateNigoriFromEncryptedTypes(
+ sync_pb::NigoriSpecifics* nigori,
+ syncable::BaseTransaction* const trans) const {
+ syncable::UpdateNigoriFromEncryptedTypes(encrypted_types_,
+ encrypt_everything_,
+ nigori);
+}
+
+void FakeSyncEncryptionHandler::AddObserver(Observer* observer) {
+ observers_.AddObserver(observer);
+}
+
+void FakeSyncEncryptionHandler::RemoveObserver(Observer* observer) {
+ observers_.RemoveObserver(observer);
+}
+
+void FakeSyncEncryptionHandler::SetEncryptionPassphrase(
+ const std::string& passphrase,
+ bool is_explicit) {
+ if (is_explicit)
+ explicit_passphrase_ = true;
+}
+
+void FakeSyncEncryptionHandler::SetDecryptionPassphrase(
+ const std::string& passphrase) {
+ // Do nothing.
+}
+
+void FakeSyncEncryptionHandler::EnableEncryptEverything() {
+ if (encrypt_everything_)
+ return;
+ encrypt_everything_ = true;
+ encrypted_types_ = ModelTypeSet::All();
+ FOR_EACH_OBSERVER(
+ Observer, observers_,
+ OnEncryptedTypesChanged(encrypted_types_, encrypt_everything_));
+}
+
+bool FakeSyncEncryptionHandler::EncryptEverythingEnabled() const {
+ return encrypt_everything_;
+}
+
+ModelTypeSet FakeSyncEncryptionHandler::GetEncryptedTypes() const {
+ return encrypted_types_;
+}
+
+bool FakeSyncEncryptionHandler::IsUsingExplicitPassphrase() const {
+ return explicit_passphrase_;
+}
+
+} // namespace syncer
« no previous file with comments | « sync/test/fake_sync_encryption_handler.h ('k') | sync/util/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698