| 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 #include "components/sync/syncable/directory.h" | 5 #include "components/sync/syncable/directory.h" | 
| 6 | 6 | 
| 7 #include <inttypes.h> | 7 #include <inttypes.h> | 
| 8 | 8 | 
| 9 #include <algorithm> | 9 #include <algorithm> | 
| 10 #include <iterator> | 10 #include <iterator> | 
| (...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 722     num_erased = kernel_->server_tags_map.erase(entry->ref(UNIQUE_SERVER_TAG)); | 722     num_erased = kernel_->server_tags_map.erase(entry->ref(UNIQUE_SERVER_TAG)); | 
| 723     DCHECK_EQ(1u, num_erased); | 723     DCHECK_EQ(1u, num_erased); | 
| 724   } | 724   } | 
| 725   RemoveFromAttachmentIndex(lock, handle, entry->ref(ATTACHMENT_METADATA)); | 725   RemoveFromAttachmentIndex(lock, handle, entry->ref(ATTACHMENT_METADATA)); | 
| 726 | 726 | 
| 727   if (save_to_journal) { | 727   if (save_to_journal) { | 
| 728     entries_to_journal->insert(std::move(entry_ptr)); | 728     entries_to_journal->insert(std::move(entry_ptr)); | 
| 729   } | 729   } | 
| 730 } | 730 } | 
| 731 | 731 | 
| 732 bool Directory::PurgeEntriesWithTypeIn(ModelTypeSet disabled_types, | 732 void Directory::PurgeEntriesWithTypeIn(ModelTypeSet disabled_types, | 
| 733                                        ModelTypeSet types_to_journal, | 733                                        ModelTypeSet types_to_journal, | 
| 734                                        ModelTypeSet types_to_unapply) { | 734                                        ModelTypeSet types_to_unapply) { | 
| 735   disabled_types.RemoveAll(ProxyTypes()); | 735   disabled_types.RemoveAll(ProxyTypes()); | 
|  | 736   if (disabled_types.Empty()) | 
|  | 737     return; | 
| 736 | 738 | 
| 737   if (disabled_types.Empty()) | 739   WriteTransaction trans(FROM_HERE, PURGE_ENTRIES, this); | 
| 738     return true; | 740 | 
|  | 741   OwnedEntryKernelSet entries_to_journal; | 
| 739 | 742 | 
| 740   { | 743   { | 
| 741     WriteTransaction trans(FROM_HERE, PURGE_ENTRIES, this); | 744     ScopedKernelLock lock(this); | 
| 742 | 745 | 
| 743     OwnedEntryKernelSet entries_to_journal; | 746     bool found_progress = false; | 
|  | 747     for (ModelTypeSet::Iterator iter = disabled_types.First(); iter.Good(); | 
|  | 748          iter.Inc()) { | 
|  | 749       if (!kernel_->persisted_info.HasEmptyDownloadProgress(iter.Get())) | 
|  | 750         found_progress = true; | 
|  | 751     } | 
| 744 | 752 | 
| 745     { | 753     // If none of the disabled types have progress markers, there's nothing to | 
| 746       ScopedKernelLock lock(this); | 754     // purge. | 
|  | 755     if (!found_progress) | 
|  | 756       return; | 
| 747 | 757 | 
| 748       bool found_progress = false; | 758     for (MetahandlesMap::iterator it = kernel_->metahandles_map.begin(); | 
| 749       for (ModelTypeSet::Iterator iter = disabled_types.First(); iter.Good(); | 759          it != kernel_->metahandles_map.end();) { | 
| 750            iter.Inc()) { | 760       EntryKernel* entry = it->second.get(); | 
| 751         if (!kernel_->persisted_info.HasEmptyDownloadProgress(iter.Get())) | 761       const sync_pb::EntitySpecifics& local_specifics = entry->ref(SPECIFICS); | 
| 752           found_progress = true; | 762       const sync_pb::EntitySpecifics& server_specifics = | 
| 753       } | 763           entry->ref(SERVER_SPECIFICS); | 
|  | 764       ModelType local_type = GetModelTypeFromSpecifics(local_specifics); | 
|  | 765       ModelType server_type = GetModelTypeFromSpecifics(server_specifics); | 
| 754 | 766 | 
| 755       // If none of the disabled types have progress markers, there's nothing to | 767       // Increment the iterator before (potentially) calling DeleteEntry, | 
| 756       // purge. | 768       // otherwise our iterator may be invalidated. | 
| 757       if (!found_progress) | 769       ++it; | 
| 758         return true; |  | 
| 759 | 770 | 
| 760       for (MetahandlesMap::iterator it = kernel_->metahandles_map.begin(); | 771       if ((IsRealDataType(local_type) && disabled_types.Has(local_type)) || | 
| 761            it != kernel_->metahandles_map.end();) { | 772           (IsRealDataType(server_type) && disabled_types.Has(server_type))) { | 
| 762         EntryKernel* entry = it->second.get(); | 773         if (types_to_unapply.Has(local_type) || | 
| 763         const sync_pb::EntitySpecifics& local_specifics = entry->ref(SPECIFICS); | 774             types_to_unapply.Has(server_type)) { | 
| 764         const sync_pb::EntitySpecifics& server_specifics = | 775           UnapplyEntry(entry); | 
| 765             entry->ref(SERVER_SPECIFICS); | 776         } else { | 
| 766         ModelType local_type = GetModelTypeFromSpecifics(local_specifics); | 777           bool save_to_journal = | 
| 767         ModelType server_type = GetModelTypeFromSpecifics(server_specifics); | 778               (types_to_journal.Has(local_type) || | 
| 768 | 779                types_to_journal.Has(server_type)) && | 
| 769         // Increment the iterator before (potentially) calling DeleteEntry, | 780               (delete_journal_->IsDeleteJournalEnabled(local_type) || | 
| 770         // otherwise our iterator may be invalidated. | 781                delete_journal_->IsDeleteJournalEnabled(server_type)); | 
| 771         ++it; | 782           DeleteEntry(lock, save_to_journal, entry, &entries_to_journal); | 
| 772 |  | 
| 773         if ((IsRealDataType(local_type) && disabled_types.Has(local_type)) || |  | 
| 774             (IsRealDataType(server_type) && disabled_types.Has(server_type))) { |  | 
| 775           if (types_to_unapply.Has(local_type) || |  | 
| 776               types_to_unapply.Has(server_type)) { |  | 
| 777             UnapplyEntry(entry); |  | 
| 778           } else { |  | 
| 779             bool save_to_journal = |  | 
| 780                 (types_to_journal.Has(local_type) || |  | 
| 781                  types_to_journal.Has(server_type)) && |  | 
| 782                 (delete_journal_->IsDeleteJournalEnabled(local_type) || |  | 
| 783                  delete_journal_->IsDeleteJournalEnabled(server_type)); |  | 
| 784             DeleteEntry(lock, save_to_journal, entry, &entries_to_journal); |  | 
| 785           } |  | 
| 786         } | 783         } | 
| 787       } | 784       } | 
|  | 785     } | 
| 788 | 786 | 
| 789       delete_journal_->AddJournalBatch(&trans, entries_to_journal); | 787     delete_journal_->AddJournalBatch(&trans, entries_to_journal); | 
| 790 | 788 | 
| 791       // Ensure meta tracking for these data types reflects the purged state. | 789     // Ensure meta tracking for these data types reflects the purged state. | 
| 792       for (ModelTypeSet::Iterator it = disabled_types.First(); it.Good(); | 790     for (ModelTypeSet::Iterator it = disabled_types.First(); it.Good(); | 
| 793            it.Inc()) { | 791          it.Inc()) { | 
| 794         kernel_->persisted_info.transaction_version[it.Get()] = 0; | 792       kernel_->persisted_info.transaction_version[it.Get()] = 0; | 
| 795 | 793 | 
| 796         // Don't discard progress markers or context for unapplied types. | 794       // Don't discard progress markers or context for unapplied types. | 
| 797         if (!types_to_unapply.Has(it.Get())) { | 795       if (!types_to_unapply.Has(it.Get())) { | 
| 798           kernel_->persisted_info.ResetDownloadProgress(it.Get()); | 796         kernel_->persisted_info.ResetDownloadProgress(it.Get()); | 
| 799           kernel_->persisted_info.datatype_context[it.Get()].Clear(); | 797         kernel_->persisted_info.datatype_context[it.Get()].Clear(); | 
| 800         } |  | 
| 801       } | 798       } | 
|  | 799     } | 
| 802 | 800 | 
| 803       kernel_->info_status = KERNEL_SHARE_INFO_DIRTY; | 801     kernel_->info_status = KERNEL_SHARE_INFO_DIRTY; | 
| 804     } |  | 
| 805   } | 802   } | 
| 806   return true; |  | 
| 807 } | 803 } | 
| 808 | 804 | 
| 809 bool Directory::ResetVersionsForType(BaseWriteTransaction* trans, | 805 bool Directory::ResetVersionsForType(BaseWriteTransaction* trans, | 
| 810                                      ModelType type) { | 806                                      ModelType type) { | 
| 811   if (!ProtocolTypes().Has(type)) | 807   if (!ProtocolTypes().Has(type)) | 
| 812     return false; | 808     return false; | 
| 813   DCHECK_NE(type, BOOKMARKS) << "Only non-hierarchical types are supported"; | 809   DCHECK_NE(type, BOOKMARKS) << "Only non-hierarchical types are supported"; | 
| 814 | 810 | 
| 815   EntryKernel* type_root = GetEntryByServerTag(ModelTypeToRootTag(type)); | 811   EntryKernel* type_root = GetEntryByServerTag(ModelTypeToRootTag(type)); | 
| 816   if (!type_root) | 812   if (!type_root) | 
| (...skipping 775 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1592 Directory::Kernel* Directory::kernel() { | 1588 Directory::Kernel* Directory::kernel() { | 
| 1593   return kernel_; | 1589   return kernel_; | 
| 1594 } | 1590 } | 
| 1595 | 1591 | 
| 1596 const Directory::Kernel* Directory::kernel() const { | 1592 const Directory::Kernel* Directory::kernel() const { | 
| 1597   return kernel_; | 1593   return kernel_; | 
| 1598 } | 1594 } | 
| 1599 | 1595 | 
| 1600 }  // namespace syncable | 1596 }  // namespace syncable | 
| 1601 }  // namespace syncer | 1597 }  // namespace syncer | 
| OLD | NEW | 
|---|