| OLD | NEW |
| 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/syncable/nigori_util.h" | 5 #include "sync/syncable/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 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 return true; | 101 return true; |
| 102 } | 102 } |
| 103 std::string type_tag = ModelTypeToRootTag(type); | 103 std::string type_tag = ModelTypeToRootTag(type); |
| 104 Entry type_root(trans, GET_BY_SERVER_TAG, type_tag); | 104 Entry type_root(trans, GET_BY_SERVER_TAG, type_tag); |
| 105 if (!type_root.good()) { | 105 if (!type_root.good()) { |
| 106 NOTREACHED(); | 106 NOTREACHED(); |
| 107 return false; | 107 return false; |
| 108 } | 108 } |
| 109 | 109 |
| 110 std::queue<Id> to_visit; | 110 std::queue<Id> to_visit; |
| 111 Id id_string; | 111 Id id_string = type_root.GetFirstChildId(); |
| 112 if (!trans->directory()->GetFirstChildId( | |
| 113 trans, type_root.Get(ID), &id_string)) { | |
| 114 NOTREACHED(); | |
| 115 return false; | |
| 116 } | |
| 117 to_visit.push(id_string); | 112 to_visit.push(id_string); |
| 118 while (!to_visit.empty()) { | 113 while (!to_visit.empty()) { |
| 119 id_string = to_visit.front(); | 114 id_string = to_visit.front(); |
| 120 to_visit.pop(); | 115 to_visit.pop(); |
| 121 if (id_string.IsRoot()) | 116 if (id_string.IsRoot()) |
| 122 continue; | 117 continue; |
| 123 | 118 |
| 124 Entry child(trans, GET_BY_ID, id_string); | 119 Entry child(trans, GET_BY_ID, id_string); |
| 125 if (!child.good()) { | 120 if (!child.good()) { |
| 126 NOTREACHED(); | 121 NOTREACHED(); |
| 127 return false; | 122 return false; |
| 128 } | 123 } |
| 129 if (child.Get(IS_DIR)) { | 124 if (child.Get(IS_DIR)) { |
| 130 Id child_id_string; | 125 Id child_id_string = child.GetFirstChildId(); |
| 131 if (!trans->directory()->GetFirstChildId( | |
| 132 trans, child.Get(ID), &child_id_string)) { | |
| 133 NOTREACHED(); | |
| 134 return false; | |
| 135 } | |
| 136 // Traverse the children. | 126 // Traverse the children. |
| 137 to_visit.push(child_id_string); | 127 to_visit.push(child_id_string); |
| 138 } | 128 } |
| 139 const sync_pb::EntitySpecifics& specifics = child.Get(SPECIFICS); | 129 const sync_pb::EntitySpecifics& specifics = child.Get(SPECIFICS); |
| 140 DCHECK_EQ(type, child.GetModelType()); | 130 DCHECK_EQ(type, child.GetModelType()); |
| 141 DCHECK_EQ(type, GetModelTypeFromSpecifics(specifics)); | 131 DCHECK_EQ(type, GetModelTypeFromSpecifics(specifics)); |
| 142 // We don't encrypt the server's permanent items. | 132 // We don't encrypt the server's permanent items. |
| 143 if (child.Get(UNIQUE_SERVER_TAG).empty()) { | 133 if (child.Get(UNIQUE_SERVER_TAG).empty()) { |
| 144 if (specifics.has_encrypted() != is_encrypted) | 134 if (specifics.has_encrypted() != is_encrypted) |
| 145 return false; | 135 return false; |
| 146 if (specifics.has_encrypted()) { | 136 if (specifics.has_encrypted()) { |
| 147 if (child.Get(NON_UNIQUE_NAME) != kEncryptedString) | 137 if (child.Get(NON_UNIQUE_NAME) != kEncryptedString) |
| 148 return false; | 138 return false; |
| 149 if (!cryptographer->CanDecryptUsingDefaultKey(specifics.encrypted())) | 139 if (!cryptographer->CanDecryptUsingDefaultKey(specifics.encrypted())) |
| 150 return false; | 140 return false; |
| 151 } | 141 } |
| 152 } | 142 } |
| 153 // Push the successor. | 143 // Push the successor. |
| 154 to_visit.push(child.Get(NEXT_ID)); | 144 to_visit.push(child.GetSuccessorId()); |
| 155 } | 145 } |
| 156 return true; | 146 return true; |
| 157 } | 147 } |
| 158 | 148 |
| 159 bool UpdateEntryWithEncryption( | 149 bool UpdateEntryWithEncryption( |
| 160 BaseTransaction* const trans, | 150 BaseTransaction* const trans, |
| 161 const sync_pb::EntitySpecifics& new_specifics, | 151 const sync_pb::EntitySpecifics& new_specifics, |
| 162 syncable::MutableEntry* entry) { | 152 syncable::MutableEntry* entry) { |
| 163 NigoriHandler* nigori_handler = trans->directory()->GetNigoriHandler(); | 153 NigoriHandler* nigori_handler = trans->directory()->GetNigoriHandler(); |
| 164 Cryptographer* cryptographer = trans->directory()->GetCryptographer(trans); | 154 Cryptographer* cryptographer = trans->directory()->GetCryptographer(trans); |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 encrypted_types.Put(APP_SETTINGS); | 298 encrypted_types.Put(APP_SETTINGS); |
| 309 if (nigori.encrypt_apps()) | 299 if (nigori.encrypt_apps()) |
| 310 encrypted_types.Put(APPS); | 300 encrypted_types.Put(APPS); |
| 311 if (nigori.encrypt_app_notifications()) | 301 if (nigori.encrypt_app_notifications()) |
| 312 encrypted_types.Put(APP_NOTIFICATIONS); | 302 encrypted_types.Put(APP_NOTIFICATIONS); |
| 313 return encrypted_types; | 303 return encrypted_types; |
| 314 } | 304 } |
| 315 | 305 |
| 316 } // namespace syncable | 306 } // namespace syncable |
| 317 } // namespace syncer | 307 } // namespace syncer |
| OLD | NEW |