| 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(BaseWriteTransaction* trans, EntryKernel* entry); |
| 540 bool InsertEntry(const ScopedKernelLock& lock, |
| 541 BaseWriteTransaction* trans, |
| 542 EntryKernel* entry); |
| 543 |
| 544 bool ReindexId(BaseWriteTransaction* trans, EntryKernel* const entry, |
| 545 const Id& new_id); |
| 546 |
| 547 bool ReindexParentId(BaseWriteTransaction* trans, EntryKernel* const entry, |
| 548 const Id& new_parent_id); |
| 549 |
| 550 // Update the attachment index for |metahandle| removing it from the index |
| 551 // under |old_metadata| entries and add it under |new_metadata| entries. |
| 552 void UpdateAttachmentIndex(const int64 metahandle, |
| 553 const sync_pb::AttachmentMetadata& old_metadata, |
| 554 const sync_pb::AttachmentMetadata& new_metadata); |
| 555 |
| 556 // Remove each of |metahandle|'s attachment ids from index_by_attachment_id. |
| 557 void RemoveFromAttachmentIndex( |
| 558 const ScopedKernelLock& lock, |
| 559 const int64 metahandle, |
| 560 const sync_pb::AttachmentMetadata& attachment_metadata); |
| 561 |
| 562 // Add each of |metahandle|'s attachment ids to the index_by_attachment_id. |
| 563 void AddToAttachmentIndex( |
| 564 const ScopedKernelLock& lock, |
| 565 const int64 metahandle, |
| 566 const sync_pb::AttachmentMetadata& attachment_metadata); |
| 567 |
| 568 void ClearDirtyMetahandles(const ScopedKernelLock& lock); |
| 569 |
| 570 DirOpenResult OpenImpl( |
| 571 const std::string& name, |
| 572 DirectoryChangeDelegate* delegate, |
| 573 const WeakHandle<TransactionObserver>& transaction_observer); |
| 549 | 574 |
| 550 // A helper that implements the logic of checking tree invariants. | 575 // A helper that implements the logic of checking tree invariants. |
| 551 bool CheckTreeInvariants(syncable::BaseTransaction* trans, | 576 bool CheckTreeInvariants(syncable::BaseTransaction* trans, |
| 552 const MetahandleSet& handles); | 577 const MetahandleSet& handles); |
| 553 | 578 |
| 554 // Helper to prime metahandles_map, ids_map, parent_child_index, | 579 // Helper to prime metahandles_map, ids_map, parent_child_index, |
| 555 // unsynced_metahandles, unapplied_update_metahandles, server_tags_map and | 580 // unsynced_metahandles, unapplied_update_metahandles, server_tags_map and |
| 556 // client_tags_map from metahandles_index. The input |handles_map| will be | 581 // client_tags_map from metahandles_index. The input |handles_map| will be |
| 557 // cleared during the initialization process. | 582 // cleared during the initialization process. |
| 558 void InitializeIndices(MetahandlesMap* handles_map); | 583 void InitializeIndices(MetahandlesMap* handles_map); |
| 559 | 584 |
| 560 // Constructs a consistent snapshot of the current Directory state and | 585 // Constructs a consistent snapshot of the current Directory state and |
| 561 // indices (by deep copy) under a ReadTransaction for use in |snapshot|. | 586 // indices (by deep copy) under a ReadTransaction for use in |snapshot|. |
| 562 // See SaveChanges() for more information. | 587 // See SaveChanges() for more information. |
| 563 void TakeSnapshotForSaveChanges(SaveChangesSnapshot* snapshot); | 588 void TakeSnapshotForSaveChanges(SaveChangesSnapshot* snapshot); |
| 564 | 589 |
| 565 // Purges from memory any unused, safe to remove entries that were | 590 // Purges from memory any unused, safe to remove entries that were |
| 566 // successfully deleted on disk as a result of the SaveChanges that processed | 591 // successfully deleted on disk as a result of the SaveChanges that processed |
| 567 // |snapshot|. See SaveChanges() for more information. | 592 // |snapshot|. See SaveChanges() for more information. |
| 568 bool VacuumAfterSaveChanges(const SaveChangesSnapshot& snapshot); | 593 bool VacuumAfterSaveChanges(const SaveChangesSnapshot& snapshot); |
| 569 | 594 |
| 570 // Rolls back dirty bits in the event that the SaveChanges that | 595 // Rolls back dirty bits in the event that the SaveChanges that |
| 571 // processed |snapshot| failed, for example, due to no disk space. | 596 // processed |snapshot| failed, for example, due to no disk space. |
| 572 void HandleSaveChangesFailure(const SaveChangesSnapshot& snapshot); | 597 void HandleSaveChangesFailure(const SaveChangesSnapshot& snapshot); |
| 573 | 598 |
| 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 | 599 // Used by CheckTreeInvariants |
| 580 void GetAllMetaHandles(BaseTransaction* trans, MetahandleSet* result); | 600 void GetAllMetaHandles(BaseTransaction* trans, MetahandleSet* result); |
| 581 bool SafeToPurgeFromMemory(WriteTransaction* trans, | 601 bool SafeToPurgeFromMemory(WriteTransaction* trans, |
| 582 const EntryKernel* const entry) const; | 602 const EntryKernel* const entry) const; |
| 583 | 603 |
| 584 // A helper used by GetTotalNodeCount. | 604 // A helper used by GetTotalNodeCount. |
| 585 void GetChildSetForKernel( | 605 void GetChildSetForKernel( |
| 586 BaseTransaction*, | 606 BaseTransaction*, |
| 587 EntryKernel* kernel_, | 607 EntryKernel* kernel_, |
| 588 std::deque<const OrderedChildSet*>* child_sets) const; | 608 std::deque<const OrderedChildSet*>* child_sets) const; |
| 589 | 609 |
| 590 // Append the handles of the children of |parent_id| to |result|. | 610 // Append the handles of the children of |parent_id| to |result|. |
| 591 void AppendChildHandles( | 611 void AppendChildHandles(const ScopedKernelLock& lock, |
| 592 const ScopedKernelLock& lock, | 612 const Id& parent_id, |
| 593 const Id& parent_id, Directory::Metahandles* result); | 613 Directory::Metahandles* result); |
| 594 | 614 |
| 595 // Helper methods used by PurgeDisabledTypes. | 615 // Helper methods used by PurgeDisabledTypes. |
| 596 void UnapplyEntry(EntryKernel* entry); | 616 void UnapplyEntry(EntryKernel* entry); |
| 597 void DeleteEntry(bool save_to_journal, | 617 void DeleteEntry(const ScopedKernelLock& lock, |
| 618 bool save_to_journal, |
| 598 EntryKernel* entry, | 619 EntryKernel* entry, |
| 599 EntryKernelSet* entries_to_journal, | 620 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 | 621 |
| 613 // A private version of the public GetMetaHandlesOfType for when you already | 622 // A private version of the public GetMetaHandlesOfType for when you already |
| 614 // have a ScopedKernelLock. | 623 // have a ScopedKernelLock. |
| 615 void GetMetaHandlesOfType(const ScopedKernelLock& lock, | 624 void GetMetaHandlesOfType(const ScopedKernelLock& lock, |
| 616 BaseTransaction* trans, | 625 BaseTransaction* trans, |
| 617 ModelType type, | 626 ModelType type, |
| 618 std::vector<int64>* result); | 627 std::vector<int64>* result); |
| 619 | 628 |
| 620 Kernel* kernel_; | 629 Kernel* kernel_; |
| 621 | 630 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 635 // are deleted in native models as well. | 644 // are deleted in native models as well. |
| 636 scoped_ptr<DeleteJournal> delete_journal_; | 645 scoped_ptr<DeleteJournal> delete_journal_; |
| 637 | 646 |
| 638 DISALLOW_COPY_AND_ASSIGN(Directory); | 647 DISALLOW_COPY_AND_ASSIGN(Directory); |
| 639 }; | 648 }; |
| 640 | 649 |
| 641 } // namespace syncable | 650 } // namespace syncable |
| 642 } // namespace syncer | 651 } // namespace syncer |
| 643 | 652 |
| 644 #endif // SYNC_SYNCABLE_DIRECTORY_H_ | 653 #endif // SYNC_SYNCABLE_DIRECTORY_H_ |
| OLD | NEW |