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

Unified Diff: chrome/browser/sync/encryption/nigori_util.cc

Issue 8468023: Move encryption related files from util folder to encryption folder. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: For review. Created 9 years, 1 month 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/encryption/nigori_util.cc
diff --git a/chrome/browser/sync/engine/nigori_util.cc b/chrome/browser/sync/encryption/nigori_util.cc
similarity index 68%
rename from chrome/browser/sync/engine/nigori_util.cc
rename to chrome/browser/sync/encryption/nigori_util.cc
index 3e0c27ce1810b1f27c784fd42c007354ebd9374f..a86cacadaf658c81d87810583982a1654296a16e 100644
--- a/chrome/browser/sync/engine/nigori_util.cc
+++ b/chrome/browser/sync/encryption/nigori_util.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/sync/engine/nigori_util.h"
+#include "chrome/browser/sync/encryption/nigori_util.h"
#include <queue>
#include <string>
@@ -11,9 +11,18 @@
#include "chrome/browser/sync/engine/syncer_util.h"
#include "chrome/browser/sync/internal_api/write_node.h"
#include "chrome/browser/sync/syncable/syncable.h"
-#include "chrome/browser/sync/util/cryptographer.h"
+#include "chrome/browser/sync/encryption/cryptographer.h"
-namespace syncable {
+using syncable::BaseTransaction;
+using syncable::Entry;
+using syncable::Id;
+using syncable::ModelType;
+using syncable::ModelTypeSet;
+using syncable::MutableEntry;
+using syncable::WriteTransaction;
+
+namespace browser_sync {
+namespace encryption {
bool ProcessUnsyncedChangesForEncryption(
WriteTransaction* const trans,
@@ -27,10 +36,10 @@ bool ProcessUnsyncedChangesForEncryption(
std::vector<int64> handles;
browser_sync::SyncerUtil::GetUnsyncedEntries(trans, &handles);
for (size_t i = 0; i < handles.size(); ++i) {
- MutableEntry entry(trans, GET_BY_HANDLE, handles[i]);
+ MutableEntry entry(trans, syncable::GET_BY_HANDLE, handles[i]);
if (!sync_api::WriteNode::UpdateEntryWithEncryption(cryptographer,
- entry.Get(SPECIFICS),
- &entry)) {
+ entry.Get(syncable::SPECIFICS),
Nicolas Zea 2011/11/17 21:04:30 indent by one more space.
+ &entry)) {
NOTREACHED();
return false;
}
@@ -44,7 +53,7 @@ bool VerifyUnsyncedChangesAreEncrypted(
std::vector<int64> handles;
browser_sync::SyncerUtil::GetUnsyncedEntries(trans, &handles);
for (size_t i = 0; i < handles.size(); ++i) {
- Entry entry(trans, GET_BY_HANDLE, handles[i]);
+ Entry entry(trans, syncable::GET_BY_HANDLE, handles[i]);
if (!entry.good()) {
NOTREACHED();
return false;
@@ -57,23 +66,24 @@ bool VerifyUnsyncedChangesAreEncrypted(
bool EntryNeedsEncryption(const ModelTypeSet& encrypted_types,
const Entry& entry) {
- if (!entry.Get(UNIQUE_SERVER_TAG).empty())
+ if (!entry.Get(syncable::UNIQUE_SERVER_TAG).empty())
return false; // We don't encrypt unique server nodes.
syncable::ModelType type = entry.GetModelType();
- if (type == PASSWORDS || type == NIGORI)
+ if (type == syncable::PASSWORDS || type == syncable::NIGORI)
return false;
// Checking NON_UNIQUE_NAME is not necessary for the correctness of encrypting
// the data, nor for determining if data is encrypted. We simply ensure it has
// been overwritten to avoid any possible leaks of sensitive data.
- return SpecificsNeedsEncryption(encrypted_types, entry.Get(SPECIFICS)) ||
+ return SpecificsNeedsEncryption(encrypted_types, entry.Get(
+ syncable::SPECIFICS)) ||
(encrypted_types.count(type) > 0 &&
- entry.Get(NON_UNIQUE_NAME) != kEncryptedString);
+ entry.Get(syncable::NON_UNIQUE_NAME) != kEncryptedString);
Nicolas Zea 2011/11/17 21:04:30 rewrite as: return SpecificsNeedsEncryption(
}
bool SpecificsNeedsEncryption(const ModelTypeSet& encrypted_types,
const sync_pb::EntitySpecifics& specifics) {
- ModelType type = GetModelTypeFromSpecifics(specifics);
- if (type == PASSWORDS || type == NIGORI)
+ ModelType type = syncable::GetModelTypeFromSpecifics(specifics);
+ if (type == syncable::PASSWORDS || type == syncable::NIGORI)
return false; // These types have their own encryption schemes.
if (encrypted_types.count(type) == 0)
return false; // This type does not require encryption
@@ -86,12 +96,12 @@ bool VerifyDataTypeEncryptionForTest(
browser_sync::Cryptographer* cryptographer,
ModelType type,
bool is_encrypted) {
- if (type == PASSWORDS || type == NIGORI) {
+ if (type == syncable::PASSWORDS || type == syncable::NIGORI) {
Nicolas Zea 2011/11/17 21:04:30 unindent this line
NOTREACHED();
return true;
}
std::string type_tag = ModelTypeToRootTag(type);
- Entry type_root(trans, GET_BY_SERVER_TAG, type_tag);
+ Entry type_root(trans, syncable::GET_BY_SERVER_TAG, type_tag);
if (!type_root.good()) {
NOTREACHED();
return false;
@@ -100,7 +110,7 @@ bool VerifyDataTypeEncryptionForTest(
std::queue<Id> to_visit;
Id id_string;
if (!trans->directory()->GetFirstChildId(
- trans, type_root.Get(ID), &id_string)) {
+ trans, type_root.Get(syncable::ID), &id_string)) {
NOTREACHED();
return false;
}
@@ -111,39 +121,40 @@ bool VerifyDataTypeEncryptionForTest(
if (id_string.IsRoot())
continue;
- Entry child(trans, GET_BY_ID, id_string);
+ Entry child(trans, syncable::GET_BY_ID, id_string);
if (!child.good()) {
NOTREACHED();
return false;
}
- if (child.Get(IS_DIR)) {
+ if (child.Get(syncable::IS_DIR)) {
Id child_id_string;
if (!trans->directory()->GetFirstChildId(
- trans, child.Get(ID), &child_id_string)) {
+ trans, child.Get(syncable::ID), &child_id_string)) {
NOTREACHED();
return false;
}
// Traverse the children.
to_visit.push(child_id_string);
}
- const sync_pb::EntitySpecifics& specifics = child.Get(SPECIFICS);
+ const sync_pb::EntitySpecifics& specifics = child.Get(syncable::SPECIFICS);
DCHECK_EQ(type, child.GetModelType());
- DCHECK_EQ(type, GetModelTypeFromSpecifics(specifics));
+ DCHECK_EQ(type, syncable::GetModelTypeFromSpecifics(specifics));
// We don't encrypt the server's permanent items.
- if (child.Get(UNIQUE_SERVER_TAG).empty()) {
+ if (child.Get(syncable::UNIQUE_SERVER_TAG).empty()) {
if (specifics.has_encrypted() != is_encrypted)
return false;
if (specifics.has_encrypted()) {
- if (child.Get(NON_UNIQUE_NAME) != kEncryptedString)
+ if (child.Get(syncable::NON_UNIQUE_NAME) != kEncryptedString)
return false;
if (!cryptographer->CanDecryptUsingDefaultKey(specifics.encrypted()))
return false;
}
}
// Push the successor.
- to_visit.push(child.Get(NEXT_ID));
+ to_visit.push(child.Get(syncable::NEXT_ID));
}
return true;
}
-} // namespace syncable
+} // namespace encryption
+} // namespace browser_sync

Powered by Google App Engine
This is Rietveld 408576698