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/sessions/sync_session.h" | 16 #include "sync/sessions/sync_session.h" |
17 #include "sync/syncable/entry.h" | 17 #include "sync/syncable/entry.h" |
18 #include "sync/syncable/mutable_entry.h" | 18 #include "sync/syncable/mutable_entry.h" |
19 #include "sync/syncable/read_transaction.h" | 19 #include "sync/syncable/read_transaction.h" |
20 #include "sync/syncable/syncable_proto_util.h" | 20 #include "sync/syncable/syncable_proto_util.h" |
21 #include "sync/syncable/syncable_util.h" | 21 #include "sync/syncable/syncable_util.h" |
22 #include "sync/syncable/write_transaction.h" | 22 #include "sync/syncable/write_transaction.h" |
23 #include "sync/util/time.h" | 23 #include "sync/util/time.h" |
24 | 24 |
25 //TODO(vishwath) Remove this include after node positions have | |
akalin
2012/10/05 00:57:59
see comment in other file
vishwath
2012/10/05 18:34:49
Done.
| |
26 // shifted to completely uing Ordinals. | |
akalin
2012/10/05 00:57:59
uing -> using
vishwath
2012/10/05 18:34:49
Done.
| |
27 // See crbug.com/145412 | |
28 #include "sync/internal_api/public/base/node_ordinal.h" | |
29 | |
25 using std::set; | 30 using std::set; |
26 using std::string; | 31 using std::string; |
27 using std::vector; | 32 using std::vector; |
28 using sync_pb::CommitResponse; | 33 using sync_pb::CommitResponse; |
29 | 34 |
30 namespace syncer { | 35 namespace syncer { |
31 | 36 |
32 using sessions::OrderedCommitSet; | 37 using sessions::OrderedCommitSet; |
33 using sessions::StatusController; | 38 using sessions::StatusController; |
34 using sessions::SyncSession; | 39 using sessions::SyncSession; |
35 using sessions::ConflictProgress; | 40 using sessions::ConflictProgress; |
36 using syncable::WriteTransaction; | 41 using syncable::WriteTransaction; |
37 using syncable::MutableEntry; | 42 using syncable::MutableEntry; |
38 using syncable::Entry; | 43 using syncable::Entry; |
39 using syncable::BASE_VERSION; | 44 using syncable::BASE_VERSION; |
40 using syncable::GET_BY_ID; | 45 using syncable::GET_BY_ID; |
41 using syncable::ID; | 46 using syncable::ID; |
42 using syncable::IS_DEL; | 47 using syncable::IS_DEL; |
43 using syncable::IS_DIR; | 48 using syncable::IS_DIR; |
44 using syncable::IS_UNAPPLIED_UPDATE; | 49 using syncable::IS_UNAPPLIED_UPDATE; |
45 using syncable::IS_UNSYNCED; | 50 using syncable::IS_UNSYNCED; |
46 using syncable::PARENT_ID; | 51 using syncable::PARENT_ID; |
47 using syncable::SERVER_IS_DEL; | 52 using syncable::SERVER_IS_DEL; |
48 using syncable::SERVER_PARENT_ID; | 53 using syncable::SERVER_PARENT_ID; |
49 using syncable::SERVER_POSITION_IN_PARENT; | 54 using syncable::SERVER_ORDINAL_IN_PARENT; |
50 using syncable::SERVER_VERSION; | 55 using syncable::SERVER_VERSION; |
51 using syncable::SYNCER; | 56 using syncable::SYNCER; |
52 using syncable::SYNCING; | 57 using syncable::SYNCING; |
53 | 58 |
54 ProcessCommitResponseCommand::ProcessCommitResponseCommand( | 59 ProcessCommitResponseCommand::ProcessCommitResponseCommand( |
55 const sessions::OrderedCommitSet& commit_set, | 60 const sessions::OrderedCommitSet& commit_set, |
56 const sync_pb::ClientToServerMessage& commit_message, | 61 const sync_pb::ClientToServerMessage& commit_message, |
57 const sync_pb::ClientToServerResponse& commit_response) | 62 const sync_pb::ClientToServerResponse& commit_response) |
58 : commit_set_(commit_set), | 63 : commit_set_(commit_set), |
59 commit_message_(commit_message), | 64 commit_message_(commit_message), |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
364 | 369 |
365 local_entry->Put(syncable::SERVER_IS_DIR, | 370 local_entry->Put(syncable::SERVER_IS_DIR, |
366 (committed_entry.folder() || | 371 (committed_entry.folder() || |
367 committed_entry.bookmarkdata().bookmark_folder())); | 372 committed_entry.bookmarkdata().bookmark_folder())); |
368 local_entry->Put(syncable::SERVER_SPECIFICS, | 373 local_entry->Put(syncable::SERVER_SPECIFICS, |
369 committed_entry.specifics()); | 374 committed_entry.specifics()); |
370 local_entry->Put(syncable::SERVER_MTIME, | 375 local_entry->Put(syncable::SERVER_MTIME, |
371 ProtoTimeToTime(committed_entry.mtime())); | 376 ProtoTimeToTime(committed_entry.mtime())); |
372 local_entry->Put(syncable::SERVER_CTIME, | 377 local_entry->Put(syncable::SERVER_CTIME, |
373 ProtoTimeToTime(committed_entry.ctime())); | 378 ProtoTimeToTime(committed_entry.ctime())); |
374 local_entry->Put(syncable::SERVER_POSITION_IN_PARENT, | 379 local_entry->Put(syncable::SERVER_ORDINAL_IN_PARENT, |
375 entry_response.position_in_parent()); | 380 Int64ToNodeOrdinal(entry_response.position_in_parent())); |
381 | |
376 // TODO(nick): The server doesn't set entry_response.server_parent_id in | 382 // TODO(nick): The server doesn't set entry_response.server_parent_id in |
377 // practice; to update SERVER_PARENT_ID appropriately here we'd need to | 383 // practice; to update SERVER_PARENT_ID appropriately here we'd need to |
378 // get the post-commit ID of the parent indicated by | 384 // get the post-commit ID of the parent indicated by |
379 // committed_entry.parent_id_string(). That should be inferrable from the | 385 // committed_entry.parent_id_string(). That should be inferrable from the |
380 // information we have, but it's a bit convoluted to pull it out directly. | 386 // information we have, but it's a bit convoluted to pull it out directly. |
381 // Getting this right is important: SERVER_PARENT_ID gets fed back into | 387 // Getting this right is important: SERVER_PARENT_ID gets fed back into |
382 // old_parent_id during the next commit. | 388 // old_parent_id during the next commit. |
383 local_entry->Put(syncable::SERVER_PARENT_ID, | 389 local_entry->Put(syncable::SERVER_PARENT_ID, |
384 local_entry->Get(syncable::PARENT_ID)); | 390 local_entry->Get(syncable::PARENT_ID)); |
385 local_entry->Put(syncable::SERVER_NON_UNIQUE_NAME, | 391 local_entry->Put(syncable::SERVER_NON_UNIQUE_NAME, |
(...skipping 27 matching lines...) Expand all Loading... | |
413 DVLOG(1) << "During commit, server changed name: " << old_name | 419 DVLOG(1) << "During commit, server changed name: " << old_name |
414 << " to new name: " << server_name; | 420 << " to new name: " << server_name; |
415 local_entry->Put(syncable::NON_UNIQUE_NAME, server_name); | 421 local_entry->Put(syncable::NON_UNIQUE_NAME, server_name); |
416 } | 422 } |
417 | 423 |
418 // The server has the final say on positioning, so apply the absolute | 424 // The server has the final say on positioning, so apply the absolute |
419 // position that it returns. | 425 // position that it returns. |
420 if (entry_response.has_position_in_parent()) { | 426 if (entry_response.has_position_in_parent()) { |
421 // The SERVER_ field should already have been written. | 427 // The SERVER_ field should already have been written. |
422 DCHECK_EQ(entry_response.position_in_parent(), | 428 DCHECK_EQ(entry_response.position_in_parent(), |
423 local_entry->Get(SERVER_POSITION_IN_PARENT)); | 429 NodeOrdinalToInt64(local_entry->Get(SERVER_ORDINAL_IN_PARENT))); |
424 | 430 |
425 // We just committed successfully, so we assume that the position | 431 // We just committed successfully, so we assume that the position |
426 // value we got applies to the PARENT_ID we submitted. | 432 // value we got applies to the PARENT_ID we submitted. |
427 syncable::Id new_prev = local_entry->ComputePrevIdFromServerPosition( | 433 syncable::Id new_prev = local_entry->ComputePrevIdFromServerPosition( |
428 local_entry->Get(PARENT_ID)); | 434 local_entry->Get(PARENT_ID)); |
429 if (!local_entry->PutPredecessor(new_prev)) { | 435 if (!local_entry->PutPredecessor(new_prev)) { |
430 // TODO(lipalani) : Propagate the error to caller. crbug.com/100444. | 436 // TODO(lipalani) : Propagate the error to caller. crbug.com/100444. |
431 NOTREACHED(); | 437 NOTREACHED(); |
432 } | 438 } |
433 } | 439 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
472 // been recursively deleted. | 478 // been recursively deleted. |
473 // TODO(nick): Here, commit_message.deleted() would be more correct than | 479 // TODO(nick): Here, commit_message.deleted() would be more correct than |
474 // local_entry->Get(IS_DEL). For example, an item could be renamed, and then | 480 // local_entry->Get(IS_DEL). For example, an item could be renamed, and then |
475 // deleted during the commit of the rename. Unit test & fix. | 481 // deleted during the commit of the rename. Unit test & fix. |
476 if (local_entry->Get(IS_DIR) && local_entry->Get(IS_DEL)) { | 482 if (local_entry->Get(IS_DIR) && local_entry->Get(IS_DEL)) { |
477 deleted_folders->insert(local_entry->Get(ID)); | 483 deleted_folders->insert(local_entry->Get(ID)); |
478 } | 484 } |
479 } | 485 } |
480 | 486 |
481 } // namespace syncer | 487 } // namespace syncer |
OLD | NEW |