diff options
author | dmikurube@chromium.org <dmikurube@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-27 11:41:39 +0000 |
---|---|---|
committer | dmikurube@chromium.org <dmikurube@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-27 11:41:39 +0000 |
commit | 4b943590b09443cc7c1ca4d801745419472e4b07 (patch) | |
tree | 3622228281babf4ead999feacfcc5597c0e6650f /webkit/fileapi | |
parent | b3bcb8f6338da8a8deeea9f349205d81a5bc8ef3 (diff) | |
download | chromium_src-4b943590b09443cc7c1ca4d801745419472e4b07.zip chromium_src-4b943590b09443cc7c1ca4d801745419472e4b07.tar.gz chromium_src-4b943590b09443cc7c1ca4d801745419472e4b07.tar.bz2 |
Modify FileSystemUsageCache::GetUsage to get the size even if dirty > 0, and add GetDirty.
BUG=74841
TEST=FileSystemUsageCacheTest.*
Review URL: http://codereview.chromium.org/6904044
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@83141 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/fileapi')
-rw-r--r-- | webkit/fileapi/file_system_usage_cache.cc | 14 | ||||
-rw-r--r-- | webkit/fileapi/file_system_usage_cache.h | 8 | ||||
-rw-r--r-- | webkit/fileapi/file_system_usage_cache_unittest.cc | 9 | ||||
-rw-r--r-- | webkit/fileapi/file_system_usage_tracker.cc | 5 |
4 files changed, 28 insertions, 8 deletions
diff --git a/webkit/fileapi/file_system_usage_cache.cc b/webkit/fileapi/file_system_usage_cache.cc index 4155d45..0445e72 100644 --- a/webkit/fileapi/file_system_usage_cache.cc +++ b/webkit/fileapi/file_system_usage_cache.cc @@ -24,13 +24,25 @@ int64 FileSystemUsageCache::GetUsage(const FilePath& usage_file_path) { int64 fs_usage; fs_usage = Read(usage_file_path, &dirty); - if (fs_usage < 0 || dirty > 0) + if (fs_usage < 0) return -1; return fs_usage; } // static +int32 FileSystemUsageCache::GetDirty(const FilePath& usage_file_path) { + uint32 dirty = 0; + int64 fs_usage; + fs_usage = Read(usage_file_path, &dirty); + + if (fs_usage < 0) + return -1; + + return static_cast<int32>(dirty); +} + +// static bool FileSystemUsageCache::IncrementDirty(const FilePath& usage_file_path) { uint32 dirty = 0; int64 fs_usage; diff --git a/webkit/fileapi/file_system_usage_cache.h b/webkit/fileapi/file_system_usage_cache.h index 84b2341..7c38bfb 100644 --- a/webkit/fileapi/file_system_usage_cache.h +++ b/webkit/fileapi/file_system_usage_cache.h @@ -12,10 +12,14 @@ namespace fileapi { class FileSystemUsageCache { public: - // Gets the size described in the .usage file. - // Returns less than zero if the size is not availble. + // Gets the size described in the .usage file even if dirty > 0. + // Returns less than zero if the .usage file is not available. static int64 GetUsage(const FilePath& usage_file_path); + // Gets the dirty count in the .usage file. + // Returns less than zero if the .usage file is not available. + static int32 GetDirty(const FilePath& usage_file_path); + // Increments or decrements the "dirty" entry in the .usage file. // Returns false if no .usage is available. static bool IncrementDirty(const FilePath& usage_file_path); diff --git a/webkit/fileapi/file_system_usage_cache_unittest.cc b/webkit/fileapi/file_system_usage_cache_unittest.cc index f73e5f9..35dadac 100644 --- a/webkit/fileapi/file_system_usage_cache_unittest.cc +++ b/webkit/fileapi/file_system_usage_cache_unittest.cc @@ -57,7 +57,8 @@ TEST_F(FileSystemUsageCacheTest, IncAndGetSizeTest) { ASSERT_EQ(FileSystemUsageCache::kUsageFileSize, FileSystemUsageCache::UpdateUsage(usage_file_path, 98214)); ASSERT_TRUE(FileSystemUsageCache::IncrementDirty(usage_file_path)); - EXPECT_EQ(-1, FileSystemUsageCache::GetUsage(usage_file_path)); + EXPECT_EQ(1, FileSystemUsageCache::GetDirty(usage_file_path)); + EXPECT_EQ(98214, FileSystemUsageCache::GetUsage(usage_file_path)); } TEST_F(FileSystemUsageCacheTest, DecAndGetSizeTest) { @@ -89,7 +90,8 @@ TEST_F(FileSystemUsageCacheTest, DecIncAndGetSizeTest) { ASSERT_TRUE(FileSystemUsageCache::IncrementDirty(usage_file_path)); // It tests DecrementDirty (which returns false) has no effect, i.e // does not make dirty = -1 after DecrementDirty. - EXPECT_EQ(-1, FileSystemUsageCache::GetUsage(usage_file_path)); + EXPECT_EQ(1, FileSystemUsageCache::GetDirty(usage_file_path)); + EXPECT_EQ(854238, FileSystemUsageCache::GetUsage(usage_file_path)); } TEST_F(FileSystemUsageCacheTest, ManyIncsSameDecsAndGetSizeTest) { @@ -112,7 +114,8 @@ TEST_F(FileSystemUsageCacheTest, ManyIncsLessDecsAndGetSizeTest) { ASSERT_TRUE(FileSystemUsageCache::IncrementDirty(usage_file_path)); for (int i = 0; i < 19; i++) ASSERT_TRUE(FileSystemUsageCache::DecrementDirty(usage_file_path)); - EXPECT_EQ(-1, FileSystemUsageCache::GetUsage(usage_file_path)); + EXPECT_EQ(1, FileSystemUsageCache::GetDirty(usage_file_path)); + EXPECT_EQ(19319, FileSystemUsageCache::GetUsage(usage_file_path)); } TEST_F(FileSystemUsageCacheTest, GetSizeWithoutCacheFileTest) { diff --git a/webkit/fileapi/file_system_usage_tracker.cc b/webkit/fileapi/file_system_usage_tracker.cc index 85943a5..687884f 100644 --- a/webkit/fileapi/file_system_usage_tracker.cc +++ b/webkit/fileapi/file_system_usage_tracker.cc @@ -59,9 +59,8 @@ class FileSystemUsageTracker::GetUsageTask else { FilePath usage_file_path = origin_base_path_.AppendASCII( FileSystemUsageCache::kUsageFileName); - fs_usage_ = FileSystemUsageCache::GetUsage(usage_file_path); - if (fs_usage_ < 0) { + if (FileSystemUsageCache::GetDirty(usage_file_path) != 0) { FilePath content_file_path = origin_base_path_; if (FileSystemUsageCache::Exists(usage_file_path)) FileSystemUsageCache::Delete(usage_file_path); @@ -70,6 +69,8 @@ class FileSystemUsageTracker::GetUsageTask // The result of ComputeDirectorySize does not include it. fs_usage_ += FileSystemUsageCache::kUsageFileSize; FileSystemUsageCache::UpdateUsage(usage_file_path, fs_usage_); + } else { + fs_usage_ = FileSystemUsageCache::GetUsage(usage_file_path); } } |