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 <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
11 #include <iterator> | 11 #include <iterator> |
12 #include <utility> | 12 #include <utility> |
13 | 13 |
14 #include "base/base64.h" | 14 #include "base/base64.h" |
15 #include "base/guid.h" | 15 #include "base/guid.h" |
16 #include "base/memory/ptr_util.h" | |
16 #include "base/metrics/histogram.h" | 17 #include "base/metrics/histogram.h" |
17 #include "base/stl_util.h" | 18 #include "base/stl_util.h" |
18 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
19 #include "base/trace_event/trace_event.h" | 20 #include "base/trace_event/trace_event.h" |
20 #include "components/sync/base/attachment_id_proto.h" | 21 #include "components/sync/base/attachment_id_proto.h" |
21 #include "components/sync/base/unique_position.h" | 22 #include "components/sync/base/unique_position.h" |
22 #include "components/sync/base/unrecoverable_error_handler.h" | 23 #include "components/sync/base/unrecoverable_error_handler.h" |
23 #include "components/sync/syncable/entry.h" | 24 #include "components/sync/syncable/entry.h" |
24 #include "components/sync/syncable/entry_kernel.h" | 25 #include "components/sync/syncable/entry_kernel.h" |
25 #include "components/sync/syncable/in_memory_directory_backing_store.h" | 26 #include "components/sync/syncable/in_memory_directory_backing_store.h" |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
96 persisted_info(info.kernel_info), | 97 persisted_info(info.kernel_info), |
97 cache_guid(info.cache_guid), | 98 cache_guid(info.cache_guid), |
98 next_metahandle(info.max_metahandle + 1), | 99 next_metahandle(info.max_metahandle + 1), |
99 delegate(delegate), | 100 delegate(delegate), |
100 transaction_observer(transaction_observer) { | 101 transaction_observer(transaction_observer) { |
101 DCHECK(delegate); | 102 DCHECK(delegate); |
102 DCHECK(transaction_observer.IsInitialized()); | 103 DCHECK(transaction_observer.IsInitialized()); |
103 } | 104 } |
104 | 105 |
105 Directory::Kernel::~Kernel() { | 106 Directory::Kernel::~Kernel() { |
106 base::STLDeleteContainerPairSecondPointers(metahandles_map.begin(), | 107 metahandles_map.clear(); |
Nicolas Zea
2016/08/29 18:36:35
Won't this happen automatically?
Avi (use Gerrit)
2016/08/29 19:12:17
Done.
| |
107 metahandles_map.end()); | |
108 } | 108 } |
109 | 109 |
110 Directory::Directory( | 110 Directory::Directory( |
111 DirectoryBackingStore* store, | 111 DirectoryBackingStore* store, |
112 const WeakHandle<UnrecoverableErrorHandler>& unrecoverable_error_handler, | 112 const WeakHandle<UnrecoverableErrorHandler>& unrecoverable_error_handler, |
113 const base::Closure& report_unrecoverable_error_function, | 113 const base::Closure& report_unrecoverable_error_function, |
114 NigoriHandler* nigori_handler, | 114 NigoriHandler* nigori_handler, |
115 Cryptographer* cryptographer) | 115 Cryptographer* cryptographer) |
116 : kernel_(NULL), | 116 : kernel_(NULL), |
117 store_(store), | 117 store_(store), |
(...skipping 18 matching lines...) Expand all Loading... | |
136 const DirOpenResult result = OpenImpl(name, delegate, transaction_observer); | 136 const DirOpenResult result = OpenImpl(name, delegate, transaction_observer); |
137 | 137 |
138 if (OPENED != result) | 138 if (OPENED != result) |
139 Close(); | 139 Close(); |
140 return result; | 140 return result; |
141 } | 141 } |
142 | 142 |
143 void Directory::InitializeIndices(MetahandlesMap* handles_map) { | 143 void Directory::InitializeIndices(MetahandlesMap* handles_map) { |
144 ScopedKernelLock lock(this); | 144 ScopedKernelLock lock(this); |
145 kernel_->metahandles_map.swap(*handles_map); | 145 kernel_->metahandles_map.swap(*handles_map); |
146 for (MetahandlesMap::const_iterator it = kernel_->metahandles_map.begin(); | 146 for (auto it = kernel_->metahandles_map.begin(); |
147 it != kernel_->metahandles_map.end(); ++it) { | 147 it != kernel_->metahandles_map.end(); ++it) { |
148 EntryKernel* entry = it->second; | 148 EntryKernel* entry = it->second.get(); |
149 if (ParentChildIndex::ShouldInclude(entry)) | 149 if (ParentChildIndex::ShouldInclude(entry)) |
150 kernel_->parent_child_index.Insert(entry); | 150 kernel_->parent_child_index.Insert(entry); |
151 const int64_t metahandle = entry->ref(META_HANDLE); | 151 const int64_t metahandle = entry->ref(META_HANDLE); |
152 if (entry->ref(IS_UNSYNCED)) | 152 if (entry->ref(IS_UNSYNCED)) |
153 kernel_->unsynced_metahandles.insert(metahandle); | 153 kernel_->unsynced_metahandles.insert(metahandle); |
154 if (entry->ref(IS_UNAPPLIED_UPDATE)) { | 154 if (entry->ref(IS_UNAPPLIED_UPDATE)) { |
155 const ModelType type = entry->GetServerModelType(); | 155 const ModelType type = entry->GetServerModelType(); |
156 kernel_->unapplied_update_metahandles[type].insert(metahandle); | 156 kernel_->unapplied_update_metahandles[type].insert(metahandle); |
157 } | 157 } |
158 if (!entry->ref(UNIQUE_SERVER_TAG).empty()) { | 158 if (!entry->ref(UNIQUE_SERVER_TAG).empty()) { |
(...skipping 19 matching lines...) Expand all Loading... | |
178 | 178 |
179 DirOpenResult Directory::OpenImpl( | 179 DirOpenResult Directory::OpenImpl( |
180 const string& name, | 180 const string& name, |
181 DirectoryChangeDelegate* delegate, | 181 DirectoryChangeDelegate* delegate, |
182 const WeakHandle<TransactionObserver>& transaction_observer) { | 182 const WeakHandle<TransactionObserver>& transaction_observer) { |
183 KernelLoadInfo info; | 183 KernelLoadInfo info; |
184 // Temporary indices before kernel_ initialized in case Load fails. We 0(1) | 184 // Temporary indices before kernel_ initialized in case Load fails. We 0(1) |
185 // swap these later. | 185 // swap these later. |
186 Directory::MetahandlesMap tmp_handles_map; | 186 Directory::MetahandlesMap tmp_handles_map; |
187 | 187 |
188 // Avoids mem leaks on failure. Harmlessly deletes the empty hash map after | |
189 // the swap in the success case. | |
190 base::STLValueDeleter<MetahandlesMap> deleter(&tmp_handles_map); | |
191 | |
192 JournalIndex delete_journals; | 188 JournalIndex delete_journals; |
193 MetahandleSet metahandles_to_purge; | 189 MetahandleSet metahandles_to_purge; |
194 | 190 |
195 DirOpenResult result = store_->Load(&tmp_handles_map, &delete_journals, | 191 DirOpenResult result = store_->Load(&tmp_handles_map, &delete_journals, |
196 &metahandles_to_purge, &info); | 192 &metahandles_to_purge, &info); |
197 if (OPENED != result) | 193 if (OPENED != result) |
198 return result; | 194 return result; |
199 | 195 |
200 DCHECK(!kernel_); | 196 DCHECK(!kernel_); |
201 kernel_ = new Kernel(name, info, delegate, transaction_observer); | 197 kernel_ = new Kernel(name, info, delegate, transaction_observer); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
280 ScopedKernelLock lock(this); | 276 ScopedKernelLock lock(this); |
281 return GetEntryByHandle(lock, metahandle); | 277 return GetEntryByHandle(lock, metahandle); |
282 } | 278 } |
283 | 279 |
284 EntryKernel* Directory::GetEntryByHandle(const ScopedKernelLock& lock, | 280 EntryKernel* Directory::GetEntryByHandle(const ScopedKernelLock& lock, |
285 int64_t metahandle) { | 281 int64_t metahandle) { |
286 // Look up in memory | 282 // Look up in memory |
287 MetahandlesMap::iterator found = kernel_->metahandles_map.find(metahandle); | 283 MetahandlesMap::iterator found = kernel_->metahandles_map.find(metahandle); |
288 if (found != kernel_->metahandles_map.end()) { | 284 if (found != kernel_->metahandles_map.end()) { |
289 // Found it in memory. Easy. | 285 // Found it in memory. Easy. |
290 return found->second; | 286 return found->second.get(); |
291 } | 287 } |
292 return NULL; | 288 return NULL; |
293 } | 289 } |
294 | 290 |
295 bool Directory::GetChildHandlesById(BaseTransaction* trans, | 291 bool Directory::GetChildHandlesById(BaseTransaction* trans, |
296 const Id& parent_id, | 292 const Id& parent_id, |
297 Directory::Metahandles* result) { | 293 Directory::Metahandles* result) { |
298 if (!SyncAssert(this == trans->directory(), FROM_HERE, | 294 if (!SyncAssert(this == trans->directory(), FROM_HERE, |
299 "Directories don't match", trans)) | 295 "Directories don't match", trans)) |
300 return false; | 296 return false; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
360 | 356 |
361 bool Directory::InsertEntry(const ScopedKernelLock& lock, | 357 bool Directory::InsertEntry(const ScopedKernelLock& lock, |
362 BaseWriteTransaction* trans, | 358 BaseWriteTransaction* trans, |
363 EntryKernel* entry) { | 359 EntryKernel* entry) { |
364 if (!SyncAssert(NULL != entry, FROM_HERE, "Entry is null", trans)) | 360 if (!SyncAssert(NULL != entry, FROM_HERE, "Entry is null", trans)) |
365 return false; | 361 return false; |
366 | 362 |
367 static const char error[] = "Entry already in memory index."; | 363 static const char error[] = "Entry already in memory index."; |
368 | 364 |
369 if (!SyncAssert(kernel_->metahandles_map | 365 if (!SyncAssert(kernel_->metahandles_map |
370 .insert(std::make_pair(entry->ref(META_HANDLE), entry)) | 366 .insert(std::make_pair(entry->ref(META_HANDLE), |
367 base::WrapUnique(entry))) | |
371 .second, | 368 .second, |
372 FROM_HERE, error, trans)) { | 369 FROM_HERE, error, trans)) { |
373 return false; | 370 return false; |
374 } | 371 } |
375 if (!SyncAssert( | 372 if (!SyncAssert( |
376 kernel_->ids_map.insert(std::make_pair(entry->ref(ID).value(), entry)) | 373 kernel_->ids_map.insert(std::make_pair(entry->ref(ID).value(), entry)) |
377 .second, | 374 .second, |
378 FROM_HERE, error, trans)) { | 375 FROM_HERE, error, trans)) { |
379 return false; | 376 return false; |
380 } | 377 } |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
592 | 589 |
593 // Need a write transaction as we are about to permanently purge entries. | 590 // Need a write transaction as we are about to permanently purge entries. |
594 WriteTransaction trans(FROM_HERE, VACUUM_AFTER_SAVE, this); | 591 WriteTransaction trans(FROM_HERE, VACUUM_AFTER_SAVE, this); |
595 ScopedKernelLock lock(this); | 592 ScopedKernelLock lock(this); |
596 // Now drop everything we can out of memory. | 593 // Now drop everything we can out of memory. |
597 for (EntryKernelSet::const_iterator i = snapshot.dirty_metas.begin(); | 594 for (EntryKernelSet::const_iterator i = snapshot.dirty_metas.begin(); |
598 i != snapshot.dirty_metas.end(); ++i) { | 595 i != snapshot.dirty_metas.end(); ++i) { |
599 MetahandlesMap::iterator found = | 596 MetahandlesMap::iterator found = |
600 kernel_->metahandles_map.find((*i)->ref(META_HANDLE)); | 597 kernel_->metahandles_map.find((*i)->ref(META_HANDLE)); |
601 EntryKernel* entry = | 598 EntryKernel* entry = |
602 (found == kernel_->metahandles_map.end() ? NULL : found->second); | 599 (found == kernel_->metahandles_map.end() ? NULL : found->second.get()); |
603 if (entry && SafeToPurgeFromMemory(&trans, entry)) { | 600 if (entry && SafeToPurgeFromMemory(&trans, entry)) { |
604 // We now drop deleted metahandles that are up to date on both the client | 601 // We now drop deleted metahandles that are up to date on both the client |
605 // and the server. | 602 // and the server. |
603 std::unique_ptr<EntryKernel> unique_entry = std::move(found->second); | |
604 | |
606 size_t num_erased = 0; | 605 size_t num_erased = 0; |
607 num_erased = kernel_->metahandles_map.erase(entry->ref(META_HANDLE)); | 606 num_erased = kernel_->metahandles_map.erase(entry->ref(META_HANDLE)); |
608 DCHECK_EQ(1u, num_erased); | 607 DCHECK_EQ(1u, num_erased); |
609 num_erased = kernel_->ids_map.erase(entry->ref(ID).value()); | 608 num_erased = kernel_->ids_map.erase(entry->ref(ID).value()); |
610 DCHECK_EQ(1u, num_erased); | 609 DCHECK_EQ(1u, num_erased); |
611 if (!entry->ref(UNIQUE_SERVER_TAG).empty()) { | 610 if (!entry->ref(UNIQUE_SERVER_TAG).empty()) { |
612 num_erased = | 611 num_erased = |
613 kernel_->server_tags_map.erase(entry->ref(UNIQUE_SERVER_TAG)); | 612 kernel_->server_tags_map.erase(entry->ref(UNIQUE_SERVER_TAG)); |
614 DCHECK_EQ(1u, num_erased); | 613 DCHECK_EQ(1u, num_erased); |
615 } | 614 } |
616 if (!entry->ref(UNIQUE_CLIENT_TAG).empty()) { | 615 if (!entry->ref(UNIQUE_CLIENT_TAG).empty()) { |
617 num_erased = | 616 num_erased = |
618 kernel_->client_tags_map.erase(entry->ref(UNIQUE_CLIENT_TAG)); | 617 kernel_->client_tags_map.erase(entry->ref(UNIQUE_CLIENT_TAG)); |
619 DCHECK_EQ(1u, num_erased); | 618 DCHECK_EQ(1u, num_erased); |
620 } | 619 } |
621 if (!SyncAssert(!kernel_->parent_child_index.Contains(entry), FROM_HERE, | 620 if (!SyncAssert(!kernel_->parent_child_index.Contains(entry), FROM_HERE, |
622 "Deleted entry still present", (&trans))) | 621 "Deleted entry still present", (&trans))) |
623 return false; | 622 return false; |
624 RemoveFromAttachmentIndex(lock, entry->ref(META_HANDLE), | 623 RemoveFromAttachmentIndex(lock, entry->ref(META_HANDLE), |
625 entry->ref(ATTACHMENT_METADATA)); | 624 entry->ref(ATTACHMENT_METADATA)); |
626 | |
627 delete entry; | |
628 } | 625 } |
629 if (trans.unrecoverable_error_set()) | 626 if (trans.unrecoverable_error_set()) |
630 return false; | 627 return false; |
631 } | 628 } |
632 return true; | 629 return true; |
633 } | 630 } |
634 | 631 |
635 void Directory::UnapplyEntry(EntryKernel* entry) { | 632 void Directory::UnapplyEntry(EntryKernel* entry) { |
636 int64_t handle = entry->ref(META_HANDLE); | 633 int64_t handle = entry->ref(META_HANDLE); |
637 ModelType server_type = | 634 ModelType server_type = |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
691 void Directory::DeleteEntry(const ScopedKernelLock& lock, | 688 void Directory::DeleteEntry(const ScopedKernelLock& lock, |
692 bool save_to_journal, | 689 bool save_to_journal, |
693 EntryKernel* entry, | 690 EntryKernel* entry, |
694 EntryKernelSet* entries_to_journal) { | 691 EntryKernelSet* entries_to_journal) { |
695 int64_t handle = entry->ref(META_HANDLE); | 692 int64_t handle = entry->ref(META_HANDLE); |
696 ModelType server_type = | 693 ModelType server_type = |
697 GetModelTypeFromSpecifics(entry->ref(SERVER_SPECIFICS)); | 694 GetModelTypeFromSpecifics(entry->ref(SERVER_SPECIFICS)); |
698 | 695 |
699 kernel_->metahandles_to_purge.insert(handle); | 696 kernel_->metahandles_to_purge.insert(handle); |
700 | 697 |
698 std::unique_ptr<EntryKernel> entry_ptr = | |
699 std::move(kernel_->metahandles_map[handle]); | |
700 | |
701 size_t num_erased = 0; | 701 size_t num_erased = 0; |
702 num_erased = kernel_->metahandles_map.erase(entry->ref(META_HANDLE)); | 702 num_erased = kernel_->metahandles_map.erase(handle); |
703 DCHECK_EQ(1u, num_erased); | 703 DCHECK_EQ(1u, num_erased); |
704 num_erased = kernel_->ids_map.erase(entry->ref(ID).value()); | 704 num_erased = kernel_->ids_map.erase(entry->ref(ID).value()); |
705 DCHECK_EQ(1u, num_erased); | 705 DCHECK_EQ(1u, num_erased); |
706 num_erased = kernel_->unsynced_metahandles.erase(handle); | 706 num_erased = kernel_->unsynced_metahandles.erase(handle); |
707 DCHECK_EQ(entry->ref(IS_UNSYNCED), num_erased > 0); | 707 DCHECK_EQ(entry->ref(IS_UNSYNCED), num_erased > 0); |
708 num_erased = kernel_->unapplied_update_metahandles[server_type].erase(handle); | 708 num_erased = kernel_->unapplied_update_metahandles[server_type].erase(handle); |
709 DCHECK_EQ(entry->ref(IS_UNAPPLIED_UPDATE), num_erased > 0); | 709 DCHECK_EQ(entry->ref(IS_UNAPPLIED_UPDATE), num_erased > 0); |
710 if (kernel_->parent_child_index.Contains(entry)) | 710 if (kernel_->parent_child_index.Contains(entry)) |
711 kernel_->parent_child_index.Remove(entry); | 711 kernel_->parent_child_index.Remove(entry); |
712 | 712 |
713 if (!entry->ref(UNIQUE_CLIENT_TAG).empty()) { | 713 if (!entry->ref(UNIQUE_CLIENT_TAG).empty()) { |
714 num_erased = kernel_->client_tags_map.erase(entry->ref(UNIQUE_CLIENT_TAG)); | 714 num_erased = kernel_->client_tags_map.erase(entry->ref(UNIQUE_CLIENT_TAG)); |
715 DCHECK_EQ(1u, num_erased); | 715 DCHECK_EQ(1u, num_erased); |
716 } | 716 } |
717 if (!entry->ref(UNIQUE_SERVER_TAG).empty()) { | 717 if (!entry->ref(UNIQUE_SERVER_TAG).empty()) { |
718 num_erased = kernel_->server_tags_map.erase(entry->ref(UNIQUE_SERVER_TAG)); | 718 num_erased = kernel_->server_tags_map.erase(entry->ref(UNIQUE_SERVER_TAG)); |
719 DCHECK_EQ(1u, num_erased); | 719 DCHECK_EQ(1u, num_erased); |
720 } | 720 } |
721 RemoveFromAttachmentIndex(lock, handle, entry->ref(ATTACHMENT_METADATA)); | 721 RemoveFromAttachmentIndex(lock, handle, entry->ref(ATTACHMENT_METADATA)); |
722 | 722 |
723 if (save_to_journal) { | 723 if (save_to_journal) { |
724 entries_to_journal->insert(entry); | 724 entries_to_journal->insert(entry_ptr.release()); |
725 } else { | |
726 delete entry; | |
727 } | 725 } |
728 } | 726 } |
729 | 727 |
730 bool Directory::PurgeEntriesWithTypeIn(ModelTypeSet disabled_types, | 728 bool Directory::PurgeEntriesWithTypeIn(ModelTypeSet disabled_types, |
731 ModelTypeSet types_to_journal, | 729 ModelTypeSet types_to_journal, |
732 ModelTypeSet types_to_unapply) { | 730 ModelTypeSet types_to_unapply) { |
733 disabled_types.RemoveAll(ProxyTypes()); | 731 disabled_types.RemoveAll(ProxyTypes()); |
734 | 732 |
735 if (disabled_types.Empty()) | 733 if (disabled_types.Empty()) |
736 return true; | 734 return true; |
(...skipping 15 matching lines...) Expand all Loading... | |
752 found_progress = true; | 750 found_progress = true; |
753 } | 751 } |
754 | 752 |
755 // If none of the disabled types have progress markers, there's nothing to | 753 // If none of the disabled types have progress markers, there's nothing to |
756 // purge. | 754 // purge. |
757 if (!found_progress) | 755 if (!found_progress) |
758 return true; | 756 return true; |
759 | 757 |
760 for (MetahandlesMap::iterator it = kernel_->metahandles_map.begin(); | 758 for (MetahandlesMap::iterator it = kernel_->metahandles_map.begin(); |
761 it != kernel_->metahandles_map.end();) { | 759 it != kernel_->metahandles_map.end();) { |
762 EntryKernel* entry = it->second; | 760 EntryKernel* entry = it->second.get(); |
763 const sync_pb::EntitySpecifics& local_specifics = entry->ref(SPECIFICS); | 761 const sync_pb::EntitySpecifics& local_specifics = entry->ref(SPECIFICS); |
764 const sync_pb::EntitySpecifics& server_specifics = | 762 const sync_pb::EntitySpecifics& server_specifics = |
765 entry->ref(SERVER_SPECIFICS); | 763 entry->ref(SERVER_SPECIFICS); |
766 ModelType local_type = GetModelTypeFromSpecifics(local_specifics); | 764 ModelType local_type = GetModelTypeFromSpecifics(local_specifics); |
767 ModelType server_type = GetModelTypeFromSpecifics(server_specifics); | 765 ModelType server_type = GetModelTypeFromSpecifics(server_specifics); |
768 | 766 |
769 // Increment the iterator before (potentially) calling DeleteEntry, | 767 // Increment the iterator before (potentially) calling DeleteEntry, |
770 // otherwise our iterator may be invalidated. | 768 // otherwise our iterator may be invalidated. |
771 ++it; | 769 ++it; |
772 | 770 |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1081 GetMetaHandlesOfType(lock, trans, type, result); | 1079 GetMetaHandlesOfType(lock, trans, type, result); |
1082 } | 1080 } |
1083 | 1081 |
1084 void Directory::GetMetaHandlesOfType(const ScopedKernelLock& lock, | 1082 void Directory::GetMetaHandlesOfType(const ScopedKernelLock& lock, |
1085 BaseTransaction* trans, | 1083 BaseTransaction* trans, |
1086 ModelType type, | 1084 ModelType type, |
1087 std::vector<int64_t>* result) { | 1085 std::vector<int64_t>* result) { |
1088 result->clear(); | 1086 result->clear(); |
1089 for (MetahandlesMap::iterator it = kernel_->metahandles_map.begin(); | 1087 for (MetahandlesMap::iterator it = kernel_->metahandles_map.begin(); |
1090 it != kernel_->metahandles_map.end(); ++it) { | 1088 it != kernel_->metahandles_map.end(); ++it) { |
1091 EntryKernel* entry = it->second; | 1089 EntryKernel* entry = it->second.get(); |
1092 const ModelType entry_type = | 1090 const ModelType entry_type = |
1093 GetModelTypeFromSpecifics(entry->ref(SPECIFICS)); | 1091 GetModelTypeFromSpecifics(entry->ref(SPECIFICS)); |
1094 if (entry_type == type) | 1092 if (entry_type == type) |
1095 result->push_back(it->first); | 1093 result->push_back(it->first); |
1096 } | 1094 } |
1097 } | 1095 } |
1098 | 1096 |
1099 void Directory::CollectMetaHandleCounts( | 1097 void Directory::CollectMetaHandleCounts( |
1100 std::vector<int>* num_entries_by_type, | 1098 std::vector<int>* num_entries_by_type, |
1101 std::vector<int>* num_to_delete_entries_by_type) { | 1099 std::vector<int>* num_to_delete_entries_by_type) { |
1102 syncable::ReadTransaction trans(FROM_HERE, this); | 1100 syncable::ReadTransaction trans(FROM_HERE, this); |
1103 ScopedKernelLock lock(this); | 1101 ScopedKernelLock lock(this); |
1104 | 1102 |
1105 for (MetahandlesMap::iterator it = kernel_->metahandles_map.begin(); | 1103 for (MetahandlesMap::iterator it = kernel_->metahandles_map.begin(); |
1106 it != kernel_->metahandles_map.end(); ++it) { | 1104 it != kernel_->metahandles_map.end(); ++it) { |
1107 EntryKernel* entry = it->second; | 1105 EntryKernel* entry = it->second.get(); |
1108 const ModelType type = GetModelTypeFromSpecifics(entry->ref(SPECIFICS)); | 1106 const ModelType type = GetModelTypeFromSpecifics(entry->ref(SPECIFICS)); |
1109 (*num_entries_by_type)[type]++; | 1107 (*num_entries_by_type)[type]++; |
1110 if (entry->ref(IS_DEL)) | 1108 if (entry->ref(IS_DEL)) |
1111 (*num_to_delete_entries_by_type)[type]++; | 1109 (*num_to_delete_entries_by_type)[type]++; |
1112 } | 1110 } |
1113 } | 1111 } |
1114 | 1112 |
1115 std::unique_ptr<base::ListValue> Directory::GetNodeDetailsForType( | 1113 std::unique_ptr<base::ListValue> Directory::GetNodeDetailsForType( |
1116 BaseTransaction* trans, | 1114 BaseTransaction* trans, |
1117 ModelType type) { | 1115 ModelType type) { |
1118 std::unique_ptr<base::ListValue> nodes(new base::ListValue()); | 1116 std::unique_ptr<base::ListValue> nodes(new base::ListValue()); |
1119 | 1117 |
1120 ScopedKernelLock lock(this); | 1118 ScopedKernelLock lock(this); |
1121 for (MetahandlesMap::iterator it = kernel_->metahandles_map.begin(); | 1119 for (MetahandlesMap::iterator it = kernel_->metahandles_map.begin(); |
1122 it != kernel_->metahandles_map.end(); ++it) { | 1120 it != kernel_->metahandles_map.end(); ++it) { |
1123 if (GetModelTypeFromSpecifics(it->second->ref(SPECIFICS)) != type) { | 1121 if (GetModelTypeFromSpecifics(it->second->ref(SPECIFICS)) != type) { |
1124 continue; | 1122 continue; |
1125 } | 1123 } |
1126 | 1124 |
1127 EntryKernel* kernel = it->second; | 1125 EntryKernel* kernel = it->second.get(); |
1128 std::unique_ptr<base::DictionaryValue> node( | 1126 std::unique_ptr<base::DictionaryValue> node( |
1129 kernel->ToValue(GetCryptographer(trans))); | 1127 kernel->ToValue(GetCryptographer(trans))); |
1130 | 1128 |
1131 // Add the position index if appropriate. This must be done here (and not | 1129 // Add the position index if appropriate. This must be done here (and not |
1132 // in EntryKernel) because the EntryKernel does not have access to its | 1130 // in EntryKernel) because the EntryKernel does not have access to its |
1133 // siblings. | 1131 // siblings. |
1134 if (kernel->ShouldMaintainPosition() && !kernel->ref(IS_DEL)) { | 1132 if (kernel->ShouldMaintainPosition() && !kernel->ref(IS_DEL)) { |
1135 node->SetInteger("positionIndex", GetPositionIndex(trans, kernel)); | 1133 node->SetInteger("positionIndex", GetPositionIndex(trans, kernel)); |
1136 } | 1134 } |
1137 | 1135 |
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1543 Directory::Kernel* Directory::kernel() { | 1541 Directory::Kernel* Directory::kernel() { |
1544 return kernel_; | 1542 return kernel_; |
1545 } | 1543 } |
1546 | 1544 |
1547 const Directory::Kernel* Directory::kernel() const { | 1545 const Directory::Kernel* Directory::kernel() const { |
1548 return kernel_; | 1546 return kernel_; |
1549 } | 1547 } |
1550 | 1548 |
1551 } // namespace syncable | 1549 } // namespace syncable |
1552 } // namespace syncer | 1550 } // namespace syncer |
OLD | NEW |