OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "chrome/browser/sync/engine/syncer_util.h" | 5 #include "chrome/browser/sync/engine/syncer_util.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 12 matching lines...) Expand all Loading... |
23 | 23 |
24 using syncable::BASE_VERSION; | 24 using syncable::BASE_VERSION; |
25 using syncable::Blob; | 25 using syncable::Blob; |
26 using syncable::CHANGES_VERSION; | 26 using syncable::CHANGES_VERSION; |
27 using syncable::CREATE; | 27 using syncable::CREATE; |
28 using syncable::CREATE_NEW_UPDATE_ITEM; | 28 using syncable::CREATE_NEW_UPDATE_ITEM; |
29 using syncable::CTIME; | 29 using syncable::CTIME; |
30 using syncable::ComparePathNames; | 30 using syncable::ComparePathNames; |
31 using syncable::Directory; | 31 using syncable::Directory; |
32 using syncable::Entry; | 32 using syncable::Entry; |
33 using syncable::ExtendedAttributeKey; | |
34 using syncable::GET_BY_HANDLE; | 33 using syncable::GET_BY_HANDLE; |
35 using syncable::GET_BY_ID; | 34 using syncable::GET_BY_ID; |
36 using syncable::ID; | 35 using syncable::ID; |
37 using syncable::IS_DEL; | 36 using syncable::IS_DEL; |
38 using syncable::IS_DIR; | 37 using syncable::IS_DIR; |
39 using syncable::IS_UNAPPLIED_UPDATE; | 38 using syncable::IS_UNAPPLIED_UPDATE; |
40 using syncable::IS_UNSYNCED; | 39 using syncable::IS_UNSYNCED; |
41 using syncable::Id; | 40 using syncable::Id; |
42 using syncable::META_HANDLE; | 41 using syncable::META_HANDLE; |
43 using syncable::MTIME; | 42 using syncable::MTIME; |
44 using syncable::MutableEntry; | 43 using syncable::MutableEntry; |
45 using syncable::MutableExtendedAttribute; | |
46 using syncable::NEXT_ID; | 44 using syncable::NEXT_ID; |
47 using syncable::NON_UNIQUE_NAME; | 45 using syncable::NON_UNIQUE_NAME; |
48 using syncable::PARENT_ID; | 46 using syncable::PARENT_ID; |
49 using syncable::PREV_ID; | 47 using syncable::PREV_ID; |
50 using syncable::ReadTransaction; | 48 using syncable::ReadTransaction; |
51 using syncable::SERVER_CTIME; | 49 using syncable::SERVER_CTIME; |
52 using syncable::SERVER_IS_DEL; | 50 using syncable::SERVER_IS_DEL; |
53 using syncable::SERVER_IS_DIR; | 51 using syncable::SERVER_IS_DIR; |
54 using syncable::SERVER_MTIME; | 52 using syncable::SERVER_MTIME; |
55 using syncable::SERVER_NON_UNIQUE_NAME; | 53 using syncable::SERVER_NON_UNIQUE_NAME; |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 server_entry.position_in_parent()); | 398 server_entry.position_in_parent()); |
401 } | 399 } |
402 | 400 |
403 local_entry->Put(SERVER_IS_DEL, server_entry.deleted()); | 401 local_entry->Put(SERVER_IS_DEL, server_entry.deleted()); |
404 // We only mark the entry as unapplied if its version is greater than the | 402 // We only mark the entry as unapplied if its version is greater than the |
405 // local data. If we're processing the update that corresponds to one of our | 403 // local data. If we're processing the update that corresponds to one of our |
406 // commit we don't apply it as time differences may occur. | 404 // commit we don't apply it as time differences may occur. |
407 if (server_entry.version() > local_entry->Get(BASE_VERSION)) { | 405 if (server_entry.version() > local_entry->Get(BASE_VERSION)) { |
408 local_entry->Put(IS_UNAPPLIED_UPDATE, true); | 406 local_entry->Put(IS_UNAPPLIED_UPDATE, true); |
409 } | 407 } |
410 ApplyExtendedAttributes(local_entry, server_entry); | |
411 } | |
412 | |
413 // static | |
414 void SyncerUtil::ApplyExtendedAttributes( | |
415 syncable::MutableEntry* local_entry, | |
416 const SyncEntity& server_entry) { | |
417 local_entry->DeleteAllExtendedAttributes(local_entry->write_transaction()); | |
418 if (server_entry.has_extended_attributes()) { | |
419 const sync_pb::ExtendedAttributes & extended_attributes = | |
420 server_entry.extended_attributes(); | |
421 for (int i = 0; i < extended_attributes.extendedattribute_size(); i++) { | |
422 const string& string_key = | |
423 extended_attributes.extendedattribute(i).key(); | |
424 ExtendedAttributeKey key(local_entry->Get(META_HANDLE), string_key); | |
425 MutableExtendedAttribute local_attribute(local_entry->write_transaction(), | |
426 CREATE, key); | |
427 SyncerProtoUtil::CopyProtoBytesIntoBlob( | |
428 extended_attributes.extendedattribute(i).value(), | |
429 local_attribute.mutable_value()); | |
430 } | |
431 } | |
432 } | 408 } |
433 | 409 |
434 // Creates a new Entry iff no Entry exists with the given id. | 410 // Creates a new Entry iff no Entry exists with the given id. |
435 // static | 411 // static |
436 void SyncerUtil::CreateNewEntry(syncable::WriteTransaction *trans, | 412 void SyncerUtil::CreateNewEntry(syncable::WriteTransaction *trans, |
437 const syncable::Id& id) { | 413 const syncable::Id& id) { |
438 syncable::MutableEntry entry(trans, syncable::GET_BY_ID, id); | 414 syncable::MutableEntry entry(trans, syncable::GET_BY_ID, id); |
439 if (!entry.good()) { | 415 if (!entry.good()) { |
440 syncable::MutableEntry new_entry(trans, syncable::CREATE_NEW_UPDATE_ITEM, | 416 syncable::MutableEntry new_entry(trans, syncable::CREATE_NEW_UPDATE_ITEM, |
441 id); | 417 id); |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
865 | 841 |
866 // |update_entry| is considered to be somewhere after |candidate|, so store | 842 // |update_entry| is considered to be somewhere after |candidate|, so store |
867 // it as the upper bound. | 843 // it as the upper bound. |
868 closest_sibling = candidate.Get(ID); | 844 closest_sibling = candidate.Get(ID); |
869 } | 845 } |
870 | 846 |
871 return closest_sibling; | 847 return closest_sibling; |
872 } | 848 } |
873 | 849 |
874 } // namespace browser_sync | 850 } // namespace browser_sync |
OLD | NEW |