| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #ifndef CHROME_BROWSER_SYNC_SYNCABLE_SYNCABLE_H_ | 5 #ifndef CHROME_BROWSER_SYNC_SYNCABLE_SYNCABLE_H_ |
| 6 #define CHROME_BROWSER_SYNC_SYNCABLE_SYNCABLE_H_ | 6 #define CHROME_BROWSER_SYNC_SYNCABLE_SYNCABLE_H_ |
| 7 | 7 |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <bitset> | 9 #include <bitset> |
| 10 #include <iosfwd> | 10 #include <iosfwd> |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 | 175 |
| 176 enum { | 176 enum { |
| 177 BIT_TEMPS_COUNT = BIT_TEMPS_END - BIT_TEMPS_BEGIN | 177 BIT_TEMPS_COUNT = BIT_TEMPS_END - BIT_TEMPS_BEGIN |
| 178 }; | 178 }; |
| 179 | 179 |
| 180 class BaseTransaction; | 180 class BaseTransaction; |
| 181 class WriteTransaction; | 181 class WriteTransaction; |
| 182 class ReadTransaction; | 182 class ReadTransaction; |
| 183 class Directory; | 183 class Directory; |
| 184 class ScopedDirLookup; | 184 class ScopedDirLookup; |
| 185 class ExtendedAttribute; | |
| 186 | 185 |
| 187 // Instead of: | 186 // Instead of: |
| 188 // Entry e = transaction.GetById(id); | 187 // Entry e = transaction.GetById(id); |
| 189 // use: | 188 // use: |
| 190 // Entry e(transaction, GET_BY_ID, id); | 189 // Entry e(transaction, GET_BY_ID, id); |
| 191 // | 190 // |
| 192 // Why? The former would require a copy constructor, and it would be difficult | 191 // Why? The former would require a copy constructor, and it would be difficult |
| 193 // to enforce that an entry never outlived its transaction if there were a copy | 192 // to enforce that an entry never outlived its transaction if there were a copy |
| 194 // constructor. | 193 // constructor. |
| 195 enum GetById { | 194 enum GetById { |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 inline bool ExistsOnClientBecauseNameIsNonEmpty() const { | 409 inline bool ExistsOnClientBecauseNameIsNonEmpty() const { |
| 411 DCHECK(kernel_); | 410 DCHECK(kernel_); |
| 412 return !kernel_->ref(NON_UNIQUE_NAME).empty(); | 411 return !kernel_->ref(NON_UNIQUE_NAME).empty(); |
| 413 } | 412 } |
| 414 | 413 |
| 415 inline bool IsRoot() const { | 414 inline bool IsRoot() const { |
| 416 DCHECK(kernel_); | 415 DCHECK(kernel_); |
| 417 return kernel_->ref(ID).IsRoot(); | 416 return kernel_->ref(ID).IsRoot(); |
| 418 } | 417 } |
| 419 | 418 |
| 420 void GetAllExtendedAttributes(BaseTransaction* trans, | |
| 421 std::set<ExtendedAttribute>* result); | |
| 422 void GetExtendedAttributesList(BaseTransaction* trans, | |
| 423 AttributeKeySet* result); | |
| 424 // Flags all extended attributes for deletion on the next SaveChanges. | |
| 425 void DeleteAllExtendedAttributes(WriteTransaction *trans); | |
| 426 | |
| 427 Directory* dir() const; | 419 Directory* dir() const; |
| 428 | 420 |
| 429 const EntryKernel GetKernelCopy() const { | 421 const EntryKernel GetKernelCopy() const { |
| 430 return *kernel_; | 422 return *kernel_; |
| 431 } | 423 } |
| 432 | 424 |
| 433 | 425 |
| 434 protected: // Don't allow creation on heap, except by sync API wrappers. | 426 protected: // Don't allow creation on heap, except by sync API wrappers. |
| 435 friend class sync_api::ReadNode; | 427 friend class sync_api::ReadNode; |
| 436 void* operator new(size_t size) { return (::operator new)(size); } | 428 void* operator new(size_t size) { return (::operator new)(size); } |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 599 // These members are only valid for CALCULATE_CHANGES. | 591 // These members are only valid for CALCULATE_CHANGES. |
| 600 const OriginalEntries* originals; | 592 const OriginalEntries* originals; |
| 601 BaseTransaction* trans; | 593 BaseTransaction* trans; |
| 602 WriterTag writer; | 594 WriterTag writer; |
| 603 typedef DirectoryChangeEvent EventType; | 595 typedef DirectoryChangeEvent EventType; |
| 604 static inline bool IsChannelShutdownEvent(const EventType& e) { | 596 static inline bool IsChannelShutdownEvent(const EventType& e) { |
| 605 return SHUTDOWN == e.todo; | 597 return SHUTDOWN == e.todo; |
| 606 } | 598 } |
| 607 }; | 599 }; |
| 608 | 600 |
| 609 struct ExtendedAttributeKey { | |
| 610 int64 metahandle; | |
| 611 std::string key; | |
| 612 inline bool operator < (const ExtendedAttributeKey& x) const { | |
| 613 if (metahandle != x.metahandle) | |
| 614 return metahandle < x.metahandle; | |
| 615 return key.compare(x.key) < 0; | |
| 616 } | |
| 617 ExtendedAttributeKey(int64 metahandle, const std::string& key) | |
| 618 : metahandle(metahandle), key(key) { } | |
| 619 }; | |
| 620 | |
| 621 struct ExtendedAttributeValue { | |
| 622 Blob value; | |
| 623 bool is_deleted; | |
| 624 bool dirty; | |
| 625 }; | |
| 626 | |
| 627 typedef std::map<ExtendedAttributeKey, ExtendedAttributeValue> | |
| 628 ExtendedAttributes; | |
| 629 | |
| 630 // A list of metahandles whose metadata should not be purged. | 601 // A list of metahandles whose metadata should not be purged. |
| 631 typedef std::multiset<int64> Pegs; | 602 typedef std::multiset<int64> Pegs; |
| 632 | 603 |
| 633 // The name Directory in this case means the entire directory | 604 // The name Directory in this case means the entire directory |
| 634 // structure within a single user account. | 605 // structure within a single user account. |
| 635 // | 606 // |
| 636 // Sqlite is a little goofy, in that each thread must access a database | 607 // Sqlite is a little goofy, in that each thread must access a database |
| 637 // via its own handle. So, a Directory object should only be accessed | 608 // via its own handle. So, a Directory object should only be accessed |
| 638 // from a single thread. Use DirectoryManager's Open() method to | 609 // from a single thread. Use DirectoryManager's Open() method to |
| 639 // always get a directory that has been properly initialized on the | 610 // always get a directory that has been properly initialized on the |
| (...skipping 14 matching lines...) Expand all Loading... |
| 654 // To prevent deadlock, the reader writer transaction lock must always | 625 // To prevent deadlock, the reader writer transaction lock must always |
| 655 // be held before acquiring the kernel lock. | 626 // be held before acquiring the kernel lock. |
| 656 class ScopedKernelLock; | 627 class ScopedKernelLock; |
| 657 class IdFilter; | 628 class IdFilter; |
| 658 class DirectoryManager; | 629 class DirectoryManager; |
| 659 struct PathMatcher; | 630 struct PathMatcher; |
| 660 | 631 |
| 661 class Directory { | 632 class Directory { |
| 662 friend class BaseTransaction; | 633 friend class BaseTransaction; |
| 663 friend class Entry; | 634 friend class Entry; |
| 664 friend class ExtendedAttribute; | |
| 665 friend class MutableEntry; | 635 friend class MutableEntry; |
| 666 friend class MutableExtendedAttribute; | |
| 667 friend class ReadTransaction; | 636 friend class ReadTransaction; |
| 668 friend class ReadTransactionWithoutDB; | 637 friend class ReadTransactionWithoutDB; |
| 669 friend class ScopedKernelLock; | 638 friend class ScopedKernelLock; |
| 670 friend class ScopedKernelUnlock; | 639 friend class ScopedKernelUnlock; |
| 671 friend class WriteTransaction; | 640 friend class WriteTransaction; |
| 672 friend class SyncableDirectoryTest; | 641 friend class SyncableDirectoryTest; |
| 673 FRIEND_TEST_ALL_PREFIXES(SyncableDirectoryTest, | 642 FRIEND_TEST_ALL_PREFIXES(SyncableDirectoryTest, |
| 674 TakeSnapshotGetsAllDirtyHandlesTest); | 643 TakeSnapshotGetsAllDirtyHandlesTest); |
| 675 FRIEND_TEST_ALL_PREFIXES(SyncableDirectoryTest, | 644 FRIEND_TEST_ALL_PREFIXES(SyncableDirectoryTest, |
| 676 TakeSnapshotGetsOnlyDirtyHandlesTest); | 645 TakeSnapshotGetsOnlyDirtyHandlesTest); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 716 KERNEL_SHARE_INFO_DIRTY | 685 KERNEL_SHARE_INFO_DIRTY |
| 717 }; | 686 }; |
| 718 | 687 |
| 719 // When the Directory is told to SaveChanges, a SaveChangesSnapshot is | 688 // When the Directory is told to SaveChanges, a SaveChangesSnapshot is |
| 720 // constructed and forms a consistent snapshot of what needs to be sent to | 689 // constructed and forms a consistent snapshot of what needs to be sent to |
| 721 // the backing store. | 690 // the backing store. |
| 722 struct SaveChangesSnapshot { | 691 struct SaveChangesSnapshot { |
| 723 KernelShareInfoStatus kernel_info_status; | 692 KernelShareInfoStatus kernel_info_status; |
| 724 PersistedKernelInfo kernel_info; | 693 PersistedKernelInfo kernel_info; |
| 725 OriginalEntries dirty_metas; | 694 OriginalEntries dirty_metas; |
| 726 ExtendedAttributes dirty_xattrs; | |
| 727 SaveChangesSnapshot() : kernel_info_status(KERNEL_SHARE_INFO_INVALID) { | 695 SaveChangesSnapshot() : kernel_info_status(KERNEL_SHARE_INFO_INVALID) { |
| 728 } | 696 } |
| 729 }; | 697 }; |
| 730 | 698 |
| 731 Directory(); | 699 Directory(); |
| 732 virtual ~Directory(); | 700 virtual ~Directory(); |
| 733 | 701 |
| 734 DirOpenResult Open(const FilePath& file_path, const std::string& name); | 702 DirOpenResult Open(const FilePath& file_path, const std::string& name); |
| 735 | 703 |
| 736 void Close(); | 704 void Close(); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 859 // syncer should call it from its PerformSyncQueries member. | 827 // syncer should call it from its PerformSyncQueries member. |
| 860 typedef std::vector<int64> UnsyncedMetaHandles; | 828 typedef std::vector<int64> UnsyncedMetaHandles; |
| 861 void GetUnsyncedMetaHandles(BaseTransaction* trans, | 829 void GetUnsyncedMetaHandles(BaseTransaction* trans, |
| 862 UnsyncedMetaHandles* result); | 830 UnsyncedMetaHandles* result); |
| 863 | 831 |
| 864 // Get all the metahandles for unapplied updates | 832 // Get all the metahandles for unapplied updates |
| 865 typedef std::vector<int64> UnappliedUpdateMetaHandles; | 833 typedef std::vector<int64> UnappliedUpdateMetaHandles; |
| 866 void GetUnappliedUpdateMetaHandles(BaseTransaction* trans, | 834 void GetUnappliedUpdateMetaHandles(BaseTransaction* trans, |
| 867 UnappliedUpdateMetaHandles* result); | 835 UnappliedUpdateMetaHandles* result); |
| 868 | 836 |
| 869 void GetAllExtendedAttributes(BaseTransaction* trans, int64 metahandle, | |
| 870 std::set<ExtendedAttribute>* result); | |
| 871 // Get all extended attribute keys associated with a metahandle | |
| 872 void GetExtendedAttributesList(BaseTransaction* trans, int64 metahandle, | |
| 873 AttributeKeySet* result); | |
| 874 // Flags all extended attributes for deletion on the next SaveChanges. | |
| 875 void DeleteAllExtendedAttributes(WriteTransaction* trans, int64 metahandle); | |
| 876 | |
| 877 // Get the channel for post save notification, used by the syncer. | 837 // Get the channel for post save notification, used by the syncer. |
| 878 inline Channel* channel() const { | 838 inline Channel* channel() const { |
| 879 return kernel_->channel; | 839 return kernel_->channel; |
| 880 } | 840 } |
| 881 | 841 |
| 882 // Checks tree metadata consistency. | 842 // Checks tree metadata consistency. |
| 883 // If full_scan is false, the function will avoid pulling any entries from the | 843 // If full_scan is false, the function will avoid pulling any entries from the |
| 884 // db and scan entries currently in ram. | 844 // db and scan entries currently in ram. |
| 885 // If full_scan is true, all entries will be pulled from the database. | 845 // If full_scan is true, all entries will be pulled from the database. |
| 886 // No return value, CHECKs will be triggered if we're given bad | 846 // No return value, CHECKs will be triggered if we're given bad |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 995 // Never hold the mutex and do anything with the database or any | 955 // Never hold the mutex and do anything with the database or any |
| 996 // other buffered IO. Violating this rule will result in deadlock. | 956 // other buffered IO. Violating this rule will result in deadlock. |
| 997 Lock mutex; | 957 Lock mutex; |
| 998 MetahandlesIndex* metahandles_index; // Entries indexed by metahandle | 958 MetahandlesIndex* metahandles_index; // Entries indexed by metahandle |
| 999 IdsIndex* ids_index; // Entries indexed by id | 959 IdsIndex* ids_index; // Entries indexed by id |
| 1000 ParentIdChildIndex* parent_id_child_index; | 960 ParentIdChildIndex* parent_id_child_index; |
| 1001 ClientTagIndex* client_tag_index; | 961 ClientTagIndex* client_tag_index; |
| 1002 // So we don't have to create an EntryKernel every time we want to | 962 // So we don't have to create an EntryKernel every time we want to |
| 1003 // look something up in an index. Needle in haystack metaphor. | 963 // look something up in an index. Needle in haystack metaphor. |
| 1004 EntryKernel needle; | 964 EntryKernel needle; |
| 1005 ExtendedAttributes* const extended_attributes; | |
| 1006 | 965 |
| 1007 // 3 in-memory indices on bits used extremely frequently by the syncer. | 966 // 3 in-memory indices on bits used extremely frequently by the syncer. |
| 1008 MetahandleSet* const unapplied_update_metahandles; | 967 MetahandleSet* const unapplied_update_metahandles; |
| 1009 MetahandleSet* const unsynced_metahandles; | 968 MetahandleSet* const unsynced_metahandles; |
| 1010 // Contains metahandles that are most likely dirty (though not | 969 // Contains metahandles that are most likely dirty (though not |
| 1011 // necessarily). Dirtyness is confirmed in TakeSnapshotForSaveChanges(). | 970 // necessarily). Dirtyness is confirmed in TakeSnapshotForSaveChanges(). |
| 1012 MetahandleSet* const dirty_metahandles; | 971 MetahandleSet* const dirty_metahandles; |
| 1013 | 972 |
| 1014 // TODO(ncarter): Figure out what the hell this is, and comment it. | 973 // TODO(ncarter): Figure out what the hell this is, and comment it. |
| 1015 Channel* const channel; | 974 Channel* const channel; |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1128 | 1087 |
| 1129 bool IsLegalNewParent(BaseTransaction* trans, const Id& id, const Id& parentid); | 1088 bool IsLegalNewParent(BaseTransaction* trans, const Id& id, const Id& parentid); |
| 1130 int ComparePathNames(const std::string& a, const std::string& b); | 1089 int ComparePathNames(const std::string& a, const std::string& b); |
| 1131 | 1090 |
| 1132 // Exposed in header as this is used as a sqlite3 callback. | 1091 // Exposed in header as this is used as a sqlite3 callback. |
| 1133 int ComparePathNames16(void*, int a_bytes, const void* a, int b_bytes, | 1092 int ComparePathNames16(void*, int a_bytes, const void* a, int b_bytes, |
| 1134 const void* b); | 1093 const void* b); |
| 1135 | 1094 |
| 1136 int64 Now(); | 1095 int64 Now(); |
| 1137 | 1096 |
| 1138 class ExtendedAttribute { | |
| 1139 public: | |
| 1140 ExtendedAttribute(BaseTransaction* trans, GetByHandle, | |
| 1141 const ExtendedAttributeKey& key); | |
| 1142 int64 metahandle() const { return i_->first.metahandle; } | |
| 1143 const std::string& key() const { return i_->first.key; } | |
| 1144 const Blob& value() const { return i_->second.value; } | |
| 1145 bool is_deleted() const { return i_->second.is_deleted; } | |
| 1146 bool good() const { return good_; } | |
| 1147 bool operator < (const ExtendedAttribute& x) const { | |
| 1148 return i_->first < x.i_->first; | |
| 1149 } | |
| 1150 protected: | |
| 1151 bool Init(BaseTransaction* trans, | |
| 1152 Directory::Kernel* const kernel, | |
| 1153 ScopedKernelLock* lock, | |
| 1154 const ExtendedAttributeKey& key); | |
| 1155 ExtendedAttribute() { } | |
| 1156 ExtendedAttributes::iterator i_; | |
| 1157 bool good_; | |
| 1158 }; | |
| 1159 | |
| 1160 class MutableExtendedAttribute : public ExtendedAttribute { | |
| 1161 public: | |
| 1162 MutableExtendedAttribute(WriteTransaction* trans, GetByHandle, | |
| 1163 const ExtendedAttributeKey& key); | |
| 1164 MutableExtendedAttribute(WriteTransaction* trans, Create, | |
| 1165 const ExtendedAttributeKey& key); | |
| 1166 | |
| 1167 Blob* mutable_value() { | |
| 1168 i_->second.dirty = true; | |
| 1169 i_->second.is_deleted = false; | |
| 1170 return &(i_->second.value); | |
| 1171 } | |
| 1172 | |
| 1173 void delete_attribute() { | |
| 1174 i_->second.dirty = true; | |
| 1175 i_->second.is_deleted = true; | |
| 1176 } | |
| 1177 }; | |
| 1178 | |
| 1179 // Get an extended attribute from an Entry by name. Returns a pointer | |
| 1180 // to a const Blob containing the attribute data, or NULL if there is | |
| 1181 // no attribute with the given name. The pointer is valid for the | |
| 1182 // duration of the Entry's transaction. | |
| 1183 const Blob* GetExtendedAttributeValue(const Entry& e, | |
| 1184 const std::string& attribute_name); | |
| 1185 | |
| 1186 // This function sets only the flags needed to get this entry to sync. | 1097 // This function sets only the flags needed to get this entry to sync. |
| 1187 void MarkForSyncing(syncable::MutableEntry* e); | 1098 void MarkForSyncing(syncable::MutableEntry* e); |
| 1188 | 1099 |
| 1189 // This is not a reset. It just sets the numeric fields which are not | 1100 // This is not a reset. It just sets the numeric fields which are not |
| 1190 // initialized by the constructor to zero. | 1101 // initialized by the constructor to zero. |
| 1191 void ZeroFields(EntryKernel* entry, int first_field); | 1102 void ZeroFields(EntryKernel* entry, int first_field); |
| 1192 | 1103 |
| 1193 } // namespace syncable | 1104 } // namespace syncable |
| 1194 | 1105 |
| 1195 std::ostream& operator <<(std::ostream&, const syncable::Blob&); | 1106 std::ostream& operator <<(std::ostream&, const syncable::Blob&); |
| 1196 | 1107 |
| 1197 browser_sync::FastDump& operator << | 1108 browser_sync::FastDump& operator << |
| 1198 (browser_sync::FastDump&, const syncable::Blob&); | 1109 (browser_sync::FastDump&, const syncable::Blob&); |
| 1199 | 1110 |
| 1200 #endif // CHROME_BROWSER_SYNC_SYNCABLE_SYNCABLE_H_ | 1111 #endif // CHROME_BROWSER_SYNC_SYNCABLE_SYNCABLE_H_ |
| OLD | NEW |