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

Side by Side Diff: sync/engine/nigori_util.cc

Issue 10698014: [Sync] Rename csync namespace to syncer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 8 years, 5 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sync/engine/nigori_util.h ('k') | sync/engine/nudge_source.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "sync/engine/nigori_util.h" 5 #include "sync/engine/nigori_util.h"
6 6
7 #include <queue> 7 #include <queue>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/json/json_writer.h" 11 #include "base/json/json_writer.h"
12 #include "sync/engine/syncer_util.h" 12 #include "sync/engine/syncer_util.h"
13 #include "sync/syncable/directory.h" 13 #include "sync/syncable/directory.h"
14 #include "sync/syncable/entry.h" 14 #include "sync/syncable/entry.h"
15 #include "sync/syncable/mutable_entry.h" 15 #include "sync/syncable/mutable_entry.h"
16 #include "sync/syncable/write_transaction.h" 16 #include "sync/syncable/write_transaction.h"
17 #include "sync/util/cryptographer.h" 17 #include "sync/util/cryptographer.h"
18 18
19 namespace syncable { 19 namespace syncable {
20 20
21 bool ProcessUnsyncedChangesForEncryption( 21 bool ProcessUnsyncedChangesForEncryption(
22 WriteTransaction* const trans, 22 WriteTransaction* const trans,
23 csync::Cryptographer* cryptographer) { 23 syncer::Cryptographer* cryptographer) {
24 DCHECK(cryptographer->is_ready()); 24 DCHECK(cryptographer->is_ready());
25 // Get list of all datatypes with unsynced changes. It's possible that our 25 // Get list of all datatypes with unsynced changes. It's possible that our
26 // local changes need to be encrypted if encryption for that datatype was 26 // local changes need to be encrypted if encryption for that datatype was
27 // just turned on (and vice versa). 27 // just turned on (and vice versa).
28 // Note: we do not attempt to re-encrypt data with a new key here as key 28 // Note: we do not attempt to re-encrypt data with a new key here as key
29 // changes in this code path are likely due to consistency issues (we have 29 // changes in this code path are likely due to consistency issues (we have
30 // to be updated to a key we already have, e.g. an old key). 30 // to be updated to a key we already have, e.g. an old key).
31 std::vector<int64> handles; 31 std::vector<int64> handles;
32 csync::SyncerUtil::GetUnsyncedEntries(trans, &handles); 32 syncer::SyncerUtil::GetUnsyncedEntries(trans, &handles);
33 for (size_t i = 0; i < handles.size(); ++i) { 33 for (size_t i = 0; i < handles.size(); ++i) {
34 MutableEntry entry(trans, GET_BY_HANDLE, handles[i]); 34 MutableEntry entry(trans, GET_BY_HANDLE, handles[i]);
35 const sync_pb::EntitySpecifics& specifics = entry.Get(SPECIFICS); 35 const sync_pb::EntitySpecifics& specifics = entry.Get(SPECIFICS);
36 // Ignore types that don't need encryption or entries that are already 36 // Ignore types that don't need encryption or entries that are already
37 // encrypted. 37 // encrypted.
38 if (!SpecificsNeedsEncryption(cryptographer->GetEncryptedTypes(), 38 if (!SpecificsNeedsEncryption(cryptographer->GetEncryptedTypes(),
39 specifics)) { 39 specifics)) {
40 continue; 40 continue;
41 } 41 }
42 if (!UpdateEntryWithEncryption(cryptographer, specifics, &entry)) { 42 if (!UpdateEntryWithEncryption(cryptographer, specifics, &entry)) {
43 NOTREACHED(); 43 NOTREACHED();
44 return false; 44 return false;
45 } 45 }
46 } 46 }
47 return true; 47 return true;
48 } 48 }
49 49
50 bool VerifyUnsyncedChangesAreEncrypted( 50 bool VerifyUnsyncedChangesAreEncrypted(
51 BaseTransaction* const trans, 51 BaseTransaction* const trans,
52 ModelTypeSet encrypted_types) { 52 ModelTypeSet encrypted_types) {
53 std::vector<int64> handles; 53 std::vector<int64> handles;
54 csync::SyncerUtil::GetUnsyncedEntries(trans, &handles); 54 syncer::SyncerUtil::GetUnsyncedEntries(trans, &handles);
55 for (size_t i = 0; i < handles.size(); ++i) { 55 for (size_t i = 0; i < handles.size(); ++i) {
56 Entry entry(trans, GET_BY_HANDLE, handles[i]); 56 Entry entry(trans, GET_BY_HANDLE, handles[i]);
57 if (!entry.good()) { 57 if (!entry.good()) {
58 NOTREACHED(); 58 NOTREACHED();
59 return false; 59 return false;
60 } 60 }
61 if (EntryNeedsEncryption(encrypted_types, entry)) 61 if (EntryNeedsEncryption(encrypted_types, entry))
62 return false; 62 return false;
63 } 63 }
64 return true; 64 return true;
(...skipping 20 matching lines...) Expand all
85 if (type == PASSWORDS || type == NIGORI) 85 if (type == PASSWORDS || type == NIGORI)
86 return false; // These types have their own encryption schemes. 86 return false; // These types have their own encryption schemes.
87 if (!encrypted_types.Has(type)) 87 if (!encrypted_types.Has(type))
88 return false; // This type does not require encryption 88 return false; // This type does not require encryption
89 return !specifics.has_encrypted(); 89 return !specifics.has_encrypted();
90 } 90 }
91 91
92 // Mainly for testing. 92 // Mainly for testing.
93 bool VerifyDataTypeEncryptionForTest( 93 bool VerifyDataTypeEncryptionForTest(
94 BaseTransaction* const trans, 94 BaseTransaction* const trans,
95 csync::Cryptographer* cryptographer, 95 syncer::Cryptographer* cryptographer,
96 ModelType type, 96 ModelType type,
97 bool is_encrypted) { 97 bool is_encrypted) {
98 if (type == PASSWORDS || type == NIGORI) { 98 if (type == PASSWORDS || type == NIGORI) {
99 NOTREACHED(); 99 NOTREACHED();
100 return true; 100 return true;
101 } 101 }
102 std::string type_tag = ModelTypeToRootTag(type); 102 std::string type_tag = ModelTypeToRootTag(type);
103 Entry type_root(trans, GET_BY_SERVER_TAG, type_tag); 103 Entry type_root(trans, GET_BY_SERVER_TAG, type_tag);
104 if (!type_root.good()) { 104 if (!type_root.good()) {
105 NOTREACHED(); 105 NOTREACHED();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 return false; 149 return false;
150 } 150 }
151 } 151 }
152 // Push the successor. 152 // Push the successor.
153 to_visit.push(child.Get(NEXT_ID)); 153 to_visit.push(child.Get(NEXT_ID));
154 } 154 }
155 return true; 155 return true;
156 } 156 }
157 157
158 bool UpdateEntryWithEncryption( 158 bool UpdateEntryWithEncryption(
159 csync::Cryptographer* cryptographer, 159 syncer::Cryptographer* cryptographer,
160 const sync_pb::EntitySpecifics& new_specifics, 160 const sync_pb::EntitySpecifics& new_specifics,
161 syncable::MutableEntry* entry) { 161 syncable::MutableEntry* entry) {
162 syncable::ModelType type = syncable::GetModelTypeFromSpecifics(new_specifics); 162 syncable::ModelType type = syncable::GetModelTypeFromSpecifics(new_specifics);
163 DCHECK_GE(type, syncable::FIRST_REAL_MODEL_TYPE); 163 DCHECK_GE(type, syncable::FIRST_REAL_MODEL_TYPE);
164 const sync_pb::EntitySpecifics& old_specifics = entry->Get(SPECIFICS); 164 const sync_pb::EntitySpecifics& old_specifics = entry->Get(SPECIFICS);
165 const syncable::ModelTypeSet encrypted_types = 165 const syncable::ModelTypeSet encrypted_types =
166 cryptographer->GetEncryptedTypes(); 166 cryptographer->GetEncryptedTypes();
167 // It's possible the nigori lost the set of encrypted types. If the current 167 // It's possible the nigori lost the set of encrypted types. If the current
168 // specifics are already encrypted, we want to ensure we continue encrypting. 168 // specifics are already encrypted, we want to ensure we continue encrypting.
169 bool was_encrypted = old_specifics.has_encrypted(); 169 bool was_encrypted = old_specifics.has_encrypted();
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 } 240 }
241 entry->Put(syncable::SPECIFICS, generated_specifics); 241 entry->Put(syncable::SPECIFICS, generated_specifics);
242 DVLOG(1) << "Overwriting specifics of type " 242 DVLOG(1) << "Overwriting specifics of type "
243 << syncable::ModelTypeToString(type) 243 << syncable::ModelTypeToString(type)
244 << " and marking for syncing."; 244 << " and marking for syncing.";
245 syncable::MarkForSyncing(entry); 245 syncable::MarkForSyncing(entry);
246 return true; 246 return true;
247 } 247 }
248 248
249 } // namespace syncable 249 } // namespace syncable
OLDNEW
« no previous file with comments | « sync/engine/nigori_util.h ('k') | sync/engine/nudge_source.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698