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 "components/sync/core/write_node.h" | 5 #include "components/sync/core/write_node.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
110 entity_specifics.mutable_bookmark()->CopyFrom(new_value); | 110 entity_specifics.mutable_bookmark()->CopyFrom(new_value); |
111 SetEntitySpecifics(entity_specifics); | 111 SetEntitySpecifics(entity_specifics); |
112 } | 112 } |
113 | 113 |
114 void WriteNode::SetNigoriSpecifics(const sync_pb::NigoriSpecifics& new_value) { | 114 void WriteNode::SetNigoriSpecifics(const sync_pb::NigoriSpecifics& new_value) { |
115 sync_pb::EntitySpecifics entity_specifics; | 115 sync_pb::EntitySpecifics entity_specifics; |
116 entity_specifics.mutable_nigori()->CopyFrom(new_value); | 116 entity_specifics.mutable_nigori()->CopyFrom(new_value); |
117 SetEntitySpecifics(entity_specifics); | 117 SetEntitySpecifics(entity_specifics); |
118 } | 118 } |
119 | 119 |
120 void WriteNode::SetPasswordSpecifics( | 120 void WriteNode::SetPasswordSpecifics(const sync_pb::PasswordSpecificsData& data, |
121 const sync_pb::PasswordSpecificsData& data) { | 121 PassphraseType passphrase_type) { |
122 DCHECK_EQ(GetModelType(), PASSWORDS); | 122 DCHECK_EQ(GetModelType(), PASSWORDS); |
123 | 123 |
124 Cryptographer* cryptographer = GetTransaction()->GetCryptographer(); | 124 Cryptographer* cryptographer = GetTransaction()->GetCryptographer(); |
125 | 125 |
126 // We have to do the idempotency check here (vs in UpdateEntryWithEncryption) | 126 // We have to do the idempotency check here (vs in UpdateEntryWithEncryption) |
127 // because Passwords have their encrypted data within the PasswordSpecifics, | 127 // because Passwords have their encrypted data within the PasswordSpecifics, |
128 // vs within the EntitySpecifics like all the other types. | 128 // vs within the EntitySpecifics like all the other types. |
129 const sync_pb::EntitySpecifics& old_specifics = GetEntitySpecifics(); | 129 const sync_pb::EntitySpecifics& old_specifics = GetEntitySpecifics(); |
130 sync_pb::EntitySpecifics entity_specifics; | 130 sync_pb::EntitySpecifics entity_specifics; |
131 // Copy over the old specifics if they exist. | 131 // Copy over the old specifics if they exist. |
132 if (GetModelTypeFromSpecifics(old_specifics) == PASSWORDS) { | 132 if (GetModelTypeFromSpecifics(old_specifics) == PASSWORDS) { |
133 entity_specifics.CopyFrom(old_specifics); | 133 entity_specifics.CopyFrom(old_specifics); |
134 } else { | 134 } else { |
135 AddDefaultFieldValue(PASSWORDS, &entity_specifics); | 135 AddDefaultFieldValue(PASSWORDS, &entity_specifics); |
136 } | 136 } |
137 sync_pb::PasswordSpecifics* password_specifics = | 137 sync_pb::PasswordSpecifics* password_specifics = |
138 entity_specifics.mutable_password(); | 138 entity_specifics.mutable_password(); |
139 // This will only update password_specifics if the underlying unencrypted blob | 139 // This will only update password_specifics if the underlying unencrypted blob |
140 // was different from |data| or was not encrypted with the proper passphrase. | 140 // was different from |data| or was not encrypted with the proper passphrase. |
141 if (!cryptographer->Encrypt(data, password_specifics->mutable_encrypted())) { | 141 if (!cryptographer->Encrypt(data, password_specifics->mutable_encrypted())) { |
142 LOG(ERROR) << "Failed to encrypt password, possibly due to sync node " | 142 LOG(ERROR) << "Failed to encrypt password, possibly due to sync node " |
143 << "corruption"; | 143 << "corruption"; |
144 return; | 144 return; |
145 } | 145 } |
146 SetEntitySpecifics(entity_specifics); | 146 SetEntitySpecifics(entity_specifics, passphrase_type); |
147 } | 147 } |
148 | 148 |
149 void WriteNode::SetEntitySpecifics(const sync_pb::EntitySpecifics& new_value) { | 149 void WriteNode::SetEntitySpecifics(const sync_pb::EntitySpecifics& new_value) { |
150 SetEntitySpecifics(new_value, PassphraseType::UNDEFINED); | |
151 } | |
152 | |
153 void WriteNode::SetEntitySpecifics(const sync_pb::EntitySpecifics& new_value, | |
154 PassphraseType passphrase_type) { | |
150 ModelType new_specifics_type = GetModelTypeFromSpecifics(new_value); | 155 ModelType new_specifics_type = GetModelTypeFromSpecifics(new_value); |
151 CHECK(!new_value.password().has_client_only_encrypted_data()); | 156 CHECK(!new_value.password().has_client_only_encrypted_data()); |
152 DCHECK_NE(new_specifics_type, UNSPECIFIED); | 157 DCHECK_NE(new_specifics_type, UNSPECIFIED); |
153 DVLOG(1) << "Writing entity specifics of type " | 158 DVLOG(1) << "Writing entity specifics of type " |
154 << ModelTypeToString(new_specifics_type); | 159 << ModelTypeToString(new_specifics_type); |
155 DCHECK_EQ(new_specifics_type, GetModelType()); | 160 DCHECK_EQ(new_specifics_type, GetModelType()); |
156 | 161 |
157 // Preserve unknown fields. | 162 // Preserve unknown fields. |
158 const sync_pb::EntitySpecifics& old_specifics = entry_->GetSpecifics(); | 163 const sync_pb::EntitySpecifics& old_specifics = entry_->GetSpecifics(); |
159 sync_pb::EntitySpecifics new_specifics; | 164 sync_pb::EntitySpecifics new_specifics; |
160 new_specifics.CopyFrom(new_value); | 165 new_specifics.CopyFrom(new_value); |
161 new_specifics.mutable_unknown_fields()->append( | 166 new_specifics.mutable_unknown_fields()->append( |
162 old_specifics.unknown_fields()); | 167 old_specifics.unknown_fields()); |
163 | 168 |
164 // Will update the entry if encryption was necessary. | 169 // Will update the entry if encryption was necessary. |
165 if (!UpdateEntryWithEncryption(GetTransaction()->GetWrappedTrans(), | 170 if (!UpdateEntryWithEncryption(GetTransaction()->GetWrappedTrans(), |
Nicolas Zea
2016/08/26 18:28:30
Given you have access to the transaction now, I do
melandory
2016/08/26 23:16:59
Oh, definitelly!
Fixed and updated CL https://cod
| |
166 new_specifics, entry_)) { | 171 new_specifics, entry_, passphrase_type)) { |
167 return; | 172 return; |
168 } | 173 } |
169 if (entry_->GetSpecifics().has_encrypted()) { | 174 if (entry_->GetSpecifics().has_encrypted()) { |
170 // EncryptIfNecessary already updated the entry for us and marked for | 175 // EncryptIfNecessary already updated the entry for us and marked for |
171 // syncing if it was needed. Now we just make a copy of the unencrypted | 176 // syncing if it was needed. Now we just make a copy of the unencrypted |
172 // specifics so that if this node is updated, we do not have to decrypt the | 177 // specifics so that if this node is updated, we do not have to decrypt the |
173 // old data. Note that this only modifies the node's local data, not the | 178 // old data. Note that this only modifies the node's local data, not the |
174 // entry itself. | 179 // entry itself. |
175 SetUnencryptedSpecifics(new_value); | 180 SetUnencryptedSpecifics(new_value); |
176 } | 181 } |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
469 syncable::Id predecessor_id = | 474 syncable::Id predecessor_id = |
470 predecessor ? predecessor->GetSyncId() : syncable::Id(); | 475 predecessor ? predecessor->GetSyncId() : syncable::Id(); |
471 return entry_->PutPredecessor(predecessor_id); | 476 return entry_->PutPredecessor(predecessor_id); |
472 } | 477 } |
473 | 478 |
474 void WriteNode::MarkForSyncing() { | 479 void WriteNode::MarkForSyncing() { |
475 syncable::MarkForSyncing(entry_); | 480 syncable::MarkForSyncing(entry_); |
476 } | 481 } |
477 | 482 |
478 } // namespace syncer | 483 } // namespace syncer |
OLD | NEW |