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/engine/syncer_util.h" | 5 #include "sync/engine/syncer_util.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
177 | 177 |
178 // Just a quick sanity check. | 178 // Just a quick sanity check. |
179 DCHECK(!local_entry.GetId().ServerKnows()); | 179 DCHECK(!local_entry.GetId().ServerKnows()); |
180 | 180 |
181 DVLOG(1) << "Reuniting lost commit response IDs. server id: " | 181 DVLOG(1) << "Reuniting lost commit response IDs. server id: " |
182 << update_id << " local id: " << local_entry.GetId() | 182 << update_id << " local id: " << local_entry.GetId() |
183 << " new version: " << new_version; | 183 << " new version: " << new_version; |
184 | 184 |
185 return local_entry.GetId(); | 185 return local_entry.GetId(); |
186 } | 186 } |
187 } else if (update.has_server_defined_unique_tag() && | |
188 !update.server_defined_unique_tag().empty()) { | |
189 // The client creates type root folders on demand with a local ID on | |
Nicolas Zea
2015/01/26 23:21:53
nit: "on demand with a local id on demand"?
stanisc
2015/01/29 00:27:37
Done.
| |
190 // demand when a progress marker for the given type is initially set. | |
191 // The server might also attempt to send a type root folder for the same | |
192 // type. It will does that during the transition period until support for | |
Nicolas Zea
2015/01/26 23:21:53
nit: " will does"
stanisc
2015/01/29 00:27:37
Done.
| |
193 // root folders is removed on the server for most types. After that the | |
194 // server will still be creating type root folders for BOOKMARKS and | |
195 // NIGORI types. | |
196 syncable::Entry local_entry(trans, syncable::GET_BY_SERVER_TAG, | |
197 update.server_defined_unique_tag()); | |
198 if (local_entry.good() && !local_entry.GetId().ServerKnows()) { | |
199 DCHECK(local_entry.GetId() != update_id); | |
200 return local_entry.GetId(); | |
201 } | |
187 } | 202 } |
203 | |
188 // Fallback: target an entry having the server ID, creating one if needed. | 204 // Fallback: target an entry having the server ID, creating one if needed. |
189 return update_id; | 205 return update_id; |
190 } | 206 } |
191 | 207 |
192 UpdateAttemptResponse AttemptToUpdateEntry( | 208 UpdateAttemptResponse AttemptToUpdateEntry( |
193 syncable::WriteTransaction* const trans, | 209 syncable::WriteTransaction* const trans, |
194 syncable::MutableEntry* const entry, | 210 syncable::MutableEntry* const entry, |
195 Cryptographer* cryptographer) { | 211 Cryptographer* cryptographer) { |
196 CHECK(entry->good()); | 212 CHECK(entry->good()); |
197 if (!entry->GetIsUnappliedUpdate()) | 213 if (!entry->GetIsUnappliedUpdate()) |
(...skipping 22 matching lines...) Expand all Loading... | |
220 const sync_pb::PasswordSpecifics& password = specifics.password(); | 236 const sync_pb::PasswordSpecifics& password = specifics.password(); |
221 if (!cryptographer->CanDecrypt(password.encrypted())) { | 237 if (!cryptographer->CanDecrypt(password.encrypted())) { |
222 DVLOG(1) << "Received an undecryptable password update, returning " | 238 DVLOG(1) << "Received an undecryptable password update, returning " |
223 << "conflict_encryption."; | 239 << "conflict_encryption."; |
224 return CONFLICT_ENCRYPTION; | 240 return CONFLICT_ENCRYPTION; |
225 } | 241 } |
226 } | 242 } |
227 | 243 |
228 if (!entry->GetServerIsDel()) { | 244 if (!entry->GetServerIsDel()) { |
229 syncable::Id new_parent = entry->GetServerParentId(); | 245 syncable::Id new_parent = entry->GetServerParentId(); |
230 Entry parent(trans, GET_BY_ID, new_parent); | 246 if (!new_parent.IsNull()) { |
231 // A note on non-directory parents: | 247 // Perform this step only if the parent is specified. |
232 // We catch most unfixable tree invariant errors at update receipt time, | 248 // The unset parent means that the implicit type root would be used. |
233 // however we deal with this case here because we may receive the child | 249 Entry parent(trans, GET_BY_ID, new_parent); |
234 // first then the illegal parent. Instead of dealing with it twice in | 250 // A note on non-directory parents: |
235 // different ways we deal with it once here to reduce the amount of code and | 251 // We catch most unfixable tree invariant errors at update receipt time, |
236 // potential errors. | 252 // however we deal with this case here because we may receive the child |
237 if (!parent.good() || parent.GetIsDel() || !parent.GetIsDir()) { | 253 // first then the illegal parent. Instead of dealing with it twice in |
238 DVLOG(1) << "Entry has bad parent, returning conflict_hierarchy."; | 254 // different ways we deal with it once here to reduce the amount of code |
239 return CONFLICT_HIERARCHY; | 255 // and |
256 // potential errors. | |
Nicolas Zea
2015/01/26 23:21:53
nit: move to previous line
stanisc
2015/01/29 00:27:37
Done.
| |
257 if (!parent.good() || parent.GetIsDel() || !parent.GetIsDir()) { | |
258 DVLOG(1) << "Entry has bad parent, returning conflict_hierarchy."; | |
259 return CONFLICT_HIERARCHY; | |
260 } | |
261 } else { | |
262 DCHECK( | |
263 !IsTypeWithServerGeneratedRoot(GetModelTypeFromSpecifics(specifics))); | |
240 } | 264 } |
241 if (entry->GetParentId() != new_parent) { | 265 if (entry->GetParentId() != new_parent) { |
242 if (!entry->GetIsDel() && !IsLegalNewParent(trans, id, new_parent)) { | 266 if (!entry->GetIsDel() && !IsLegalNewParent(trans, id, new_parent)) { |
243 DVLOG(1) << "Not updating item " << id | 267 DVLOG(1) << "Not updating item " << id |
244 << ", illegal new parent (would cause loop)."; | 268 << ", illegal new parent (would cause loop)."; |
245 return CONFLICT_HIERARCHY; | 269 return CONFLICT_HIERARCHY; |
246 } | 270 } |
247 } | 271 } |
248 } else if (entry->GetIsDir()) { | 272 } else if (entry->GetIsDir()) { |
249 Directory::Metahandles handles; | 273 Directory::Metahandles handles; |
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
645 if (update.version() < target->GetServerVersion()) { | 669 if (update.version() < target->GetServerVersion()) { |
646 LOG(WARNING) << "Update older than current server version for " | 670 LOG(WARNING) << "Update older than current server version for " |
647 << *target << " Update:" | 671 << *target << " Update:" |
648 << SyncerProtoUtil::SyncEntityDebugString(update); | 672 << SyncerProtoUtil::SyncEntityDebugString(update); |
649 return VERIFY_SUCCESS; // Expected in new sync protocol. | 673 return VERIFY_SUCCESS; // Expected in new sync protocol. |
650 } | 674 } |
651 return VERIFY_UNDECIDED; | 675 return VERIFY_UNDECIDED; |
652 } | 676 } |
653 | 677 |
654 } // namespace syncer | 678 } // namespace syncer |
OLD | NEW |