OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <bitset> | 10 #include <bitset> |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 inline std::string& mutable_ref(StringField field) { | 328 inline std::string& mutable_ref(StringField field) { |
329 return string_fields[field - STRING_FIELDS_BEGIN]; | 329 return string_fields[field - STRING_FIELDS_BEGIN]; |
330 } | 330 } |
331 inline sync_pb::EntitySpecifics& mutable_ref(ProtoField field) { | 331 inline sync_pb::EntitySpecifics& mutable_ref(ProtoField field) { |
332 return specifics_fields[field - PROTO_FIELDS_BEGIN]; | 332 return specifics_fields[field - PROTO_FIELDS_BEGIN]; |
333 } | 333 } |
334 inline Id& mutable_ref(IdField field) { | 334 inline Id& mutable_ref(IdField field) { |
335 return id_fields[field - ID_FIELDS_BEGIN]; | 335 return id_fields[field - ID_FIELDS_BEGIN]; |
336 } | 336 } |
337 | 337 |
| 338 // Does a case in-sensitive search for a given string, which must be |
| 339 // lower case. |
| 340 bool ContainsString(const std::string& lowercase_query) const; |
| 341 |
338 // Dumps all kernel info into a DictionaryValue and returns it. | 342 // Dumps all kernel info into a DictionaryValue and returns it. |
339 // Transfers ownership of the DictionaryValue to the caller. | 343 // Transfers ownership of the DictionaryValue to the caller. |
340 DictionaryValue* ToValue() const; | 344 DictionaryValue* ToValue() const; |
341 | 345 |
342 private: | 346 private: |
343 // Tracks whether this entry needs to be saved to the database. | 347 // Tracks whether this entry needs to be saved to the database. |
344 bool dirty_; | 348 bool dirty_; |
345 }; | 349 }; |
346 | 350 |
347 // A read-only meta entry. | 351 // A read-only meta entry. |
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
839 struct DirectoryEventTraits { | 843 struct DirectoryEventTraits { |
840 typedef DirectoryEvent EventType; | 844 typedef DirectoryEvent EventType; |
841 static inline bool IsChannelShutdownEvent(const DirectoryEvent& event) { | 845 static inline bool IsChannelShutdownEvent(const DirectoryEvent& event) { |
842 return DIRECTORY_DESTROYED == event; | 846 return DIRECTORY_DESTROYED == event; |
843 } | 847 } |
844 }; | 848 }; |
845 public: | 849 public: |
846 typedef EventChannel<DirectoryEventTraits, base::Lock> Channel; | 850 typedef EventChannel<DirectoryEventTraits, base::Lock> Channel; |
847 typedef std::vector<int64> ChildHandles; | 851 typedef std::vector<int64> ChildHandles; |
848 | 852 |
849 // Returns the child meta handles for given parent id. | 853 // Returns the child meta handles for given parent id. Clears |
850 void GetChildHandles(BaseTransaction*, const Id& parent_id, | 854 // |result| if there are no children. |
| 855 void GetChildHandlesById(BaseTransaction*, const Id& parent_id, |
| 856 ChildHandles* result); |
| 857 |
| 858 // Returns the child meta handles for given meta handle. Clears |
| 859 // |result| if there are no children. |
| 860 void GetChildHandlesByHandle(BaseTransaction*, int64 handle, |
851 ChildHandles* result); | 861 ChildHandles* result); |
852 | 862 |
853 // Find the first or last child in the positional ordering under a parent, | 863 // Find the first or last child in the positional ordering under a parent, |
854 // and return its id. Returns a root Id if parent has no children. | 864 // and return its id. Returns a root Id if parent has no children. |
855 virtual Id GetFirstChildId(BaseTransaction* trans, const Id& parent_id); | 865 virtual Id GetFirstChildId(BaseTransaction* trans, const Id& parent_id); |
856 Id GetLastChildId(BaseTransaction* trans, const Id& parent_id); | 866 Id GetLastChildId(BaseTransaction* trans, const Id& parent_id); |
857 | 867 |
858 // Compute a local predecessor position for |update_item|. The position | 868 // Compute a local predecessor position for |update_item|. The position |
859 // is determined by the SERVER_POSITION_IN_PARENT value of |update_item|, | 869 // is determined by the SERVER_POSITION_IN_PARENT value of |update_item|, |
860 // as well as the SERVER_POSITION_IN_PARENT values of any up-to-date | 870 // as well as the SERVER_POSITION_IN_PARENT values of any up-to-date |
861 // children of |parent_id|. | 871 // children of |parent_id|. |
862 Id ComputePrevIdFromServerPosition( | 872 Id ComputePrevIdFromServerPosition( |
863 const EntryKernel* update_item, | 873 const EntryKernel* update_item, |
864 const syncable::Id& parent_id); | 874 const syncable::Id& parent_id); |
865 | 875 |
866 // SaveChanges works by taking a consistent snapshot of the current Directory | 876 // SaveChanges works by taking a consistent snapshot of the current Directory |
867 // state and indices (by deep copy) under a ReadTransaction, passing this | 877 // state and indices (by deep copy) under a ReadTransaction, passing this |
868 // snapshot to the backing store under no transaction, and finally cleaning | 878 // snapshot to the backing store under no transaction, and finally cleaning |
869 // up by either purging entries no longer needed (this part done under a | 879 // up by either purging entries no longer needed (this part done under a |
870 // WriteTransaction) or rolling back the dirty bits. It also uses | 880 // WriteTransaction) or rolling back the dirty bits. It also uses |
871 // internal locking to enforce SaveChanges operations are mutually exclusive. | 881 // internal locking to enforce SaveChanges operations are mutually exclusive. |
872 // | 882 // |
873 // WARNING: THIS METHOD PERFORMS SYNCHRONOUS I/O VIA SQLITE. | 883 // WARNING: THIS METHOD PERFORMS SYNCHRONOUS I/O VIA SQLITE. |
874 bool SaveChanges(); | 884 bool SaveChanges(); |
875 | 885 |
| 886 // Fill in |result| with all entry kernels. |
| 887 void GetAllEntryKernels(BaseTransaction* trans, |
| 888 std::vector<const EntryKernel*>* result); |
| 889 |
876 // Returns the number of entities with the unsynced bit set. | 890 // Returns the number of entities with the unsynced bit set. |
877 int64 unsynced_entity_count() const; | 891 int64 unsynced_entity_count() const; |
878 | 892 |
879 // Get GetUnsyncedMetaHandles should only be called after SaveChanges and | 893 // Get GetUnsyncedMetaHandles should only be called after SaveChanges and |
880 // before any new entries have been created. The intention is that the | 894 // before any new entries have been created. The intention is that the |
881 // syncer should call it from its PerformSyncQueries member. | 895 // syncer should call it from its PerformSyncQueries member. |
882 typedef std::vector<int64> UnsyncedMetaHandles; | 896 typedef std::vector<int64> UnsyncedMetaHandles; |
883 void GetUnsyncedMetaHandles(BaseTransaction* trans, | 897 void GetUnsyncedMetaHandles(BaseTransaction* trans, |
884 UnsyncedMetaHandles* result); | 898 UnsyncedMetaHandles* result); |
885 | 899 |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1065 ParentIdChildIndex::iterator GetParentChildIndexLowerBound( | 1079 ParentIdChildIndex::iterator GetParentChildIndexLowerBound( |
1066 const ScopedKernelLock& lock, | 1080 const ScopedKernelLock& lock, |
1067 const Id& parent_id); | 1081 const Id& parent_id); |
1068 | 1082 |
1069 // Return an iterator to just past the end of the range of the | 1083 // Return an iterator to just past the end of the range of the |
1070 // children of |parent_id| in the kernel's parent_id_child_index. | 1084 // children of |parent_id| in the kernel's parent_id_child_index. |
1071 ParentIdChildIndex::iterator GetParentChildIndexUpperBound( | 1085 ParentIdChildIndex::iterator GetParentChildIndexUpperBound( |
1072 const ScopedKernelLock& lock, | 1086 const ScopedKernelLock& lock, |
1073 const Id& parent_id); | 1087 const Id& parent_id); |
1074 | 1088 |
| 1089 // Append the handles of the children of |parent_id| to |result|. |
| 1090 void AppendChildHandles( |
| 1091 const ScopedKernelLock& lock, |
| 1092 const Id& parent_id, Directory::ChildHandles* result); |
| 1093 |
1075 Kernel* kernel_; | 1094 Kernel* kernel_; |
1076 | 1095 |
1077 DirectoryBackingStore* store_; | 1096 DirectoryBackingStore* store_; |
1078 }; | 1097 }; |
1079 | 1098 |
1080 class ScopedKernelLock { | 1099 class ScopedKernelLock { |
1081 public: | 1100 public: |
1082 explicit ScopedKernelLock(const Directory*); | 1101 explicit ScopedKernelLock(const Directory*); |
1083 ~ScopedKernelLock() {} | 1102 ~ScopedKernelLock() {} |
1084 | 1103 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1173 | 1192 |
1174 // This is not a reset. It just sets the numeric fields which are not | 1193 // This is not a reset. It just sets the numeric fields which are not |
1175 // initialized by the constructor to zero. | 1194 // initialized by the constructor to zero. |
1176 void ZeroFields(EntryKernel* entry, int first_field); | 1195 void ZeroFields(EntryKernel* entry, int first_field); |
1177 | 1196 |
1178 } // namespace syncable | 1197 } // namespace syncable |
1179 | 1198 |
1180 std::ostream& operator <<(std::ostream&, const syncable::Blob&); | 1199 std::ostream& operator <<(std::ostream&, const syncable::Blob&); |
1181 | 1200 |
1182 #endif // CHROME_BROWSER_SYNC_SYNCABLE_SYNCABLE_H_ | 1201 #endif // CHROME_BROWSER_SYNC_SYNCABLE_SYNCABLE_H_ |
OLD | NEW |