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

Side by Side Diff: sync/syncable/directory.h

Issue 11441026: [Sync] Add support for loading, updating and querying delete journals in (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years 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
« no previous file with comments | « no previous file | sync/syncable/directory.cc » ('j') | sync/syncable/directory.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 SYNC_SYNCABLE_DIRECTORY_H_ 5 #ifndef SYNC_SYNCABLE_DIRECTORY_H_
6 #define SYNC_SYNCABLE_DIRECTORY_H_ 6 #define SYNC_SYNCABLE_DIRECTORY_H_
7 7
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/file_util.h" 12 #include "base/file_util.h"
13 #include "base/gtest_prod_util.h" 13 #include "base/gtest_prod_util.h"
14 #include "sync/internal_api/public/util/report_unrecoverable_error_function.h" 14 #include "sync/internal_api/public/util/report_unrecoverable_error_function.h"
15 #include "sync/internal_api/public/util/weak_handle.h" 15 #include "sync/internal_api/public/util/weak_handle.h"
16 #include "sync/syncable/dir_open_result.h" 16 #include "sync/syncable/dir_open_result.h"
17 #include "sync/syncable/entry_kernel.h" 17 #include "sync/syncable/entry_kernel.h"
18 #include "sync/syncable/metahandle_set.h" 18 #include "sync/syncable/metahandle_set.h"
19 #include "sync/syncable/scoped_kernel_lock.h" 19 #include "sync/syncable/scoped_kernel_lock.h"
20 #include "sync/syncable/syncable-inl.h"
20 21
21 namespace syncer { 22 namespace syncer {
22 23
23 class Cryptographer; 24 class Cryptographer;
24 class UnrecoverableErrorHandler; 25 class UnrecoverableErrorHandler;
25 26
26 namespace syncable { 27 namespace syncable {
27 28
28 class BaseTransaction; 29 class BaseTransaction;
29 class DirectoryChangeDelegate; 30 class DirectoryChangeDelegate;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 108
108 // Reason for unlinking. 109 // Reason for unlinking.
109 enum UnlinkReason { 110 enum UnlinkReason {
110 NODE_MANIPULATION, // To be used by any operation manipulating the linked 111 NODE_MANIPULATION, // To be used by any operation manipulating the linked
111 // list. 112 // list.
112 DATA_TYPE_PURGE // To be used when purging a dataype. 113 DATA_TYPE_PURGE // To be used when purging a dataype.
113 }; 114 };
114 115
115 class EntryKernelLessByMetaHandle { 116 class EntryKernelLessByMetaHandle {
116 public: 117 public:
117 inline bool operator()(const EntryKernel& a, 118 inline bool operator()(const EntryKernel* a,
118 const EntryKernel& b) const { 119 const EntryKernel* b) const {
119 return a.ref(META_HANDLE) < b.ref(META_HANDLE); 120 return a->ref(META_HANDLE) < b->ref(META_HANDLE);
120 } 121 }
121 }; 122 };
122 123
123 typedef std::set<EntryKernel, EntryKernelLessByMetaHandle> EntryKernelSet; 124 typedef std::set<const EntryKernel*, EntryKernelLessByMetaHandle>
125 EntryKernelSet;
124 126
125 enum InvariantCheckLevel { 127 enum InvariantCheckLevel {
126 OFF = 0, // No checking. 128 OFF = 0, // No checking.
127 VERIFY_CHANGES = 1, // Checks only mutated entries. Does not check hierarchy. 129 VERIFY_CHANGES = 1, // Checks only mutated entries. Does not check hierarchy.
128 FULL_DB_VERIFICATION = 2 // Check every entry. This can be expensive. 130 FULL_DB_VERIFICATION = 2 // Check every entry. This can be expensive.
129 }; 131 };
130 132
131 class Directory { 133 class Directory {
132 friend class BaseTransaction; 134 friend class BaseTransaction;
133 friend class Entry; 135 friend class Entry;
134 friend class MutableEntry; 136 friend class MutableEntry;
135 friend class ReadTransaction; 137 friend class ReadTransaction;
136 friend class ReadTransactionWithoutDB; 138 friend class ReadTransactionWithoutDB;
137 friend class ScopedKernelLock; 139 friend class ScopedKernelLock;
138 friend class ScopedKernelUnlock; 140 friend class ScopedKernelUnlock;
139 friend class WriteTransaction; 141 friend class WriteTransaction;
140 friend class SyncableDirectoryTest; 142 friend class SyncableDirectoryTest;
143 FRIEND_TEST_ALL_PREFIXES(SyncableDirectoryTest, ManageDeleteJournals);
141 FRIEND_TEST_ALL_PREFIXES(SyncableDirectoryTest, 144 FRIEND_TEST_ALL_PREFIXES(SyncableDirectoryTest,
142 TakeSnapshotGetsAllDirtyHandlesTest); 145 TakeSnapshotGetsAllDirtyHandlesTest);
143 FRIEND_TEST_ALL_PREFIXES(SyncableDirectoryTest, 146 FRIEND_TEST_ALL_PREFIXES(SyncableDirectoryTest,
144 TakeSnapshotGetsOnlyDirtyHandlesTest); 147 TakeSnapshotGetsOnlyDirtyHandlesTest);
145 FRIEND_TEST_ALL_PREFIXES(SyncableDirectoryTest, 148 FRIEND_TEST_ALL_PREFIXES(SyncableDirectoryTest,
146 TakeSnapshotGetsMetahandlesToPurge); 149 TakeSnapshotGetsMetahandlesToPurge);
147 150
148 public: 151 public:
149 static const FilePath::CharType kSyncDatabaseFilename[]; 152 static const FilePath::CharType kSyncDatabaseFilename[];
150 153
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 // constructed and forms a consistent snapshot of what needs to be sent to 208 // constructed and forms a consistent snapshot of what needs to be sent to
206 // the backing store. 209 // the backing store.
207 struct SaveChangesSnapshot { 210 struct SaveChangesSnapshot {
208 SaveChangesSnapshot(); 211 SaveChangesSnapshot();
209 ~SaveChangesSnapshot(); 212 ~SaveChangesSnapshot();
210 213
211 KernelShareInfoStatus kernel_info_status; 214 KernelShareInfoStatus kernel_info_status;
212 PersistedKernelInfo kernel_info; 215 PersistedKernelInfo kernel_info;
213 EntryKernelSet dirty_metas; 216 EntryKernelSet dirty_metas;
214 MetahandleSet metahandles_to_purge; 217 MetahandleSet metahandles_to_purge;
218 EntryKernelSet delete_journals;
219 MetahandleSet delete_journals_to_purge;
215 }; 220 };
216 221
217 // Does not take ownership of |encryptor|. 222 // Does not take ownership of |encryptor|.
218 // |report_unrecoverable_error_function| may be NULL. 223 // |report_unrecoverable_error_function| may be NULL.
219 // Takes ownership of |store|. 224 // Takes ownership of |store|.
220 Directory( 225 Directory(
221 DirectoryBackingStore* store, 226 DirectoryBackingStore* store,
222 UnrecoverableErrorHandler* unrecoverable_error_handler, 227 UnrecoverableErrorHandler* unrecoverable_error_handler,
223 ReportUnrecoverableErrorFunction 228 ReportUnrecoverableErrorFunction
224 report_unrecoverable_error_function, 229 report_unrecoverable_error_function,
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 report_unrecoverable_error_function_(); 312 report_unrecoverable_error_function_();
308 } 313 }
309 } 314 }
310 315
311 // Called to set the unrecoverable error on the directory and to propagate 316 // Called to set the unrecoverable error on the directory and to propagate
312 // the error to upper layers. 317 // the error to upper layers.
313 void OnUnrecoverableError(const BaseTransaction* trans, 318 void OnUnrecoverableError(const BaseTransaction* trans,
314 const tracked_objects::Location& location, 319 const tracked_objects::Location& location,
315 const std::string & message); 320 const std::string & message);
316 321
322 // Add/remove |entry| to/from |delete_journals_| according to its
323 // SERVER_IS_DEL field and |was_deleted|.
324 void UpdateDeleteJournalForServerDelete(BaseTransaction* trans,
325 bool was_deleted,
326 const EntryKernel& entry);
327
328 // Return entries of specified type in |delete_journals_|. This should be
329 // called ONCE in model association. |deleted_entries| can be used to
330 // detect deleted sync data that's not persisted in native model to
331 // prevent back-from-dead problem. |deleted_entries| are only valid during
332 // lifetime of |trans|. |type| is added to |passive_delete_journal_types_| to
333 // enable periodically saving/clearing of delete journals of |type| because
334 // new journals added later are not needed until next model association.
335 void GetDeleteJournals(BaseTransaction* trans, ModelType type,
336 EntryKernelSet* deleted_entries);
337
338 // Purge entries of specified type in |delete_journals_| if their handles are
339 // in |to_purge|. This should be called after model association and
340 // |to_purge| should contain handles of the entries whose deletions are
341 // confirmed in native model.
342 void PurgeDeleteJournals(BaseTransaction* trans,
343 const MetahandleSet& to_purge);
344
317 protected: // for friends, mainly used by Entry constructors 345 protected: // for friends, mainly used by Entry constructors
318 virtual EntryKernel* GetEntryByHandle(int64 handle); 346 virtual EntryKernel* GetEntryByHandle(int64 handle);
319 virtual EntryKernel* GetEntryByHandle(int64 metahandle, 347 virtual EntryKernel* GetEntryByHandle(int64 metahandle,
320 ScopedKernelLock* lock); 348 ScopedKernelLock* lock);
321 virtual EntryKernel* GetEntryById(const Id& id); 349 virtual EntryKernel* GetEntryById(const Id& id);
322 EntryKernel* GetEntryByServerTag(const std::string& tag); 350 EntryKernel* GetEntryByServerTag(const std::string& tag);
323 virtual EntryKernel* GetEntryByClientTag(const std::string& tag); 351 virtual EntryKernel* GetEntryByClientTag(const std::string& tag);
324 EntryKernel* GetRootEntry(); 352 EntryKernel* GetRootEntry();
325 bool ReindexId(WriteTransaction* trans, EntryKernel* const entry, 353 bool ReindexId(WriteTransaction* trans, EntryKernel* const entry,
326 const Id& new_id); 354 const Id& new_id);
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 base::Lock save_changes_mutex; 612 base::Lock save_changes_mutex;
585 613
586 // The next metahandle is protected by kernel mutex. 614 // The next metahandle is protected by kernel mutex.
587 int64 next_metahandle; 615 int64 next_metahandle;
588 616
589 // The delegate for directory change events. Must not be NULL. 617 // The delegate for directory change events. Must not be NULL.
590 DirectoryChangeDelegate* const delegate; 618 DirectoryChangeDelegate* const delegate;
591 619
592 // The transaction observer. 620 // The transaction observer.
593 const WeakHandle<TransactionObserver> transaction_observer; 621 const WeakHandle<TransactionObserver> transaction_observer;
622
623 // Contains deleted entries that may not be persisted in native models. And
624 // in case of unrecoverable error, all purged entries are moved here for
625 // bookkeeping to prevent back-from-dead entries that are deleted elsewhere
626 // when sync's down.
627 IdsIndex* delete_journals_;
628
629 // Contains meta handles of deleted entries that have been persisted or
630 // undeleted, thus can be removed from database.
631 MetahandleSet* const delete_journals_to_purge_;
594 }; 632 };
595 633
596 // Helper method used to do searches on |parent_id_child_index|. 634 // Helper method used to do searches on |parent_id_child_index|.
597 ParentIdChildIndex::iterator LocateInParentChildIndex( 635 ParentIdChildIndex::iterator LocateInParentChildIndex(
598 const ScopedKernelLock& lock, 636 const ScopedKernelLock& lock,
599 const Id& parent_id, 637 const Id& parent_id,
600 int64 position_in_parent, 638 int64 position_in_parent,
601 const Id& item_id_for_tiebreaking); 639 const Id& item_id_for_tiebreaking);
602 640
603 // Return an iterator to the beginning of the range of the children of 641 // Return an iterator to the beginning of the range of the children of
(...skipping 12 matching lines...) Expand all
616 void AppendChildHandles( 654 void AppendChildHandles(
617 const ScopedKernelLock& lock, 655 const ScopedKernelLock& lock,
618 const Id& parent_id, Directory::ChildHandles* result); 656 const Id& parent_id, Directory::ChildHandles* result);
619 657
620 // Return a pointer to what is probably (but not certainly) the 658 // Return a pointer to what is probably (but not certainly) the
621 // first child of |parent_id|, or NULL if |parent_id| definitely has 659 // first child of |parent_id|, or NULL if |parent_id| definitely has
622 // no children. 660 // no children.
623 EntryKernel* GetPossibleFirstChild( 661 EntryKernel* GetPossibleFirstChild(
624 const ScopedKernelLock& lock, const Id& parent_id); 662 const ScopedKernelLock& lock, const Id& parent_id);
625 663
664 // Return true if delete journals of |type| are maintained.
665 static bool IsDeleteJournalEnabled(ModelType type);
666
626 Kernel* kernel_; 667 Kernel* kernel_;
627 668
628 scoped_ptr<DirectoryBackingStore> store_; 669 scoped_ptr<DirectoryBackingStore> store_;
629 670
630 UnrecoverableErrorHandler* const unrecoverable_error_handler_; 671 UnrecoverableErrorHandler* const unrecoverable_error_handler_;
631 const ReportUnrecoverableErrorFunction report_unrecoverable_error_function_; 672 const ReportUnrecoverableErrorFunction report_unrecoverable_error_function_;
632 bool unrecoverable_error_set_; 673 bool unrecoverable_error_set_;
633 674
634 // Not owned. 675 // Not owned.
635 NigoriHandler* const nigori_handler_; 676 NigoriHandler* const nigori_handler_;
636 Cryptographer* const cryptographer_; 677 Cryptographer* const cryptographer_;
637 678
679 // Delete journals of these types can be cleared from memory after being
680 // saved to database.
681 ModelTypeSet passive_delete_journal_types_;
682
638 InvariantCheckLevel invariant_check_level_; 683 InvariantCheckLevel invariant_check_level_;
639 }; 684 };
640 685
641 } // namespace syncable 686 } // namespace syncable
642 } // namespace syncer 687 } // namespace syncer
643 688
644 #endif // SYNC_SYNCABLE_DIRECTORY_H_ 689 #endif // SYNC_SYNCABLE_DIRECTORY_H_
OLDNEW
« no previous file with comments | « no previous file | sync/syncable/directory.cc » ('j') | sync/syncable/directory.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698