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

Unified Diff: storage/browser/fileapi/file_system_usage_cache.cc

Issue 2389583002: Remove stl_util's deletion functions from storage/. (Closed)
Patch Set: nits Created 4 years, 2 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
« no previous file with comments | « storage/browser/fileapi/file_system_usage_cache.h ('k') | storage/browser/quota/storage_monitor.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: storage/browser/fileapi/file_system_usage_cache.cc
diff --git a/storage/browser/fileapi/file_system_usage_cache.cc b/storage/browser/fileapi/file_system_usage_cache.cc
index 44d291fc60aa48378beb2df5eca427bc3c751a62..c96021e9fabfe1f6307ec2bff9b033473f2697f6 100644
--- a/storage/browser/fileapi/file_system_usage_cache.cc
+++ b/storage/browser/fileapi/file_system_usage_cache.cc
@@ -11,6 +11,7 @@
#include "base/bind.h"
#include "base/files/file_util.h"
+#include "base/memory/ptr_util.h"
#include "base/pickle.h"
#include "base/stl_util.h"
#include "base/trace_event/trace_event.h"
@@ -161,7 +162,7 @@ bool FileSystemUsageCache::Delete(const base::FilePath& usage_file_path) {
void FileSystemUsageCache::CloseCacheFiles() {
TRACE_EVENT0("FileSystem", "UsageCache::CloseCacheFiles");
DCHECK(CalledOnValidThread());
- base::STLDeleteValues(&cache_files_);
+ cache_files_.clear();
timer_.reset();
}
@@ -228,24 +229,22 @@ base::File* FileSystemUsageCache::GetFile(const base::FilePath& file_path) {
CloseCacheFiles();
ScheduleCloseTimer();
- base::File* new_file = NULL;
- std::pair<CacheFiles::iterator, bool> inserted =
- cache_files_.insert(std::make_pair(file_path, new_file));
- if (!inserted.second)
- return inserted.first->second;
-
- new_file = new base::File(file_path,
- base::File::FLAG_OPEN_ALWAYS |
- base::File::FLAG_READ |
- base::File::FLAG_WRITE);
- if (!new_file->IsValid()) {
- cache_files_.erase(inserted.first);
- delete new_file;
- return NULL;
+ auto& entry = cache_files_[file_path];
+ if (entry)
+ return entry.get();
+
+ // Because there are no null entries in cache_files_, the [] inserted a blank
+ // pointer, so let's populate the cache.
+ entry = base::MakeUnique<base::File>(file_path, base::File::FLAG_OPEN_ALWAYS |
+ base::File::FLAG_READ |
+ base::File::FLAG_WRITE);
+
+ if (!entry->IsValid()) {
+ cache_files_.erase(file_path);
+ return nullptr;
}
- inserted.first->second = new_file;
- return new_file;
+ return entry.get();
}
bool FileSystemUsageCache::ReadBytes(const base::FilePath& file_path,
« no previous file with comments | « storage/browser/fileapi/file_system_usage_cache.h ('k') | storage/browser/quota/storage_monitor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698