summaryrefslogtreecommitdiffstats
path: root/webkit/fileapi/quota_file_util.cc
diff options
context:
space:
mode:
authordmikurube@google.com <dmikurube@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-26 12:21:51 +0000
committerdmikurube@google.com <dmikurube@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-26 12:21:51 +0000
commit3a7f439361a10ba1e8a001b6ecbe36c81836cf55 (patch)
tree9b335dd6f82df60a4c5081ccc6e1da866e2b826b /webkit/fileapi/quota_file_util.cc
parentd04ebe5ddba584e5302507ebd7caee9669188009 (diff)
downloadchromium_src-3a7f439361a10ba1e8a001b6ecbe36c81836cf55.zip
chromium_src-3a7f439361a10ba1e8a001b6ecbe36c81836cf55.tar.gz
chromium_src-3a7f439361a10ba1e8a001b6ecbe36c81836cf55.tar.bz2
Update .usage in QuotaFileUtil and FileWriterDelegate.
BUG=74841 TEST=QuotaFileUtilTest.*,FileWriterDelegateTest.*,FileSystemOperationWriteTest.* git-svn-id: svn://svn.chromium.org/chrome/trunk/src@83006 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/fileapi/quota_file_util.cc')
-rw-r--r--webkit/fileapi/quota_file_util.cc90
1 files changed, 82 insertions, 8 deletions
diff --git a/webkit/fileapi/quota_file_util.cc b/webkit/fileapi/quota_file_util.cc
index 3a78e62..820b6a8 100644
--- a/webkit/fileapi/quota_file_util.cc
+++ b/webkit/fileapi/quota_file_util.cc
@@ -6,6 +6,10 @@
#include "base/file_util.h"
#include "base/logging.h"
+#include "webkit/fileapi/file_system_context.h"
+#include "webkit/fileapi/file_system_operation_context.h"
+#include "webkit/fileapi/file_system_path_manager.h"
+#include "webkit/fileapi/file_system_usage_cache.h"
namespace fileapi {
@@ -37,6 +41,28 @@ static bool CanCopy(
return true;
}
+static FilePath InitUsageFile(FileSystemOperationContext* fs_context) {
+ FilePath base_path = fs_context->file_system_context()->path_manager()->
+ ValidateFileSystemRootAndGetPathOnFileThread(fs_context->src_origin_url(),
+ fs_context->src_type(), FilePath(), false);
+ FilePath usage_file_path =
+ base_path.AppendASCII(FileSystemUsageCache::kUsageFileName);
+
+ if (FileSystemUsageCache::Exists(usage_file_path))
+ FileSystemUsageCache::IncrementDirty(usage_file_path);
+
+ return usage_file_path;
+}
+
+static void UpdateUsageFile(const FilePath& usage_file_path, int64 growth) {
+ if (FileSystemUsageCache::Exists(usage_file_path))
+ FileSystemUsageCache::DecrementDirty(usage_file_path);
+
+ int64 usage = FileSystemUsageCache::GetUsage(usage_file_path);
+ if (usage >= 0)
+ FileSystemUsageCache::UpdateUsage(usage_file_path, usage + growth);
+}
+
} // namespace (anonymous)
// static
@@ -49,16 +75,52 @@ base::PlatformFileError QuotaFileUtil::CopyOrMoveFile(
const FilePath& src_file_path,
const FilePath& dest_file_path,
bool copy) {
+ FilePath usage_file_path = InitUsageFile(fs_context);
+
+ int64 growth = 0;
+
// It assumes copy/move operations are always in the same fs currently.
// TODO(dmikurube): Do quota check if moving between different fs.
if (copy) {
int64 allowed_bytes_growth = fs_context->allowed_bytes_growth();
// The third argument (growth) is not used for now.
- if (!CanCopy(src_file_path, dest_file_path, allowed_bytes_growth, NULL))
+ if (!CanCopy(src_file_path, dest_file_path, allowed_bytes_growth,
+ &growth)) {
+ FileSystemUsageCache::DecrementDirty(usage_file_path);
return base::PLATFORM_FILE_ERROR_NO_SPACE;
+ }
+ } else {
+ base::PlatformFileInfo dest_file_info;
+ if (!file_util::GetFileInfo(dest_file_path, &dest_file_info))
+ dest_file_info.size = 0;
+ growth = -dest_file_info.size;
}
- return FileSystemFileUtil::GetInstance()->CopyOrMoveFile(fs_context,
- src_file_path, dest_file_path, copy);
+
+ base::PlatformFileError error = FileSystemFileUtil::GetInstance()->
+ CopyOrMoveFile(fs_context, src_file_path, dest_file_path, copy);
+
+ UpdateUsageFile(usage_file_path, growth);
+
+ return error;
+}
+
+base::PlatformFileError QuotaFileUtil::DeleteFile(
+ FileSystemOperationContext* fs_context,
+ const FilePath& file_path) {
+ FilePath usage_file_path = InitUsageFile(fs_context);
+
+ int64 growth = 0;
+ base::PlatformFileInfo file_info;
+ if (!file_util::GetFileInfo(file_path, &file_info))
+ file_info.size = 0;
+ growth = -file_info.size;
+
+ base::PlatformFileError error = FileSystemFileUtil::GetInstance()->
+ DeleteFile(fs_context, file_path);
+
+ UpdateUsageFile(usage_file_path, growth);
+
+ return error;
}
base::PlatformFileError QuotaFileUtil::Truncate(
@@ -66,17 +128,29 @@ base::PlatformFileError QuotaFileUtil::Truncate(
const FilePath& path,
int64 length) {
int64 allowed_bytes_growth = fs_context->allowed_bytes_growth();
+ FilePath usage_file_path = InitUsageFile(fs_context);
+
+ int64 growth = 0;
+ base::PlatformFileInfo file_info;
+ if (!file_util::GetFileInfo(path, &file_info)) {
+ FileSystemUsageCache::DecrementDirty(usage_file_path);
+ return base::PLATFORM_FILE_ERROR_FAILED;
+ }
+ growth = length - file_info.size;
if (allowed_bytes_growth != kNoLimit) {
- base::PlatformFileInfo file_info;
- if (!file_util::GetFileInfo(path, &file_info))
- return base::PLATFORM_FILE_ERROR_FAILED;
- if (length - file_info.size > allowed_bytes_growth)
+ if (growth > allowed_bytes_growth) {
+ FileSystemUsageCache::DecrementDirty(usage_file_path);
return base::PLATFORM_FILE_ERROR_NO_SPACE;
+ }
}
- return FileSystemFileUtil::GetInstance()->Truncate(
+ base::PlatformFileError error = FileSystemFileUtil::GetInstance()->Truncate(
fs_context, path, length);
+
+ UpdateUsageFile(usage_file_path, growth);
+
+ return error;
}
} // namespace fileapi