| 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 "sync/syncable/directory.h" | 5 #include "sync/syncable/directory.h" |
| 6 | 6 |
| 7 #include <stddef.h> |
| 8 #include <stdint.h> |
| 9 |
| 7 #include <algorithm> | 10 #include <algorithm> |
| 8 #include <iterator> | 11 #include <iterator> |
| 9 | 12 |
| 10 #include "base/base64.h" | 13 #include "base/base64.h" |
| 11 #include "base/guid.h" | 14 #include "base/guid.h" |
| 12 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
| 13 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
| 14 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/trace_event/trace_event.h" | 18 #include "base/trace_event/trace_event.h" |
| 16 #include "sync/internal_api/public/base/attachment_id_proto.h" | 19 #include "sync/internal_api/public/base/attachment_id_proto.h" |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 } | 142 } |
| 140 | 143 |
| 141 void Directory::InitializeIndices(MetahandlesMap* handles_map) { | 144 void Directory::InitializeIndices(MetahandlesMap* handles_map) { |
| 142 ScopedKernelLock lock(this); | 145 ScopedKernelLock lock(this); |
| 143 kernel_->metahandles_map.swap(*handles_map); | 146 kernel_->metahandles_map.swap(*handles_map); |
| 144 for (MetahandlesMap::const_iterator it = kernel_->metahandles_map.begin(); | 147 for (MetahandlesMap::const_iterator it = kernel_->metahandles_map.begin(); |
| 145 it != kernel_->metahandles_map.end(); ++it) { | 148 it != kernel_->metahandles_map.end(); ++it) { |
| 146 EntryKernel* entry = it->second; | 149 EntryKernel* entry = it->second; |
| 147 if (ParentChildIndex::ShouldInclude(entry)) | 150 if (ParentChildIndex::ShouldInclude(entry)) |
| 148 kernel_->parent_child_index.Insert(entry); | 151 kernel_->parent_child_index.Insert(entry); |
| 149 const int64 metahandle = entry->ref(META_HANDLE); | 152 const int64_t metahandle = entry->ref(META_HANDLE); |
| 150 if (entry->ref(IS_UNSYNCED)) | 153 if (entry->ref(IS_UNSYNCED)) |
| 151 kernel_->unsynced_metahandles.insert(metahandle); | 154 kernel_->unsynced_metahandles.insert(metahandle); |
| 152 if (entry->ref(IS_UNAPPLIED_UPDATE)) { | 155 if (entry->ref(IS_UNAPPLIED_UPDATE)) { |
| 153 const ModelType type = entry->GetServerModelType(); | 156 const ModelType type = entry->GetServerModelType(); |
| 154 kernel_->unapplied_update_metahandles[type].insert(metahandle); | 157 kernel_->unapplied_update_metahandles[type].insert(metahandle); |
| 155 } | 158 } |
| 156 if (!entry->ref(UNIQUE_SERVER_TAG).empty()) { | 159 if (!entry->ref(UNIQUE_SERVER_TAG).empty()) { |
| 157 DCHECK(kernel_->server_tags_map.find(entry->ref(UNIQUE_SERVER_TAG)) == | 160 DCHECK(kernel_->server_tags_map.find(entry->ref(UNIQUE_SERVER_TAG)) == |
| 158 kernel_->server_tags_map.end()) | 161 kernel_->server_tags_map.end()) |
| 159 << "Unexpected duplicate use of client tag"; | 162 << "Unexpected duplicate use of client tag"; |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 EntryKernel* Directory::GetEntryByServerTag(const string& tag) { | 270 EntryKernel* Directory::GetEntryByServerTag(const string& tag) { |
| 268 ScopedKernelLock lock(this); | 271 ScopedKernelLock lock(this); |
| 269 DCHECK(kernel_); | 272 DCHECK(kernel_); |
| 270 TagsMap::iterator it = kernel_->server_tags_map.find(tag); | 273 TagsMap::iterator it = kernel_->server_tags_map.find(tag); |
| 271 if (it != kernel_->server_tags_map.end()) { | 274 if (it != kernel_->server_tags_map.end()) { |
| 272 return it->second; | 275 return it->second; |
| 273 } | 276 } |
| 274 return NULL; | 277 return NULL; |
| 275 } | 278 } |
| 276 | 279 |
| 277 EntryKernel* Directory::GetEntryByHandle(int64 metahandle) { | 280 EntryKernel* Directory::GetEntryByHandle(int64_t metahandle) { |
| 278 ScopedKernelLock lock(this); | 281 ScopedKernelLock lock(this); |
| 279 return GetEntryByHandle(lock, metahandle); | 282 return GetEntryByHandle(lock, metahandle); |
| 280 } | 283 } |
| 281 | 284 |
| 282 EntryKernel* Directory::GetEntryByHandle(const ScopedKernelLock& lock, | 285 EntryKernel* Directory::GetEntryByHandle(const ScopedKernelLock& lock, |
| 283 int64 metahandle) { | 286 int64_t metahandle) { |
| 284 // Look up in memory | 287 // Look up in memory |
| 285 MetahandlesMap::iterator found = | 288 MetahandlesMap::iterator found = |
| 286 kernel_->metahandles_map.find(metahandle); | 289 kernel_->metahandles_map.find(metahandle); |
| 287 if (found != kernel_->metahandles_map.end()) { | 290 if (found != kernel_->metahandles_map.end()) { |
| 288 // Found it in memory. Easy. | 291 // Found it in memory. Easy. |
| 289 return found->second; | 292 return found->second; |
| 290 } | 293 } |
| 291 return NULL; | 294 return NULL; |
| 292 } | 295 } |
| 293 | 296 |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 // Update the indices that depend on the PARENT_ID field. | 437 // Update the indices that depend on the PARENT_ID field. |
| 435 ScopedParentChildIndexUpdater index_updater(lock, entry, | 438 ScopedParentChildIndexUpdater index_updater(lock, entry, |
| 436 &kernel_->parent_child_index); | 439 &kernel_->parent_child_index); |
| 437 entry->put(PARENT_ID, new_parent_id); | 440 entry->put(PARENT_ID, new_parent_id); |
| 438 } | 441 } |
| 439 return true; | 442 return true; |
| 440 } | 443 } |
| 441 | 444 |
| 442 void Directory::RemoveFromAttachmentIndex( | 445 void Directory::RemoveFromAttachmentIndex( |
| 443 const ScopedKernelLock& lock, | 446 const ScopedKernelLock& lock, |
| 444 const int64 metahandle, | 447 const int64_t metahandle, |
| 445 const sync_pb::AttachmentMetadata& attachment_metadata) { | 448 const sync_pb::AttachmentMetadata& attachment_metadata) { |
| 446 for (int i = 0; i < attachment_metadata.record_size(); ++i) { | 449 for (int i = 0; i < attachment_metadata.record_size(); ++i) { |
| 447 AttachmentIdUniqueId unique_id = | 450 AttachmentIdUniqueId unique_id = |
| 448 attachment_metadata.record(i).id().unique_id(); | 451 attachment_metadata.record(i).id().unique_id(); |
| 449 IndexByAttachmentId::iterator iter = | 452 IndexByAttachmentId::iterator iter = |
| 450 kernel_->index_by_attachment_id.find(unique_id); | 453 kernel_->index_by_attachment_id.find(unique_id); |
| 451 if (iter != kernel_->index_by_attachment_id.end()) { | 454 if (iter != kernel_->index_by_attachment_id.end()) { |
| 452 iter->second.erase(metahandle); | 455 iter->second.erase(metahandle); |
| 453 if (iter->second.empty()) { | 456 if (iter->second.empty()) { |
| 454 kernel_->index_by_attachment_id.erase(iter); | 457 kernel_->index_by_attachment_id.erase(iter); |
| 455 } | 458 } |
| 456 } | 459 } |
| 457 } | 460 } |
| 458 } | 461 } |
| 459 | 462 |
| 460 void Directory::AddToAttachmentIndex( | 463 void Directory::AddToAttachmentIndex( |
| 461 const ScopedKernelLock& lock, | 464 const ScopedKernelLock& lock, |
| 462 const int64 metahandle, | 465 const int64_t metahandle, |
| 463 const sync_pb::AttachmentMetadata& attachment_metadata) { | 466 const sync_pb::AttachmentMetadata& attachment_metadata) { |
| 464 for (int i = 0; i < attachment_metadata.record_size(); ++i) { | 467 for (int i = 0; i < attachment_metadata.record_size(); ++i) { |
| 465 AttachmentIdUniqueId unique_id = | 468 AttachmentIdUniqueId unique_id = |
| 466 attachment_metadata.record(i).id().unique_id(); | 469 attachment_metadata.record(i).id().unique_id(); |
| 467 IndexByAttachmentId::iterator iter = | 470 IndexByAttachmentId::iterator iter = |
| 468 kernel_->index_by_attachment_id.find(unique_id); | 471 kernel_->index_by_attachment_id.find(unique_id); |
| 469 if (iter == kernel_->index_by_attachment_id.end()) { | 472 if (iter == kernel_->index_by_attachment_id.end()) { |
| 470 iter = kernel_->index_by_attachment_id.insert(std::make_pair( | 473 iter = kernel_->index_by_attachment_id.insert(std::make_pair( |
| 471 unique_id, | 474 unique_id, |
| 472 MetahandleSet())).first; | 475 MetahandleSet())).first; |
| 473 } | 476 } |
| 474 iter->second.insert(metahandle); | 477 iter->second.insert(metahandle); |
| 475 } | 478 } |
| 476 } | 479 } |
| 477 | 480 |
| 478 void Directory::UpdateAttachmentIndex( | 481 void Directory::UpdateAttachmentIndex( |
| 479 const int64 metahandle, | 482 const int64_t metahandle, |
| 480 const sync_pb::AttachmentMetadata& old_metadata, | 483 const sync_pb::AttachmentMetadata& old_metadata, |
| 481 const sync_pb::AttachmentMetadata& new_metadata) { | 484 const sync_pb::AttachmentMetadata& new_metadata) { |
| 482 ScopedKernelLock lock(this); | 485 ScopedKernelLock lock(this); |
| 483 RemoveFromAttachmentIndex(lock, metahandle, old_metadata); | 486 RemoveFromAttachmentIndex(lock, metahandle, old_metadata); |
| 484 AddToAttachmentIndex(lock, metahandle, new_metadata); | 487 AddToAttachmentIndex(lock, metahandle, new_metadata); |
| 485 } | 488 } |
| 486 | 489 |
| 487 void Directory::GetMetahandlesByAttachmentId( | 490 void Directory::GetMetahandlesByAttachmentId( |
| 488 BaseTransaction* trans, | 491 BaseTransaction* trans, |
| 489 const sync_pb::AttachmentIdProto& attachment_id_proto, | 492 const sync_pb::AttachmentIdProto& attachment_id_proto, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 510 kernel_->dirty_metahandles.clear(); | 513 kernel_->dirty_metahandles.clear(); |
| 511 } | 514 } |
| 512 | 515 |
| 513 bool Directory::SafeToPurgeFromMemory(WriteTransaction* trans, | 516 bool Directory::SafeToPurgeFromMemory(WriteTransaction* trans, |
| 514 const EntryKernel* const entry) const { | 517 const EntryKernel* const entry) const { |
| 515 bool safe = entry->ref(IS_DEL) && !entry->is_dirty() && | 518 bool safe = entry->ref(IS_DEL) && !entry->is_dirty() && |
| 516 !entry->ref(SYNCING) && !entry->ref(IS_UNAPPLIED_UPDATE) && | 519 !entry->ref(SYNCING) && !entry->ref(IS_UNAPPLIED_UPDATE) && |
| 517 !entry->ref(IS_UNSYNCED); | 520 !entry->ref(IS_UNSYNCED); |
| 518 | 521 |
| 519 if (safe) { | 522 if (safe) { |
| 520 int64 handle = entry->ref(META_HANDLE); | 523 int64_t handle = entry->ref(META_HANDLE); |
| 521 const ModelType type = entry->GetServerModelType(); | 524 const ModelType type = entry->GetServerModelType(); |
| 522 if (!SyncAssert(kernel_->dirty_metahandles.count(handle) == 0U, | 525 if (!SyncAssert(kernel_->dirty_metahandles.count(handle) == 0U, |
| 523 FROM_HERE, | 526 FROM_HERE, |
| 524 "Dirty metahandles should be empty", trans)) | 527 "Dirty metahandles should be empty", trans)) |
| 525 return false; | 528 return false; |
| 526 // TODO(tim): Bug 49278. | 529 // TODO(tim): Bug 49278. |
| 527 if (!SyncAssert(!kernel_->unsynced_metahandles.count(handle), | 530 if (!SyncAssert(!kernel_->unsynced_metahandles.count(handle), |
| 528 FROM_HERE, | 531 FROM_HERE, |
| 529 "Unsynced handles should be empty", | 532 "Unsynced handles should be empty", |
| 530 trans)) | 533 trans)) |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 640 | 643 |
| 641 delete entry; | 644 delete entry; |
| 642 } | 645 } |
| 643 if (trans.unrecoverable_error_set()) | 646 if (trans.unrecoverable_error_set()) |
| 644 return false; | 647 return false; |
| 645 } | 648 } |
| 646 return true; | 649 return true; |
| 647 } | 650 } |
| 648 | 651 |
| 649 void Directory::UnapplyEntry(EntryKernel* entry) { | 652 void Directory::UnapplyEntry(EntryKernel* entry) { |
| 650 int64 handle = entry->ref(META_HANDLE); | 653 int64_t handle = entry->ref(META_HANDLE); |
| 651 ModelType server_type = GetModelTypeFromSpecifics( | 654 ModelType server_type = GetModelTypeFromSpecifics( |
| 652 entry->ref(SERVER_SPECIFICS)); | 655 entry->ref(SERVER_SPECIFICS)); |
| 653 | 656 |
| 654 // Clear enough so that on the next sync cycle all local data will | 657 // Clear enough so that on the next sync cycle all local data will |
| 655 // be overwritten. | 658 // be overwritten. |
| 656 // Note: do not modify the root node in order to preserve the | 659 // Note: do not modify the root node in order to preserve the |
| 657 // initial sync ended bit for this type (else on the next restart | 660 // initial sync ended bit for this type (else on the next restart |
| 658 // this type will be treated as disabled and therefore fully purged). | 661 // this type will be treated as disabled and therefore fully purged). |
| 659 if (entry->ref(PARENT_ID).IsRoot()) { | 662 if (entry->ref(PARENT_ID).IsRoot()) { |
| 660 ModelType root_type = server_type; | 663 ModelType root_type = server_type; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 699 // At this point locally created items that aren't synced will become locally | 702 // At this point locally created items that aren't synced will become locally |
| 700 // deleted items, and purged on the next snapshot. All other items will match | 703 // deleted items, and purged on the next snapshot. All other items will match |
| 701 // the state they would have had if they were just created via a server | 704 // the state they would have had if they were just created via a server |
| 702 // update. See MutableEntry::MutableEntry(.., CreateNewUpdateItem, ..). | 705 // update. See MutableEntry::MutableEntry(.., CreateNewUpdateItem, ..). |
| 703 } | 706 } |
| 704 | 707 |
| 705 void Directory::DeleteEntry(const ScopedKernelLock& lock, | 708 void Directory::DeleteEntry(const ScopedKernelLock& lock, |
| 706 bool save_to_journal, | 709 bool save_to_journal, |
| 707 EntryKernel* entry, | 710 EntryKernel* entry, |
| 708 EntryKernelSet* entries_to_journal) { | 711 EntryKernelSet* entries_to_journal) { |
| 709 int64 handle = entry->ref(META_HANDLE); | 712 int64_t handle = entry->ref(META_HANDLE); |
| 710 ModelType server_type = GetModelTypeFromSpecifics( | 713 ModelType server_type = GetModelTypeFromSpecifics( |
| 711 entry->ref(SERVER_SPECIFICS)); | 714 entry->ref(SERVER_SPECIFICS)); |
| 712 | 715 |
| 713 kernel_->metahandles_to_purge.insert(handle); | 716 kernel_->metahandles_to_purge.insert(handle); |
| 714 | 717 |
| 715 size_t num_erased = 0; | 718 size_t num_erased = 0; |
| 716 num_erased = kernel_->metahandles_map.erase(entry->ref(META_HANDLE)); | 719 num_erased = kernel_->metahandles_map.erase(entry->ref(META_HANDLE)); |
| 717 DCHECK_EQ(1u, num_erased); | 720 DCHECK_EQ(1u, num_erased); |
| 718 num_erased = kernel_->ids_map.erase(entry->ref(ID).value()); | 721 num_erased = kernel_->ids_map.erase(entry->ref(ID).value()); |
| 719 DCHECK_EQ(1u, num_erased); | 722 DCHECK_EQ(1u, num_erased); |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 939 ScopedKernelLock lock(this); | 942 ScopedKernelLock lock(this); |
| 940 kernel_->persisted_info.download_progress[model_type].CopyFrom(new_progress); | 943 kernel_->persisted_info.download_progress[model_type].CopyFrom(new_progress); |
| 941 kernel_->info_status = KERNEL_SHARE_INFO_DIRTY; | 944 kernel_->info_status = KERNEL_SHARE_INFO_DIRTY; |
| 942 } | 945 } |
| 943 | 946 |
| 944 bool Directory::HasEmptyDownloadProgress(ModelType type) const { | 947 bool Directory::HasEmptyDownloadProgress(ModelType type) const { |
| 945 ScopedKernelLock lock(this); | 948 ScopedKernelLock lock(this); |
| 946 return kernel_->persisted_info.HasEmptyDownloadProgress(type); | 949 return kernel_->persisted_info.HasEmptyDownloadProgress(type); |
| 947 } | 950 } |
| 948 | 951 |
| 949 int64 Directory::GetTransactionVersion(ModelType type) const { | 952 int64_t Directory::GetTransactionVersion(ModelType type) const { |
| 950 kernel_->transaction_mutex.AssertAcquired(); | 953 kernel_->transaction_mutex.AssertAcquired(); |
| 951 return kernel_->persisted_info.transaction_version[type]; | 954 return kernel_->persisted_info.transaction_version[type]; |
| 952 } | 955 } |
| 953 | 956 |
| 954 void Directory::IncrementTransactionVersion(ModelType type) { | 957 void Directory::IncrementTransactionVersion(ModelType type) { |
| 955 kernel_->transaction_mutex.AssertAcquired(); | 958 kernel_->transaction_mutex.AssertAcquired(); |
| 956 kernel_->persisted_info.transaction_version[type]++; | 959 kernel_->persisted_info.transaction_version[type]++; |
| 957 kernel_->info_status = KERNEL_SHARE_INFO_DIRTY; | 960 kernel_->info_status = KERNEL_SHARE_INFO_DIRTY; |
| 958 } | 961 } |
| 959 | 962 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1078 } | 1081 } |
| 1079 | 1082 |
| 1080 void Directory::GetUnsyncedMetaHandles(BaseTransaction* trans, | 1083 void Directory::GetUnsyncedMetaHandles(BaseTransaction* trans, |
| 1081 Metahandles* result) { | 1084 Metahandles* result) { |
| 1082 result->clear(); | 1085 result->clear(); |
| 1083 ScopedKernelLock lock(this); | 1086 ScopedKernelLock lock(this); |
| 1084 copy(kernel_->unsynced_metahandles.begin(), | 1087 copy(kernel_->unsynced_metahandles.begin(), |
| 1085 kernel_->unsynced_metahandles.end(), back_inserter(*result)); | 1088 kernel_->unsynced_metahandles.end(), back_inserter(*result)); |
| 1086 } | 1089 } |
| 1087 | 1090 |
| 1088 int64 Directory::unsynced_entity_count() const { | 1091 int64_t Directory::unsynced_entity_count() const { |
| 1089 ScopedKernelLock lock(this); | 1092 ScopedKernelLock lock(this); |
| 1090 return kernel_->unsynced_metahandles.size(); | 1093 return kernel_->unsynced_metahandles.size(); |
| 1091 } | 1094 } |
| 1092 | 1095 |
| 1093 bool Directory::TypeHasUnappliedUpdates(ModelType type) { | 1096 bool Directory::TypeHasUnappliedUpdates(ModelType type) { |
| 1094 ScopedKernelLock lock(this); | 1097 ScopedKernelLock lock(this); |
| 1095 return !kernel_->unapplied_update_metahandles[type].empty(); | 1098 return !kernel_->unapplied_update_metahandles[type].empty(); |
| 1096 } | 1099 } |
| 1097 | 1100 |
| 1098 void Directory::GetUnappliedUpdateMetaHandles( | 1101 void Directory::GetUnappliedUpdateMetaHandles(BaseTransaction* trans, |
| 1099 BaseTransaction* trans, | 1102 FullModelTypeSet server_types, |
| 1100 FullModelTypeSet server_types, | 1103 std::vector<int64_t>* result) { |
| 1101 std::vector<int64>* result) { | |
| 1102 result->clear(); | 1104 result->clear(); |
| 1103 ScopedKernelLock lock(this); | 1105 ScopedKernelLock lock(this); |
| 1104 for (int i = UNSPECIFIED; i < MODEL_TYPE_COUNT; ++i) { | 1106 for (int i = UNSPECIFIED; i < MODEL_TYPE_COUNT; ++i) { |
| 1105 const ModelType type = ModelTypeFromInt(i); | 1107 const ModelType type = ModelTypeFromInt(i); |
| 1106 if (server_types.Has(type)) { | 1108 if (server_types.Has(type)) { |
| 1107 std::copy(kernel_->unapplied_update_metahandles[type].begin(), | 1109 std::copy(kernel_->unapplied_update_metahandles[type].begin(), |
| 1108 kernel_->unapplied_update_metahandles[type].end(), | 1110 kernel_->unapplied_update_metahandles[type].end(), |
| 1109 back_inserter(*result)); | 1111 back_inserter(*result)); |
| 1110 } | 1112 } |
| 1111 } | 1113 } |
| 1112 } | 1114 } |
| 1113 | 1115 |
| 1114 void Directory::GetMetaHandlesOfType(BaseTransaction* trans, | 1116 void Directory::GetMetaHandlesOfType(BaseTransaction* trans, |
| 1115 ModelType type, | 1117 ModelType type, |
| 1116 std::vector<int64>* result) { | 1118 std::vector<int64_t>* result) { |
| 1117 ScopedKernelLock lock(this); | 1119 ScopedKernelLock lock(this); |
| 1118 GetMetaHandlesOfType(lock, trans, type, result); | 1120 GetMetaHandlesOfType(lock, trans, type, result); |
| 1119 } | 1121 } |
| 1120 | 1122 |
| 1121 void Directory::GetMetaHandlesOfType(const ScopedKernelLock& lock, | 1123 void Directory::GetMetaHandlesOfType(const ScopedKernelLock& lock, |
| 1122 BaseTransaction* trans, | 1124 BaseTransaction* trans, |
| 1123 ModelType type, | 1125 ModelType type, |
| 1124 std::vector<int64>* result) { | 1126 std::vector<int64_t>* result) { |
| 1125 result->clear(); | 1127 result->clear(); |
| 1126 for (MetahandlesMap::iterator it = kernel_->metahandles_map.begin(); | 1128 for (MetahandlesMap::iterator it = kernel_->metahandles_map.begin(); |
| 1127 it != kernel_->metahandles_map.end(); ++it) { | 1129 it != kernel_->metahandles_map.end(); ++it) { |
| 1128 EntryKernel* entry = it->second; | 1130 EntryKernel* entry = it->second; |
| 1129 const ModelType entry_type = | 1131 const ModelType entry_type = |
| 1130 GetModelTypeFromSpecifics(entry->ref(SPECIFICS)); | 1132 GetModelTypeFromSpecifics(entry->ref(SPECIFICS)); |
| 1131 if (entry_type == type) | 1133 if (entry_type == type) |
| 1132 result->push_back(it->first); | 1134 result->push_back(it->first); |
| 1133 } | 1135 } |
| 1134 } | 1136 } |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1203 bool Directory::FullyCheckTreeInvariants(syncable::BaseTransaction* trans) { | 1205 bool Directory::FullyCheckTreeInvariants(syncable::BaseTransaction* trans) { |
| 1204 MetahandleSet handles; | 1206 MetahandleSet handles; |
| 1205 GetAllMetaHandles(trans, &handles); | 1207 GetAllMetaHandles(trans, &handles); |
| 1206 return CheckTreeInvariants(trans, handles); | 1208 return CheckTreeInvariants(trans, handles); |
| 1207 } | 1209 } |
| 1208 | 1210 |
| 1209 bool Directory::CheckTreeInvariants(syncable::BaseTransaction* trans, | 1211 bool Directory::CheckTreeInvariants(syncable::BaseTransaction* trans, |
| 1210 const MetahandleSet& handles) { | 1212 const MetahandleSet& handles) { |
| 1211 MetahandleSet::const_iterator i; | 1213 MetahandleSet::const_iterator i; |
| 1212 for (i = handles.begin() ; i != handles.end() ; ++i) { | 1214 for (i = handles.begin() ; i != handles.end() ; ++i) { |
| 1213 int64 metahandle = *i; | 1215 int64_t metahandle = *i; |
| 1214 Entry e(trans, GET_BY_HANDLE, metahandle); | 1216 Entry e(trans, GET_BY_HANDLE, metahandle); |
| 1215 if (!SyncAssert(e.good(), FROM_HERE, "Entry is bad", trans)) | 1217 if (!SyncAssert(e.good(), FROM_HERE, "Entry is bad", trans)) |
| 1216 return false; | 1218 return false; |
| 1217 syncable::Id id = e.GetId(); | 1219 syncable::Id id = e.GetId(); |
| 1218 syncable::Id parentid = e.GetParentId(); | 1220 syncable::Id parentid = e.GetParentId(); |
| 1219 | 1221 |
| 1220 if (id.IsRoot()) { | 1222 if (id.IsRoot()) { |
| 1221 if (!SyncAssert(e.GetIsDir(), FROM_HERE, | 1223 if (!SyncAssert(e.GetIsDir(), FROM_HERE, |
| 1222 "Entry should be a directory", | 1224 "Entry should be a directory", |
| 1223 trans)) | 1225 trans)) |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1261 if (!SyncAssert(handles.end() != handles.find(parent.GetMetahandle()), | 1263 if (!SyncAssert(handles.end() != handles.find(parent.GetMetahandle()), |
| 1262 FROM_HERE, "Parent should be in the index.", trans)) | 1264 FROM_HERE, "Parent should be in the index.", trans)) |
| 1263 return false; | 1265 return false; |
| 1264 parentid = parent.GetParentId(); | 1266 parentid = parent.GetParentId(); |
| 1265 if (!SyncAssert(--safety_count > 0, FROM_HERE, | 1267 if (!SyncAssert(--safety_count > 0, FROM_HERE, |
| 1266 "Count should be greater than zero.", trans)) | 1268 "Count should be greater than zero.", trans)) |
| 1267 return false; | 1269 return false; |
| 1268 } | 1270 } |
| 1269 } | 1271 } |
| 1270 } | 1272 } |
| 1271 int64 base_version = e.GetBaseVersion(); | 1273 int64_t base_version = e.GetBaseVersion(); |
| 1272 int64 server_version = e.GetServerVersion(); | 1274 int64_t server_version = e.GetServerVersion(); |
| 1273 bool using_unique_client_tag = !e.GetUniqueClientTag().empty(); | 1275 bool using_unique_client_tag = !e.GetUniqueClientTag().empty(); |
| 1274 if (CHANGES_VERSION == base_version || 0 == base_version) { | 1276 if (CHANGES_VERSION == base_version || 0 == base_version) { |
| 1275 ModelType model_type = e.GetModelType(); | 1277 ModelType model_type = e.GetModelType(); |
| 1276 bool is_client_creatable_type_root_folder = | 1278 bool is_client_creatable_type_root_folder = |
| 1277 parentid.IsRoot() && | 1279 parentid.IsRoot() && |
| 1278 IsTypeWithClientGeneratedRoot(model_type) && | 1280 IsTypeWithClientGeneratedRoot(model_type) && |
| 1279 e.GetUniqueServerTag() == ModelTypeToRootTag(model_type); | 1281 e.GetUniqueServerTag() == ModelTypeToRootTag(model_type); |
| 1280 if (e.GetIsUnappliedUpdate()) { | 1282 if (e.GetIsUnappliedUpdate()) { |
| 1281 // Must be a new item, or a de-duplicated unique client tag | 1283 // Must be a new item, or a de-duplicated unique client tag |
| 1282 // that was created both locally and remotely, or a type root folder | 1284 // that was created both locally and remotely, or a type root folder |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1354 // This is not always true in the case that an item is deleted while the | 1356 // This is not always true in the case that an item is deleted while the |
| 1355 // initial commit is in flight. See crbug.com/426865. | 1357 // initial commit is in flight. See crbug.com/426865. |
| 1356 } | 1358 } |
| 1357 return true; | 1359 return true; |
| 1358 } | 1360 } |
| 1359 | 1361 |
| 1360 void Directory::SetInvariantCheckLevel(InvariantCheckLevel check_level) { | 1362 void Directory::SetInvariantCheckLevel(InvariantCheckLevel check_level) { |
| 1361 invariant_check_level_ = check_level; | 1363 invariant_check_level_ = check_level; |
| 1362 } | 1364 } |
| 1363 | 1365 |
| 1364 int64 Directory::NextMetahandle() { | 1366 int64_t Directory::NextMetahandle() { |
| 1365 ScopedKernelLock lock(this); | 1367 ScopedKernelLock lock(this); |
| 1366 int64 metahandle = (kernel_->next_metahandle)++; | 1368 int64_t metahandle = (kernel_->next_metahandle)++; |
| 1367 return metahandle; | 1369 return metahandle; |
| 1368 } | 1370 } |
| 1369 | 1371 |
| 1370 // Generates next client ID based on a randomly generated GUID. | 1372 // Generates next client ID based on a randomly generated GUID. |
| 1371 Id Directory::NextId() { | 1373 Id Directory::NextId() { |
| 1372 return Id::CreateFromClientString(base::GenerateGUID()); | 1374 return Id::CreateFromClientString(base::GenerateGUID()); |
| 1373 } | 1375 } |
| 1374 | 1376 |
| 1375 bool Directory::HasChildren(BaseTransaction* trans, const Id& id) { | 1377 bool Directory::HasChildren(BaseTransaction* trans, const Id& id) { |
| 1376 ScopedKernelLock lock(this); | 1378 ScopedKernelLock lock(this); |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1535 ModelType type, | 1537 ModelType type, |
| 1536 AttachmentIdList* ids) { | 1538 AttachmentIdList* ids) { |
| 1537 // TODO(maniscalco): Maintain an index by ModelType and rewrite this method to | 1539 // TODO(maniscalco): Maintain an index by ModelType and rewrite this method to |
| 1538 // use it. The approach below is likely very expensive because it iterates | 1540 // use it. The approach below is likely very expensive because it iterates |
| 1539 // all entries (bug 415199). | 1541 // all entries (bug 415199). |
| 1540 DCHECK(trans); | 1542 DCHECK(trans); |
| 1541 DCHECK(ids); | 1543 DCHECK(ids); |
| 1542 ids->clear(); | 1544 ids->clear(); |
| 1543 AttachmentIdSet on_server_id_set; | 1545 AttachmentIdSet on_server_id_set; |
| 1544 AttachmentIdSet not_on_server_id_set; | 1546 AttachmentIdSet not_on_server_id_set; |
| 1545 std::vector<int64> metahandles; | 1547 std::vector<int64_t> metahandles; |
| 1546 { | 1548 { |
| 1547 ScopedKernelLock lock(this); | 1549 ScopedKernelLock lock(this); |
| 1548 GetMetaHandlesOfType(lock, trans, type, &metahandles); | 1550 GetMetaHandlesOfType(lock, trans, type, &metahandles); |
| 1549 std::vector<int64>::const_iterator iter = metahandles.begin(); | 1551 std::vector<int64_t>::const_iterator iter = metahandles.begin(); |
| 1550 const std::vector<int64>::const_iterator end = metahandles.end(); | 1552 const std::vector<int64_t>::const_iterator end = metahandles.end(); |
| 1551 // For all of this type's entries... | 1553 // For all of this type's entries... |
| 1552 for (; iter != end; ++iter) { | 1554 for (; iter != end; ++iter) { |
| 1553 EntryKernel* entry = GetEntryByHandle(lock, *iter); | 1555 EntryKernel* entry = GetEntryByHandle(lock, *iter); |
| 1554 DCHECK(entry); | 1556 DCHECK(entry); |
| 1555 const sync_pb::AttachmentMetadata metadata = | 1557 const sync_pb::AttachmentMetadata metadata = |
| 1556 entry->ref(ATTACHMENT_METADATA); | 1558 entry->ref(ATTACHMENT_METADATA); |
| 1557 // for each of this entry's attachments... | 1559 // for each of this entry's attachments... |
| 1558 for (int i = 0; i < metadata.record_size(); ++i) { | 1560 for (int i = 0; i < metadata.record_size(); ++i) { |
| 1559 AttachmentId id = | 1561 AttachmentId id = |
| 1560 AttachmentId::CreateFromProto(metadata.record(i).id()); | 1562 AttachmentId::CreateFromProto(metadata.record(i).id()); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1593 Directory::Kernel* Directory::kernel() { | 1595 Directory::Kernel* Directory::kernel() { |
| 1594 return kernel_; | 1596 return kernel_; |
| 1595 } | 1597 } |
| 1596 | 1598 |
| 1597 const Directory::Kernel* Directory::kernel() const { | 1599 const Directory::Kernel* Directory::kernel() const { |
| 1598 return kernel_; | 1600 return kernel_; |
| 1599 } | 1601 } |
| 1600 | 1602 |
| 1601 } // namespace syncable | 1603 } // namespace syncable |
| 1602 } // namespace syncer | 1604 } // namespace syncer |
| OLD | NEW |