| 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 656 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 667 friend class ReadTransaction; | 667 friend class ReadTransaction; |
| 668 friend class ReadTransactionWithoutDB; | 668 friend class ReadTransactionWithoutDB; |
| 669 friend class ScopedKernelLock; | 669 friend class ScopedKernelLock; |
| 670 friend class ScopedKernelUnlock; | 670 friend class ScopedKernelUnlock; |
| 671 friend class WriteTransaction; | 671 friend class WriteTransaction; |
| 672 friend class SyncableDirectoryTest; | 672 friend class SyncableDirectoryTest; |
| 673 FRIEND_TEST_ALL_PREFIXES(SyncableDirectoryTest, | 673 FRIEND_TEST_ALL_PREFIXES(SyncableDirectoryTest, |
| 674 TakeSnapshotGetsAllDirtyHandlesTest); | 674 TakeSnapshotGetsAllDirtyHandlesTest); |
| 675 FRIEND_TEST_ALL_PREFIXES(SyncableDirectoryTest, | 675 FRIEND_TEST_ALL_PREFIXES(SyncableDirectoryTest, |
| 676 TakeSnapshotGetsOnlyDirtyHandlesTest); | 676 TakeSnapshotGetsOnlyDirtyHandlesTest); |
| 677 FRIEND_TEST_ALL_PREFIXES(SyncableDirectoryTest, TestPurgeEntriesWithTypeIn); |
| 677 | 678 |
| 678 public: | 679 public: |
| 679 class EventListenerHookup; | 680 class EventListenerHookup; |
| 680 | 681 |
| 681 // Various data that the Directory::Kernel we are backing (persisting data | 682 // Various data that the Directory::Kernel we are backing (persisting data |
| 682 // for) needs saved across runs of the application. | 683 // for) needs saved across runs of the application. |
| 683 struct PersistedKernelInfo { | 684 struct PersistedKernelInfo { |
| 684 // Last sync timestamp fetched from the server. | 685 // Last sync timestamp fetched from the server. |
| 685 int64 last_download_timestamp[MODEL_TYPE_COUNT]; | 686 int64 last_download_timestamp[MODEL_TYPE_COUNT]; |
| 686 // true iff we ever reached the end of the changelog. | 687 // true iff we ever reached the end of the changelog. |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 887 void CheckTreeInvariants(syncable::BaseTransaction* trans, | 888 void CheckTreeInvariants(syncable::BaseTransaction* trans, |
| 888 bool full_scan); | 889 bool full_scan); |
| 889 | 890 |
| 890 void CheckTreeInvariants(syncable::BaseTransaction* trans, | 891 void CheckTreeInvariants(syncable::BaseTransaction* trans, |
| 891 const OriginalEntries* originals); | 892 const OriginalEntries* originals); |
| 892 | 893 |
| 893 void CheckTreeInvariants(syncable::BaseTransaction* trans, | 894 void CheckTreeInvariants(syncable::BaseTransaction* trans, |
| 894 const MetahandleSet& handles, | 895 const MetahandleSet& handles, |
| 895 const IdFilter& idfilter); | 896 const IdFilter& idfilter); |
| 896 | 897 |
| 898 // Purges all data associated with any entries whose ModelType or |
| 899 // ServerModelType is found in |types|, from _both_ memory and disk. |
| 900 // Only valid, "real" model types are allowed in |types| (see model_type.h |
| 901 // for definitions). "Purge" is just meant to distinguish from "deleting" |
| 902 // entries, which means something different in the syncable namespace. |
| 903 // WARNING! This can be real slow, as it iterates over all entries. |
| 904 // WARNING! Performs synchronous I/O. |
| 905 void PurgeEntriesWithTypeIn(const std::set<ModelType>& types); |
| 906 |
| 897 private: | 907 private: |
| 898 // Helper to prime ids_index, parent_id_and_names_index, unsynced_metahandles | 908 // Helper to prime ids_index, parent_id_and_names_index, unsynced_metahandles |
| 899 // and unapplied_metahandles from metahandles_index. | 909 // and unapplied_metahandles from metahandles_index. |
| 900 void InitializeIndices(); | 910 void InitializeIndices(); |
| 901 | 911 |
| 902 // Constructs a consistent snapshot of the current Directory state and | 912 // Constructs a consistent snapshot of the current Directory state and |
| 903 // indices (by deep copy) under a ReadTransaction for use in |snapshot|. | 913 // indices (by deep copy) under a ReadTransaction for use in |snapshot|. |
| 904 // See SaveChanges() for more information. | 914 // See SaveChanges() for more information. |
| 905 void TakeSnapshotForSaveChanges(SaveChangesSnapshot* snapshot); | 915 void TakeSnapshotForSaveChanges(SaveChangesSnapshot* snapshot); |
| 906 | 916 |
| 907 // Purges from memory any unused, safe to remove entries that were | 917 // Purges from memory any unused, safe to remove entries that were |
| 908 // successfully deleted on disk as a result of the SaveChanges that processed | 918 // successfully deleted on disk as a result of the SaveChanges that processed |
| 909 // |snapshot|. See SaveChanges() for more information. | 919 // |snapshot|. See SaveChanges() for more information. |
| 910 void VacuumAfterSaveChanges(const SaveChangesSnapshot& snapshot); | 920 void VacuumAfterSaveChanges(const SaveChangesSnapshot& snapshot); |
| 911 | 921 |
| 912 // Rolls back dirty bits in the event that the SaveChanges that | 922 // Rolls back dirty bits in the event that the SaveChanges that |
| 913 // processed |snapshot| failed, for example, due to no disk space. | 923 // processed |snapshot| failed, for example, due to no disk space. |
| 914 void HandleSaveChangesFailure(const SaveChangesSnapshot& snapshot); | 924 void HandleSaveChangesFailure(const SaveChangesSnapshot& snapshot); |
| 915 | 925 |
| 916 // For new entry creation only | 926 // For new entry creation only |
| 917 void InsertEntry(EntryKernel* entry, ScopedKernelLock* lock); | 927 void InsertEntry(EntryKernel* entry, ScopedKernelLock* lock); |
| 918 void InsertEntry(EntryKernel* entry); | 928 void InsertEntry(EntryKernel* entry); |
| 919 | 929 |
| 920 // Used by CheckTreeInvariants | 930 // Used by CheckTreeInvariants |
| 921 void GetAllMetaHandles(BaseTransaction* trans, MetahandleSet* result); | 931 void GetAllMetaHandles(BaseTransaction* trans, MetahandleSet* result); |
| 922 | |
| 923 bool SafeToPurgeFromMemory(const EntryKernel* const entry) const; | 932 bool SafeToPurgeFromMemory(const EntryKernel* const entry) const; |
| 924 | 933 |
| 925 // Helper method used to implement GetFirstChildId/GetLastChildId. | 934 // Helper method used to implement GetFirstChildId/GetLastChildId. |
| 926 Id GetChildWithNullIdField(IdField field, | 935 Id GetChildWithNullIdField(IdField field, |
| 927 BaseTransaction* trans, | 936 BaseTransaction* trans, |
| 928 const Id& parent_id); | 937 const Id& parent_id); |
| 929 | 938 |
| 930 Directory& operator = (const Directory&); | 939 Directory& operator = (const Directory&); |
| 931 | 940 |
| 932 // TODO(sync): If lookups and inserts in these sets become | 941 // TODO(sync): If lookups and inserts in these sets become |
| (...skipping 10 matching lines...) Expand all Loading... |
| 943 // This index contains EntryKernels ordered by parent ID and metahandle. | 952 // This index contains EntryKernels ordered by parent ID and metahandle. |
| 944 // It allows efficient lookup of the children of a given parent. | 953 // It allows efficient lookup of the children of a given parent. |
| 945 typedef std::set<EntryKernel*, LessParentIdAndHandle> ParentIdChildIndex; | 954 typedef std::set<EntryKernel*, LessParentIdAndHandle> ParentIdChildIndex; |
| 946 | 955 |
| 947 // Contains both deleted and existing entries with tags. | 956 // Contains both deleted and existing entries with tags. |
| 948 // We can't store only existing tags because the client would create | 957 // We can't store only existing tags because the client would create |
| 949 // items that had a duplicated ID in the end, resulting in a DB key | 958 // items that had a duplicated ID in the end, resulting in a DB key |
| 950 // violation. ID reassociation would fail after an attempted commit. | 959 // violation. ID reassociation would fail after an attempted commit. |
| 951 typedef std::set<EntryKernel*, | 960 typedef std::set<EntryKernel*, |
| 952 LessField<StringField, UNIQUE_CLIENT_TAG> > ClientTagIndex; | 961 LessField<StringField, UNIQUE_CLIENT_TAG> > ClientTagIndex; |
| 953 typedef std::vector<int64> MetahandlesToPurge; | |
| 954 | 962 |
| 955 private: | 963 private: |
| 956 | 964 |
| 957 struct Kernel { | 965 struct Kernel { |
| 958 Kernel(const FilePath& db_path, const std::string& name, | 966 Kernel(const FilePath& db_path, const std::string& name, |
| 959 const KernelLoadInfo& info); | 967 const KernelLoadInfo& info); |
| 960 | 968 |
| 961 ~Kernel(); | 969 ~Kernel(); |
| 962 | 970 |
| 963 void AddRef(); // For convenience. | 971 void AddRef(); // For convenience. |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1177 void ZeroFields(EntryKernel* entry, int first_field); | 1185 void ZeroFields(EntryKernel* entry, int first_field); |
| 1178 | 1186 |
| 1179 } // namespace syncable | 1187 } // namespace syncable |
| 1180 | 1188 |
| 1181 std::ostream& operator <<(std::ostream&, const syncable::Blob&); | 1189 std::ostream& operator <<(std::ostream&, const syncable::Blob&); |
| 1182 | 1190 |
| 1183 browser_sync::FastDump& operator << | 1191 browser_sync::FastDump& operator << |
| 1184 (browser_sync::FastDump&, const syncable::Blob&); | 1192 (browser_sync::FastDump&, const syncable::Blob&); |
| 1185 | 1193 |
| 1186 #endif // CHROME_BROWSER_SYNC_SYNCABLE_SYNCABLE_H_ | 1194 #endif // CHROME_BROWSER_SYNC_SYNCABLE_SYNCABLE_H_ |
| OLD | NEW |