Chromium Code Reviews| 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 697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 708 | 708 |
| 709 // Handle success or failure. | 709 // Handle success or failure. |
| 710 if (success) | 710 if (success) |
| 711 VacuumAfterSaveChanges(snapshot); | 711 VacuumAfterSaveChanges(snapshot); |
| 712 else | 712 else |
| 713 HandleSaveChangesFailure(snapshot); | 713 HandleSaveChangesFailure(snapshot); |
| 714 return success; | 714 return success; |
| 715 } | 715 } |
| 716 | 716 |
| 717 void Directory::VacuumAfterSaveChanges(const SaveChangesSnapshot& snapshot) { | 717 void Directory::VacuumAfterSaveChanges(const SaveChangesSnapshot& snapshot) { |
| 718 if (snapshot.dirty_metas.empty()) | |
| 719 return; | |
| 720 | |
| 718 // Need a write transaction as we are about to permanently purge entries. | 721 // Need a write transaction as we are about to permanently purge entries. |
| 719 WriteTransaction trans(FROM_HERE, VACUUM_AFTER_SAVE, this); | 722 WriteTransaction trans(FROM_HERE, VACUUM_AFTER_SAVE, this); |
| 720 ScopedKernelLock lock(this); | 723 ScopedKernelLock lock(this); |
| 721 kernel_->flushed_metahandles.Push(0); // Begin flush marker | |
| 722 // Now drop everything we can out of memory. | 724 // Now drop everything we can out of memory. |
| 723 for (EntryKernelSet::const_iterator i = snapshot.dirty_metas.begin(); | 725 for (EntryKernelSet::const_iterator i = snapshot.dirty_metas.begin(); |
| 724 i != snapshot.dirty_metas.end(); ++i) { | 726 i != snapshot.dirty_metas.end(); ++i) { |
| 725 kernel_->needle.put(META_HANDLE, i->ref(META_HANDLE)); | 727 kernel_->needle.put(META_HANDLE, i->ref(META_HANDLE)); |
| 726 MetahandlesIndex::iterator found = | 728 MetahandlesIndex::iterator found = |
| 727 kernel_->metahandles_index->find(&kernel_->needle); | 729 kernel_->metahandles_index->find(&kernel_->needle); |
| 728 EntryKernel* entry = (found == kernel_->metahandles_index->end() ? | 730 EntryKernel* entry = (found == kernel_->metahandles_index->end() ? |
| 729 NULL : *found); | 731 NULL : *found); |
| 730 if (entry && SafeToPurgeFromMemory(entry)) { | 732 if (entry && SafeToPurgeFromMemory(entry)) { |
| 731 // We now drop deleted metahandles that are up to date on both the client | 733 // We now drop deleted metahandles that are up to date on both the client |
| 732 // and the server. | 734 // and the server. |
| 733 size_t num_erased = 0; | 735 size_t num_erased = 0; |
| 734 int64 handle = entry->ref(META_HANDLE); | |
| 735 kernel_->flushed_metahandles.Push(handle); | |
| 736 num_erased = kernel_->ids_index->erase(entry); | 736 num_erased = kernel_->ids_index->erase(entry); |
| 737 DCHECK_EQ(1u, num_erased); | 737 DCHECK_EQ(1u, num_erased); |
| 738 num_erased = kernel_->metahandles_index->erase(entry); | 738 num_erased = kernel_->metahandles_index->erase(entry); |
| 739 DCHECK_EQ(1u, num_erased); | 739 DCHECK_EQ(1u, num_erased); |
| 740 | 740 |
| 741 // Might not be in it | 741 // Might not be in it |
| 742 num_erased = kernel_->client_tag_index->erase(entry); | 742 num_erased = kernel_->client_tag_index->erase(entry); |
| 743 DCHECK_EQ(entry->ref(UNIQUE_CLIENT_TAG).empty(), !num_erased); | 743 DCHECK_EQ(entry->ref(UNIQUE_CLIENT_TAG).empty(), !num_erased); |
| 744 CHECK(!kernel_->parent_id_child_index->count(entry)); | 744 CHECK(!kernel_->parent_id_child_index->count(entry)); |
| 745 delete entry; | 745 delete entry; |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1151 const char* name, | 1151 const char* name, |
| 1152 WriterTag writer, | 1152 WriterTag writer, |
| 1153 Directory* directory) | 1153 Directory* directory) |
| 1154 : from_here_(from_here), name_(name), writer_(writer), | 1154 : from_here_(from_here), name_(name), writer_(writer), |
| 1155 directory_(directory), dirkernel_(directory->kernel_) { | 1155 directory_(directory), dirkernel_(directory->kernel_) { |
| 1156 dirkernel_->observers->Notify( | 1156 dirkernel_->observers->Notify( |
| 1157 &TransactionObserver::OnTransactionStart, from_here_, writer_); | 1157 &TransactionObserver::OnTransactionStart, from_here_, writer_); |
| 1158 } | 1158 } |
| 1159 | 1159 |
| 1160 BaseTransaction::~BaseTransaction() { | 1160 BaseTransaction::~BaseTransaction() { |
| 1161 dirkernel_->observers->Notify( | 1161 if (writer_ != INVALID) { |
|
rlarocque
2011/11/15 01:08:56
What would happen if we removed this code altogeth
rlarocque
2011/11/15 01:23:06
Never mind, I see how it's used now. We use some
| |
| 1162 &TransactionObserver::OnTransactionEnd, from_here_, writer_); | 1162 dirkernel_->observers->Notify( |
| 1163 &TransactionObserver::OnTransactionEnd, from_here_, writer_); | |
| 1164 } | |
| 1163 } | 1165 } |
| 1164 | 1166 |
| 1165 ReadTransaction::ReadTransaction(const tracked_objects::Location& location, | 1167 ReadTransaction::ReadTransaction(const tracked_objects::Location& location, |
| 1166 Directory* directory) | 1168 Directory* directory) |
| 1167 : BaseTransaction(location, "Read", INVALID, directory) { | 1169 : BaseTransaction(location, "Read", INVALID, directory) { |
| 1168 Lock(); | 1170 Lock(); |
| 1169 } | 1171 } |
| 1170 | 1172 |
| 1171 ReadTransaction::ReadTransaction(const tracked_objects::Location& location, | 1173 ReadTransaction::ReadTransaction(const tracked_objects::Location& location, |
| 1172 const ScopedDirLookup& scoped_dir) | 1174 const ScopedDirLookup& scoped_dir) |
| (...skipping 846 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2019 if (entry->ref(NEXT_ID).IsRoot() || | 2021 if (entry->ref(NEXT_ID).IsRoot() || |
| 2020 entry->ref(NEXT_ID) != entry->ref(PREV_ID)) { | 2022 entry->ref(NEXT_ID) != entry->ref(PREV_ID)) { |
| 2021 return entry; | 2023 return entry; |
| 2022 } | 2024 } |
| 2023 } | 2025 } |
| 2024 // There were no children in the linked list. | 2026 // There were no children in the linked list. |
| 2025 return NULL; | 2027 return NULL; |
| 2026 } | 2028 } |
| 2027 | 2029 |
| 2028 } // namespace syncable | 2030 } // namespace syncable |
| OLD | NEW |