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

Unified Diff: sync/syncable/nigori_util.cc

Issue 10844005: [Sync] Refactor GetEncryptedTypes usage. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Always trigger OnEncryptedTypesChanged on init 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: sync/syncable/nigori_util.cc
diff --git a/sync/syncable/nigori_util.cc b/sync/syncable/nigori_util.cc
index 72d9281c7ace6ed1e29480bea49fc3ac2cd1b3ea..4b595164790f728047f0e85e174ee30aee134745 100644
--- a/sync/syncable/nigori_util.cc
+++ b/sync/syncable/nigori_util.cc
@@ -11,6 +11,7 @@
#include "base/json/json_writer.h"
#include "sync/syncable/directory.h"
#include "sync/syncable/entry.h"
+#include "sync/syncable/nigori_handler.h"
#include "sync/syncable/mutable_entry.h"
#include "sync/syncable/syncable_util.h"
#include "sync/syncable/write_transaction.h"
@@ -20,9 +21,12 @@ namespace syncer {
namespace syncable {
bool ProcessUnsyncedChangesForEncryption(
- WriteTransaction* const trans,
- Cryptographer* cryptographer) {
+ WriteTransaction* const trans) {
+ NigoriHandler* nigori_handler = trans->directory()->GetNigoriHandler();
+ ModelTypeSet encrypted_types = nigori_handler->GetEncryptedTypes(trans);
+ Cryptographer* cryptographer = trans->directory()->GetCryptographer(trans);
DCHECK(cryptographer->is_ready());
+
// Get list of all datatypes with unsynced changes. It's possible that our
// local changes need to be encrypted if encryption for that datatype was
// just turned on (and vice versa).
@@ -36,14 +40,10 @@ bool ProcessUnsyncedChangesForEncryption(
const sync_pb::EntitySpecifics& specifics = entry.Get(SPECIFICS);
// Ignore types that don't need encryption or entries that are already
// encrypted.
- if (!SpecificsNeedsEncryption(cryptographer->GetEncryptedTypes(),
- specifics)) {
+ if (!SpecificsNeedsEncryption(encrypted_types, specifics))
continue;
- }
- if (!UpdateEntryWithEncryption(cryptographer, specifics, &entry)) {
- NOTREACHED();
+ if (!UpdateEntryWithEncryption(trans, specifics, &entry))
return false;
- }
}
return true;
}
@@ -93,9 +93,9 @@ bool SpecificsNeedsEncryption(ModelTypeSet encrypted_types,
// Mainly for testing.
bool VerifyDataTypeEncryptionForTest(
BaseTransaction* const trans,
- Cryptographer* cryptographer,
ModelType type,
bool is_encrypted) {
+ Cryptographer* cryptographer = trans->directory()->GetCryptographer(trans);
if (type == PASSWORDS || type == NIGORI) {
NOTREACHED();
return true;
@@ -157,13 +157,15 @@ bool VerifyDataTypeEncryptionForTest(
}
bool UpdateEntryWithEncryption(
- Cryptographer* cryptographer,
+ BaseTransaction* const trans,
const sync_pb::EntitySpecifics& new_specifics,
syncable::MutableEntry* entry) {
+ NigoriHandler* nigori_handler = trans->directory()->GetNigoriHandler();
+ Cryptographer* cryptographer = trans->directory()->GetCryptographer(trans);
ModelType type = GetModelTypeFromSpecifics(new_specifics);
DCHECK_GE(type, FIRST_REAL_MODEL_TYPE);
const sync_pb::EntitySpecifics& old_specifics = entry->Get(SPECIFICS);
- const ModelTypeSet encrypted_types = cryptographer->GetEncryptedTypes();
+ const ModelTypeSet encrypted_types = nigori_handler->GetEncryptedTypes(trans);
// It's possible the nigori lost the set of encrypted types. If the current
// specifics are already encrypted, we want to ensure we continue encrypting.
bool was_encrypted = old_specifics.has_encrypted();

Powered by Google App Engine
This is Rietveld 408576698