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_commit_response_command.h" | 5 #include "sync/engine/process_commit_response_command.h" |
6 | 6 |
7 #include <cstddef> | 7 #include <cstddef> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/location.h" | 13 #include "base/location.h" |
14 #include "sync/engine/syncer_proto_util.h" | 14 #include "sync/engine/syncer_proto_util.h" |
15 #include "sync/engine/syncer_util.h" | 15 #include "sync/engine/syncer_util.h" |
| 16 #include "sync/internal_api/public/base/unique_position.h" |
16 #include "sync/sessions/sync_session.h" | 17 #include "sync/sessions/sync_session.h" |
17 #include "sync/syncable/entry.h" | 18 #include "sync/syncable/entry.h" |
18 #include "sync/syncable/mutable_entry.h" | 19 #include "sync/syncable/mutable_entry.h" |
19 #include "sync/syncable/read_transaction.h" | 20 #include "sync/syncable/read_transaction.h" |
20 #include "sync/syncable/syncable_proto_util.h" | 21 #include "sync/syncable/syncable_proto_util.h" |
21 #include "sync/syncable/syncable_util.h" | 22 #include "sync/syncable/syncable_util.h" |
22 #include "sync/syncable/write_transaction.h" | 23 #include "sync/syncable/write_transaction.h" |
23 #include "sync/util/time.h" | 24 #include "sync/util/time.h" |
24 | 25 |
25 // TODO(vishwath): Remove this include after node positions have | |
26 // shifted to completely using Ordinals. | |
27 // See http://crbug.com/145412 . | |
28 #include "sync/internal_api/public/base/node_ordinal.h" | |
29 | |
30 using std::set; | 26 using std::set; |
31 using std::string; | 27 using std::string; |
32 using std::vector; | 28 using std::vector; |
33 using sync_pb::CommitResponse; | 29 using sync_pb::CommitResponse; |
34 | 30 |
35 namespace syncer { | 31 namespace syncer { |
36 | 32 |
37 using sessions::OrderedCommitSet; | 33 using sessions::OrderedCommitSet; |
38 using sessions::StatusController; | 34 using sessions::StatusController; |
39 using sessions::SyncSession; | 35 using sessions::SyncSession; |
40 using syncable::WriteTransaction; | 36 using syncable::WriteTransaction; |
41 using syncable::MutableEntry; | 37 using syncable::MutableEntry; |
42 using syncable::Entry; | 38 using syncable::Entry; |
43 using syncable::BASE_VERSION; | 39 using syncable::BASE_VERSION; |
44 using syncable::GET_BY_ID; | 40 using syncable::GET_BY_ID; |
45 using syncable::ID; | 41 using syncable::ID; |
46 using syncable::IS_DEL; | 42 using syncable::IS_DEL; |
47 using syncable::IS_DIR; | 43 using syncable::IS_DIR; |
48 using syncable::IS_UNAPPLIED_UPDATE; | 44 using syncable::IS_UNAPPLIED_UPDATE; |
49 using syncable::IS_UNSYNCED; | 45 using syncable::IS_UNSYNCED; |
50 using syncable::PARENT_ID; | 46 using syncable::PARENT_ID; |
51 using syncable::SERVER_IS_DEL; | 47 using syncable::SERVER_IS_DEL; |
52 using syncable::SERVER_PARENT_ID; | 48 using syncable::SERVER_PARENT_ID; |
53 using syncable::SERVER_ORDINAL_IN_PARENT; | |
54 using syncable::SERVER_VERSION; | 49 using syncable::SERVER_VERSION; |
55 using syncable::SYNCER; | 50 using syncable::SYNCER; |
56 using syncable::SYNCING; | 51 using syncable::SYNCING; |
57 | 52 |
58 ProcessCommitResponseCommand::ProcessCommitResponseCommand( | 53 ProcessCommitResponseCommand::ProcessCommitResponseCommand( |
59 const sessions::OrderedCommitSet& commit_set, | 54 const sessions::OrderedCommitSet& commit_set, |
60 const sync_pb::ClientToServerMessage& commit_message, | 55 const sync_pb::ClientToServerMessage& commit_message, |
61 const sync_pb::ClientToServerResponse& commit_response) | 56 const sync_pb::ClientToServerResponse& commit_response) |
62 : commit_set_(commit_set), | 57 : commit_set_(commit_set), |
63 commit_message_(commit_message), | 58 commit_message_(commit_message), |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 | 349 |
355 local_entry->Put(syncable::SERVER_IS_DIR, | 350 local_entry->Put(syncable::SERVER_IS_DIR, |
356 (committed_entry.folder() || | 351 (committed_entry.folder() || |
357 committed_entry.bookmarkdata().bookmark_folder())); | 352 committed_entry.bookmarkdata().bookmark_folder())); |
358 local_entry->Put(syncable::SERVER_SPECIFICS, | 353 local_entry->Put(syncable::SERVER_SPECIFICS, |
359 committed_entry.specifics()); | 354 committed_entry.specifics()); |
360 local_entry->Put(syncable::SERVER_MTIME, | 355 local_entry->Put(syncable::SERVER_MTIME, |
361 ProtoTimeToTime(committed_entry.mtime())); | 356 ProtoTimeToTime(committed_entry.mtime())); |
362 local_entry->Put(syncable::SERVER_CTIME, | 357 local_entry->Put(syncable::SERVER_CTIME, |
363 ProtoTimeToTime(committed_entry.ctime())); | 358 ProtoTimeToTime(committed_entry.ctime())); |
364 local_entry->Put(syncable::SERVER_ORDINAL_IN_PARENT, | 359 if (committed_entry.has_unique_position()) { |
365 Int64ToNodeOrdinal(entry_response.position_in_parent())); | 360 local_entry->Put(syncable::SERVER_UNIQUE_POSITION, |
| 361 UniquePosition::FromBytes( |
| 362 committed_entry.unique_position())); |
| 363 } |
366 | 364 |
367 // TODO(nick): The server doesn't set entry_response.server_parent_id in | 365 // TODO(nick): The server doesn't set entry_response.server_parent_id in |
368 // practice; to update SERVER_PARENT_ID appropriately here we'd need to | 366 // practice; to update SERVER_PARENT_ID appropriately here we'd need to |
369 // get the post-commit ID of the parent indicated by | 367 // get the post-commit ID of the parent indicated by |
370 // committed_entry.parent_id_string(). That should be inferrable from the | 368 // committed_entry.parent_id_string(). That should be inferrable from the |
371 // information we have, but it's a bit convoluted to pull it out directly. | 369 // information we have, but it's a bit convoluted to pull it out directly. |
372 // Getting this right is important: SERVER_PARENT_ID gets fed back into | 370 // Getting this right is important: SERVER_PARENT_ID gets fed back into |
373 // old_parent_id during the next commit. | 371 // old_parent_id during the next commit. |
374 local_entry->Put(syncable::SERVER_PARENT_ID, | 372 local_entry->Put(syncable::SERVER_PARENT_ID, |
375 local_entry->Get(syncable::PARENT_ID)); | 373 local_entry->Get(syncable::PARENT_ID)); |
(...skipping 22 matching lines...) Expand all Loading... |
398 const string& server_name = | 396 const string& server_name = |
399 GetResultingPostCommitName(committed_entry, entry_response); | 397 GetResultingPostCommitName(committed_entry, entry_response); |
400 const string& old_name = | 398 const string& old_name = |
401 local_entry->Get(syncable::NON_UNIQUE_NAME); | 399 local_entry->Get(syncable::NON_UNIQUE_NAME); |
402 | 400 |
403 if (!server_name.empty() && old_name != server_name) { | 401 if (!server_name.empty() && old_name != server_name) { |
404 DVLOG(1) << "During commit, server changed name: " << old_name | 402 DVLOG(1) << "During commit, server changed name: " << old_name |
405 << " to new name: " << server_name; | 403 << " to new name: " << server_name; |
406 local_entry->Put(syncable::NON_UNIQUE_NAME, server_name); | 404 local_entry->Put(syncable::NON_UNIQUE_NAME, server_name); |
407 } | 405 } |
408 | |
409 // The server has the final say on positioning, so apply the absolute | |
410 // position that it returns. | |
411 if (entry_response.has_position_in_parent()) { | |
412 // The SERVER_ field should already have been written. | |
413 DCHECK_EQ(entry_response.position_in_parent(), | |
414 NodeOrdinalToInt64(local_entry->Get(SERVER_ORDINAL_IN_PARENT))); | |
415 | |
416 // We just committed successfully, so we assume that the position | |
417 // value we got applies to the PARENT_ID we submitted. | |
418 syncable::Id new_prev = local_entry->ComputePrevIdFromServerPosition( | |
419 local_entry->Get(PARENT_ID)); | |
420 if (!local_entry->PutPredecessor(new_prev)) { | |
421 // TODO(lipalani) : Propagate the error to caller. crbug.com/100444. | |
422 NOTREACHED(); | |
423 } | |
424 } | |
425 } | 406 } |
426 | 407 |
427 void ProcessCommitResponseCommand::ProcessSuccessfulCommitResponse( | 408 void ProcessCommitResponseCommand::ProcessSuccessfulCommitResponse( |
428 const sync_pb::SyncEntity& committed_entry, | 409 const sync_pb::SyncEntity& committed_entry, |
429 const sync_pb::CommitResponse_EntryResponse& entry_response, | 410 const sync_pb::CommitResponse_EntryResponse& entry_response, |
430 const syncable::Id& pre_commit_id, syncable::MutableEntry* local_entry, | 411 const syncable::Id& pre_commit_id, syncable::MutableEntry* local_entry, |
431 bool syncing_was_set, set<syncable::Id>* deleted_folders) { | 412 bool syncing_was_set, set<syncable::Id>* deleted_folders) { |
432 DCHECK(local_entry->Get(IS_UNSYNCED)); | 413 DCHECK(local_entry->Get(IS_UNSYNCED)); |
433 | 414 |
434 // Update SERVER_VERSION and BASE_VERSION. | 415 // Update SERVER_VERSION and BASE_VERSION. |
(...skipping 28 matching lines...) Expand all Loading... |
463 // been recursively deleted. | 444 // been recursively deleted. |
464 // TODO(nick): Here, commit_message.deleted() would be more correct than | 445 // TODO(nick): Here, commit_message.deleted() would be more correct than |
465 // local_entry->Get(IS_DEL). For example, an item could be renamed, and then | 446 // local_entry->Get(IS_DEL). For example, an item could be renamed, and then |
466 // deleted during the commit of the rename. Unit test & fix. | 447 // deleted during the commit of the rename. Unit test & fix. |
467 if (local_entry->Get(IS_DIR) && local_entry->Get(IS_DEL)) { | 448 if (local_entry->Get(IS_DIR) && local_entry->Get(IS_DEL)) { |
468 deleted_folders->insert(local_entry->Get(ID)); | 449 deleted_folders->insert(local_entry->Get(ID)); |
469 } | 450 } |
470 } | 451 } |
471 | 452 |
472 } // namespace syncer | 453 } // namespace syncer |
OLD | NEW |