Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Unified Diff: components/sync/syncable/directory.cc

Issue 2287783002: Remove stl_util's STLValueDeleter. (Closed)
Patch Set: fix Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/sync/syncable/directory.cc
diff --git a/components/sync/syncable/directory.cc b/components/sync/syncable/directory.cc
index 1ed94cad1f5ea9d04384a634e733515044fedc1f..2828f15ebfee17c3a4d791ca466d20cce49a72e7 100644
--- a/components/sync/syncable/directory.cc
+++ b/components/sync/syncable/directory.cc
@@ -13,6 +13,7 @@
#include "base/base64.h"
#include "base/guid.h"
+#include "base/memory/ptr_util.h"
#include "base/metrics/histogram.h"
#include "base/stl_util.h"
#include "base/strings/string_number_conversions.h"
@@ -103,8 +104,7 @@ Directory::Kernel::Kernel(
}
Directory::Kernel::~Kernel() {
- base::STLDeleteContainerPairSecondPointers(metahandles_map.begin(),
- metahandles_map.end());
+ 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.
}
Directory::Directory(
@@ -143,9 +143,9 @@ DirOpenResult Directory::Open(
void Directory::InitializeIndices(MetahandlesMap* handles_map) {
ScopedKernelLock lock(this);
kernel_->metahandles_map.swap(*handles_map);
- for (MetahandlesMap::const_iterator it = kernel_->metahandles_map.begin();
+ for (auto it = kernel_->metahandles_map.begin();
it != kernel_->metahandles_map.end(); ++it) {
- EntryKernel* entry = it->second;
+ EntryKernel* entry = it->second.get();
if (ParentChildIndex::ShouldInclude(entry))
kernel_->parent_child_index.Insert(entry);
const int64_t metahandle = entry->ref(META_HANDLE);
@@ -185,10 +185,6 @@ DirOpenResult Directory::OpenImpl(
// swap these later.
Directory::MetahandlesMap tmp_handles_map;
- // Avoids mem leaks on failure. Harmlessly deletes the empty hash map after
- // the swap in the success case.
- base::STLValueDeleter<MetahandlesMap> deleter(&tmp_handles_map);
-
JournalIndex delete_journals;
MetahandleSet metahandles_to_purge;
@@ -287,7 +283,7 @@ EntryKernel* Directory::GetEntryByHandle(const ScopedKernelLock& lock,
MetahandlesMap::iterator found = kernel_->metahandles_map.find(metahandle);
if (found != kernel_->metahandles_map.end()) {
// Found it in memory. Easy.
- return found->second;
+ return found->second.get();
}
return NULL;
}
@@ -367,7 +363,8 @@ bool Directory::InsertEntry(const ScopedKernelLock& lock,
static const char error[] = "Entry already in memory index.";
if (!SyncAssert(kernel_->metahandles_map
- .insert(std::make_pair(entry->ref(META_HANDLE), entry))
+ .insert(std::make_pair(entry->ref(META_HANDLE),
+ base::WrapUnique(entry)))
.second,
FROM_HERE, error, trans)) {
return false;
@@ -599,10 +596,12 @@ bool Directory::VacuumAfterSaveChanges(const SaveChangesSnapshot& snapshot) {
MetahandlesMap::iterator found =
kernel_->metahandles_map.find((*i)->ref(META_HANDLE));
EntryKernel* entry =
- (found == kernel_->metahandles_map.end() ? NULL : found->second);
+ (found == kernel_->metahandles_map.end() ? NULL : found->second.get());
if (entry && SafeToPurgeFromMemory(&trans, entry)) {
// We now drop deleted metahandles that are up to date on both the client
// and the server.
+ std::unique_ptr<EntryKernel> unique_entry = std::move(found->second);
+
size_t num_erased = 0;
num_erased = kernel_->metahandles_map.erase(entry->ref(META_HANDLE));
DCHECK_EQ(1u, num_erased);
@@ -623,8 +622,6 @@ bool Directory::VacuumAfterSaveChanges(const SaveChangesSnapshot& snapshot) {
return false;
RemoveFromAttachmentIndex(lock, entry->ref(META_HANDLE),
entry->ref(ATTACHMENT_METADATA));
-
- delete entry;
}
if (trans.unrecoverable_error_set())
return false;
@@ -698,8 +695,11 @@ void Directory::DeleteEntry(const ScopedKernelLock& lock,
kernel_->metahandles_to_purge.insert(handle);
+ std::unique_ptr<EntryKernel> entry_ptr =
+ std::move(kernel_->metahandles_map[handle]);
+
size_t num_erased = 0;
- num_erased = kernel_->metahandles_map.erase(entry->ref(META_HANDLE));
+ num_erased = kernel_->metahandles_map.erase(handle);
DCHECK_EQ(1u, num_erased);
num_erased = kernel_->ids_map.erase(entry->ref(ID).value());
DCHECK_EQ(1u, num_erased);
@@ -721,9 +721,7 @@ void Directory::DeleteEntry(const ScopedKernelLock& lock,
RemoveFromAttachmentIndex(lock, handle, entry->ref(ATTACHMENT_METADATA));
if (save_to_journal) {
- entries_to_journal->insert(entry);
- } else {
- delete entry;
+ entries_to_journal->insert(entry_ptr.release());
}
}
@@ -759,7 +757,7 @@ bool Directory::PurgeEntriesWithTypeIn(ModelTypeSet disabled_types,
for (MetahandlesMap::iterator it = kernel_->metahandles_map.begin();
it != kernel_->metahandles_map.end();) {
- EntryKernel* entry = it->second;
+ EntryKernel* entry = it->second.get();
const sync_pb::EntitySpecifics& local_specifics = entry->ref(SPECIFICS);
const sync_pb::EntitySpecifics& server_specifics =
entry->ref(SERVER_SPECIFICS);
@@ -1088,7 +1086,7 @@ void Directory::GetMetaHandlesOfType(const ScopedKernelLock& lock,
result->clear();
for (MetahandlesMap::iterator it = kernel_->metahandles_map.begin();
it != kernel_->metahandles_map.end(); ++it) {
- EntryKernel* entry = it->second;
+ EntryKernel* entry = it->second.get();
const ModelType entry_type =
GetModelTypeFromSpecifics(entry->ref(SPECIFICS));
if (entry_type == type)
@@ -1104,7 +1102,7 @@ void Directory::CollectMetaHandleCounts(
for (MetahandlesMap::iterator it = kernel_->metahandles_map.begin();
it != kernel_->metahandles_map.end(); ++it) {
- EntryKernel* entry = it->second;
+ EntryKernel* entry = it->second.get();
const ModelType type = GetModelTypeFromSpecifics(entry->ref(SPECIFICS));
(*num_entries_by_type)[type]++;
if (entry->ref(IS_DEL))
@@ -1124,7 +1122,7 @@ std::unique_ptr<base::ListValue> Directory::GetNodeDetailsForType(
continue;
}
- EntryKernel* kernel = it->second;
+ EntryKernel* kernel = it->second.get();
std::unique_ptr<base::DictionaryValue> node(
kernel->ToValue(GetCryptographer(trans)));

Powered by Google App Engine
This is Rietveld 408576698