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

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

Issue 265853004: Revert of Keep track of which attachments are referenced by which sync entries. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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
« no previous file with comments | « sync/sync_internal_api.gypi ('k') | sync/syncable/directory.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <deque> 8 #include <deque>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
(...skipping 29 matching lines...) Expand all
40 class ScopedKernelLock; 40 class ScopedKernelLock;
41 class TransactionObserver; 41 class TransactionObserver;
42 class WriteTransaction; 42 class WriteTransaction;
43 43
44 enum InvariantCheckLevel { 44 enum InvariantCheckLevel {
45 OFF = 0, // No checking. 45 OFF = 0, // No checking.
46 VERIFY_CHANGES = 1, // Checks only mutated entries. Does not check hierarchy. 46 VERIFY_CHANGES = 1, // Checks only mutated entries. Does not check hierarchy.
47 FULL_DB_VERIFICATION = 2 // Check every entry. This can be expensive. 47 FULL_DB_VERIFICATION = 2 // Check every entry. This can be expensive.
48 }; 48 };
49 49
50 // Directory stores and manages EntryKernels.
51 //
52 // This class is tightly coupled to several other classes (see friends).
53 class SYNC_EXPORT Directory { 50 class SYNC_EXPORT Directory {
54 friend class BaseTransaction; 51 friend class BaseTransaction;
55 friend class Entry; 52 friend class Entry;
56 friend class ModelNeutralMutableEntry; 53 friend class ModelNeutralMutableEntry;
57 friend class MutableEntry; 54 friend class MutableEntry;
58 friend class ReadTransaction; 55 friend class ReadTransaction;
59 friend class ScopedKernelLock; 56 friend class ScopedKernelLock;
60 friend class WriteTransaction; 57 friend class WriteTransaction;
61 friend class SyncableDirectoryTest; 58 friend class SyncableDirectoryTest;
62 friend class syncer::TestUserShare; 59 friend class syncer::TestUserShare;
(...skipping 13 matching lines...) Expand all
76 // 73 //
77 // It gets worse, though. The Anroid STL library has a bug that means it may 74 // It gets worse, though. The Anroid STL library has a bug that means it may
78 // invalidate all iterators when you erase from the map, too. That means that 75 // invalidate all iterators when you erase from the map, too. That means that
79 // you can't iterate while erasing. STLDeleteElements(), std::remove_if(), 76 // you can't iterate while erasing. STLDeleteElements(), std::remove_if(),
80 // and other similar functions are off-limits too, until this bug is fixed. 77 // and other similar functions are off-limits too, until this bug is fixed.
81 // 78 //
82 // See http://sourceforge.net/p/stlport/bugs/239/. 79 // See http://sourceforge.net/p/stlport/bugs/239/.
83 typedef base::hash_map<int64, EntryKernel*> MetahandlesMap; 80 typedef base::hash_map<int64, EntryKernel*> MetahandlesMap;
84 typedef base::hash_map<std::string, EntryKernel*> IdsMap; 81 typedef base::hash_map<std::string, EntryKernel*> IdsMap;
85 typedef base::hash_map<std::string, EntryKernel*> TagsMap; 82 typedef base::hash_map<std::string, EntryKernel*> TagsMap;
86 typedef std::string AttachmentIdUniqueId;
87 typedef base::hash_map<AttachmentIdUniqueId, MetahandleSet>
88 IndexByAttachmentId;
89 83
90 static const base::FilePath::CharType kSyncDatabaseFilename[]; 84 static const base::FilePath::CharType kSyncDatabaseFilename[];
91 85
92 // The dirty/clean state of kernel fields backed by the share_info table. 86 // The dirty/clean state of kernel fields backed by the share_info table.
93 // This is public so it can be used in SaveChangesSnapshot for persistence. 87 // This is public so it can be used in SaveChangesSnapshot for persistence.
94 enum KernelShareInfoStatus { 88 enum KernelShareInfoStatus {
95 KERNEL_SHARE_INFO_INVALID, 89 KERNEL_SHARE_INFO_INVALID,
96 KERNEL_SHARE_INFO_VALID, 90 KERNEL_SHARE_INFO_VALID,
97 KERNEL_SHARE_INFO_DIRTY 91 KERNEL_SHARE_INFO_DIRTY
98 }; 92 };
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 // Returns: true on success, false if an error was encountered. 376 // Returns: true on success, false if an error was encountered.
383 virtual bool PurgeEntriesWithTypeIn(ModelTypeSet disabled_types, 377 virtual bool PurgeEntriesWithTypeIn(ModelTypeSet disabled_types,
384 ModelTypeSet types_to_journal, 378 ModelTypeSet types_to_journal,
385 ModelTypeSet types_to_unapply); 379 ModelTypeSet types_to_unapply);
386 380
387 // Resets the base_versions and server_versions of all synced entities 381 // Resets the base_versions and server_versions of all synced entities
388 // associated with |type| to 1. 382 // associated with |type| to 1.
389 // WARNING! This can be slow, as it iterates over all entries for a type. 383 // WARNING! This can be slow, as it iterates over all entries for a type.
390 bool ResetVersionsForType(BaseWriteTransaction* trans, ModelType type); 384 bool ResetVersionsForType(BaseWriteTransaction* trans, ModelType type);
391 385
392 // Returns true iff the attachment identified by |attachment_id_proto| is
393 // linked to an entry.
394 //
395 // An attachment linked to a deleted entry is still considered linked if the
396 // entry hasn't yet been purged.
397 bool IsAttachmentLinked(
398 const sync_pb::AttachmentIdProto& attachment_id_proto) const;
399
400 protected: // for friends, mainly used by Entry constructors 386 protected: // for friends, mainly used by Entry constructors
401 virtual EntryKernel* GetEntryByHandle(int64 handle); 387 virtual EntryKernel* GetEntryByHandle(int64 handle);
402 virtual EntryKernel* GetEntryByHandle(int64 metahandle, 388 virtual EntryKernel* GetEntryByHandle(int64 metahandle,
403 ScopedKernelLock* lock); 389 ScopedKernelLock* lock);
404 virtual EntryKernel* GetEntryById(const Id& id); 390 virtual EntryKernel* GetEntryById(const Id& id);
405 EntryKernel* GetEntryByServerTag(const std::string& tag); 391 EntryKernel* GetEntryByServerTag(const std::string& tag);
406 virtual EntryKernel* GetEntryByClientTag(const std::string& tag); 392 virtual EntryKernel* GetEntryByClientTag(const std::string& tag);
407 bool ReindexId(BaseWriteTransaction* trans, EntryKernel* const entry, 393 bool ReindexId(BaseWriteTransaction* trans, EntryKernel* const entry,
408 const Id& new_id); 394 const Id& new_id);
409 bool ReindexParentId(BaseWriteTransaction* trans, EntryKernel* const entry, 395 bool ReindexParentId(BaseWriteTransaction* trans, EntryKernel* const entry,
410 const Id& new_parent_id); 396 const Id& new_parent_id);
411 // Update the attachment index for |metahandle| removing it from the index
412 // under |old_metadata| entries and add it under |new_metadata| entries.
413 void UpdateAttachmentIndex(const int64 metahandle,
414 const sync_pb::AttachmentMetadata& old_metadata,
415 const sync_pb::AttachmentMetadata& new_metadata);
416 void ClearDirtyMetahandles(); 397 void ClearDirtyMetahandles();
417 398
418 DirOpenResult OpenImpl( 399 DirOpenResult OpenImpl(
419 const std::string& name, 400 const std::string& name,
420 DirectoryChangeDelegate* delegate, 401 DirectoryChangeDelegate* delegate,
421 const WeakHandle<TransactionObserver>& transaction_observer); 402 const WeakHandle<TransactionObserver>& transaction_observer);
422 403
423 private: 404 private:
424 struct Kernel { 405 struct Kernel {
425 // |delegate| must not be NULL. |transaction_observer| must be 406 // |delegate| must not be NULL. |transaction_observer| must be
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 444
464 // Entries indexed by client tag. 445 // Entries indexed by client tag.
465 // This map does not include any entries with non-existent client tags. 446 // This map does not include any entries with non-existent client tags.
466 // IS_DEL items are included. 447 // IS_DEL items are included.
467 TagsMap client_tags_map; 448 TagsMap client_tags_map;
468 449
469 // Contains non-deleted items, indexed according to parent and position 450 // Contains non-deleted items, indexed according to parent and position
470 // within parent. Protected by the ScopedKernelLock. 451 // within parent. Protected by the ScopedKernelLock.
471 ParentChildIndex parent_child_index; 452 ParentChildIndex parent_child_index;
472 453
473 // This index keeps track of which metahandles refer to a given attachment.
474 // Think of it as the inverse of EntryKernel's AttachmentMetadata Records.
475 //
476 // Because entries can be undeleted (e.g. PutIsDel(false)), entries should
477 // not removed from the index until they are actually deleted from memory.
478 //
479 // All access should go through IsAttachmentLinked,
480 // RemoveFromAttachmentIndex, AddToAttachmentIndex, and
481 // UpdateAttachmentIndex methods to avoid iterator invalidation errors.
482 IndexByAttachmentId index_by_attachment_id;
483
484 // 3 in-memory indices on bits used extremely frequently by the syncer. 454 // 3 in-memory indices on bits used extremely frequently by the syncer.
485 // |unapplied_update_metahandles| is keyed by the server model type. 455 // |unapplied_update_metahandles| is keyed by the server model type.
486 MetahandleSet unapplied_update_metahandles[MODEL_TYPE_COUNT]; 456 MetahandleSet unapplied_update_metahandles[MODEL_TYPE_COUNT];
487 MetahandleSet unsynced_metahandles; 457 MetahandleSet unsynced_metahandles;
488 // Contains metahandles that are most likely dirty (though not 458 // Contains metahandles that are most likely dirty (though not
489 // necessarily). Dirtyness is confirmed in TakeSnapshotForSaveChanges(). 459 // necessarily). Dirtyness is confirmed in TakeSnapshotForSaveChanges().
490 MetahandleSet dirty_metahandles; 460 MetahandleSet dirty_metahandles;
491 461
492 // When a purge takes place, we remove items from all our indices and stash 462 // When a purge takes place, we remove items from all our indices and stash
493 // them in here so that SaveChanges can persist their permanent deletion. 463 // them in here so that SaveChanges can persist their permanent deletion.
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 536
567 // Append the handles of the children of |parent_id| to |result|. 537 // Append the handles of the children of |parent_id| to |result|.
568 void AppendChildHandles( 538 void AppendChildHandles(
569 const ScopedKernelLock& lock, 539 const ScopedKernelLock& lock,
570 const Id& parent_id, Directory::Metahandles* result); 540 const Id& parent_id, Directory::Metahandles* result);
571 541
572 // Helper methods used by PurgeDisabledTypes. 542 // Helper methods used by PurgeDisabledTypes.
573 void UnapplyEntry(EntryKernel* entry); 543 void UnapplyEntry(EntryKernel* entry);
574 void DeleteEntry(bool save_to_journal, 544 void DeleteEntry(bool save_to_journal,
575 EntryKernel* entry, 545 EntryKernel* entry,
576 EntryKernelSet* entries_to_journal, 546 EntryKernelSet* entries_to_journal);
577 const ScopedKernelLock& lock);
578
579 // Remove each of |metahandle|'s attachment ids from index_by_attachment_id.
580 void RemoveFromAttachmentIndex(
581 const int64 metahandle,
582 const sync_pb::AttachmentMetadata& attachment_metadata,
583 const ScopedKernelLock& lock);
584 // Add each of |metahandle|'s attachment ids to the index_by_attachment_id.
585 void AddToAttachmentIndex(
586 const int64 metahandle,
587 const sync_pb::AttachmentMetadata& attachment_metadata,
588 const ScopedKernelLock& lock);
589 547
590 Kernel* kernel_; 548 Kernel* kernel_;
591 549
592 scoped_ptr<DirectoryBackingStore> store_; 550 scoped_ptr<DirectoryBackingStore> store_;
593 551
594 UnrecoverableErrorHandler* const unrecoverable_error_handler_; 552 UnrecoverableErrorHandler* const unrecoverable_error_handler_;
595 const ReportUnrecoverableErrorFunction report_unrecoverable_error_function_; 553 const ReportUnrecoverableErrorFunction report_unrecoverable_error_function_;
596 bool unrecoverable_error_set_; 554 bool unrecoverable_error_set_;
597 555
598 // Not owned. 556 // Not owned.
599 NigoriHandler* const nigori_handler_; 557 NigoriHandler* const nigori_handler_;
600 Cryptographer* const cryptographer_; 558 Cryptographer* const cryptographer_;
601 559
602 InvariantCheckLevel invariant_check_level_; 560 InvariantCheckLevel invariant_check_level_;
603 561
604 // Maintain deleted entries not in |kernel_| until it's verified that they 562 // Maintain deleted entries not in |kernel_| until it's verified that they
605 // are deleted in native models as well. 563 // are deleted in native models as well.
606 scoped_ptr<DeleteJournal> delete_journal_; 564 scoped_ptr<DeleteJournal> delete_journal_;
607 565
608 DISALLOW_COPY_AND_ASSIGN(Directory); 566 DISALLOW_COPY_AND_ASSIGN(Directory);
609 }; 567 };
610 568
611 } // namespace syncable 569 } // namespace syncable
612 } // namespace syncer 570 } // namespace syncer
613 571
614 #endif // SYNC_SYNCABLE_DIRECTORY_H_ 572 #endif // SYNC_SYNCABLE_DIRECTORY_H_
OLDNEW
« no previous file with comments | « sync/sync_internal_api.gypi ('k') | sync/syncable/directory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698