Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 413 // persist modified entry on disk. e.g. SyncBackupManager uses this to | 413 // persist modified entry on disk. e.g. SyncBackupManager uses this to |
| 414 // preserve sync preferences in DB on disk. | 414 // preserve sync preferences in DB on disk. |
| 415 void UnmarkDirtyEntry(WriteTransaction* trans, Entry* entry); | 415 void UnmarkDirtyEntry(WriteTransaction* trans, Entry* entry); |
| 416 | 416 |
| 417 // Clears |id_set| and fills it with the ids of attachments that need to be | 417 // Clears |id_set| and fills it with the ids of attachments that need to be |
| 418 // uploaded to the sync server. | 418 // uploaded to the sync server. |
| 419 void GetAttachmentIdsToUpload(BaseTransaction* trans, | 419 void GetAttachmentIdsToUpload(BaseTransaction* trans, |
| 420 ModelType type, | 420 ModelType type, |
| 421 AttachmentIdSet* id_set); | 421 AttachmentIdSet* id_set); |
| 422 | 422 |
| 423 protected: // for friends, mainly used by Entry constructors | |
| 424 virtual EntryKernel* GetEntryByHandle(int64 handle); | |
| 425 virtual EntryKernel* GetEntryByHandle(int64 metahandle, | |
| 426 ScopedKernelLock* lock); | |
| 427 virtual EntryKernel* GetEntryById(const Id& id); | |
| 428 EntryKernel* GetEntryByServerTag(const std::string& tag); | |
| 429 virtual EntryKernel* GetEntryByClientTag(const std::string& tag); | |
| 430 bool ReindexId(BaseWriteTransaction* trans, EntryKernel* const entry, | |
| 431 const Id& new_id); | |
| 432 bool ReindexParentId(BaseWriteTransaction* trans, EntryKernel* const entry, | |
| 433 const Id& new_parent_id); | |
| 434 // Update the attachment index for |metahandle| removing it from the index | |
| 435 // under |old_metadata| entries and add it under |new_metadata| entries. | |
| 436 void UpdateAttachmentIndex(const int64 metahandle, | |
| 437 const sync_pb::AttachmentMetadata& old_metadata, | |
| 438 const sync_pb::AttachmentMetadata& new_metadata); | |
| 439 void ClearDirtyMetahandles(); | |
| 440 | |
| 441 DirOpenResult OpenImpl( | |
| 442 const std::string& name, | |
| 443 DirectoryChangeDelegate* delegate, | |
| 444 const WeakHandle<TransactionObserver>& transaction_observer); | |
| 445 | |
| 446 private: | 423 private: |
| 447 struct Kernel { | 424 struct Kernel { |
| 448 // |delegate| must not be NULL. |transaction_observer| must be | 425 // |delegate| must not be NULL. |transaction_observer| must be |
| 449 // initialized. | 426 // initialized. |
| 450 Kernel(const std::string& name, const KernelLoadInfo& info, | 427 Kernel(const std::string& name, const KernelLoadInfo& info, |
| 451 DirectoryChangeDelegate* delegate, | 428 DirectoryChangeDelegate* delegate, |
| 452 const WeakHandle<TransactionObserver>& transaction_observer); | 429 const WeakHandle<TransactionObserver>& transaction_observer); |
| 453 | 430 |
| 454 ~Kernel(); | 431 ~Kernel(); |
| 455 | 432 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 536 // The next metahandle is protected by kernel mutex. | 513 // The next metahandle is protected by kernel mutex. |
| 537 int64 next_metahandle; | 514 int64 next_metahandle; |
| 538 | 515 |
| 539 // The delegate for directory change events. Must not be NULL. | 516 // The delegate for directory change events. Must not be NULL. |
| 540 DirectoryChangeDelegate* const delegate; | 517 DirectoryChangeDelegate* const delegate; |
| 541 | 518 |
| 542 // The transaction observer. | 519 // The transaction observer. |
| 543 const WeakHandle<TransactionObserver> transaction_observer; | 520 const WeakHandle<TransactionObserver> transaction_observer; |
| 544 }; | 521 }; |
| 545 | 522 |
| 546 // These private versions expect the kernel lock to already be held | 523 // You'll notice that some of these methods have two forms. One that takes a |
| 547 // before calling. | 524 // ScopedKernelLock and one that doesn't. The general pattern is that those |
| 548 EntryKernel* GetEntryById(const Id& id, ScopedKernelLock* const lock); | 525 // without a ScopedKernelLock parameter construct one internally before |
| 526 // calling the form that takes one. | |
| 527 | |
| 528 virtual EntryKernel* GetEntryByHandle(int64 handle); | |
| 529 virtual EntryKernel* GetEntryByHandle(const ScopedKernelLock& lock, | |
| 530 int64 metahandle); | |
| 531 | |
| 532 virtual EntryKernel* GetEntryById(const Id& id); | |
| 533 virtual EntryKernel* GetEntryById(const ScopedKernelLock& lock, const Id& id); | |
| 534 | |
| 535 EntryKernel* GetEntryByServerTag(const std::string& tag); | |
| 536 virtual EntryKernel* GetEntryByClientTag(const std::string& tag); | |
| 537 | |
| 538 // For new entry creation only | |
| 539 bool InsertEntry(const ScopedKernelLock& lock, | |
|
Nicolas Zea
2014/09/22 19:46:26
nit: be consistent about ordering of locking versi
maniscalco
2014/09/22 19:54:59
Done.
| |
| 540 BaseWriteTransaction* trans, | |
| 541 EntryKernel* entry); | |
| 542 bool InsertEntry(BaseWriteTransaction* trans, EntryKernel* entry); | |
| 543 | |
| 544 bool ReindexId(BaseWriteTransaction* trans, EntryKernel* const entry, | |
| 545 const Id& new_id); | |
| 546 bool ReindexParentId(BaseWriteTransaction* trans, EntryKernel* const entry, | |
|
Nicolas Zea
2014/09/22 19:46:25
nit: newline above, since this isn't a pair of loc
maniscalco
2014/09/22 19:54:59
Done.
| |
| 547 const Id& new_parent_id); | |
| 548 | |
| 549 // Update the attachment index for |metahandle| removing it from the index | |
| 550 // under |old_metadata| entries and add it under |new_metadata| entries. | |
| 551 void UpdateAttachmentIndex(const int64 metahandle, | |
| 552 const sync_pb::AttachmentMetadata& old_metadata, | |
| 553 const sync_pb::AttachmentMetadata& new_metadata); | |
| 554 | |
| 555 // Remove each of |metahandle|'s attachment ids from index_by_attachment_id. | |
| 556 void RemoveFromAttachmentIndex( | |
| 557 const ScopedKernelLock& lock, | |
| 558 const int64 metahandle, | |
| 559 const sync_pb::AttachmentMetadata& attachment_metadata); | |
| 560 // Add each of |metahandle|'s attachment ids to the index_by_attachment_id. | |
|
Nicolas Zea
2014/09/22 19:46:26
nit: newline above?
maniscalco
2014/09/22 19:54:59
Done.
| |
| 561 void AddToAttachmentIndex( | |
| 562 const ScopedKernelLock& lock, | |
| 563 const int64 metahandle, | |
| 564 const sync_pb::AttachmentMetadata& attachment_metadata); | |
| 565 | |
| 566 void ClearDirtyMetahandles(const ScopedKernelLock& lock); | |
| 567 | |
| 568 DirOpenResult OpenImpl( | |
| 569 const std::string& name, | |
| 570 DirectoryChangeDelegate* delegate, | |
| 571 const WeakHandle<TransactionObserver>& transaction_observer); | |
| 549 | 572 |
| 550 // A helper that implements the logic of checking tree invariants. | 573 // A helper that implements the logic of checking tree invariants. |
| 551 bool CheckTreeInvariants(syncable::BaseTransaction* trans, | 574 bool CheckTreeInvariants(syncable::BaseTransaction* trans, |
| 552 const MetahandleSet& handles); | 575 const MetahandleSet& handles); |
| 553 | 576 |
| 554 // Helper to prime metahandles_map, ids_map, parent_child_index, | 577 // Helper to prime metahandles_map, ids_map, parent_child_index, |
| 555 // unsynced_metahandles, unapplied_update_metahandles, server_tags_map and | 578 // unsynced_metahandles, unapplied_update_metahandles, server_tags_map and |
| 556 // client_tags_map from metahandles_index. The input |handles_map| will be | 579 // client_tags_map from metahandles_index. The input |handles_map| will be |
| 557 // cleared during the initialization process. | 580 // cleared during the initialization process. |
| 558 void InitializeIndices(MetahandlesMap* handles_map); | 581 void InitializeIndices(MetahandlesMap* handles_map); |
| 559 | 582 |
| 560 // Constructs a consistent snapshot of the current Directory state and | 583 // Constructs a consistent snapshot of the current Directory state and |
| 561 // indices (by deep copy) under a ReadTransaction for use in |snapshot|. | 584 // indices (by deep copy) under a ReadTransaction for use in |snapshot|. |
| 562 // See SaveChanges() for more information. | 585 // See SaveChanges() for more information. |
| 563 void TakeSnapshotForSaveChanges(SaveChangesSnapshot* snapshot); | 586 void TakeSnapshotForSaveChanges(SaveChangesSnapshot* snapshot); |
| 564 | 587 |
| 565 // Purges from memory any unused, safe to remove entries that were | 588 // Purges from memory any unused, safe to remove entries that were |
| 566 // successfully deleted on disk as a result of the SaveChanges that processed | 589 // successfully deleted on disk as a result of the SaveChanges that processed |
| 567 // |snapshot|. See SaveChanges() for more information. | 590 // |snapshot|. See SaveChanges() for more information. |
| 568 bool VacuumAfterSaveChanges(const SaveChangesSnapshot& snapshot); | 591 bool VacuumAfterSaveChanges(const SaveChangesSnapshot& snapshot); |
| 569 | 592 |
| 570 // Rolls back dirty bits in the event that the SaveChanges that | 593 // Rolls back dirty bits in the event that the SaveChanges that |
| 571 // processed |snapshot| failed, for example, due to no disk space. | 594 // processed |snapshot| failed, for example, due to no disk space. |
| 572 void HandleSaveChangesFailure(const SaveChangesSnapshot& snapshot); | 595 void HandleSaveChangesFailure(const SaveChangesSnapshot& snapshot); |
| 573 | 596 |
| 574 // For new entry creation only | |
| 575 bool InsertEntry(BaseWriteTransaction* trans, | |
| 576 EntryKernel* entry, ScopedKernelLock* lock); | |
| 577 bool InsertEntry(BaseWriteTransaction* trans, EntryKernel* entry); | |
| 578 | |
| 579 // Used by CheckTreeInvariants | 597 // Used by CheckTreeInvariants |
| 580 void GetAllMetaHandles(BaseTransaction* trans, MetahandleSet* result); | 598 void GetAllMetaHandles(BaseTransaction* trans, MetahandleSet* result); |
| 581 bool SafeToPurgeFromMemory(WriteTransaction* trans, | 599 bool SafeToPurgeFromMemory(WriteTransaction* trans, |
| 582 const EntryKernel* const entry) const; | 600 const EntryKernel* const entry) const; |
| 583 | 601 |
| 584 // A helper used by GetTotalNodeCount. | 602 // A helper used by GetTotalNodeCount. |
| 585 void GetChildSetForKernel( | 603 void GetChildSetForKernel( |
| 586 BaseTransaction*, | 604 BaseTransaction*, |
| 587 EntryKernel* kernel_, | 605 EntryKernel* kernel_, |
| 588 std::deque<const OrderedChildSet*>* child_sets) const; | 606 std::deque<const OrderedChildSet*>* child_sets) const; |
| 589 | 607 |
| 590 // Append the handles of the children of |parent_id| to |result|. | 608 // Append the handles of the children of |parent_id| to |result|. |
| 591 void AppendChildHandles( | 609 void AppendChildHandles(const ScopedKernelLock& lock, |
| 592 const ScopedKernelLock& lock, | 610 const Id& parent_id, |
| 593 const Id& parent_id, Directory::Metahandles* result); | 611 Directory::Metahandles* result); |
| 594 | 612 |
| 595 // Helper methods used by PurgeDisabledTypes. | 613 // Helper methods used by PurgeDisabledTypes. |
| 596 void UnapplyEntry(EntryKernel* entry); | 614 void UnapplyEntry(EntryKernel* entry); |
| 597 void DeleteEntry(bool save_to_journal, | 615 void DeleteEntry(const ScopedKernelLock& lock, |
| 616 bool save_to_journal, | |
| 598 EntryKernel* entry, | 617 EntryKernel* entry, |
| 599 EntryKernelSet* entries_to_journal, | 618 EntryKernelSet* entries_to_journal); |
| 600 const ScopedKernelLock& lock); | |
| 601 | |
| 602 // Remove each of |metahandle|'s attachment ids from index_by_attachment_id. | |
| 603 void RemoveFromAttachmentIndex( | |
| 604 const int64 metahandle, | |
| 605 const sync_pb::AttachmentMetadata& attachment_metadata, | |
| 606 const ScopedKernelLock& lock); | |
| 607 // Add each of |metahandle|'s attachment ids to the index_by_attachment_id. | |
| 608 void AddToAttachmentIndex( | |
| 609 const int64 metahandle, | |
| 610 const sync_pb::AttachmentMetadata& attachment_metadata, | |
| 611 const ScopedKernelLock& lock); | |
| 612 | 619 |
| 613 // A private version of the public GetMetaHandlesOfType for when you already | 620 // A private version of the public GetMetaHandlesOfType for when you already |
| 614 // have a ScopedKernelLock. | 621 // have a ScopedKernelLock. |
| 615 void GetMetaHandlesOfType(const ScopedKernelLock& lock, | 622 void GetMetaHandlesOfType(const ScopedKernelLock& lock, |
| 616 BaseTransaction* trans, | 623 BaseTransaction* trans, |
| 617 ModelType type, | 624 ModelType type, |
| 618 std::vector<int64>* result); | 625 std::vector<int64>* result); |
| 619 | 626 |
| 620 Kernel* kernel_; | 627 Kernel* kernel_; |
| 621 | 628 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 635 // are deleted in native models as well. | 642 // are deleted in native models as well. |
| 636 scoped_ptr<DeleteJournal> delete_journal_; | 643 scoped_ptr<DeleteJournal> delete_journal_; |
| 637 | 644 |
| 638 DISALLOW_COPY_AND_ASSIGN(Directory); | 645 DISALLOW_COPY_AND_ASSIGN(Directory); |
| 639 }; | 646 }; |
| 640 | 647 |
| 641 } // namespace syncable | 648 } // namespace syncable |
| 642 } // namespace syncer | 649 } // namespace syncer |
| 643 | 650 |
| 644 #endif // SYNC_SYNCABLE_DIRECTORY_H_ | 651 #endif // SYNC_SYNCABLE_DIRECTORY_H_ |
| OLD | NEW |