Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(157)

Side by Side Diff: chrome/browser/sync/syncable/syncable.h

Issue 6588119: First-time sync: asymptotic running time improvement (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/chrome/Release
Patch Set: Fix unit_tests Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 DCHECK(kernel_); 409 DCHECK(kernel_);
410 return kernel_->ref(ID).IsRoot(); 410 return kernel_->ref(ID).IsRoot();
411 } 411 }
412 412
413 Directory* dir() const; 413 Directory* dir() const;
414 414
415 const EntryKernel GetKernelCopy() const { 415 const EntryKernel GetKernelCopy() const {
416 return *kernel_; 416 return *kernel_;
417 } 417 }
418 418
419 // Compute a local predecessor position for |update_item|, based on its
420 // absolute server position. The returned ID will be a valid predecessor
421 // under SERVER_PARENT_ID that is consistent with the
422 // SERVER_POSITION_IN_PARENT ordering.
423 Id ComputePrevIdFromServerPosition(const Id& parent_id) const;
424
419 protected: // Don't allow creation on heap, except by sync API wrappers. 425 protected: // Don't allow creation on heap, except by sync API wrappers.
420 friend class sync_api::ReadNode; 426 friend class sync_api::ReadNode;
421 void* operator new(size_t size) { return (::operator new)(size); } 427 void* operator new(size_t size) { return (::operator new)(size); }
422 428
423 inline Entry(BaseTransaction* trans) 429 inline Entry(BaseTransaction* trans)
424 : basetrans_(trans), 430 : basetrans_(trans),
425 kernel_(NULL) { } 431 kernel_(NULL) { }
426 432
427 protected: 433 protected:
428 434
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 601
596 // Items are only in this index if they have a non-empty client tag value. 602 // Items are only in this index if they have a non-empty client tag value.
597 static bool ShouldInclude(const EntryKernel* a); 603 static bool ShouldInclude(const EntryKernel* a);
598 }; 604 };
599 605
600 // This index contains EntryKernels ordered by parent ID and metahandle. 606 // This index contains EntryKernels ordered by parent ID and metahandle.
601 // It allows efficient lookup of the children of a given parent. 607 // It allows efficient lookup of the children of a given parent.
602 struct ParentIdAndHandleIndexer { 608 struct ParentIdAndHandleIndexer {
603 // This index is of the parent ID and metahandle. We use a custom 609 // This index is of the parent ID and metahandle. We use a custom
604 // comparator. 610 // comparator.
605 class Comparator; 611 class Comparator {
612 public:
613 bool operator() (const syncable::EntryKernel* a,
614 const syncable::EntryKernel* b) const;
615 };
606 616
607 // This index does not include deleted items. 617 // This index does not include deleted items.
608 static bool ShouldInclude(const EntryKernel* a); 618 static bool ShouldInclude(const EntryKernel* a);
609 }; 619 };
610 620
611 // Given an Indexer providing the semantics of an index, defines the 621 // Given an Indexer providing the semantics of an index, defines the
612 // set type used to actually contain the index. 622 // set type used to actually contain the index.
613 template <typename Indexer> 623 template <typename Indexer>
614 struct Index { 624 struct Index {
615 typedef std::set<EntryKernel*, typename Indexer::Comparator> Set; 625 typedef std::set<EntryKernel*, typename Indexer::Comparator> Set;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 // or are public and take a Transaction* argument. 686 // or are public and take a Transaction* argument.
677 // 687 //
678 // All methods which require the kernel lock to be already held take a 688 // All methods which require the kernel lock to be already held take a
679 // ScopeKernelLock* argument. 689 // ScopeKernelLock* argument.
680 // 690 //
681 // To prevent deadlock, the reader writer transaction lock must always 691 // To prevent deadlock, the reader writer transaction lock must always
682 // be held before acquiring the kernel lock. 692 // be held before acquiring the kernel lock.
683 class ScopedKernelLock; 693 class ScopedKernelLock;
684 class IdFilter; 694 class IdFilter;
685 class DirectoryManager; 695 class DirectoryManager;
686 struct PathMatcher;
687 696
688 class Directory { 697 class Directory {
689 friend class BaseTransaction; 698 friend class BaseTransaction;
690 friend class Entry; 699 friend class Entry;
691 friend class MutableEntry; 700 friend class MutableEntry;
692 friend class ReadTransaction; 701 friend class ReadTransaction;
693 friend class ReadTransactionWithoutDB; 702 friend class ReadTransactionWithoutDB;
694 friend class ScopedKernelLock; 703 friend class ScopedKernelLock;
695 friend class ScopedKernelUnlock; 704 friend class ScopedKernelUnlock;
696 friend class WriteTransaction; 705 friend class WriteTransaction;
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
858 static inline bool IsChannelShutdownEvent(const DirectoryEvent& event) { 867 static inline bool IsChannelShutdownEvent(const DirectoryEvent& event) {
859 return DIRECTORY_DESTROYED == event; 868 return DIRECTORY_DESTROYED == event;
860 } 869 }
861 }; 870 };
862 public: 871 public:
863 typedef EventChannel<DirectoryEventTraits, base::Lock> Channel; 872 typedef EventChannel<DirectoryEventTraits, base::Lock> Channel;
864 typedef std::vector<int64> ChildHandles; 873 typedef std::vector<int64> ChildHandles;
865 874
866 // Returns the child meta handles for given parent id. 875 // Returns the child meta handles for given parent id.
867 void GetChildHandles(BaseTransaction*, const Id& parent_id, 876 void GetChildHandles(BaseTransaction*, const Id& parent_id,
868 const std::string& path_spec, ChildHandles* result);
869 void GetChildHandles(BaseTransaction*, const Id& parent_id,
870 ChildHandles* result); 877 ChildHandles* result);
871 void GetChildHandlesImpl(BaseTransaction* trans, const Id& parent_id,
872 PathMatcher* matcher, ChildHandles* result);
873 878
874 // Find the first or last child in the positional ordering under a parent, 879 // Find the first or last child in the positional ordering under a parent,
875 // and return its id. Returns a root Id if parent has no children. 880 // and return its id. Returns a root Id if parent has no children.
876 virtual Id GetFirstChildId(BaseTransaction* trans, const Id& parent_id); 881 virtual Id GetFirstChildId(BaseTransaction* trans, const Id& parent_id);
877 Id GetLastChildId(BaseTransaction* trans, const Id& parent_id); 882 Id GetLastChildId(BaseTransaction* trans, const Id& parent_id);
878 883
884 // Compute a local predecessor position for |update_item|. The position
885 // is determined by the SERVER_POSITION_IN_PARENT value of |update_item|,
886 // as well as the SERVER_POSITION_IN_PARENT values of any up-to-date
887 // children of |parent_id|.
888 Id ComputePrevIdFromServerPosition(
889 const EntryKernel* update_item,
890 const syncable::Id& parent_id);
891
879 // SaveChanges works by taking a consistent snapshot of the current Directory 892 // SaveChanges works by taking a consistent snapshot of the current Directory
880 // state and indices (by deep copy) under a ReadTransaction, passing this 893 // state and indices (by deep copy) under a ReadTransaction, passing this
881 // snapshot to the backing store under no transaction, and finally cleaning 894 // snapshot to the backing store under no transaction, and finally cleaning
882 // up by either purging entries no longer needed (this part done under a 895 // up by either purging entries no longer needed (this part done under a
883 // WriteTransaction) or rolling back the dirty bits. It also uses 896 // WriteTransaction) or rolling back the dirty bits. It also uses
884 // internal locking to enforce SaveChanges operations are mutually exclusive. 897 // internal locking to enforce SaveChanges operations are mutually exclusive.
885 // 898 //
886 // WARNING: THIS METHOD PERFORMS SYNCHRONOUS I/O VIA SQLITE. 899 // WARNING: THIS METHOD PERFORMS SYNCHRONOUS I/O VIA SQLITE.
887 bool SaveChanges(); 900 bool SaveChanges();
888 901
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
951 void HandleSaveChangesFailure(const SaveChangesSnapshot& snapshot); 964 void HandleSaveChangesFailure(const SaveChangesSnapshot& snapshot);
952 965
953 // For new entry creation only 966 // For new entry creation only
954 void InsertEntry(EntryKernel* entry, ScopedKernelLock* lock); 967 void InsertEntry(EntryKernel* entry, ScopedKernelLock* lock);
955 void InsertEntry(EntryKernel* entry); 968 void InsertEntry(EntryKernel* entry);
956 969
957 // Used by CheckTreeInvariants 970 // Used by CheckTreeInvariants
958 void GetAllMetaHandles(BaseTransaction* trans, MetahandleSet* result); 971 void GetAllMetaHandles(BaseTransaction* trans, MetahandleSet* result);
959 bool SafeToPurgeFromMemory(const EntryKernel* const entry) const; 972 bool SafeToPurgeFromMemory(const EntryKernel* const entry) const;
960 973
961 // Helper method used to implement GetFirstChildId/GetLastChildId.
962 Id GetChildWithNullIdField(IdField field,
963 BaseTransaction* trans,
964 const Id& parent_id);
965
966 // Internal setters that do not acquire a lock internally. These are unsafe 974 // Internal setters that do not acquire a lock internally. These are unsafe
967 // on their own; caller must guarantee exclusive access manually by holding 975 // on their own; caller must guarantee exclusive access manually by holding
968 // a ScopedKernelLock. 976 // a ScopedKernelLock.
969 void set_initial_sync_ended_for_type_unsafe(ModelType type, bool x); 977 void set_initial_sync_ended_for_type_unsafe(ModelType type, bool x);
970 void SetNotificationStateUnsafe(const std::string& notification_state); 978 void SetNotificationStateUnsafe(const std::string& notification_state);
971 979
972 Directory& operator = (const Directory&); 980 Directory& operator = (const Directory&);
973 981
974 public: 982 public:
975 typedef Index<MetahandleIndexer>::Set MetahandlesIndex; 983 typedef Index<MetahandleIndexer>::Set MetahandlesIndex;
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
1066 base::Lock save_changes_mutex; 1074 base::Lock save_changes_mutex;
1067 1075
1068 // The next metahandle is protected by kernel mutex. 1076 // The next metahandle is protected by kernel mutex.
1069 int64 next_metahandle; 1077 int64 next_metahandle;
1070 1078
1071 // Keep a history of recently flushed metahandles for debugging 1079 // Keep a history of recently flushed metahandles for debugging
1072 // purposes. Protected by the save_changes_mutex. 1080 // purposes. Protected by the save_changes_mutex.
1073 DebugQueue<int64, 1000> flushed_metahandles; 1081 DebugQueue<int64, 1000> flushed_metahandles;
1074 }; 1082 };
1075 1083
1084 // Helper method used to do searches on |parent_id_child_index|.
1085 ParentIdChildIndex::iterator LocateInParentChildIndex(
1086 const ScopedKernelLock& lock,
1087 const Id& parent_id,
1088 int64 position_in_parent,
1089 const Id& item_id_for_tiebreaking);
1090
1091 // Return an iterator to the beginning of the range of the children of
1092 // |parent_id| in the kernel's parent_id_child_index.
1093 ParentIdChildIndex::iterator GetParentChildIndexLowerBound(
1094 const ScopedKernelLock& lock,
1095 const Id& parent_id);
1096
1097 // Return an iterator to just past the end of the range of the
1098 // children of |parent_id| in the kernel's parent_id_child_index.
1099 ParentIdChildIndex::iterator GetParentChildIndexUpperBound(
1100 const ScopedKernelLock& lock,
1101 const Id& parent_id);
1102
1076 Kernel* kernel_; 1103 Kernel* kernel_;
1077 1104
1078 DirectoryBackingStore* store_; 1105 DirectoryBackingStore* store_;
1079 }; 1106 };
1080 1107
1081 class ScopedKernelLock { 1108 class ScopedKernelLock {
1082 public: 1109 public:
1083 explicit ScopedKernelLock(const Directory*); 1110 explicit ScopedKernelLock(const Directory*);
1084 ~ScopedKernelLock() {} 1111 ~ScopedKernelLock() {}
1085 1112
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
1172 1199
1173 // This is not a reset. It just sets the numeric fields which are not 1200 // This is not a reset. It just sets the numeric fields which are not
1174 // initialized by the constructor to zero. 1201 // initialized by the constructor to zero.
1175 void ZeroFields(EntryKernel* entry, int first_field); 1202 void ZeroFields(EntryKernel* entry, int first_field);
1176 1203
1177 } // namespace syncable 1204 } // namespace syncable
1178 1205
1179 std::ostream& operator <<(std::ostream&, const syncable::Blob&); 1206 std::ostream& operator <<(std::ostream&, const syncable::Blob&);
1180 1207
1181 #endif // CHROME_BROWSER_SYNC_SYNCABLE_SYNCABLE_H_ 1208 #endif // CHROME_BROWSER_SYNC_SYNCABLE_SYNCABLE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698