| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/sync/syncable/syncable.h" | 5 #include "chrome/browser/sync/syncable/syncable.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cstring> | 8 #include <cstring> |
| 9 #include <functional> | 9 #include <functional> |
| 10 #include <iomanip> | 10 #include <iomanip> |
| (...skipping 801 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 812 | 812 |
| 813 // Might not be in it | 813 // Might not be in it |
| 814 num_erased = kernel_->client_tag_index->erase(entry); | 814 num_erased = kernel_->client_tag_index->erase(entry); |
| 815 DCHECK_EQ(entry->ref(UNIQUE_CLIENT_TAG).empty(), !num_erased); | 815 DCHECK_EQ(entry->ref(UNIQUE_CLIENT_TAG).empty(), !num_erased); |
| 816 CHECK(!kernel_->parent_id_child_index->count(entry)); | 816 CHECK(!kernel_->parent_id_child_index->count(entry)); |
| 817 delete entry; | 817 delete entry; |
| 818 } | 818 } |
| 819 } | 819 } |
| 820 } | 820 } |
| 821 | 821 |
| 822 void Directory::PurgeEntriesWithTypeIn(ModelEnumSet types) { | 822 void Directory::PurgeEntriesWithTypeIn(ModelTypeSet types) { |
| 823 if (types.Empty()) | 823 if (types.Empty()) |
| 824 return; | 824 return; |
| 825 | 825 |
| 826 { | 826 { |
| 827 WriteTransaction trans(FROM_HERE, PURGE_ENTRIES, this); | 827 WriteTransaction trans(FROM_HERE, PURGE_ENTRIES, this); |
| 828 { | 828 { |
| 829 ScopedKernelLock lock(this); | 829 ScopedKernelLock lock(this); |
| 830 MetahandlesIndex::iterator it = kernel_->metahandles_index->begin(); | 830 MetahandlesIndex::iterator it = kernel_->metahandles_index->begin(); |
| 831 while (it != kernel_->metahandles_index->end()) { | 831 while (it != kernel_->metahandles_index->end()) { |
| 832 const sync_pb::EntitySpecifics& local_specifics = (*it)->ref(SPECIFICS); | 832 const sync_pb::EntitySpecifics& local_specifics = (*it)->ref(SPECIFICS); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 856 num_erased = kernel_->parent_id_child_index->erase(entry); | 856 num_erased = kernel_->parent_id_child_index->erase(entry); |
| 857 DCHECK_EQ(entry->ref(IS_DEL), !num_erased); | 857 DCHECK_EQ(entry->ref(IS_DEL), !num_erased); |
| 858 kernel_->metahandles_index->erase(it++); | 858 kernel_->metahandles_index->erase(it++); |
| 859 delete entry; | 859 delete entry; |
| 860 } else { | 860 } else { |
| 861 ++it; | 861 ++it; |
| 862 } | 862 } |
| 863 } | 863 } |
| 864 | 864 |
| 865 // Ensure meta tracking for these data types reflects the deleted state. | 865 // Ensure meta tracking for these data types reflects the deleted state. |
| 866 for (syncable::ModelEnumSet::Iterator it = types.First(); | 866 for (syncable::ModelTypeSet::Iterator it = types.First(); |
| 867 it.Good(); it.Inc()) { | 867 it.Good(); it.Inc()) { |
| 868 set_initial_sync_ended_for_type_unsafe(it.Get(), false); | 868 set_initial_sync_ended_for_type_unsafe(it.Get(), false); |
| 869 kernel_->persisted_info.reset_download_progress(it.Get()); | 869 kernel_->persisted_info.reset_download_progress(it.Get()); |
| 870 } | 870 } |
| 871 } | 871 } |
| 872 } | 872 } |
| 873 } | 873 } |
| 874 | 874 |
| 875 void Directory::HandleSaveChangesFailure(const SaveChangesSnapshot& snapshot) { | 875 void Directory::HandleSaveChangesFailure(const SaveChangesSnapshot& snapshot) { |
| 876 ScopedKernelLock lock(this); | 876 ScopedKernelLock lock(this); |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1018 ScopedKernelLock lock(this); | 1018 ScopedKernelLock lock(this); |
| 1019 copy(kernel_->unsynced_metahandles->begin(), | 1019 copy(kernel_->unsynced_metahandles->begin(), |
| 1020 kernel_->unsynced_metahandles->end(), back_inserter(*result)); | 1020 kernel_->unsynced_metahandles->end(), back_inserter(*result)); |
| 1021 } | 1021 } |
| 1022 | 1022 |
| 1023 int64 Directory::unsynced_entity_count() const { | 1023 int64 Directory::unsynced_entity_count() const { |
| 1024 ScopedKernelLock lock(this); | 1024 ScopedKernelLock lock(this); |
| 1025 return kernel_->unsynced_metahandles->size(); | 1025 return kernel_->unsynced_metahandles->size(); |
| 1026 } | 1026 } |
| 1027 | 1027 |
| 1028 FullModelEnumSet Directory::GetServerTypesWithUnappliedUpdates( | 1028 FullModelTypeSet Directory::GetServerTypesWithUnappliedUpdates( |
| 1029 BaseTransaction* trans) const { | 1029 BaseTransaction* trans) const { |
| 1030 syncable::FullModelEnumSet server_types; | 1030 syncable::FullModelTypeSet server_types; |
| 1031 ScopedKernelLock lock(this); | 1031 ScopedKernelLock lock(this); |
| 1032 for (int i = UNSPECIFIED; i < MODEL_TYPE_COUNT; ++i) { | 1032 for (int i = UNSPECIFIED; i < MODEL_TYPE_COUNT; ++i) { |
| 1033 const ModelType type = ModelTypeFromInt(i); | 1033 const ModelType type = ModelTypeFromInt(i); |
| 1034 if (!kernel_->unapplied_update_metahandles[type].empty()) { | 1034 if (!kernel_->unapplied_update_metahandles[type].empty()) { |
| 1035 server_types.Put(type); | 1035 server_types.Put(type); |
| 1036 } | 1036 } |
| 1037 } | 1037 } |
| 1038 return server_types; | 1038 return server_types; |
| 1039 } | 1039 } |
| 1040 | 1040 |
| 1041 void Directory::GetUnappliedUpdateMetaHandles( | 1041 void Directory::GetUnappliedUpdateMetaHandles( |
| 1042 BaseTransaction* trans, | 1042 BaseTransaction* trans, |
| 1043 FullModelEnumSet server_types, | 1043 FullModelTypeSet server_types, |
| 1044 UnappliedUpdateMetaHandles* result) { | 1044 UnappliedUpdateMetaHandles* result) { |
| 1045 result->clear(); | 1045 result->clear(); |
| 1046 ScopedKernelLock lock(this); | 1046 ScopedKernelLock lock(this); |
| 1047 for (int i = UNSPECIFIED; i < MODEL_TYPE_COUNT; ++i) { | 1047 for (int i = UNSPECIFIED; i < MODEL_TYPE_COUNT; ++i) { |
| 1048 const ModelType type = ModelTypeFromInt(i); | 1048 const ModelType type = ModelTypeFromInt(i); |
| 1049 if (server_types.Has(type)) { | 1049 if (server_types.Has(type)) { |
| 1050 std::copy(kernel_->unapplied_update_metahandles[type].begin(), | 1050 std::copy(kernel_->unapplied_update_metahandles[type].begin(), |
| 1051 kernel_->unapplied_update_metahandles[type].end(), | 1051 kernel_->unapplied_update_metahandles[type].end(), |
| 1052 back_inserter(*result)); | 1052 back_inserter(*result)); |
| 1053 } | 1053 } |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1301 // Not actually mutated, so erase from |mutations_|. | 1301 // Not actually mutated, so erase from |mutations_|. |
| 1302 mutations_.erase(it++); | 1302 mutations_.erase(it++); |
| 1303 } | 1303 } |
| 1304 } | 1304 } |
| 1305 return ImmutableEntryKernelMutationMap(&mutations_); | 1305 return ImmutableEntryKernelMutationMap(&mutations_); |
| 1306 } | 1306 } |
| 1307 | 1307 |
| 1308 void WriteTransaction::UnlockAndNotify( | 1308 void WriteTransaction::UnlockAndNotify( |
| 1309 const ImmutableEntryKernelMutationMap& mutations) { | 1309 const ImmutableEntryKernelMutationMap& mutations) { |
| 1310 // Work while transaction mutex is held. | 1310 // Work while transaction mutex is held. |
| 1311 ModelEnumSet models_with_changes; | 1311 ModelTypeSet models_with_changes; |
| 1312 bool has_mutations = !mutations.Get().empty(); | 1312 bool has_mutations = !mutations.Get().empty(); |
| 1313 if (has_mutations) { | 1313 if (has_mutations) { |
| 1314 models_with_changes = NotifyTransactionChangingAndEnding(mutations); | 1314 models_with_changes = NotifyTransactionChangingAndEnding(mutations); |
| 1315 } | 1315 } |
| 1316 Unlock(); | 1316 Unlock(); |
| 1317 | 1317 |
| 1318 // Work after mutex is relased. | 1318 // Work after mutex is relased. |
| 1319 if (has_mutations) { | 1319 if (has_mutations) { |
| 1320 NotifyTransactionComplete(models_with_changes); | 1320 NotifyTransactionComplete(models_with_changes); |
| 1321 } | 1321 } |
| 1322 } | 1322 } |
| 1323 | 1323 |
| 1324 ModelEnumSet WriteTransaction::NotifyTransactionChangingAndEnding( | 1324 ModelTypeSet WriteTransaction::NotifyTransactionChangingAndEnding( |
| 1325 const ImmutableEntryKernelMutationMap& mutations) { | 1325 const ImmutableEntryKernelMutationMap& mutations) { |
| 1326 dirkernel_->transaction_mutex.AssertAcquired(); | 1326 dirkernel_->transaction_mutex.AssertAcquired(); |
| 1327 DCHECK(!mutations.Get().empty()); | 1327 DCHECK(!mutations.Get().empty()); |
| 1328 | 1328 |
| 1329 WriteTransactionInfo write_transaction_info( | 1329 WriteTransactionInfo write_transaction_info( |
| 1330 dirkernel_->next_write_transaction_id, from_here_, writer_, mutations); | 1330 dirkernel_->next_write_transaction_id, from_here_, writer_, mutations); |
| 1331 ++dirkernel_->next_write_transaction_id; | 1331 ++dirkernel_->next_write_transaction_id; |
| 1332 | 1332 |
| 1333 ImmutableWriteTransactionInfo immutable_write_transaction_info( | 1333 ImmutableWriteTransactionInfo immutable_write_transaction_info( |
| 1334 &write_transaction_info); | 1334 &write_transaction_info); |
| 1335 DirectoryChangeDelegate* const delegate = dirkernel_->delegate; | 1335 DirectoryChangeDelegate* const delegate = dirkernel_->delegate; |
| 1336 if (writer_ == syncable::SYNCAPI) { | 1336 if (writer_ == syncable::SYNCAPI) { |
| 1337 delegate->HandleCalculateChangesChangeEventFromSyncApi( | 1337 delegate->HandleCalculateChangesChangeEventFromSyncApi( |
| 1338 immutable_write_transaction_info, this); | 1338 immutable_write_transaction_info, this); |
| 1339 } else { | 1339 } else { |
| 1340 delegate->HandleCalculateChangesChangeEventFromSyncer( | 1340 delegate->HandleCalculateChangesChangeEventFromSyncer( |
| 1341 immutable_write_transaction_info, this); | 1341 immutable_write_transaction_info, this); |
| 1342 } | 1342 } |
| 1343 | 1343 |
| 1344 ModelEnumSet models_with_changes = | 1344 ModelTypeSet models_with_changes = |
| 1345 delegate->HandleTransactionEndingChangeEvent( | 1345 delegate->HandleTransactionEndingChangeEvent( |
| 1346 immutable_write_transaction_info, this); | 1346 immutable_write_transaction_info, this); |
| 1347 | 1347 |
| 1348 dirkernel_->transaction_observer.Call(FROM_HERE, | 1348 dirkernel_->transaction_observer.Call(FROM_HERE, |
| 1349 &TransactionObserver::OnTransactionWrite, | 1349 &TransactionObserver::OnTransactionWrite, |
| 1350 immutable_write_transaction_info, models_with_changes); | 1350 immutable_write_transaction_info, models_with_changes); |
| 1351 | 1351 |
| 1352 return models_with_changes; | 1352 return models_with_changes; |
| 1353 } | 1353 } |
| 1354 | 1354 |
| 1355 void WriteTransaction::NotifyTransactionComplete( | 1355 void WriteTransaction::NotifyTransactionComplete( |
| 1356 ModelEnumSet models_with_changes) { | 1356 ModelTypeSet models_with_changes) { |
| 1357 dirkernel_->delegate->HandleTransactionCompleteChangeEvent( | 1357 dirkernel_->delegate->HandleTransactionCompleteChangeEvent( |
| 1358 models_with_changes); | 1358 models_with_changes); |
| 1359 } | 1359 } |
| 1360 | 1360 |
| 1361 WriteTransaction::~WriteTransaction() { | 1361 WriteTransaction::~WriteTransaction() { |
| 1362 const ImmutableEntryKernelMutationMap& mutations = RecordMutations(); | 1362 const ImmutableEntryKernelMutationMap& mutations = RecordMutations(); |
| 1363 | 1363 |
| 1364 if (OFF != kInvariantCheckLevel) { | 1364 if (OFF != kInvariantCheckLevel) { |
| 1365 const bool full_scan = (FULL_DB_VERIFICATION == kInvariantCheckLevel); | 1365 const bool full_scan = (FULL_DB_VERIFICATION == kInvariantCheckLevel); |
| 1366 if (full_scan) | 1366 if (full_scan) |
| (...skipping 745 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2112 if (entry->ref(NEXT_ID).IsRoot() || | 2112 if (entry->ref(NEXT_ID).IsRoot() || |
| 2113 entry->ref(NEXT_ID) != entry->ref(PREV_ID)) { | 2113 entry->ref(NEXT_ID) != entry->ref(PREV_ID)) { |
| 2114 return entry; | 2114 return entry; |
| 2115 } | 2115 } |
| 2116 } | 2116 } |
| 2117 // There were no children in the linked list. | 2117 // There were no children in the linked list. |
| 2118 return NULL; | 2118 return NULL; |
| 2119 } | 2119 } |
| 2120 | 2120 |
| 2121 } // namespace syncable | 2121 } // namespace syncable |
| OLD | NEW |