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

Unified Diff: net/disk_cache/simple/simple_synchronous_entry.cc

Issue 14295013: Simple Cache: DoomEntriesBetween() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: first round of comments Created 7 years, 8 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: net/disk_cache/simple/simple_synchronous_entry.cc
diff --git a/net/disk_cache/simple/simple_synchronous_entry.cc b/net/disk_cache/simple/simple_synchronous_entry.cc
index 509755a0508ad76243c2a29f3e37576c53ac19ef..a4768c2f695426bc187f5cda6fcd4048bf414c16 100644
--- a/net/disk_cache/simple/simple_synchronous_entry.cc
+++ b/net/disk_cache/simple/simple_synchronous_entry.cc
@@ -40,6 +40,9 @@ using base::WritePlatformFile;
namespace disk_cache {
+using simple_util::ConvertEntryHashKeyToHexString;
+using simple_util::GetEntryHashKeyAsHexString;
+using simple_util::GetFilenameFromHexStringAndIndex;
using simple_util::GetFilenameFromKeyAndIndex;
using simple_util::GetDataSizeFromKeyAndFileSize;
using simple_util::GetFileSizeFromKeyAndDataSize;
@@ -82,18 +85,46 @@ void SimpleSynchronousEntry::CreateEntry(
}
// static
+bool SimpleSynchronousEntry::DeleteFilesForEntry(const FilePath& path,
+ const std::string& hash_key) {
+ bool result = true;
+ for (int i = 0; i < kSimpleEntryFileCount; ++i) {
+ FilePath to_delete = path.AppendASCII(
+ GetFilenameFromHexStringAndIndex(hash_key, i));
+ if (!file_util::Delete(to_delete, false)) {
+ result = false;
+ DLOG(ERROR) << "Could not delete " << to_delete.MaybeAsASCII();
+ }
+ }
+ return result;
+}
+
+// static
void SimpleSynchronousEntry::DoomEntry(
const FilePath& path,
const std::string& key,
const scoped_refptr<TaskRunner>& callback_runner,
const net::CompletionCallback& callback) {
- for (int i = 0; i < kSimpleEntryFileCount; ++i) {
- FilePath to_delete = path.AppendASCII(GetFilenameFromKeyAndIndex(key, i));
- bool ALLOW_UNUSED result = file_util::Delete(to_delete, false);
- DLOG_IF(ERROR, !result) << "Could not delete " << to_delete.MaybeAsASCII();
- }
+ bool deleted_well = DeleteFilesForEntry(path,
+ GetEntryHashKeyAsHexString(key));
+ int result = deleted_well ? net::OK : net::ERR_FAILED;
+ callback_runner->PostTask(FROM_HERE, base::Bind(callback, result));
+}
+
+// static
+void SimpleSynchronousEntry::DoomEntrySet(
+ scoped_ptr<std::set<uint64> > key_hashes,
+ const FilePath& path,
+ scoped_refptr<TaskRunner> callback_runner,
+ const net::CompletionCallback& callback) {
+ bool deleted_well = true;
+ for (std::set<uint64>::const_iterator it = key_hashes->begin(),
+ end = key_hashes->end(); it != end; ++it)
+ deleted_well &= DeleteFilesForEntry(path,
+ ConvertEntryHashKeyToHexString((*it)));
+ int result = deleted_well ? net::OK : net::ERR_FAILED;
if (!callback.is_null())
- callback_runner->PostTask(FROM_HERE, base::Bind(callback, net::OK));
+ callback_runner->PostTask(FROM_HERE, base::Bind(callback, result));
}
void SimpleSynchronousEntry::Close() {
@@ -301,8 +332,7 @@ int SimpleSynchronousEntry::InitializeForCreate() {
void SimpleSynchronousEntry::Doom() {
// TODO(gavinp): Consider if we should guard against redundant Doom() calls.
- DoomEntry(path_, key_,
- scoped_refptr<base::TaskRunner>(), net::CompletionCallback());
+ DeleteFilesForEntry(path_, GetEntryHashKeyAsHexString(key_));
}
} // namespace disk_cache

Powered by Google App Engine
This is Rietveld 408576698