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

Unified Diff: webkit/fileapi/file_system_usage_cache.cc

Issue 7608018: Handle inconsistency between DB and Files (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed regression Created 9 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
« no previous file with comments | « webkit/fileapi/file_system_usage_cache.h ('k') | webkit/fileapi/obfuscated_file_system_file_util.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/fileapi/file_system_usage_cache.cc
diff --git a/webkit/fileapi/file_system_usage_cache.cc b/webkit/fileapi/file_system_usage_cache.cc
index 6fa788e8fbcc5e6f931c3d28dfb965d1b71ae467..4ac3a1b098a2f97445db294ee5a02a4e7a96e7e8 100644
--- a/webkit/fileapi/file_system_usage_cache.cc
+++ b/webkit/fileapi/file_system_usage_cache.cc
@@ -11,18 +11,21 @@
namespace fileapi {
const char FileSystemUsageCache::kUsageFileName[] = ".usage";
-const char FileSystemUsageCache::kUsageFileHeader[] = "FSU3";
+const char FileSystemUsageCache::kUsageFileHeader[] = "FSU4";
const int FileSystemUsageCache::kUsageFileHeaderSize = 4;
+
+/* Pickle::{Read,Write}Bool treat bool as int */
const int FileSystemUsageCache::kUsageFileSize =
sizeof(Pickle::Header) +
FileSystemUsageCache::kUsageFileHeaderSize +
- sizeof(int32) + sizeof(int64);
+ sizeof(int) + sizeof(int32) + sizeof(int64);
// static
int64 FileSystemUsageCache::GetUsage(const FilePath& usage_file_path) {
+ bool is_valid = true;
uint32 dirty = 0;
int64 fs_usage;
- fs_usage = Read(usage_file_path, &dirty);
+ fs_usage = Read(usage_file_path, &is_valid, &dirty);
if (fs_usage < 0)
return -1;
@@ -32,9 +35,10 @@ int64 FileSystemUsageCache::GetUsage(const FilePath& usage_file_path) {
// static
int32 FileSystemUsageCache::GetDirty(const FilePath& usage_file_path) {
+ bool is_valid = true;
uint32 dirty = 0;
int64 fs_usage;
- fs_usage = Read(usage_file_path, &dirty);
+ fs_usage = Read(usage_file_path, &is_valid, &dirty);
if (fs_usage < 0)
return -1;
@@ -44,46 +48,67 @@ int32 FileSystemUsageCache::GetDirty(const FilePath& usage_file_path) {
// static
bool FileSystemUsageCache::IncrementDirty(const FilePath& usage_file_path) {
+ bool is_valid = true;
uint32 dirty = 0;
int64 fs_usage;
- fs_usage = Read(usage_file_path, &dirty);
+ fs_usage = Read(usage_file_path, &is_valid, &dirty);
if (fs_usage < 0)
return false;
- return Write(usage_file_path, dirty + 1, fs_usage) >= 0;
+ return Write(usage_file_path, is_valid, dirty + 1, fs_usage) >= 0;
}
// static
bool FileSystemUsageCache::DecrementDirty(const FilePath& usage_file_path) {
+ bool is_valid = true;
uint32 dirty = 0;
int64 fs_usage;
- fs_usage = Read(usage_file_path, &dirty);
+ fs_usage = Read(usage_file_path, &is_valid, &dirty);
if (fs_usage < 0 || dirty <= 0)
return false;
- return Write(usage_file_path, dirty - 1, fs_usage) >= 0;
+ return Write(usage_file_path, is_valid, dirty - 1, fs_usage) >= 0;
+}
+
+// static
+bool FileSystemUsageCache::Invalidate(const FilePath& usage_file_path) {
+ bool is_valid = true;
+ uint32 dirty = 0;
+ int64 fs_usage;
+ fs_usage = Read(usage_file_path, &is_valid, &dirty);
+
+ return fs_usage >= 0 && Write(usage_file_path, false, dirty, fs_usage);
+}
+
+bool FileSystemUsageCache::IsValid(const FilePath& usage_file_path) {
+ bool is_valid = true;
+ uint32 dirty = 0;
+ int64 fs_usage;
+ fs_usage = Read(usage_file_path, &is_valid, &dirty);
+ return is_valid;
}
// static
int FileSystemUsageCache::AtomicUpdateUsageByDelta(
const FilePath& usage_file_path, int64 delta) {
+ bool is_valid = true;
uint32 dirty = 0;
int64 fs_usage;
// TODO(dmikurube): Make sure that usage_file_path is available.
- fs_usage = Read(usage_file_path, &dirty);
+ fs_usage = Read(usage_file_path, &is_valid, &dirty);
if (fs_usage < 0)
return -1;
- return Write(usage_file_path, dirty, fs_usage + delta);
+ return Write(usage_file_path, is_valid, dirty, fs_usage + delta);
}
// static
int FileSystemUsageCache::UpdateUsage(const FilePath& usage_file_path,
int64 fs_usage) {
- return Write(usage_file_path, 0, fs_usage);
+ return Write(usage_file_path, true, 0, fs_usage);
}
// static
@@ -98,6 +123,7 @@ bool FileSystemUsageCache::Delete(const FilePath& usage_file_path) {
// static
int64 FileSystemUsageCache::Read(const FilePath& usage_file_path,
+ bool* is_valid,
uint32* dirty) {
char buffer[kUsageFileSize];
const char *header;
@@ -110,6 +136,7 @@ int64 FileSystemUsageCache::Read(const FilePath& usage_file_path,
int64 fs_usage;
if (!read_pickle.ReadBytes(&iter, &header, kUsageFileHeaderSize) ||
+ !read_pickle.ReadBool(&iter, is_valid) ||
!read_pickle.ReadUInt32(&iter, dirty) ||
!read_pickle.ReadInt64(&iter, &fs_usage))
return -1;
@@ -125,9 +152,12 @@ int64 FileSystemUsageCache::Read(const FilePath& usage_file_path,
// static
int FileSystemUsageCache::Write(const FilePath& usage_file_path,
- uint32 dirty, int64 fs_usage) {
+ bool is_valid,
+ uint32 dirty,
+ int64 fs_usage) {
Pickle write_pickle;
write_pickle.WriteBytes(kUsageFileHeader, kUsageFileHeaderSize);
+ write_pickle.WriteBool(is_valid);
write_pickle.WriteUInt32(dirty);
write_pickle.WriteInt64(fs_usage);
« no previous file with comments | « webkit/fileapi/file_system_usage_cache.h ('k') | webkit/fileapi/obfuscated_file_system_file_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698