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/engine/process_updates_command.h" | 5 #include "sync/engine/process_updates_command.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
11 #include "sync/engine/syncer.h" | 11 #include "sync/engine/syncer.h" |
12 #include "sync/engine/syncer_proto_util.h" | 12 #include "sync/engine/syncer_proto_util.h" |
13 #include "sync/engine/syncer_util.h" | 13 #include "sync/engine/syncer_util.h" |
14 #include "sync/sessions/sync_session.h" | 14 #include "sync/sessions/sync_session.h" |
15 #include "sync/syncable/directory.h" | 15 #include "sync/syncable/directory.h" |
16 #include "sync/syncable/mutable_entry.h" | 16 #include "sync/syncable/mutable_entry.h" |
17 #include "sync/syncable/syncable_proto_util.h" | 17 #include "sync/syncable/syncable_proto_util.h" |
18 #include "sync/syncable/syncable_util.h" | 18 #include "sync/syncable/syncable_util.h" |
19 #include "sync/syncable/write_transaction.h" | 19 #include "sync/syncable/write_transaction.h" |
20 #include "sync/util/cryptographer.h" | 20 #include "sync/util/cryptographer.h" |
21 | 21 |
22 // TODO(vishwath): Remove this include after node positions have | |
23 // shifted to completely using Ordinals. | |
24 // See http://crbug.com/145412 . | |
25 #include "sync/internal_api/public/base/node_ordinal.h" | |
26 | |
27 using std::vector; | 22 using std::vector; |
28 | 23 |
29 namespace syncer { | 24 namespace syncer { |
30 | 25 |
31 using sessions::SyncSession; | 26 using sessions::SyncSession; |
32 using sessions::StatusController; | 27 using sessions::StatusController; |
33 | 28 |
34 using syncable::GET_BY_ID; | 29 using syncable::GET_BY_ID; |
35 | 30 |
36 ProcessUpdatesCommand::ProcessUpdatesCommand() {} | 31 ProcessUpdatesCommand::ProcessUpdatesCommand() {} |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 } | 302 } |
308 // Force application of this update, no matter what. | 303 // Force application of this update, no matter what. |
309 target_entry.Put(syncable::IS_UNAPPLIED_UPDATE, true); | 304 target_entry.Put(syncable::IS_UNAPPLIED_UPDATE, true); |
310 } | 305 } |
311 | 306 |
312 // If this is a newly received undecryptable update, and the only thing that | 307 // If this is a newly received undecryptable update, and the only thing that |
313 // has changed are the specifics, store the original decryptable specifics, | 308 // has changed are the specifics, store the original decryptable specifics, |
314 // (on which any current or future local changes are based) before we | 309 // (on which any current or future local changes are based) before we |
315 // overwrite SERVER_SPECIFICS. | 310 // overwrite SERVER_SPECIFICS. |
316 // MTIME, CTIME, and NON_UNIQUE_NAME are not enforced. | 311 // MTIME, CTIME, and NON_UNIQUE_NAME are not enforced. |
| 312 |
| 313 bool position_matches = true; |
| 314 if (target_entry.GetModelType() == BOOKMARKS && !update.deleted()) { |
| 315 std::string update_tag = GetUniqueBookmarkTagFromUpdate(update); |
| 316 if (UniquePosition::IsValidSuffix(update_tag)) { |
| 317 position_matches = GetUpdatePosition(update, update_tag).Equals( |
| 318 target_entry.Get(syncable::SERVER_UNIQUE_POSITION)); |
| 319 } else { |
| 320 NOTREACHED(); |
| 321 position_matches = false; |
| 322 } |
| 323 } |
| 324 |
317 if (!update.deleted() && !target_entry.Get(syncable::SERVER_IS_DEL) && | 325 if (!update.deleted() && !target_entry.Get(syncable::SERVER_IS_DEL) && |
318 (SyncableIdFromProto(update.parent_id_string()) == | 326 (SyncableIdFromProto(update.parent_id_string()) == |
319 target_entry.Get(syncable::SERVER_PARENT_ID)) && | 327 target_entry.Get(syncable::SERVER_PARENT_ID)) && |
320 (update.position_in_parent() == | 328 position_matches && |
321 NodeOrdinalToInt64( | |
322 target_entry.Get(syncable::SERVER_ORDINAL_IN_PARENT))) && | |
323 update.has_specifics() && update.specifics().has_encrypted() && | 329 update.has_specifics() && update.specifics().has_encrypted() && |
324 !cryptographer->CanDecrypt(update.specifics().encrypted())) { | 330 !cryptographer->CanDecrypt(update.specifics().encrypted())) { |
325 sync_pb::EntitySpecifics prev_specifics = | 331 sync_pb::EntitySpecifics prev_specifics = |
326 target_entry.Get(syncable::SERVER_SPECIFICS); | 332 target_entry.Get(syncable::SERVER_SPECIFICS); |
327 // We only store the old specifics if they were decryptable and applied and | 333 // We only store the old specifics if they were decryptable and applied and |
328 // there is no BASE_SERVER_SPECIFICS already. Else do nothing. | 334 // there is no BASE_SERVER_SPECIFICS already. Else do nothing. |
329 if (!target_entry.Get(syncable::IS_UNAPPLIED_UPDATE) && | 335 if (!target_entry.Get(syncable::IS_UNAPPLIED_UPDATE) && |
330 !IsRealDataType(GetModelTypeFromSpecifics( | 336 !IsRealDataType(GetModelTypeFromSpecifics( |
331 target_entry.Get(syncable::BASE_SERVER_SPECIFICS))) && | 337 target_entry.Get(syncable::BASE_SERVER_SPECIFICS))) && |
332 (!prev_specifics.has_encrypted() || | 338 (!prev_specifics.has_encrypted() || |
(...skipping 10 matching lines...) Expand all Loading... |
343 target_entry.Put(syncable::BASE_SERVER_SPECIFICS, | 349 target_entry.Put(syncable::BASE_SERVER_SPECIFICS, |
344 sync_pb::EntitySpecifics()); | 350 sync_pb::EntitySpecifics()); |
345 } | 351 } |
346 | 352 |
347 UpdateServerFieldsFromUpdate(&target_entry, update, name); | 353 UpdateServerFieldsFromUpdate(&target_entry, update, name); |
348 | 354 |
349 return SUCCESS_PROCESSED; | 355 return SUCCESS_PROCESSED; |
350 } | 356 } |
351 | 357 |
352 } // namespace syncer | 358 } // namespace syncer |
OLD | NEW |