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

Unified Diff: webkit/fileapi/quota_file_util.cc

Issue 7608011: Simplify directory path accounting. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rolled in CR feedback. 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/quota_file_util.h ('k') | webkit/fileapi/quota_file_util_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/fileapi/quota_file_util.cc
diff --git a/webkit/fileapi/quota_file_util.cc b/webkit/fileapi/quota_file_util.cc
index 56fbcb7a033a36033272be0f926f39e295b4af04..f894cbb94d4c5281791c8c72da2f267b93db6aaa 100644
--- a/webkit/fileapi/quota_file_util.cc
+++ b/webkit/fileapi/quota_file_util.cc
@@ -18,12 +18,32 @@ namespace fileapi {
const int64 QuotaFileUtil::kNoLimit = kint64max;
-// See the comment in the header file as for these constants.
-const int64 QuotaFileUtil::kFilePathCostPerChar = 2;
-const int64 QuotaFileUtil::kFilePathCostPerFile = 146;
-
namespace {
+// Checks if copying in the same filesystem can be performed.
+// This method is not called for moving within a single filesystem.
+bool CanCopy(
+ const FilePath& src_file_path,
+ const FilePath& dest_file_path,
+ int64 allowed_bytes_growth,
+ int64* growth) {
+ base::PlatformFileInfo src_file_info;
+ if (!file_util::GetFileInfo(src_file_path, &src_file_info)) {
+ // Falling through to the actual copy/move operation.
+ return true;
+ }
+ base::PlatformFileInfo dest_file_info;
+ if (!file_util::GetFileInfo(dest_file_path, &dest_file_info))
+ dest_file_info.size = 0;
+ if (allowed_bytes_growth != QuotaFileUtil::kNoLimit &&
+ src_file_info.size - dest_file_info.size > allowed_bytes_growth)
+ return false;
+ if (growth != NULL)
+ *growth = src_file_info.size - dest_file_info.size;
+
+ return true;
+}
+
// A helper class to hook quota_util() methods before and after modifications.
class ScopedOriginUpdateHelper {
public:
@@ -51,9 +71,8 @@ class ScopedOriginUpdateHelper {
}
void NotifyUpdate(int64 growth) {
- if (operation_context_->allowed_bytes_growth() != QuotaFileUtil::kNoLimit)
- operation_context_->set_allowed_bytes_growth(
- operation_context_->allowed_bytes_growth() - growth);
+ operation_context_->set_allowed_bytes_growth(
+ operation_context_->allowed_bytes_growth() - growth);
if (quota_util_)
quota_util_->UpdateOriginUsageOnFileThread(
quota_manager_proxy_, origin_url_, type_, growth);
@@ -82,124 +101,6 @@ QuotaFileUtil* QuotaFileUtil::CreateDefault() {
return new QuotaFileUtil(new FileSystemFileUtil());
}
-int64 QuotaFileUtil::ComputeFilePathCost(const FilePath& file_path) const {
- return kFilePathCostPerFile +
- file_path.BaseName().value().length() * kFilePathCostPerChar;
-}
-
-PlatformFileError QuotaFileUtil::CreateOrOpen(
- FileSystemOperationContext* fs_context,
- const FilePath& file_path, int file_flags,
- PlatformFile* file_handle, bool* created) {
- DCHECK(fs_context);
- scoped_ptr<ScopedOriginUpdateHelper> helper;
-
- int64 allowed_bytes_growth = fs_context->allowed_bytes_growth();
- int64 growth = 0;
-
- if (!file_util::PathExists(file_path))
- growth = ComputeFilePathCost(fs_context->src_virtual_path());
-
- if (growth > 0) {
- helper.reset(new ScopedOriginUpdateHelper(
- fs_context,
- fs_context->src_origin_url(),
- fs_context->src_type()));
-
- if (allowed_bytes_growth != kNoLimit && growth > allowed_bytes_growth)
- return base::PLATFORM_FILE_ERROR_NO_SPACE;
- }
-
- base::PlatformFileError error = underlying_file_util_->CreateOrOpen(
- fs_context, file_path, file_flags, file_handle, created);
-
- if (growth > 0) {
- if (error == base::PLATFORM_FILE_OK)
- helper->NotifyUpdate(growth);
- }
-
- return error;
-}
-
-PlatformFileError QuotaFileUtil::EnsureFileExists(
- FileSystemOperationContext* fs_context,
- const FilePath& file_path,
- bool* created) {
- DCHECK(fs_context);
- scoped_ptr<ScopedOriginUpdateHelper> helper;
-
- int64 allowed_bytes_growth = fs_context->allowed_bytes_growth();
- int64 growth = 0;
-
- if (!file_util::PathExists(file_path))
- growth = ComputeFilePathCost(fs_context->src_virtual_path());
-
- if (growth > 0) {
- helper.reset(new ScopedOriginUpdateHelper(
- fs_context,
- fs_context->src_origin_url(),
- fs_context->src_type()));
-
- if (allowed_bytes_growth != kNoLimit && growth > allowed_bytes_growth)
- return base::PLATFORM_FILE_ERROR_NO_SPACE;
- }
-
- base::PlatformFileError error = underlying_file_util_->EnsureFileExists(
- fs_context, file_path, created);
-
- if (growth > 0 &&error == base::PLATFORM_FILE_OK)
- helper->NotifyUpdate(growth);
-
- return error;
-}
-
-PlatformFileError QuotaFileUtil::CreateDirectory(
- FileSystemOperationContext* fs_context,
- const FilePath& file_path,
- bool exclusive,
- bool recursive) {
- DCHECK(fs_context);
- scoped_ptr<ScopedOriginUpdateHelper> helper;
-
- int64 allowed_bytes_growth = fs_context->allowed_bytes_growth();
- int64 growth = 0;
-
- if (!exclusive || !file_util::PathExists(file_path)) {
- if (recursive) {
- FilePath last_path;
- for (FilePath path = fs_context->src_virtual_path();
- path.value() != last_path.value() &&
- !fs_context->src_file_system_file_util()->PathExists(
- fs_context, fs_context->src_virtual_path());
- path = path.DirName()) {
- growth += ComputeFilePathCost(fs_context->src_virtual_path());
- last_path = path;
- }
- } else {
- growth += ComputeFilePathCost(fs_context->src_virtual_path());
- }
- }
-
- if (growth > 0) {
- helper.reset(new ScopedOriginUpdateHelper(
- fs_context,
- fs_context->src_origin_url(),
- fs_context->src_type()));
-
- if (allowed_bytes_growth != kNoLimit && growth > allowed_bytes_growth)
- return base::PLATFORM_FILE_ERROR_NO_SPACE;
- }
-
- base::PlatformFileError error = base::PLATFORM_FILE_OK;
- error = underlying_file_util_->CreateDirectory(
- fs_context, file_path, exclusive, recursive);
-
- if (growth > 0 && error == base::PLATFORM_FILE_OK)
- helper->NotifyUpdate(growth);
-
- return error;
-}
-
base::PlatformFileError QuotaFileUtil::CopyOrMoveFile(
FileSystemOperationContext* fs_context,
const FilePath& src_file_path,
@@ -221,21 +122,13 @@ base::PlatformFileError QuotaFileUtil::CopyOrMoveFile(
if (copy) {
int64 allowed_bytes_growth = fs_context->allowed_bytes_growth();
// The third argument (growth) is not used for now.
- if (!CanCopyFile(fs_context, src_file_path, dest_file_path,
- allowed_bytes_growth, &growth))
+ if (!CanCopy(src_file_path, dest_file_path, allowed_bytes_growth, &growth))
return base::PLATFORM_FILE_ERROR_NO_SPACE;
- } else { // move
- int64 allowed_bytes_growth = fs_context->allowed_bytes_growth();
+ } else {
base::PlatformFileInfo dest_file_info;
- int64 src_file_path_cost =
- ComputeFilePathCost(fs_context->src_virtual_path());
- int64 dest_file_path_cost =
- ComputeFilePathCost(fs_context->dest_virtual_path());
if (!file_util::GetFileInfo(dest_file_path, &dest_file_info))
dest_file_info.size = 0;
- growth = -dest_file_info.size - src_file_path_cost + dest_file_path_cost;
- if (allowed_bytes_growth != kNoLimit && growth > allowed_bytes_growth)
- return base::PLATFORM_FILE_ERROR_NO_SPACE;
+ growth = -dest_file_info.size;
}
base::PlatformFileError error = underlying_file_util_->CopyOrMoveFile(
@@ -261,10 +154,9 @@ base::PlatformFileError QuotaFileUtil::DeleteFile(
int64 growth = 0;
base::PlatformFileInfo file_info;
- if (file_util::GetFileInfo(file_path, &file_info)) {
- growth -= file_info.size +
- ComputeFilePathCost(fs_context->src_virtual_path());
- }
+ if (!file_util::GetFileInfo(file_path, &file_info))
+ file_info.size = 0;
+ growth = -file_info.size;
base::PlatformFileError error = underlying_file_util_->DeleteFile(
fs_context, file_path);
@@ -275,28 +167,6 @@ base::PlatformFileError QuotaFileUtil::DeleteFile(
return error;
}
-base::PlatformFileError QuotaFileUtil::DeleteSingleDirectory(
- FileSystemOperationContext* fs_context,
- const FilePath& file_path) {
- DCHECK(fs_context);
- ScopedOriginUpdateHelper helper(
- fs_context,
- fs_context->src_origin_url(),
- fs_context->src_type());
-
- int64 growth = 0;
- if (file_util::DirectoryExists(file_path))
- growth -= ComputeFilePathCost(fs_context->src_virtual_path());
-
- base::PlatformFileError error = underlying_file_util_->DeleteSingleDirectory(
- fs_context, file_path);
-
- if (error == base::PLATFORM_FILE_OK)
- helper.NotifyUpdate(growth);
-
- return error;
-}
-
base::PlatformFileError QuotaFileUtil::Truncate(
FileSystemOperationContext* fs_context,
const FilePath& path,
@@ -325,32 +195,4 @@ base::PlatformFileError QuotaFileUtil::Truncate(
return error;
}
-// Checks if copying in the same filesystem can be performed.
-// This method is not called for moving within a single filesystem.
-bool QuotaFileUtil::CanCopyFile(
- FileSystemOperationContext* fs_context,
- const FilePath& src_file_path,
- const FilePath& dest_file_path,
- int64 allowed_bytes_growth,
- int64* growth) const {
- DCHECK(growth);
- base::PlatformFileInfo src_file_info;
- if (!file_util::GetFileInfo(src_file_path, &src_file_info)) {
- // Falling through to the actual copy/move operation.
- return true;
- }
- base::PlatformFileInfo dest_file_info;
- int dest_file_path_cost = 0;
- if (!file_util::GetFileInfo(dest_file_path, &dest_file_info)) {
- dest_file_info.size = 0;
- dest_file_path_cost = ComputeFilePathCost(fs_context->dest_virtual_path());
- }
- *growth = src_file_info.size - dest_file_info.size + dest_file_path_cost;
- if (allowed_bytes_growth != QuotaFileUtil::kNoLimit &&
- *growth > allowed_bytes_growth)
- return false;
-
- return true;
-}
-
} // namespace fileapi
« no previous file with comments | « webkit/fileapi/quota_file_util.h ('k') | webkit/fileapi/quota_file_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698