| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/syncable/nigori_util.h" | 5 #include "sync/syncable/nigori_util.h" |
| 6 | 6 |
| 7 #include <stddef.h> |
| 8 #include <stdint.h> |
| 9 |
| 7 #include <queue> | 10 #include <queue> |
| 8 #include <string> | 11 #include <string> |
| 9 #include <vector> | 12 #include <vector> |
| 10 | 13 |
| 11 #include "base/json/json_writer.h" | 14 #include "base/json/json_writer.h" |
| 12 #include "sync/syncable/directory.h" | 15 #include "sync/syncable/directory.h" |
| 13 #include "sync/syncable/entry.h" | 16 #include "sync/syncable/entry.h" |
| 17 #include "sync/syncable/mutable_entry.h" |
| 14 #include "sync/syncable/nigori_handler.h" | 18 #include "sync/syncable/nigori_handler.h" |
| 15 #include "sync/syncable/mutable_entry.h" | |
| 16 #include "sync/syncable/syncable_util.h" | 19 #include "sync/syncable/syncable_util.h" |
| 17 #include "sync/syncable/syncable_write_transaction.h" | 20 #include "sync/syncable/syncable_write_transaction.h" |
| 18 #include "sync/util/cryptographer.h" | 21 #include "sync/util/cryptographer.h" |
| 19 | 22 |
| 20 namespace syncer { | 23 namespace syncer { |
| 21 namespace syncable { | 24 namespace syncable { |
| 22 | 25 |
| 23 bool ProcessUnsyncedChangesForEncryption( | 26 bool ProcessUnsyncedChangesForEncryption( |
| 24 WriteTransaction* const trans) { | 27 WriteTransaction* const trans) { |
| 25 NigoriHandler* nigori_handler = trans->directory()->GetNigoriHandler(); | 28 NigoriHandler* nigori_handler = trans->directory()->GetNigoriHandler(); |
| 26 ModelTypeSet encrypted_types = nigori_handler->GetEncryptedTypes(trans); | 29 ModelTypeSet encrypted_types = nigori_handler->GetEncryptedTypes(trans); |
| 27 Cryptographer* cryptographer = trans->directory()->GetCryptographer(trans); | 30 Cryptographer* cryptographer = trans->directory()->GetCryptographer(trans); |
| 28 DCHECK(cryptographer->is_ready()); | 31 DCHECK(cryptographer->is_ready()); |
| 29 | 32 |
| 30 // Get list of all datatypes with unsynced changes. It's possible that our | 33 // Get list of all datatypes with unsynced changes. It's possible that our |
| 31 // local changes need to be encrypted if encryption for that datatype was | 34 // local changes need to be encrypted if encryption for that datatype was |
| 32 // just turned on (and vice versa). | 35 // just turned on (and vice versa). |
| 33 // Note: we do not attempt to re-encrypt data with a new key here as key | 36 // Note: we do not attempt to re-encrypt data with a new key here as key |
| 34 // changes in this code path are likely due to consistency issues (we have | 37 // changes in this code path are likely due to consistency issues (we have |
| 35 // to be updated to a key we already have, e.g. an old key). | 38 // to be updated to a key we already have, e.g. an old key). |
| 36 std::vector<int64> handles; | 39 std::vector<int64_t> handles; |
| 37 GetUnsyncedEntries(trans, &handles); | 40 GetUnsyncedEntries(trans, &handles); |
| 38 for (size_t i = 0; i < handles.size(); ++i) { | 41 for (size_t i = 0; i < handles.size(); ++i) { |
| 39 MutableEntry entry(trans, GET_BY_HANDLE, handles[i]); | 42 MutableEntry entry(trans, GET_BY_HANDLE, handles[i]); |
| 40 const sync_pb::EntitySpecifics& specifics = entry.GetSpecifics(); | 43 const sync_pb::EntitySpecifics& specifics = entry.GetSpecifics(); |
| 41 // Ignore types that don't need encryption or entries that are already | 44 // Ignore types that don't need encryption or entries that are already |
| 42 // encrypted. | 45 // encrypted. |
| 43 if (!SpecificsNeedsEncryption(encrypted_types, specifics)) | 46 if (!SpecificsNeedsEncryption(encrypted_types, specifics)) |
| 44 continue; | 47 continue; |
| 45 if (!UpdateEntryWithEncryption(trans, specifics, &entry)) | 48 if (!UpdateEntryWithEncryption(trans, specifics, &entry)) |
| 46 return false; | 49 return false; |
| 47 } | 50 } |
| 48 return true; | 51 return true; |
| 49 } | 52 } |
| 50 | 53 |
| 51 bool VerifyUnsyncedChangesAreEncrypted( | 54 bool VerifyUnsyncedChangesAreEncrypted( |
| 52 BaseTransaction* const trans, | 55 BaseTransaction* const trans, |
| 53 ModelTypeSet encrypted_types) { | 56 ModelTypeSet encrypted_types) { |
| 54 std::vector<int64> handles; | 57 std::vector<int64_t> handles; |
| 55 GetUnsyncedEntries(trans, &handles); | 58 GetUnsyncedEntries(trans, &handles); |
| 56 for (size_t i = 0; i < handles.size(); ++i) { | 59 for (size_t i = 0; i < handles.size(); ++i) { |
| 57 Entry entry(trans, GET_BY_HANDLE, handles[i]); | 60 Entry entry(trans, GET_BY_HANDLE, handles[i]); |
| 58 if (!entry.good()) { | 61 if (!entry.good()) { |
| 59 NOTREACHED(); | 62 NOTREACHED(); |
| 60 return false; | 63 return false; |
| 61 } | 64 } |
| 62 if (EntryNeedsEncryption(encrypted_types, entry)) | 65 if (EntryNeedsEncryption(encrypted_types, entry)) |
| 63 return false; | 66 return false; |
| 64 } | 67 } |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 encrypted_types.Put(FAVICON_TRACKING); | 320 encrypted_types.Put(FAVICON_TRACKING); |
| 318 if (nigori.encrypt_articles()) | 321 if (nigori.encrypt_articles()) |
| 319 encrypted_types.Put(ARTICLES); | 322 encrypted_types.Put(ARTICLES); |
| 320 if (nigori.encrypt_app_list()) | 323 if (nigori.encrypt_app_list()) |
| 321 encrypted_types.Put(APP_LIST); | 324 encrypted_types.Put(APP_LIST); |
| 322 return encrypted_types; | 325 return encrypted_types; |
| 323 } | 326 } |
| 324 | 327 |
| 325 } // namespace syncable | 328 } // namespace syncable |
| 326 } // namespace syncer | 329 } // namespace syncer |
| OLD | NEW |