summaryrefslogtreecommitdiffstats
path: root/webkit/fileapi
diff options
context:
space:
mode:
authordmikurube@chromium.org <dmikurube@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-25 15:03:15 +0000
committerdmikurube@chromium.org <dmikurube@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-25 15:03:15 +0000
commitffac1ac44fd244d857620c9ca04e3a119af20084 (patch)
tree46fab447e7eb9ba76f67b2f42e93af860b7505c0 /webkit/fileapi
parent9a9359592a0895932fa423160283e91d34028a3d (diff)
downloadchromium_src-ffac1ac44fd244d857620c9ca04e3a119af20084.zip
chromium_src-ffac1ac44fd244d857620c9ca04e3a119af20084.tar.gz
chromium_src-ffac1ac44fd244d857620c9ca04e3a119af20084.tar.bz2
Change quota to account directories and path names in the filesystem.
BUG=89841 TEST=FileSystemQuotaClientTest.*,FileSystemQuotaTest.*,FileSystemObfuscatedQuotaTest.*,QuotaFileUtilTest.* Review URL: http://codereview.chromium.org/7347003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@93881 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/fileapi')
-rw-r--r--webkit/fileapi/file_system_file_util.cc89
-rw-r--r--webkit/fileapi/file_system_operation.cc75
-rw-r--r--webkit/fileapi/file_system_operation.h13
-rw-r--r--webkit/fileapi/file_system_operation_context.cc30
-rw-r--r--webkit/fileapi/file_system_operation_context.h20
-rw-r--r--webkit/fileapi/file_system_quota_client_unittest.cc111
-rw-r--r--webkit/fileapi/file_system_quota_unittest.cc185
-rw-r--r--webkit/fileapi/file_system_test_helper.cc4
-rw-r--r--webkit/fileapi/file_system_test_helper.h1
-rw-r--r--webkit/fileapi/local_file_system_file_util.cc1
-rw-r--r--webkit/fileapi/obfuscated_file_system_file_util.cc18
-rw-r--r--webkit/fileapi/quota_file_util.cc223
-rw-r--r--webkit/fileapi/quota_file_util.h55
-rw-r--r--webkit/fileapi/quota_file_util_unittest.cc465
-rw-r--r--webkit/fileapi/sandbox_mount_point_provider.cc5
-rw-r--r--webkit/fileapi/sandbox_mount_point_provider.h2
16 files changed, 894 insertions, 403 deletions
diff --git a/webkit/fileapi/file_system_file_util.cc b/webkit/fileapi/file_system_file_util.cc
index 13f2527..7765962 100644
--- a/webkit/fileapi/file_system_file_util.cc
+++ b/webkit/fileapi/file_system_file_util.cc
@@ -142,10 +142,13 @@ PlatformFileError FileSystemFileUtil::ReadDirectory(
}
PlatformFileError FileSystemFileUtil::CreateDirectory(
- FileSystemOperationContext* unused,
+ FileSystemOperationContext* fs_context,
const FilePath& file_path,
bool exclusive,
bool recursive) {
+ if (fs_context->do_not_write_actually())
+ return base::PLATFORM_FILE_OK;
+
// If parent dir of file doesn't exist.
if (!recursive && !file_util::PathExists(file_path.DirName()))
return base::PLATFORM_FILE_ERROR_NOT_FOUND;
@@ -256,30 +259,21 @@ FileSystemFileUtil::PerformCommonCheckAndPreparationForMoveAndCopy(
(context->src_type() == context->dest_type());
FileSystemFileUtil* dest_util = context->dest_file_system_file_util();
DCHECK(dest_util);
- FileSystemOperationContext local_dest_context(
- context->file_system_context(), dest_util);
- FileSystemOperationContext* dest_context;
- if (same_file_system) {
- dest_context = context;
+ if (same_file_system)
DCHECK(context->src_file_system_file_util() ==
context->dest_file_system_file_util());
- } else {
- // All the single-path virtual FSFU methods expect the context information
- // to be in the src_* variables, not the dest_* variables, so we have to
- // make a new context if we want to call them on the dest_file_path.
- dest_context = &local_dest_context;
- dest_context->set_src_type(context->dest_type());
- dest_context->set_src_origin_url(context->dest_origin_url());
- dest_context->set_src_virtual_path(context->dest_virtual_path());
- dest_context->set_allowed_bytes_growth(context->allowed_bytes_growth());
- }
+ // All the single-path virtual FSFU methods expect the context information
+ // to be in the src_* variables, not the dest_* variables, so we have to
+ // make a new context if we want to call them on the dest_file_path.
+ scoped_ptr<FileSystemOperationContext> dest_context(
+ context->CreateInheritedContextForDest());
// Exits earlier if the source path does not exist.
if (!PathExists(context, src_file_path))
return base::PLATFORM_FILE_ERROR_NOT_FOUND;
// The parent of the |dest_file_path| does not exist.
- if (!ParentExists(dest_context, dest_util, dest_file_path))
+ if (!ParentExists(dest_context.get(), dest_util, dest_file_path))
return base::PLATFORM_FILE_ERROR_NOT_FOUND;
// It is an error to try to copy/move an entry into its child.
@@ -287,14 +281,14 @@ FileSystemFileUtil::PerformCommonCheckAndPreparationForMoveAndCopy(
return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
// Now it is ok to return if the |dest_file_path| does not exist.
- if (!dest_util->PathExists(dest_context, dest_file_path))
+ if (!dest_util->PathExists(dest_context.get(), dest_file_path))
return base::PLATFORM_FILE_OK;
// |src_file_path| exists and is a directory.
// |dest_file_path| exists and is a file.
bool src_is_directory = DirectoryExists(context, src_file_path);
bool dest_is_directory =
- dest_util->DirectoryExists(dest_context, dest_file_path);
+ dest_util->DirectoryExists(dest_context.get(), dest_file_path);
if (src_is_directory && !dest_is_directory)
return base::PLATFORM_FILE_ERROR_INVALID_OPERATION;
@@ -313,10 +307,11 @@ FileSystemFileUtil::PerformCommonCheckAndPreparationForMoveAndCopy(
// the file_util's Copy or Move method doesn't perform overwrite
// on all platforms, so we delete the destination directory here.
// TODO(kinuko): may be better to change the file_util::{Copy,Move}.
- if (base::PLATFORM_FILE_OK !=
- dest_util->Delete(dest_context, dest_file_path,
- false /* recursive */)) {
- if (!dest_util->IsDirectoryEmpty(dest_context, dest_file_path))
+ PlatformFileError error = dest_util->Delete(
+ dest_context.get(), dest_file_path, false /* recursive */);
+ context->ImportAllowedBytesGrowth(*dest_context);
+ if (base::PLATFORM_FILE_OK != error) {
+ if (!dest_util->IsDirectoryEmpty(dest_context.get(), dest_file_path))
return base::PLATFORM_FILE_ERROR_NOT_EMPTY;
return base::PLATFORM_FILE_ERROR_FAILED;
}
@@ -353,27 +348,21 @@ PlatformFileError FileSystemFileUtil::CopyOrMoveDirectory(
const FilePath& dest_file_path,
bool copy) {
FileSystemFileUtil* dest_util = context->dest_file_system_file_util();
- FileSystemOperationContext dest_context(
- context->file_system_context(), dest_util);
- // All the single-path virtual FSFU methods expect the context information to
- // be in the src_* variables, not the dest_* variables, so we have to make a
- // new context if we want to call them on the dest_file_path.
- dest_context.set_src_type(context->dest_type());
- dest_context.set_src_origin_url(context->dest_origin_url());
- dest_context.set_src_virtual_path(context->dest_virtual_path());
- dest_context.set_allowed_bytes_growth(context->allowed_bytes_growth());
+ scoped_ptr<FileSystemOperationContext> dest_context(
+ context->CreateInheritedContextForDest());
// Re-check PerformCommonCheckAndPreparationForMoveAndCopy() by DCHECK.
DCHECK(DirectoryExists(context, src_file_path));
- DCHECK(ParentExists(&dest_context, dest_util, dest_file_path));
- DCHECK(!dest_util->PathExists(&dest_context, dest_file_path));
+ DCHECK(ParentExists(dest_context.get(), dest_util, dest_file_path));
+ DCHECK(!dest_util->PathExists(dest_context.get(), dest_file_path));
if ((context->src_origin_url() == context->dest_origin_url()) &&
(context->src_type() == context->dest_type()))
DCHECK(!src_file_path.IsParent(dest_file_path));
- if (!dest_util->DirectoryExists(&dest_context, dest_file_path)) {
- PlatformFileError error = dest_util->CreateDirectory(&dest_context,
+ if (!dest_util->DirectoryExists(dest_context.get(), dest_file_path)) {
+ PlatformFileError error = dest_util->CreateDirectory(dest_context.get(),
dest_file_path, false, false);
+ context->ImportAllowedBytesGrowth(*dest_context);
if (error != base::PLATFORM_FILE_OK)
return error;
}
@@ -386,13 +375,21 @@ PlatformFileError FileSystemFileUtil::CopyOrMoveDirectory(
src_file_path.AppendRelativePath(src_file_path_each, &dest_file_path_each);
if (file_enum->IsDirectory()) {
- PlatformFileError error = dest_util->CreateDirectory(&dest_context,
- dest_file_path_each, false, false);
+ scoped_ptr<FileSystemOperationContext> new_directory_context(
+ dest_context->CreateInheritedContextWithNewVirtualPaths(
+ dest_file_path_each, FilePath()));
+ PlatformFileError error = dest_util->CreateDirectory(
+ new_directory_context.get(), dest_file_path_each, false, false);
+ context->ImportAllowedBytesGrowth(*new_directory_context);
if (error != base::PLATFORM_FILE_OK)
return error;
} else {
+ scoped_ptr<FileSystemOperationContext> copy_context(
+ context->CreateInheritedContextWithNewVirtualPaths(
+ src_file_path_each, dest_file_path_each));
PlatformFileError error = CopyOrMoveFileHelper(
- context, src_file_path_each, dest_file_path_each, copy);
+ copy_context.get(), src_file_path_each, dest_file_path_each, copy);
+ context->ImportAllowedBytesGrowth(*copy_context);
if (error != base::PLATFORM_FILE_OK)
return error;
}
@@ -478,7 +475,12 @@ PlatformFileError FileSystemFileUtil::DeleteDirectoryRecursive(
directories.push(file_path_each);
} else {
// DeleteFile here is the virtual overridden member function.
- PlatformFileError error = DeleteFile(context, file_path_each);
+ scoped_ptr<FileSystemOperationContext> inherited_context(
+ context->CreateInheritedContextWithNewVirtualPaths(
+ file_path_each, FilePath()));
+ PlatformFileError error =
+ DeleteFile(inherited_context.get(), file_path_each);
+ context->ImportAllowedBytesGrowth(*inherited_context);
if (error == base::PLATFORM_FILE_ERROR_NOT_FOUND)
return base::PLATFORM_FILE_ERROR_FAILED;
else if (error != base::PLATFORM_FILE_OK)
@@ -487,7 +489,12 @@ PlatformFileError FileSystemFileUtil::DeleteDirectoryRecursive(
}
while (!directories.empty()) {
- PlatformFileError error = DeleteSingleDirectory(context, directories.top());
+ scoped_ptr<FileSystemOperationContext> inherited_context(
+ context->CreateInheritedContextWithNewVirtualPaths(
+ directories.top(), FilePath()));
+ PlatformFileError error =
+ DeleteSingleDirectory(inherited_context.get(), directories.top());
+ context->ImportAllowedBytesGrowth(*inherited_context);
if (error == base::PLATFORM_FILE_ERROR_NOT_FOUND)
return base::PLATFORM_FILE_ERROR_FAILED;
else if (error != base::PLATFORM_FILE_OK)
diff --git a/webkit/fileapi/file_system_operation.cc b/webkit/fileapi/file_system_operation.cc
index 4aa663c..c2281cc 100644
--- a/webkit/fileapi/file_system_operation.cc
+++ b/webkit/fileapi/file_system_operation.cc
@@ -86,14 +86,33 @@ void FileSystemOperation::CreateFile(const GURL& path,
}
file_system_operation_context_.set_src_origin_url(origin_url);
file_system_operation_context_.set_src_type(type);
+ file_system_operation_context_.set_src_virtual_path(virtual_path);
if (!file_system_operation_context_.src_file_system_file_util())
file_system_operation_context_.set_src_file_system_file_util(
file_system_file_util);
+ exclusive_ = exclusive;
+
+ GetUsageAndQuotaThenCallback(origin_url, callback_factory_.NewCallback(
+ &FileSystemOperation::DelayedCreateFileForQuota));
+}
+
+void FileSystemOperation::DelayedCreateFileForQuota(
+ quota::QuotaStatusCode status, int64 usage, int64 quota) {
+ if (file_system_context()->IsStorageUnlimited(
+ file_system_operation_context()->src_origin_url()) ||
+ quota == QuotaFileUtil::kNoLimit) {
+ file_system_operation_context_.set_allowed_bytes_growth(
+ QuotaFileUtil::kNoLimit);
+ } else {
+ file_system_operation_context_.set_allowed_bytes_growth(quota - usage);
+ }
FileSystemFileUtilProxy::EnsureFileExists(
file_system_operation_context_,
- proxy_, virtual_path, callback_factory_.NewCallback(
- exclusive ? &FileSystemOperation::DidEnsureFileExistsExclusive
- : &FileSystemOperation::DidEnsureFileExistsNonExclusive));
+ proxy_,
+ file_system_operation_context_.src_virtual_path(),
+ callback_factory_.NewCallback(
+ exclusive_ ? &FileSystemOperation::DidEnsureFileExistsExclusive
+ : &FileSystemOperation::DidEnsureFileExistsNonExclusive));
}
void FileSystemOperation::CreateDirectory(const GURL& path,
@@ -116,12 +135,34 @@ void FileSystemOperation::CreateDirectory(const GURL& path,
}
file_system_operation_context_.set_src_origin_url(origin_url);
file_system_operation_context_.set_src_type(type);
+ file_system_operation_context_.set_src_virtual_path(virtual_path);
if (!file_system_operation_context_.src_file_system_file_util())
file_system_operation_context_.set_src_file_system_file_util(
file_system_file_util);
+ exclusive_ = exclusive;
+ recursive_ = recursive;
+
+ GetUsageAndQuotaThenCallback(origin_url, callback_factory_.NewCallback(
+ &FileSystemOperation::DelayedCreateDirectoryForQuota));
+}
+
+void FileSystemOperation::DelayedCreateDirectoryForQuota(
+ quota::QuotaStatusCode status, int64 usage, int64 quota) {
+ if (file_system_context()->IsStorageUnlimited(
+ file_system_operation_context()->src_origin_url()) ||
+ quota == QuotaFileUtil::kNoLimit) {
+ file_system_operation_context_.set_allowed_bytes_growth(
+ QuotaFileUtil::kNoLimit);
+ } else {
+ file_system_operation_context_.set_allowed_bytes_growth(quota - usage);
+ }
FileSystemFileUtilProxy::CreateDirectory(
file_system_operation_context_,
- proxy_, virtual_path, exclusive, recursive, callback_factory_.NewCallback(
+ proxy_,
+ file_system_operation_context_.src_virtual_path(),
+ exclusive_,
+ recursive_,
+ callback_factory_.NewCallback(
&FileSystemOperation::DidFinishFileOperation));
}
@@ -410,7 +451,7 @@ void FileSystemOperation::Write(
void FileSystemOperation::DelayedWriteForQuota(quota::QuotaStatusCode status,
int64 usage, int64 quota) {
if (file_system_context()->IsStorageUnlimited(
- file_system_operation_context()->dest_origin_url()) ||
+ file_system_operation_context()->src_origin_url()) ||
quota == QuotaFileUtil::kNoLimit) {
file_system_operation_context_.set_allowed_bytes_growth(
QuotaFileUtil::kNoLimit);
@@ -456,7 +497,7 @@ void FileSystemOperation::Truncate(const GURL& path, int64 length) {
void FileSystemOperation::DelayedTruncateForQuota(quota::QuotaStatusCode status,
int64 usage, int64 quota) {
if (file_system_context()->IsStorageUnlimited(
- file_system_operation_context()->dest_origin_url()) ||
+ file_system_operation_context()->src_origin_url()) ||
quota == QuotaFileUtil::kNoLimit) {
file_system_operation_context_.set_allowed_bytes_growth(
QuotaFileUtil::kNoLimit);
@@ -538,14 +579,32 @@ void FileSystemOperation::OpenFile(const GURL& path,
}
file_system_operation_context_.set_src_origin_url(origin_url);
file_system_operation_context_.set_src_type(type);
+ file_system_operation_context_.set_src_virtual_path(virtual_path);
if (!file_system_operation_context_.src_file_system_file_util())
file_system_operation_context_.set_src_file_system_file_util(
file_system_file_util);
+ file_flags_ = file_flags;
+
+ GetUsageAndQuotaThenCallback(origin_url, callback_factory_.NewCallback(
+ &FileSystemOperation::DelayedOpenFileForQuota));
+}
+
+void FileSystemOperation::DelayedOpenFileForQuota(quota::QuotaStatusCode status,
+ int64 usage, int64 quota) {
+ if (file_system_context()->IsStorageUnlimited(
+ file_system_operation_context()->dest_origin_url()) ||
+ quota == QuotaFileUtil::kNoLimit) {
+ file_system_operation_context_.set_allowed_bytes_growth(
+ QuotaFileUtil::kNoLimit);
+ } else {
+ file_system_operation_context_.set_allowed_bytes_growth(quota - usage);
+ }
+
FileSystemFileUtilProxy::CreateOrOpen(
file_system_operation_context_,
proxy_,
- virtual_path,
- file_flags,
+ file_system_operation_context_.src_virtual_path(),
+ file_flags_,
callback_factory_.NewCallback(
&FileSystemOperation::DidOpenFile));
}
diff --git a/webkit/fileapi/file_system_operation.h b/webkit/fileapi/file_system_operation.h
index 7dbe61a..f6835b0 100644
--- a/webkit/fileapi/file_system_operation.h
+++ b/webkit/fileapi/file_system_operation.h
@@ -110,6 +110,10 @@ class FileSystemOperation {
const GURL& origin_url,
quota::QuotaManager::GetUsageAndQuotaCallback* callback);
+ void DelayedCreateFileForQuota(quota::QuotaStatusCode status,
+ int64 usage, int64 quota);
+ void DelayedCreateDirectoryForQuota(quota::QuotaStatusCode status,
+ int64 usage, int64 quota);
void DelayedCopyForQuota(quota::QuotaStatusCode status,
int64 usage, int64 quota);
void DelayedMoveForQuota(quota::QuotaStatusCode status,
@@ -118,6 +122,8 @@ class FileSystemOperation {
int64 usage, int64 quota);
void DelayedTruncateForQuota(quota::QuotaStatusCode status,
int64 usage, int64 quota);
+ void DelayedOpenFileForQuota(quota::QuotaStatusCode status,
+ int64 usage, int64 quota);
// A callback used for OpenFileSystem.
void DidGetRootPath(bool success,
@@ -243,6 +249,13 @@ class FileSystemOperation {
// requesting process.
base::ProcessHandle peer_handle_;
+ // Options for CreateFile and CreateDirectory.
+ bool exclusive_;
+ bool recursive_;
+
+ // Options for OpenFile.
+ int file_flags_;
+
// Length to be truncated.
int64 length_;
diff --git a/webkit/fileapi/file_system_operation_context.cc b/webkit/fileapi/file_system_operation_context.cc
index d7bfbbb..bfd5055 100644
--- a/webkit/fileapi/file_system_operation_context.cc
+++ b/webkit/fileapi/file_system_operation_context.cc
@@ -17,10 +17,38 @@ FileSystemOperationContext::FileSystemOperationContext(
dest_file_system_file_util_(file_system_file_util),
src_type_(kFileSystemTypeUnknown),
dest_type_(kFileSystemTypeUnknown),
- allowed_bytes_growth_(0) {
+ allowed_bytes_growth_(0),
+ do_not_write_actually_(false) {
}
FileSystemOperationContext::~FileSystemOperationContext() {
}
+FileSystemOperationContext*
+FileSystemOperationContext::CreateInheritedContextForDest() const {
+ FileSystemOperationContext* context = new FileSystemOperationContext(
+ file_system_context_.get(), dest_file_system_file_util_);
+ context->set_src_origin_url(dest_origin_url_);
+ context->set_src_type(dest_type_);
+ context->set_allowed_bytes_growth(allowed_bytes_growth_);
+ context->set_do_not_write_actually(do_not_write_actually_);
+ context->set_src_virtual_path(dest_virtual_path_);
+ return context;
+}
+
+FileSystemOperationContext*
+FileSystemOperationContext::CreateInheritedContextWithNewVirtualPaths(
+ const FilePath& new_src_virtual_path,
+ const FilePath& new_dest_virtual_path) const {
+ FileSystemOperationContext* context = new FileSystemOperationContext(*this);
+ context->set_src_virtual_path(new_src_virtual_path);
+ context->set_dest_virtual_path(new_dest_virtual_path);
+ return context;
+}
+
+void FileSystemOperationContext::ImportAllowedBytesGrowth(
+ const FileSystemOperationContext& other) {
+ allowed_bytes_growth_ = other.allowed_bytes_growth();
+}
+
} // namespace fileapi
diff --git a/webkit/fileapi/file_system_operation_context.h b/webkit/fileapi/file_system_operation_context.h
index 7b2b4d2..04f216cea 100644
--- a/webkit/fileapi/file_system_operation_context.h
+++ b/webkit/fileapi/file_system_operation_context.h
@@ -101,6 +101,25 @@ class FileSystemOperationContext {
int64 allowed_bytes_growth() const { return allowed_bytes_growth_; }
+ // TODO(dmikurube): Eliminate this flag eventually.
+ // This flag is temporarily prepared to allow ObfuscatedFSFU to account
+ // directories' cost without making actual directories. This should be
+ // dealed with more fundamentally.
+ void set_do_not_write_actually(
+ bool do_not_write_actually) {
+ do_not_write_actually_ = do_not_write_actually;
+ }
+
+ bool do_not_write_actually() const {
+ return do_not_write_actually_;
+ }
+
+ FileSystemOperationContext* CreateInheritedContextForDest() const;
+ FileSystemOperationContext* CreateInheritedContextWithNewVirtualPaths(
+ const FilePath& new_src_virtual_path,
+ const FilePath& new_dest_virtual_path) const;
+ void ImportAllowedBytesGrowth(const FileSystemOperationContext& other);
+
private:
scoped_refptr<FileSystemContext> file_system_context_;
// These *_file_system_file_util_ are not "owned" by
@@ -114,6 +133,7 @@ class FileSystemOperationContext {
FileSystemType src_type_; // Also used for any single-path operation.
FileSystemType dest_type_;
int64 allowed_bytes_growth_;
+ bool do_not_write_actually_;
// Used for delayed operation by quota.
FilePath src_virtual_path_; // Also used for any single-path operation.
diff --git a/webkit/fileapi/file_system_quota_client_unittest.cc b/webkit/fileapi/file_system_quota_client_unittest.cc
index 8b14b6c..d54978a 100644
--- a/webkit/fileapi/file_system_quota_client_unittest.cc
+++ b/webkit/fileapi/file_system_quota_client_unittest.cc
@@ -18,6 +18,7 @@
#include "webkit/fileapi/file_system_usage_cache.h"
#include "webkit/fileapi/file_system_util.h"
#include "webkit/fileapi/sandbox_mount_point_provider.h"
+#include "webkit/fileapi/quota_file_util.h"
#include "webkit/quota/quota_types.h"
namespace fileapi {
@@ -76,7 +77,7 @@ class FileSystemQuotaClientTest : public testing::Test {
}
void GetOriginUsageAsync(FileSystemQuotaClient* quota_client,
- const char* origin_url,
+ const std::string& origin_url,
quota::StorageType type) {
quota_client->GetOriginUsage(GURL(origin_url), type,
callback_factory_.NewCallback(
@@ -84,7 +85,7 @@ class FileSystemQuotaClientTest : public testing::Test {
}
int64 GetOriginUsage(FileSystemQuotaClient* quota_client,
- const char* origin_url,
+ const std::string& origin_url,
quota::StorageType type) {
GetOriginUsageAsync(quota_client, origin_url, type);
MessageLoop::current()->RunAllPending();
@@ -103,7 +104,7 @@ class FileSystemQuotaClientTest : public testing::Test {
const std::set<GURL>& GetOriginsForHost(FileSystemQuotaClient* quota_client,
quota::StorageType type,
- const char* host) {
+ const std::string& host) {
origins_.clear();
quota_client->GetOriginsForHost(type, host,
callback_factory_.NewCallback(
@@ -113,14 +114,14 @@ class FileSystemQuotaClientTest : public testing::Test {
}
void RunAdditionalOriginUsageTask(FileSystemQuotaClient* quota_client,
- const char* origin_url,
+ const std::string& origin_url,
quota::StorageType type) {
quota_client->GetOriginUsage(GURL(origin_url), type,
callback_factory_.NewCallback(
&FileSystemQuotaClientTest::OnGetAdditionalUsage));
}
- FilePath GetOriginBasePath(const char* origin_url,
+ FilePath GetOriginBasePath(const std::string& origin_url,
quota::StorageType type) {
// Note: this test assumes sandbox_provider impl is used for
// temporary and persistent filesystem.
@@ -132,7 +133,7 @@ class FileSystemQuotaClientTest : public testing::Test {
FileSystemOperationContext* CreateFileSystemOperationContext(
FileSystemFileUtil* file_util,
const FilePath& virtual_path,
- const char* origin_url,
+ const std::string& origin_url,
quota::StorageType type) {
FileSystemOperationContext* context =
new FileSystemOperationContext(file_system_context_, file_util);
@@ -144,7 +145,7 @@ class FileSystemQuotaClientTest : public testing::Test {
}
bool CreateFileSystemDirectory(const FilePath& path,
- const char* origin_url,
+ const std::string& origin_url,
quota::StorageType type) {
FileSystemFileUtil* file_util =
file_system_context_->path_manager()->GetFileSystemFileUtil(
@@ -162,7 +163,7 @@ class FileSystemQuotaClientTest : public testing::Test {
bool CreateFileSystemFile(const FilePath& path,
int64 file_size,
- const char* origin_url,
+ const std::string& origin_url,
quota::StorageType type) {
if (path.empty())
return false;
@@ -204,8 +205,27 @@ class FileSystemQuotaClientTest : public testing::Test {
}
}
+ int64 ComputeFilePathsCostForOriginAndType(const TestFile* files,
+ int num_files,
+ const std::string& origin_url,
+ quota::StorageType type) {
+ int64 file_paths_cost = 0;
+ for (int i = 0; i < num_files; i++) {
+ if (files[i].type == type &&
+ GURL(files[i].origin_url) == GURL(origin_url)) {
+ FilePath path = FilePath().AppendASCII(files[i].name);
+ if (!path.empty()) {
+ // TODO(dmikurube): Use QuotaFileUtil in the actual -FileUtil stack.
+ file_paths_cost +=
+ QuotaFileUtil::GetInstance()->ComputeFilePathCost(path);
+ }
+ }
+ }
+ return file_paths_cost;
+ }
+
void DeleteOriginData(FileSystemQuotaClient* quota_client,
- const char* origin,
+ const std::string& origin,
quota::StorageType type) {
deletion_status_ = quota::kQuotaStatusUnknown;
quota_client->DeleteOriginData(
@@ -275,9 +295,11 @@ TEST_F(FileSystemQuotaClientTest, OneFileTest) {
{false, "foo", 4921, kDummyURL1, kTemporary},
};
InitializeOriginFiles(quota_client.get(), kFiles, ARRAYSIZE_UNSAFE(kFiles));
+ const int64 file_paths_cost = ComputeFilePathsCostForOriginAndType(
+ kFiles, ARRAYSIZE_UNSAFE(kFiles), kDummyURL1, kTemporary);
for (int i = 0; i < 2; i++) {
- EXPECT_EQ(4921,
+ EXPECT_EQ(4921 + file_paths_cost,
GetOriginUsage(quota_client.get(), kDummyURL1, kTemporary));
}
}
@@ -290,9 +312,11 @@ TEST_F(FileSystemQuotaClientTest, TwoFilesTest) {
{false, "bar", 41, kDummyURL1, kTemporary},
};
InitializeOriginFiles(quota_client.get(), kFiles, ARRAYSIZE_UNSAFE(kFiles));
+ const int64 file_paths_cost = ComputeFilePathsCostForOriginAndType(
+ kFiles, ARRAYSIZE_UNSAFE(kFiles), kDummyURL1, kTemporary);
for (int i = 0; i < 2; i++) {
- EXPECT_EQ(10310 + 41,
+ EXPECT_EQ(10310 + 41 + file_paths_cost,
GetOriginUsage(quota_client.get(), kDummyURL1, kTemporary));
}
}
@@ -306,9 +330,11 @@ TEST_F(FileSystemQuotaClientTest, EmptyFilesTest) {
{false, "baz", 0, kDummyURL1, kTemporary},
};
InitializeOriginFiles(quota_client.get(), kFiles, ARRAYSIZE_UNSAFE(kFiles));
+ const int64 file_paths_cost = ComputeFilePathsCostForOriginAndType(
+ kFiles, ARRAYSIZE_UNSAFE(kFiles), kDummyURL1, kTemporary);
for (int i = 0; i < 2; i++) {
- EXPECT_EQ(0,
+ EXPECT_EQ(file_paths_cost,
GetOriginUsage(quota_client.get(), kDummyURL1, kTemporary));
}
}
@@ -322,9 +348,11 @@ TEST_F(FileSystemQuotaClientTest, SubDirectoryTest) {
{false, "bar", 4814, kDummyURL1, kTemporary},
};
InitializeOriginFiles(quota_client.get(), kFiles, ARRAYSIZE_UNSAFE(kFiles));
+ const int64 file_paths_cost = ComputeFilePathsCostForOriginAndType(
+ kFiles, ARRAYSIZE_UNSAFE(kFiles), kDummyURL1, kTemporary);
for (int i = 0; i < 2; i++) {
- EXPECT_EQ(11921 + 4814,
+ EXPECT_EQ(11921 + 4814 + file_paths_cost,
GetOriginUsage(quota_client.get(), kDummyURL1, kTemporary));
}
}
@@ -342,11 +370,15 @@ TEST_F(FileSystemQuotaClientTest, MultiTypeTest) {
{false, "bar", 9, kDummyURL1, kPersistent},
};
InitializeOriginFiles(quota_client.get(), kFiles, ARRAYSIZE_UNSAFE(kFiles));
+ const int64 file_paths_cost_temporary = ComputeFilePathsCostForOriginAndType(
+ kFiles, ARRAYSIZE_UNSAFE(kFiles), kDummyURL1, kTemporary);
+ const int64 file_paths_cost_persistent = ComputeFilePathsCostForOriginAndType(
+ kFiles, ARRAYSIZE_UNSAFE(kFiles), kDummyURL1, kTemporary);
for (int i = 0; i < 2; i++) {
- EXPECT_EQ(133 + 14,
+ EXPECT_EQ(133 + 14 + file_paths_cost_temporary,
GetOriginUsage(quota_client.get(), kDummyURL1, kTemporary));
- EXPECT_EQ(193 + 9,
+ EXPECT_EQ(193 + 9 + file_paths_cost_persistent,
GetOriginUsage(quota_client.get(), kDummyURL1, kPersistent));
}
}
@@ -372,15 +404,25 @@ TEST_F(FileSystemQuotaClientTest, MultiDomainTest) {
{false, "baz", 18, kDummyURL2, kPersistent},
};
InitializeOriginFiles(quota_client.get(), kFiles, ARRAYSIZE_UNSAFE(kFiles));
+ const int64 file_paths_cost_temporary1 = ComputeFilePathsCostForOriginAndType(
+ kFiles, ARRAYSIZE_UNSAFE(kFiles), kDummyURL1, kTemporary);
+ const int64 file_paths_cost_persistent1 =
+ ComputeFilePathsCostForOriginAndType(kFiles, ARRAYSIZE_UNSAFE(kFiles),
+ kDummyURL1, kPersistent);
+ const int64 file_paths_cost_temporary2 = ComputeFilePathsCostForOriginAndType(
+ kFiles, ARRAYSIZE_UNSAFE(kFiles), kDummyURL2, kTemporary);
+ const int64 file_paths_cost_persistent2 =
+ ComputeFilePathsCostForOriginAndType(kFiles, ARRAYSIZE_UNSAFE(kFiles),
+ kDummyURL2, kPersistent);
for (int i = 0; i < 2; i++) {
- EXPECT_EQ(1331 + 134,
+ EXPECT_EQ(1331 + 134 + file_paths_cost_temporary1,
GetOriginUsage(quota_client.get(), kDummyURL1, kTemporary));
- EXPECT_EQ(1903 + 19,
+ EXPECT_EQ(1903 + 19 + file_paths_cost_persistent1,
GetOriginUsage(quota_client.get(), kDummyURL1, kPersistent));
- EXPECT_EQ(1319 + 113,
+ EXPECT_EQ(1319 + 113 + file_paths_cost_temporary2,
GetOriginUsage(quota_client.get(), kDummyURL2, kTemporary));
- EXPECT_EQ(2013 + 18,
+ EXPECT_EQ(2013 + 18 + file_paths_cost_persistent2,
GetOriginUsage(quota_client.get(), kDummyURL2, kPersistent));
}
}
@@ -393,6 +435,8 @@ TEST_F(FileSystemQuotaClientTest, GetUsage_MultipleTasks) {
{false, "bar", 22, kDummyURL1, kTemporary},
};
InitializeOriginFiles(quota_client.get(), kFiles, ARRAYSIZE_UNSAFE(kFiles));
+ const int64 file_paths_cost = ComputeFilePathsCostForOriginAndType(
+ kFiles, ARRAYSIZE_UNSAFE(kFiles), kDummyURL1, kTemporary);
// Dispatching three GetUsage tasks.
set_additional_callback_count(0);
@@ -400,7 +444,7 @@ TEST_F(FileSystemQuotaClientTest, GetUsage_MultipleTasks) {
RunAdditionalOriginUsageTask(quota_client.get(), kDummyURL1, kTemporary);
RunAdditionalOriginUsageTask(quota_client.get(), kDummyURL1, kTemporary);
MessageLoop::current()->RunAllPending();
- EXPECT_EQ(11 + 22, usage());
+ EXPECT_EQ(11 + 22 + file_paths_cost, usage());
EXPECT_EQ(2, additional_callback_count());
// Once more, in a different order.
@@ -409,7 +453,7 @@ TEST_F(FileSystemQuotaClientTest, GetUsage_MultipleTasks) {
GetOriginUsageAsync(quota_client.get(), kDummyURL1, kTemporary);
RunAdditionalOriginUsageTask(quota_client.get(), kDummyURL1, kTemporary);
MessageLoop::current()->RunAllPending();
- EXPECT_EQ(11 + 22, usage());
+ EXPECT_EQ(11 + 22 + file_paths_cost, usage());
EXPECT_EQ(2, additional_callback_count());
}
@@ -493,6 +537,21 @@ TEST_F(FileSystemQuotaClientTest, DeleteOriginTest) {
{false, "g", 64, "https://bar.com/", kTemporary},
};
InitializeOriginFiles(quota_client.get(), kFiles, ARRAYSIZE_UNSAFE(kFiles));
+ const int64 file_paths_cost_temporary_foo_https =
+ ComputeFilePathsCostForOriginAndType(kFiles, ARRAYSIZE_UNSAFE(kFiles),
+ "https://foo.com/", kTemporary);
+ const int64 file_paths_cost_persistent_foo =
+ ComputeFilePathsCostForOriginAndType(kFiles, ARRAYSIZE_UNSAFE(kFiles),
+ "http://foo.com/", kPersistent);
+ const int64 file_paths_cost_temporary_bar =
+ ComputeFilePathsCostForOriginAndType(kFiles, ARRAYSIZE_UNSAFE(kFiles),
+ "http://bar.com/", kTemporary);
+ const int64 file_paths_cost_temporary_bar_https =
+ ComputeFilePathsCostForOriginAndType(kFiles, ARRAYSIZE_UNSAFE(kFiles),
+ "https://bar.com/", kTemporary);
+ const int64 file_paths_cost_persistent_bar_https =
+ ComputeFilePathsCostForOriginAndType(kFiles, ARRAYSIZE_UNSAFE(kFiles),
+ "https://bar.com/", kPersistent);
DeleteOriginData(quota_client.get(), "http://foo.com/", kTemporary);
MessageLoop::current()->RunAllPending();
@@ -513,23 +572,23 @@ TEST_F(FileSystemQuotaClientTest, DeleteOriginTest) {
EXPECT_EQ(0, GetOriginUsage(
quota_client.get(), "http://buz.com/", kTemporary));
- EXPECT_EQ(2,
+ EXPECT_EQ(2 + file_paths_cost_temporary_foo_https,
GetOriginUsage(quota_client.get(),
"https://foo.com/",
kTemporary));
- EXPECT_EQ(4,
+ EXPECT_EQ(4 + file_paths_cost_persistent_foo,
GetOriginUsage(quota_client.get(),
"http://foo.com/",
kPersistent));
- EXPECT_EQ(8,
+ EXPECT_EQ(8 + file_paths_cost_temporary_bar,
GetOriginUsage(quota_client.get(),
"http://bar.com/",
kTemporary));
- EXPECT_EQ(32,
+ EXPECT_EQ(32 + file_paths_cost_persistent_bar_https,
GetOriginUsage(quota_client.get(),
"https://bar.com/",
kPersistent));
- EXPECT_EQ(64,
+ EXPECT_EQ(64 + file_paths_cost_temporary_bar_https,
GetOriginUsage(quota_client.get(),
"https://bar.com/",
kTemporary));
diff --git a/webkit/fileapi/file_system_quota_unittest.cc b/webkit/fileapi/file_system_quota_unittest.cc
index a2dd58cd..bfc5603 100644
--- a/webkit/fileapi/file_system_quota_unittest.cc
+++ b/webkit/fileapi/file_system_quota_unittest.cc
@@ -16,12 +16,14 @@
#include "base/scoped_temp_dir.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "webkit/fileapi/file_system_callback_dispatcher.h"
+#include "webkit/fileapi/file_system_context.h"
#include "webkit/fileapi/file_system_operation.h"
#include "webkit/fileapi/file_system_test_helper.h"
#include "webkit/fileapi/file_system_usage_cache.h"
#include "webkit/fileapi/file_system_util.h"
#include "webkit/fileapi/local_file_system_file_util.h"
#include "webkit/fileapi/quota_file_util.h"
+#include "webkit/quota/mock_special_storage_policy.h"
#include "webkit/quota/quota_manager.h"
namespace fileapi {
@@ -31,9 +33,10 @@ const int kFileOperationStatusNotSet = 1;
class FileSystemQuotaTest : public testing::Test {
public:
FileSystemQuotaTest()
- : local_file_util_(
- new LocalFileSystemFileUtil(QuotaFileUtil::GetInstance())),
+ : quota_file_util_(QuotaFileUtil::GetInstance()),
+ local_file_util_(new LocalFileSystemFileUtil(quota_file_util_)),
callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
+ file_path_cost_(0),
status_(kFileOperationStatusNotSet),
quota_status_(quota::kQuotaStatusUnknown),
usage_(-1),
@@ -89,25 +92,32 @@ class FileSystemQuotaTest : public testing::Test {
return file_util::DirectoryExists(PlatformPath(virtual_path));
}
- FilePath CreateVirtualTemporaryFileInDir(const FilePath& virtual_dir_path) {
- FilePath absolute_dir_path(PlatformPath(virtual_dir_path));
- FilePath absolute_file_path;
- EXPECT_TRUE(file_util::CreateTemporaryFileInDir(absolute_dir_path,
- &absolute_file_path));
- return virtual_dir_path.Append(absolute_file_path.BaseName());
+ int64 ComputeFilePathCost(const FilePath& file_path) {
+ return quota_file_util_->ComputeFilePathCost(file_path);
}
- FilePath CreateVirtualTemporaryDirInDir(const FilePath& virtual_dir_path) {
- FilePath absolute_parent_dir_path(PlatformPath(virtual_dir_path));
- FilePath absolute_child_dir_path;
- EXPECT_TRUE(file_util::CreateTemporaryDirInDir(absolute_parent_dir_path,
- FILE_PATH_LITERAL(""),
- &absolute_child_dir_path));
- return virtual_dir_path.Append(absolute_child_dir_path.BaseName());
+ void CreateVirtualDirectory(const FilePath& virtual_path) {
+ operation()->CreateDirectory(URLForPath(virtual_path), false, false);
+ MessageLoop::current()->RunAllPending();
+ file_path_cost_ += ComputeFilePathCost(virtual_path);
+ }
+
+ void CreateVirtualFile(const FilePath& virtual_path) {
+ operation()->CreateFile(URLForPath(virtual_path), false);
+ MessageLoop::current()->RunAllPending();
+ file_path_cost_ += ComputeFilePathCost(virtual_path);
+ }
+
+ void set_file_path_cost(int64 file_path_cost) {
+ file_path_cost_ = file_path_cost;
+ }
+
+ int64 file_path_cost() const {
+ return file_path_cost_;
}
- FilePath CreateVirtualTemporaryDir() {
- return CreateVirtualTemporaryDirInDir(FilePath());
+ void AddToFilePathCost(int64 addition) {
+ file_path_cost_ += addition;
}
FilePath child_dir_path_;
@@ -116,24 +126,41 @@ class FileSystemQuotaTest : public testing::Test {
FilePath grandchild_file1_path_;
FilePath grandchild_file2_path_;
- private:
+ protected:
FileSystemTestOriginHelper test_helper_;
ScopedTempDir work_dir_;
scoped_refptr<quota::QuotaManager> quota_manager_;
+ QuotaFileUtil* quota_file_util_;
scoped_ptr<LocalFileSystemFileUtil> local_file_util_;
base::ScopedCallbackFactory<FileSystemQuotaTest> callback_factory_;
+ int64 file_path_cost_;
+
// For post-operation status.
int status_;
quota::QuotaStatusCode quota_status_;
int64 usage_;
int64 quota_;
+ private:
DISALLOW_COPY_AND_ASSIGN(FileSystemQuotaTest);
};
+class FileSystemObfuscatedQuotaTest : public FileSystemQuotaTest {
+ public:
+ virtual void SetUp();
+
+ int64 RevokeUsageCache() {
+ quota_manager_->ResetUsageTracker(test_helper_.storage_type());
+ return test_helper_.RevokeUsageCache();
+ }
+
+ private:
+ scoped_refptr<FileSystemContext> file_system_context_;
+};
+
namespace {
class MockDispatcher : public FileSystemCallbackDispatcher {
@@ -214,17 +241,24 @@ void FileSystemQuotaTest::OnGetUsageAndQuota(
}
void FileSystemQuotaTest::PrepareFileSet(const FilePath& virtual_path) {
- child_dir_path_ = CreateVirtualTemporaryDirInDir(virtual_path);
- child_file1_path_ = CreateVirtualTemporaryFileInDir(virtual_path);
- child_file2_path_ = CreateVirtualTemporaryFileInDir(virtual_path);
- grandchild_file1_path_ = CreateVirtualTemporaryFileInDir(child_dir_path_);
- grandchild_file2_path_ = CreateVirtualTemporaryFileInDir(child_dir_path_);
+ child_dir_path_ = virtual_path.AppendASCII("childdir");
+ CreateVirtualDirectory(child_dir_path_);
+ child_file1_path_ = virtual_path.AppendASCII("childfile1");
+ CreateVirtualFile(child_file1_path_);
+ child_file2_path_ = virtual_path.AppendASCII("childlongfile2");
+ CreateVirtualFile(child_file2_path_);
+ grandchild_file1_path_ = child_dir_path_.AppendASCII("grchildfile1");
+ CreateVirtualFile(grandchild_file1_path_);
+ grandchild_file2_path_ = child_dir_path_.AppendASCII("grchildlongfile2");
+ CreateVirtualFile(grandchild_file2_path_);
}
TEST_F(FileSystemQuotaTest, TestMoveSuccessSrcDirRecursive) {
- FilePath src_dir_path(CreateVirtualTemporaryDir());
+ FilePath src_dir_path = FilePath(FILE_PATH_LITERAL("src"));
+ CreateVirtualDirectory(src_dir_path);
PrepareFileSet(src_dir_path);
- FilePath dest_dir_path(CreateVirtualTemporaryDir());
+ FilePath dest_dir_path = FilePath(FILE_PATH_LITERAL("dest"));
+ CreateVirtualDirectory(dest_dir_path);
EXPECT_EQ(0, ActualSize());
@@ -238,14 +272,16 @@ TEST_F(FileSystemQuotaTest, TestMoveSuccessSrcDirRecursive) {
const int64 usage_file_size = FileSystemUsageCache::kUsageFileSize;
EXPECT_EQ(all_file_size, ActualSize());
- EXPECT_EQ(all_file_size + usage_file_size, SizeInUsageFile());
+ EXPECT_EQ(all_file_size + usage_file_size + file_path_cost(),
+ SizeInUsageFile());
GetUsageAndQuotaFromQuotaManager();
EXPECT_EQ(quota::kQuotaStatusOk, quota_status());
- EXPECT_EQ(all_file_size + usage_file_size, usage());
+ EXPECT_EQ(all_file_size + usage_file_size + file_path_cost(), usage());
ASSERT_LT(all_file_size, quota());
operation()->Move(URLForPath(src_dir_path), URLForPath(dest_dir_path));
MessageLoop::current()->RunAllPending();
+ AddToFilePathCost(-ComputeFilePathCost(src_dir_path));
EXPECT_EQ(base::PLATFORM_FILE_OK, status());
EXPECT_TRUE(VirtualDirectoryExists(dest_dir_path.Append(
@@ -255,18 +291,21 @@ TEST_F(FileSystemQuotaTest, TestMoveSuccessSrcDirRecursive) {
grandchild_file1_path_.BaseName())));
EXPECT_EQ(all_file_size, ActualSize());
- EXPECT_EQ(all_file_size + usage_file_size, SizeInUsageFile());
+ EXPECT_EQ(all_file_size + usage_file_size + file_path_cost(),
+ SizeInUsageFile());
GetUsageAndQuotaFromQuotaManager();
EXPECT_EQ(quota::kQuotaStatusOk, quota_status());
- EXPECT_EQ(all_file_size + usage_file_size, usage());
+ EXPECT_EQ(all_file_size + usage_file_size + file_path_cost(), usage());
ASSERT_LT(all_file_size, quota());
}
TEST_F(FileSystemQuotaTest, TestCopySuccessSrcDirRecursive) {
- FilePath src_dir_path(CreateVirtualTemporaryDir());
+ FilePath src_dir_path = FilePath(FILE_PATH_LITERAL("src"));
+ CreateVirtualDirectory(src_dir_path);
PrepareFileSet(src_dir_path);
- FilePath dest_dir1_path(CreateVirtualTemporaryDir());
- FilePath dest_dir2_path(CreateVirtualTemporaryDir());
+ FilePath dest_dir1_path = FilePath(FILE_PATH_LITERAL("dest1"));
+ CreateVirtualDirectory(dest_dir1_path);
+ FilePath dest_dir2_path = FilePath(FILE_PATH_LITERAL("destnonexisting2"));
EXPECT_EQ(0, ActualSize());
@@ -282,14 +321,20 @@ TEST_F(FileSystemQuotaTest, TestCopySuccessSrcDirRecursive) {
const int64 usage_file_size = FileSystemUsageCache::kUsageFileSize;
EXPECT_EQ(all_file_size, ActualSize());
- EXPECT_EQ(all_file_size + usage_file_size, SizeInUsageFile());
+ EXPECT_EQ(all_file_size + usage_file_size + file_path_cost(),
+ SizeInUsageFile());
GetUsageAndQuotaFromQuotaManager();
EXPECT_EQ(quota::kQuotaStatusOk, quota_status());
- EXPECT_EQ(all_file_size + usage_file_size, usage());
+ EXPECT_EQ(all_file_size + usage_file_size + file_path_cost(), usage());
ASSERT_LT(all_file_size, quota());
operation()->Copy(URLForPath(src_dir_path), URLForPath(dest_dir1_path));
MessageLoop::current()->RunAllPending();
+ AddToFilePathCost(ComputeFilePathCost(child_dir_path_) +
+ ComputeFilePathCost(child_file1_path_) +
+ ComputeFilePathCost(child_file2_path_) +
+ ComputeFilePathCost(grandchild_file1_path_) +
+ ComputeFilePathCost(grandchild_file2_path_));
EXPECT_EQ(base::PLATFORM_FILE_OK, status());
EXPECT_TRUE(VirtualDirectoryExists(src_dir_path.Append(
@@ -305,26 +350,86 @@ TEST_F(FileSystemQuotaTest, TestCopySuccessSrcDirRecursive) {
grandchild_file1_path_.BaseName())));
EXPECT_EQ(2 * all_file_size, ActualSize());
- EXPECT_EQ(2 * all_file_size + usage_file_size, SizeInUsageFile());
+ EXPECT_EQ(2 * all_file_size + usage_file_size + file_path_cost(),
+ SizeInUsageFile());
GetUsageAndQuotaFromQuotaManager();
EXPECT_EQ(quota::kQuotaStatusOk, quota_status());
- EXPECT_EQ(2 * all_file_size + usage_file_size, usage());
+ EXPECT_EQ(2 * all_file_size + usage_file_size + file_path_cost(), usage());
ASSERT_LT(2 * all_file_size, quota());
operation()->Copy(URLForPath(child_dir_path_), URLForPath(dest_dir2_path));
MessageLoop::current()->RunAllPending();
+ AddToFilePathCost(ComputeFilePathCost(dest_dir2_path) +
+ ComputeFilePathCost(grandchild_file1_path_) +
+ ComputeFilePathCost(grandchild_file2_path_));
EXPECT_EQ(base::PLATFORM_FILE_OK, status());
EXPECT_EQ(2 * child_file_size + 3 * grandchild_file_size,
ActualSize());
- EXPECT_EQ(2 * child_file_size + 3 * grandchild_file_size + usage_file_size,
- SizeInUsageFile());
+ EXPECT_EQ(2 * child_file_size + 3 * grandchild_file_size + usage_file_size +
+ file_path_cost(), SizeInUsageFile());
GetUsageAndQuotaFromQuotaManager();
EXPECT_EQ(quota::kQuotaStatusOk, quota_status());
- EXPECT_EQ(2 * child_file_size + 3 * grandchild_file_size + usage_file_size,
- usage());
+ EXPECT_EQ(2 * child_file_size + 3 * grandchild_file_size + usage_file_size +
+ file_path_cost(), usage());
ASSERT_LT(2 * child_file_size + 3 * grandchild_file_size, quota());
}
+void FileSystemObfuscatedQuotaTest::SetUp() {
+ ASSERT_TRUE(work_dir_.CreateUniqueTempDir());
+ FilePath filesystem_dir_path = work_dir_.path().AppendASCII("filesystem");
+ file_util::CreateDirectory(filesystem_dir_path);
+
+ quota_manager_ = new quota::QuotaManager(
+ false /* is_incognito */,
+ filesystem_dir_path,
+ base::MessageLoopProxy::CreateForCurrentThread(),
+ base::MessageLoopProxy::CreateForCurrentThread(),
+ NULL);
+
+ file_system_context_ = new FileSystemContext(
+ base::MessageLoopProxy::CreateForCurrentThread(),
+ base::MessageLoopProxy::CreateForCurrentThread(),
+ new quota::MockSpecialStoragePolicy(),
+ quota_manager_->proxy(),
+ filesystem_dir_path,
+ false /* incognito */,
+ true /* allow_file_access_from_files */,
+ false /* unlimitedquota */,
+ NULL);
+
+ test_helper_.SetUp(file_system_context_,
+ NULL /* sandbox_provider's internal file_util */);
+}
+
+TEST_F(FileSystemObfuscatedQuotaTest, TestRevokeUsageCache) {
+ FilePath dir_path = FilePath(FILE_PATH_LITERAL("test"));
+ CreateVirtualDirectory(dir_path);
+ PrepareFileSet(dir_path);
+
+ operation()->Truncate(URLForPath(child_file1_path_), 3000);
+ operation()->Truncate(URLForPath(child_file2_path_), 400);
+ operation()->Truncate(URLForPath(grandchild_file1_path_), 10);
+ operation()->Truncate(URLForPath(grandchild_file2_path_), 6);
+ MessageLoop::current()->RunAllPending();
+
+ const int64 all_file_size = 3000 + 400 + 10 + 6;
+
+ EXPECT_EQ(all_file_size + file_path_cost(), SizeInUsageFile());
+ GetUsageAndQuotaFromQuotaManager();
+ EXPECT_EQ(quota::kQuotaStatusOk, quota_status());
+ EXPECT_EQ(all_file_size + file_path_cost(), usage());
+ ASSERT_LT(all_file_size, quota());
+
+ RevokeUsageCache();
+ EXPECT_EQ(-1, SizeInUsageFile());
+
+ GetUsageAndQuotaFromQuotaManager();
+ EXPECT_EQ(quota::kQuotaStatusOk, quota_status());
+ EXPECT_EQ(all_file_size + file_path_cost(), SizeInUsageFile());
+ EXPECT_EQ(all_file_size + file_path_cost(), usage());
+ ASSERT_LT(all_file_size, quota());
+}
+
} // namespace fileapi
diff --git a/webkit/fileapi/file_system_test_helper.cc b/webkit/fileapi/file_system_test_helper.cc
index 6eb3538..dd5bfa4 100644
--- a/webkit/fileapi/file_system_test_helper.cc
+++ b/webkit/fileapi/file_system_test_helper.cc
@@ -165,6 +165,10 @@ int64 FileSystemTestOriginHelper::GetCachedOriginUsage() const {
return FileSystemUsageCache::GetUsage(GetUsageCachePath());
}
+bool FileSystemTestOriginHelper::RevokeUsageCache() const {
+ return file_util::Delete(GetUsageCachePath(), false);
+}
+
int64 FileSystemTestOriginHelper::ComputeCurrentOriginUsage() const {
// Depending on the file_util GetOriginRootPath() may include usage
// cache file size or may not. Here we subtract the initial size to
diff --git a/webkit/fileapi/file_system_test_helper.h b/webkit/fileapi/file_system_test_helper.h
index 5f8ab88..2092248 100644
--- a/webkit/fileapi/file_system_test_helper.h
+++ b/webkit/fileapi/file_system_test_helper.h
@@ -60,6 +60,7 @@ class FileSystemTestOriginHelper {
FilePath GetUsageCachePath() const;
int64 GetCachedOriginUsage() const;
+ bool RevokeUsageCache() const;
int64 ComputeCurrentOriginUsage() const;
FileSystemOperation* NewOperation(
diff --git a/webkit/fileapi/local_file_system_file_util.cc b/webkit/fileapi/local_file_system_file_util.cc
index 729da6a..535d008 100644
--- a/webkit/fileapi/local_file_system_file_util.cc
+++ b/webkit/fileapi/local_file_system_file_util.cc
@@ -121,6 +121,7 @@ PlatformFileError LocalFileSystemFileUtil::CopyOrMoveFile(
context, local_src_path, local_dest_path, copy);
}
+// TODO(dmikurube): Make it independent from CopyOrMoveFile.
PlatformFileError LocalFileSystemFileUtil::CopyInForeignFile(
FileSystemOperationContext* context,
const FilePath& src_file_path,
diff --git a/webkit/fileapi/obfuscated_file_system_file_util.cc b/webkit/fileapi/obfuscated_file_system_file_util.cc
index 1ab2922..961eae9 100644
--- a/webkit/fileapi/obfuscated_file_system_file_util.cc
+++ b/webkit/fileapi/obfuscated_file_system_file_util.cc
@@ -265,6 +265,12 @@ PlatformFileError ObfuscatedFileSystemFileUtil::CreateDirectory(
}
if (!recursive && components.size() - index > 1)
return base::PLATFORM_FILE_ERROR_NOT_FOUND;
+ // TODO(dmikurube): Eliminate do_not_write_actually in future.
+ bool do_not_write_actually = context->do_not_write_actually();
+ context->set_do_not_write_actually(true);
+ underlying_file_util_->CreateDirectory(context,
+ FilePath(), exclusive, recursive);
+ context->set_do_not_write_actually(do_not_write_actually);
for (; index < components.size(); ++index) {
FileInfo file_info;
file_info.name = components[index];
@@ -762,15 +768,17 @@ PlatformFileError ObfuscatedFileSystemFileUtil::CreateFile(
return base::PLATFORM_FILE_ERROR_FAILED;
path = path.AppendASCII(StringPrintf("%02" PRIu64, directory_number));
- PlatformFileError error;
- error = underlying_file_util_->CreateDirectory(
- context, path, false /* exclusive */, false /* recursive */);
- if (base::PLATFORM_FILE_OK != error)
- return error;
+ if (file_util::DirectoryExists(path.DirName())) {
+ if (!file_util::DirectoryExists(path) && !file_util::CreateDirectory(path))
+ return base::PLATFORM_FILE_ERROR_FAILED;
+ } else {
+ return base::PLATFORM_FILE_ERROR_NOT_FOUND;
+ }
path = path.AppendASCII(StringPrintf("%08" PRIu64, number));
FilePath data_path = LocalPathToDataPath(origin_url, type, path);
if (data_path.empty())
return base::PLATFORM_FILE_ERROR_FAILED;
+ PlatformFileError error;
bool created = false;
if (!source_path.empty()) {
DCHECK(!file_flags);
diff --git a/webkit/fileapi/quota_file_util.cc b/webkit/fileapi/quota_file_util.cc
index 93f3522..83daf74 100644
--- a/webkit/fileapi/quota_file_util.cc
+++ b/webkit/fileapi/quota_file_util.cc
@@ -18,31 +18,11 @@ namespace fileapi {
const int64 QuotaFileUtil::kNoLimit = kint64max;
-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;
+// See the comment in the header file as for these constants.
+const int64 QuotaFileUtil::kFilePathCostPerChar = 2;
+const int64 QuotaFileUtil::kFilePathCostPerFile = 146;
- return true;
-}
+namespace {
// A helper class to hook quota_util() methods before and after modifications.
class ScopedOriginUpdateHelper {
@@ -71,8 +51,9 @@ class ScopedOriginUpdateHelper {
}
void NotifyUpdate(int64 growth) {
- operation_context_->set_allowed_bytes_growth(
- operation_context_->allowed_bytes_growth() - growth);
+ if (operation_context_->allowed_bytes_growth() != QuotaFileUtil::kNoLimit)
+ 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);
@@ -94,6 +75,124 @@ QuotaFileUtil* QuotaFileUtil::GetInstance() {
return Singleton<QuotaFileUtil>::get();
}
+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 = FileSystemFileUtil::GetInstance()->
+ 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 = FileSystemFileUtil::GetInstance()->
+ 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 = FileSystemFileUtil::GetInstance()->
+ 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,
@@ -115,14 +214,21 @@ 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 (!CanCopy(src_file_path, dest_file_path, allowed_bytes_growth,
- &growth))
+ if (!CanCopyFile(fs_context, src_file_path, dest_file_path,
+ allowed_bytes_growth, &growth))
return base::PLATFORM_FILE_ERROR_NO_SPACE;
- } else {
+ } else { // move
+ int64 allowed_bytes_growth = fs_context->allowed_bytes_growth();
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;
+ 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;
}
base::PlatformFileError error = FileSystemFileUtil::GetInstance()->
@@ -148,9 +254,10 @@ base::PlatformFileError QuotaFileUtil::DeleteFile(
int64 growth = 0;
base::PlatformFileInfo file_info;
- if (!file_util::GetFileInfo(file_path, &file_info))
- file_info.size = 0;
- growth = -file_info.size;
+ if (file_util::GetFileInfo(file_path, &file_info)) {
+ growth -= file_info.size +
+ ComputeFilePathCost(fs_context->src_virtual_path());
+ }
base::PlatformFileError error = FileSystemFileUtil::GetInstance()->
DeleteFile(fs_context, file_path);
@@ -161,6 +268,28 @@ 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 = FileSystemFileUtil::GetInstance()->
+ 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,
@@ -189,4 +318,32 @@ 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
diff --git a/webkit/fileapi/quota_file_util.h b/webkit/fileapi/quota_file_util.h
index eb34541..e7fc2d7 100644
--- a/webkit/fileapi/quota_file_util.h
+++ b/webkit/fileapi/quota_file_util.h
@@ -18,28 +18,69 @@ class QuotaFileUtil : public FileSystemFileUtil {
static const int64 kNoLimit;
+ // TODO(dmikurube): Make this function variable by the constructor.
+ int64 ComputeFilePathCost(const FilePath& file_path) const;
+
+ virtual base::PlatformFileError CreateOrOpen(
+ FileSystemOperationContext* fs_context,
+ const FilePath& file_path, int file_flags,
+ PlatformFile* file_handle, bool* created) OVERRIDE;
+
+ virtual base::PlatformFileError EnsureFileExists(
+ FileSystemOperationContext* fs_context,
+ const FilePath& file_path,
+ bool* created) OVERRIDE;
+
+ virtual base::PlatformFileError CreateDirectory(
+ FileSystemOperationContext* fs_context,
+ const FilePath& file_path,
+ bool exclusive,
+ bool recursive) OVERRIDE;
+
virtual base::PlatformFileError CopyOrMoveFile(
- FileSystemOperationContext* fs_context,
- const FilePath& src_file_path,
- const FilePath& dest_file_path,
- bool copy);
+ FileSystemOperationContext* fs_context,
+ const FilePath& src_file_path,
+ const FilePath& dest_file_path,
+ bool copy) OVERRIDE;
virtual base::PlatformFileError DeleteFile(
FileSystemOperationContext* fs_context,
- const FilePath& file_path);
+ const FilePath& file_path) OVERRIDE;
- // TODO(dmikurube): Charge some amount of quota for directories.
+ virtual base::PlatformFileError DeleteSingleDirectory(
+ FileSystemOperationContext* fs_context,
+ const FilePath& file_path) OVERRIDE;
virtual base::PlatformFileError Truncate(
FileSystemOperationContext* fs_context,
const FilePath& path,
- int64 length);
+ int64 length) OVERRIDE;
friend struct DefaultSingletonTraits<QuotaFileUtil>;
DISALLOW_COPY_AND_ASSIGN(QuotaFileUtil);
protected:
QuotaFileUtil() {}
+
+ private:
+ // TODO(dmikurube): Make these constants variable by the constructor.
+ //
+ // These values are based on Obfuscation DB. See crbug.com/86114 for the
+ // source of these numbers. These should be revisited if
+ // * the underlying tables change,
+ // * indexes in levelDB change, or
+ // * another path name indexer is provided in addition to levelDB.
+ //
+ // When these values are changed, the usage cache should be bumped up.
+ static const int64 kFilePathCostPerChar;
+ static const int64 kFilePathCostPerFile;
+
+ bool CanCopyFile(
+ FileSystemOperationContext* fs_context,
+ const FilePath& src_file_path,
+ const FilePath& dest_file_path,
+ int64 allowed_bytes_growth,
+ int64* growth) const;
};
} // namespace fileapi
diff --git a/webkit/fileapi/quota_file_util_unittest.cc b/webkit/fileapi/quota_file_util_unittest.cc
index 930026e..f8c90c1 100644
--- a/webkit/fileapi/quota_file_util_unittest.cc
+++ b/webkit/fileapi/quota_file_util_unittest.cc
@@ -17,19 +17,20 @@
#include "webkit/fileapi/file_system_test_helper.h"
#include "webkit/fileapi/file_system_types.h"
#include "webkit/fileapi/file_system_usage_cache.h"
-#include "webkit/fileapi/obfuscated_file_system_file_util.h"
+#include "webkit/fileapi/quota_file_util.h"
namespace fileapi {
class QuotaFileUtilTest : public testing::Test {
public:
QuotaFileUtilTest()
- : callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
+ : quota_file_util_(QuotaFileUtil::GetInstance()),
+ callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
}
void SetUp() {
ASSERT_TRUE(data_dir_.CreateUniqueTempDir());
- quota_test_helper_.SetUp(data_dir_.path(), QuotaFileUtil::GetInstance());
+ quota_test_helper_.SetUp(data_dir_.path(), quota_file_util_);
obfuscated_test_helper_.SetUp(
quota_test_helper_.file_system_context(), NULL);
base_dir_ = obfuscated_test_helper_.GetOriginRootPath();
@@ -41,36 +42,58 @@ class QuotaFileUtilTest : public testing::Test {
}
protected:
- FileSystemOperationContext* NewContext() {
- return quota_test_helper_.NewOperationContext();
+ FileSystemOperationContext* NewContext(
+ int64 allowed_bytes_growth,
+ const FilePath& src_virtual_path,
+ const FilePath& dest_virtual_path) {
+ FileSystemOperationContext* context =
+ quota_test_helper_.NewOperationContext();
+ context->set_allowed_bytes_growth(allowed_bytes_growth);
+ context->set_src_virtual_path(src_virtual_path);
+ context->set_dest_virtual_path(dest_virtual_path);
+ return context;
}
FilePath Path(const std::string& file_name) {
return base_dir_.AppendASCII(file_name);
}
- base::PlatformFileError CreateFile(const char* file_name,
- base::PlatformFile* file_handle, bool* created) {
- int file_flags = base::PLATFORM_FILE_CREATE |
- base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_ASYNC;
-
- scoped_ptr<FileSystemOperationContext> context(NewContext());
- return QuotaFileUtil::GetInstance()->CreateOrOpen(
- context.get(), Path(file_name), file_flags, file_handle, created);
+ int64 ComputeFilePathCost(const char* file_name) {
+ return quota_file_util_->ComputeFilePathCost(
+ FilePath().AppendASCII(file_name));
}
- base::PlatformFileError EnsureFileExists(const char* file_name,
- bool* created) {
- scoped_ptr<FileSystemOperationContext> context(NewContext());
+ base::PlatformFileError EnsureFileExists(
+ const char* file_name, bool* created) {
+ int64 file_path_cost = ComputeFilePathCost(file_name);
+ scoped_ptr<FileSystemOperationContext> context(NewContext(
+ file_path_cost, Path(file_name), FilePath()));
return QuotaFileUtil::GetInstance()->EnsureFileExists(
context.get(), Path(file_name), created);
}
+ base::PlatformFileError Truncate(
+ const char* file_name, int64 size, int64 quota) {
+ scoped_ptr<FileSystemOperationContext> context(NewContext(
+ quota, Path(file_name), FilePath()));
+ return QuotaFileUtil::GetInstance()->Truncate(
+ context.get(), Path(file_name), size);
+ }
+
+ void CheckUsage(int64 estimated_content, int64 estimated_path) {
+ ASSERT_EQ(estimated_content + estimated_path,
+ quota_test_helper().GetCachedOriginUsage());
+ ASSERT_EQ(quota_test_helper().ComputeCurrentOriginUsage() +
+ estimated_path,
+ quota_test_helper().GetCachedOriginUsage());
+ }
+
const FileSystemTestOriginHelper& quota_test_helper() const {
return quota_test_helper_;
}
private:
+ QuotaFileUtil* quota_file_util_;
ScopedTempDir data_dir_;
FilePath base_dir_;
FileSystemTestOriginHelper obfuscated_test_helper_;
@@ -82,25 +105,54 @@ class QuotaFileUtilTest : public testing::Test {
TEST_F(QuotaFileUtilTest, CreateAndClose) {
const char *file_name = "test_file";
+ int64 file_path_cost = ComputeFilePathCost(file_name);
+
+ int file_flags = base::PLATFORM_FILE_CREATE |
+ base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_ASYNC;
base::PlatformFile file_handle;
bool created;
+ scoped_ptr<FileSystemOperationContext> context;
+
+ created = false;
+ context.reset(NewContext(file_path_cost - 1, Path(file_name), FilePath()));
+ ASSERT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE,
+ QuotaFileUtil::GetInstance()->CreateOrOpen(
+ context.get(), Path(file_name), file_flags, &file_handle, &created));
+ ASSERT_FALSE(created);
+
+ created = false;
+ context.reset(NewContext(file_path_cost, Path(file_name), FilePath()));
ASSERT_EQ(base::PLATFORM_FILE_OK,
- CreateFile(file_name, &file_handle, &created));
+ QuotaFileUtil::GetInstance()->CreateOrOpen(
+ context.get(), Path(file_name), file_flags, &file_handle, &created));
ASSERT_TRUE(created);
- scoped_ptr<FileSystemOperationContext> context(NewContext());
+ context.reset(NewContext(0, FilePath(), FilePath()));
EXPECT_EQ(base::PLATFORM_FILE_OK,
QuotaFileUtil::GetInstance()->Close(context.get(), file_handle));
}
TEST_F(QuotaFileUtilTest, EnsureFileExists) {
const char *file_name = "foobar";
+
bool created;
+ scoped_ptr<FileSystemOperationContext> context;
+
+ created = false;
+ context.reset(NewContext(
+ ComputeFilePathCost(file_name) - 1, Path(file_name), FilePath()));
+ ASSERT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE,
+ QuotaFileUtil::GetInstance()->EnsureFileExists(
+ context.get(), Path(file_name), &created));
+ ASSERT_FALSE(created);
+
+ created = false;
ASSERT_EQ(base::PLATFORM_FILE_OK, EnsureFileExists(file_name, &created));
ASSERT_TRUE(created);
+ created = false;
ASSERT_EQ(base::PLATFORM_FILE_OK, EnsureFileExists(file_name, &created));
- EXPECT_FALSE(created);
+ ASSERT_FALSE(created);
}
TEST_F(QuotaFileUtilTest, Truncate) {
@@ -110,294 +162,248 @@ TEST_F(QuotaFileUtilTest, Truncate) {
ASSERT_EQ(base::PLATFORM_FILE_OK, EnsureFileExists(file_name, &created));
ASSERT_TRUE(created);
- scoped_ptr<FileSystemOperationContext> truncate_context;
+ scoped_ptr<FileSystemOperationContext> context;
- truncate_context.reset(NewContext());
- truncate_context->set_allowed_bytes_growth(1020);
- ASSERT_EQ(base::PLATFORM_FILE_OK,
- QuotaFileUtil::GetInstance()->Truncate(truncate_context.get(),
- Path(file_name),
- 1020));
- ASSERT_EQ(1020, quota_test_helper().GetCachedOriginUsage());
- ASSERT_EQ(quota_test_helper().ComputeCurrentOriginUsage(),
- quota_test_helper().GetCachedOriginUsage());
-
- truncate_context.reset(NewContext());
- truncate_context->set_allowed_bytes_growth(0);
- ASSERT_EQ(base::PLATFORM_FILE_OK,
- QuotaFileUtil::GetInstance()->Truncate(truncate_context.get(),
- Path(file_name),
- 0));
- ASSERT_EQ(0, quota_test_helper().GetCachedOriginUsage());
- ASSERT_EQ(quota_test_helper().ComputeCurrentOriginUsage(),
- quota_test_helper().GetCachedOriginUsage());
-
- truncate_context.reset(NewContext());
- truncate_context->set_allowed_bytes_growth(1020);
- EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE,
- QuotaFileUtil::GetInstance()->Truncate(truncate_context.get(),
- Path(file_name),
- 1021));
- ASSERT_EQ(0, quota_test_helper().GetCachedOriginUsage());
- ASSERT_EQ(quota_test_helper().ComputeCurrentOriginUsage(),
- quota_test_helper().GetCachedOriginUsage());
+ ASSERT_EQ(base::PLATFORM_FILE_OK, Truncate(file_name, 1020, 1020));
+ CheckUsage(1020, ComputeFilePathCost(file_name));
+
+ ASSERT_EQ(base::PLATFORM_FILE_OK, Truncate(file_name, 0, 0));
+ CheckUsage(0, ComputeFilePathCost(file_name));
+
+ ASSERT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE,
+ Truncate(file_name, 1021, 1020));
+ CheckUsage(0, ComputeFilePathCost(file_name));
}
TEST_F(QuotaFileUtilTest, CopyFile) {
+ int64 file_path_cost = 0;
const char *from_file = "fromfile";
- const char *obstacle_file = "obstaclefile";
+ const char *prior_file = "obstaclefile";
const char *to_file1 = "tofile1";
- const char *to_file2 = "tofile2";
+ const char *to_file2 = "tomuchlongerfile2";
bool created;
ASSERT_EQ(base::PLATFORM_FILE_OK, EnsureFileExists(from_file, &created));
ASSERT_TRUE(created);
- ASSERT_EQ(base::PLATFORM_FILE_OK, EnsureFileExists(obstacle_file, &created));
+ file_path_cost += ComputeFilePathCost(from_file);
+ ASSERT_EQ(base::PLATFORM_FILE_OK, EnsureFileExists(prior_file, &created));
ASSERT_TRUE(created);
+ file_path_cost += ComputeFilePathCost(prior_file);
scoped_ptr<FileSystemOperationContext> context;
- context.reset(NewContext());
- context->set_allowed_bytes_growth(QuotaFileUtil::kNoLimit);
- ASSERT_EQ(base::PLATFORM_FILE_OK,
- QuotaFileUtil::GetInstance()->Truncate(context.get(),
- Path(from_file),
- 1020));
- ASSERT_EQ(1020, quota_test_helper().GetCachedOriginUsage());
- ASSERT_EQ(quota_test_helper().ComputeCurrentOriginUsage(),
- quota_test_helper().GetCachedOriginUsage());
-
- context.reset(NewContext());
- context->set_allowed_bytes_growth(QuotaFileUtil::kNoLimit);
- ASSERT_EQ(base::PLATFORM_FILE_OK,
- QuotaFileUtil::GetInstance()->Truncate(context.get(),
- Path(obstacle_file),
- 1));
- ASSERT_EQ(1021, quota_test_helper().GetCachedOriginUsage());
- ASSERT_EQ(quota_test_helper().ComputeCurrentOriginUsage(),
- quota_test_helper().GetCachedOriginUsage());
-
- context.reset(NewContext());
- context->set_allowed_bytes_growth(1020);
+ ASSERT_EQ(base::PLATFORM_FILE_OK, Truncate(from_file, 1020, 1020));
+ CheckUsage(1020, file_path_cost);
+
+ ASSERT_EQ(base::PLATFORM_FILE_OK, Truncate(prior_file, 1, 1));
+ CheckUsage(1021, file_path_cost);
+
+ context.reset(NewContext(1020 + ComputeFilePathCost(to_file1),
+ Path(from_file), Path(to_file1)));
ASSERT_EQ(base::PLATFORM_FILE_OK,
QuotaFileUtil::GetInstance()->Copy(context.get(),
Path(from_file),
Path(to_file1)));
- ASSERT_EQ(2041, quota_test_helper().GetCachedOriginUsage());
- ASSERT_EQ(quota_test_helper().ComputeCurrentOriginUsage(),
- quota_test_helper().GetCachedOriginUsage());
+ file_path_cost += ComputeFilePathCost(to_file1);
+ CheckUsage(2041, file_path_cost);
- context.reset(NewContext());
- context->set_allowed_bytes_growth(1019);
+ context.reset(NewContext(1020 + ComputeFilePathCost(to_file2) - 1,
+ Path(from_file), Path(to_file2)));
ASSERT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE,
QuotaFileUtil::GetInstance()->Copy(context.get(),
Path(from_file),
Path(to_file2)));
- ASSERT_EQ(2041, quota_test_helper().GetCachedOriginUsage());
- ASSERT_EQ(quota_test_helper().ComputeCurrentOriginUsage(),
- quota_test_helper().GetCachedOriginUsage());
+ CheckUsage(2041, file_path_cost);
- context.reset(NewContext());
- context->set_allowed_bytes_growth(1019);
+ context.reset(NewContext(1019, Path(from_file), Path(prior_file)));
ASSERT_EQ(base::PLATFORM_FILE_OK,
QuotaFileUtil::GetInstance()->Copy(context.get(),
Path(from_file),
- Path(obstacle_file)));
- ASSERT_EQ(3060, quota_test_helper().GetCachedOriginUsage());
- ASSERT_EQ(quota_test_helper().ComputeCurrentOriginUsage(),
- quota_test_helper().GetCachedOriginUsage());
+ Path(prior_file)));
+ CheckUsage(3060, file_path_cost);
}
TEST_F(QuotaFileUtilTest, CopyDirectory) {
+ int64 file_path_cost = 0;
const char *from_dir = "fromdir";
const char *from_file1 = "fromdir/fromfile1";
- const char *from_file2 = "fromdir/fromfile2";
+ const char *from_file2 = "fromdir/fromlongerfile2";
const char *to_dir1 = "todir1";
- const char *to_dir2 = "todir2";
+ const char *to_dir2 = "tolongerdir2";
bool created;
scoped_ptr<FileSystemOperationContext> context;
- context.reset(NewContext());
+ context.reset(NewContext(ComputeFilePathCost(from_dir),
+ Path(from_dir), FilePath()));
ASSERT_EQ(base::PLATFORM_FILE_OK,
QuotaFileUtil::GetInstance()->CreateDirectory(context.get(),
Path(from_dir),
false, false));
+ file_path_cost += ComputeFilePathCost(from_dir);
+
ASSERT_EQ(base::PLATFORM_FILE_OK, EnsureFileExists(from_file1, &created));
ASSERT_TRUE(created);
+ file_path_cost += ComputeFilePathCost(from_file1);
ASSERT_EQ(base::PLATFORM_FILE_OK, EnsureFileExists(from_file2, &created));
ASSERT_TRUE(created);
+ file_path_cost += ComputeFilePathCost(from_file2);
- context.reset(NewContext());
- context->set_allowed_bytes_growth(QuotaFileUtil::kNoLimit);
- ASSERT_EQ(base::PLATFORM_FILE_OK,
- QuotaFileUtil::GetInstance()->Truncate(context.get(),
- Path(from_file1),
- 520));
- ASSERT_EQ(520, quota_test_helper().GetCachedOriginUsage());
- ASSERT_EQ(quota_test_helper().ComputeCurrentOriginUsage(),
- quota_test_helper().GetCachedOriginUsage());
-
- context.reset(NewContext());
- context->set_allowed_bytes_growth(QuotaFileUtil::kNoLimit);
- ASSERT_EQ(base::PLATFORM_FILE_OK,
- QuotaFileUtil::GetInstance()->Truncate(context.get(),
- Path(from_file2),
- 500));
- ASSERT_EQ(1020, quota_test_helper().GetCachedOriginUsage());
- ASSERT_EQ(quota_test_helper().ComputeCurrentOriginUsage(),
- quota_test_helper().GetCachedOriginUsage());
-
- context.reset(NewContext());
- context->set_allowed_bytes_growth(1020);
+ ASSERT_EQ(base::PLATFORM_FILE_OK, Truncate(from_file1, 520, 520));
+ CheckUsage(520, file_path_cost);
+
+ ASSERT_EQ(base::PLATFORM_FILE_OK, Truncate(from_file2, 500, 500));
+ CheckUsage(1020, file_path_cost);
+
+ context.reset(NewContext(1020 +
+ ComputeFilePathCost(to_dir1) +
+ ComputeFilePathCost(from_file1) +
+ ComputeFilePathCost(from_file2),
+ Path(from_dir), Path(to_dir1)));
ASSERT_EQ(base::PLATFORM_FILE_OK,
QuotaFileUtil::GetInstance()->Copy(context.get(),
Path(from_dir),
Path(to_dir1)));
- ASSERT_EQ(2040, quota_test_helper().GetCachedOriginUsage());
- ASSERT_EQ(quota_test_helper().ComputeCurrentOriginUsage(),
- quota_test_helper().GetCachedOriginUsage());
-
- context.reset(NewContext());
- context->set_allowed_bytes_growth(1019);
+ file_path_cost += ComputeFilePathCost(to_dir1) +
+ ComputeFilePathCost(from_file1) +
+ ComputeFilePathCost(from_file2);
+ CheckUsage(2040, file_path_cost);
+
+ context.reset(NewContext(1020 +
+ ComputeFilePathCost(to_dir2) +
+ ComputeFilePathCost(from_file1) +
+ ComputeFilePathCost(from_file2) - 1,
+ Path(from_dir), Path(to_dir2)));
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE,
QuotaFileUtil::GetInstance()->Copy(context.get(),
Path(from_dir),
Path(to_dir2)));
- ASSERT_TRUE(2540 == quota_test_helper().GetCachedOriginUsage() ||
- 2560 == quota_test_helper().GetCachedOriginUsage());
- ASSERT_EQ(quota_test_helper().ComputeCurrentOriginUsage(),
- quota_test_helper().GetCachedOriginUsage());
+ int64 file_path_cost1 = file_path_cost +
+ ComputeFilePathCost(to_dir2) + ComputeFilePathCost(from_file1);
+ int64 file_path_cost2 = file_path_cost +
+ ComputeFilePathCost(to_dir2) + ComputeFilePathCost(from_file2);
+ ASSERT_TRUE((2560 + file_path_cost1) ==
+ quota_test_helper().GetCachedOriginUsage() ||
+ (2540 + file_path_cost2) ==
+ quota_test_helper().GetCachedOriginUsage());
+ ASSERT_TRUE((quota_test_helper().ComputeCurrentOriginUsage() + file_path_cost1
+ == quota_test_helper().GetCachedOriginUsage()) ||
+ (quota_test_helper().ComputeCurrentOriginUsage() + file_path_cost2
+ == quota_test_helper().GetCachedOriginUsage()));
}
TEST_F(QuotaFileUtilTest, MoveFile) {
+ int64 file_path_cost = 0;
const char *from_file = "fromfile";
- const char *obstacle_file = "obstaclefile";
+ const char *prior_file = "obstaclelongnamefile";
const char *to_file = "tofile";
bool created;
ASSERT_EQ(base::PLATFORM_FILE_OK, EnsureFileExists(from_file, &created));
ASSERT_TRUE(created);
+ file_path_cost += ComputeFilePathCost(from_file);
scoped_ptr<FileSystemOperationContext> context;
- context.reset(NewContext());
- context->set_allowed_bytes_growth(QuotaFileUtil::kNoLimit);
- ASSERT_EQ(base::PLATFORM_FILE_OK,
- QuotaFileUtil::GetInstance()->Truncate(context.get(),
- Path(from_file),
- 1020));
- ASSERT_EQ(1020, quota_test_helper().GetCachedOriginUsage());
- ASSERT_EQ(quota_test_helper().ComputeCurrentOriginUsage(),
- quota_test_helper().GetCachedOriginUsage());
-
- context.reset(NewContext());
- context->set_allowed_bytes_growth(0);
+ ASSERT_EQ(base::PLATFORM_FILE_OK, Truncate(from_file, 1020, 1020));
+ CheckUsage(1020, file_path_cost);
+
+ context.reset(NewContext(0, Path(from_file), Path(to_file)));
ASSERT_EQ(base::PLATFORM_FILE_OK,
QuotaFileUtil::GetInstance()->Move(context.get(),
Path(from_file),
Path(to_file)));
- ASSERT_EQ(1020, quota_test_helper().GetCachedOriginUsage());
- ASSERT_EQ(quota_test_helper().ComputeCurrentOriginUsage(),
- quota_test_helper().GetCachedOriginUsage());
+ file_path_cost -= ComputeFilePathCost(from_file);
+ file_path_cost += ComputeFilePathCost(to_file);
+ CheckUsage(1020, file_path_cost);
ASSERT_EQ(base::PLATFORM_FILE_OK, EnsureFileExists(from_file, &created));
ASSERT_TRUE(created);
- ASSERT_EQ(base::PLATFORM_FILE_OK, EnsureFileExists(obstacle_file, &created));
+ file_path_cost += ComputeFilePathCost(from_file);
+ ASSERT_EQ(base::PLATFORM_FILE_OK, EnsureFileExists(prior_file, &created));
ASSERT_TRUE(created);
+ file_path_cost += ComputeFilePathCost(prior_file);
- context.reset(NewContext());
- context->set_allowed_bytes_growth(QuotaFileUtil::kNoLimit);
- ASSERT_EQ(base::PLATFORM_FILE_OK,
- QuotaFileUtil::GetInstance()->Truncate(context.get(),
- Path(from_file),
- 1020));
- ASSERT_EQ(2040, quota_test_helper().GetCachedOriginUsage());
- ASSERT_EQ(quota_test_helper().ComputeCurrentOriginUsage(),
- quota_test_helper().GetCachedOriginUsage());
-
- context.reset(NewContext());
- context->set_allowed_bytes_growth(QuotaFileUtil::kNoLimit);
- ASSERT_EQ(base::PLATFORM_FILE_OK,
- QuotaFileUtil::GetInstance()->Truncate(context.get(),
- Path(obstacle_file),
- 1));
- ASSERT_EQ(2041, quota_test_helper().GetCachedOriginUsage());
- ASSERT_EQ(quota_test_helper().ComputeCurrentOriginUsage(),
- quota_test_helper().GetCachedOriginUsage());
-
- context.reset(NewContext());
- context->set_allowed_bytes_growth(0);
+ ASSERT_EQ(base::PLATFORM_FILE_OK, Truncate(from_file, 1020, 1020));
+ CheckUsage(2040, file_path_cost);
+
+ ASSERT_EQ(base::PLATFORM_FILE_OK, Truncate(prior_file, 1, 1));
+ CheckUsage(2041, file_path_cost);
+
+ context.reset(NewContext(ComputeFilePathCost(prior_file) -
+ ComputeFilePathCost(from_file) - 1 - 1,
+ Path(from_file), Path(prior_file)));
+ ASSERT_EQ(base::PLATFORM_FILE_ERROR_NO_SPACE,
+ QuotaFileUtil::GetInstance()->Move(context.get(),
+ Path(from_file),
+ Path(prior_file)));
+ CheckUsage(2041, file_path_cost);
+
+ context.reset(NewContext(ComputeFilePathCost(prior_file) -
+ ComputeFilePathCost(from_file) - 1,
+ Path(from_file), Path(prior_file)));
ASSERT_EQ(base::PLATFORM_FILE_OK,
QuotaFileUtil::GetInstance()->Move(context.get(),
Path(from_file),
- Path(obstacle_file)));
- ASSERT_EQ(2040, quota_test_helper().GetCachedOriginUsage());
- ASSERT_EQ(quota_test_helper().ComputeCurrentOriginUsage(),
- quota_test_helper().GetCachedOriginUsage());
+ Path(prior_file)));
+ file_path_cost -= ComputeFilePathCost(from_file);
+ file_path_cost += ComputeFilePathCost(prior_file);
+ CheckUsage(2040, file_path_cost);
}
TEST_F(QuotaFileUtilTest, MoveDirectory) {
+ int64 file_path_cost = 0;
const char *from_dir = "fromdir";
const char *from_file = "fromdir/fromfile";
const char *to_dir1 = "todir1";
- const char *to_dir2 = "todir2";
+ const char *to_dir2 = "tolongnamedir2";
bool created;
scoped_ptr<FileSystemOperationContext> context;
- context.reset(NewContext());
+ context.reset(NewContext(QuotaFileUtil::kNoLimit,
+ Path(from_dir), FilePath()));
ASSERT_EQ(base::PLATFORM_FILE_OK,
QuotaFileUtil::GetInstance()->CreateDirectory(context.get(),
Path(from_dir),
false, false));
+ file_path_cost += ComputeFilePathCost(from_dir);
ASSERT_EQ(base::PLATFORM_FILE_OK, EnsureFileExists(from_file, &created));
ASSERT_TRUE(created);
+ file_path_cost += ComputeFilePathCost(from_file);
- context.reset(NewContext());
- context->set_allowed_bytes_growth(QuotaFileUtil::kNoLimit);
- ASSERT_EQ(base::PLATFORM_FILE_OK,
- QuotaFileUtil::GetInstance()->Truncate(context.get(),
- Path(from_file),
- 1020));
- ASSERT_EQ(1020, quota_test_helper().GetCachedOriginUsage());
- ASSERT_EQ(quota_test_helper().ComputeCurrentOriginUsage(),
- quota_test_helper().GetCachedOriginUsage());
-
- context.reset(NewContext());
- context->set_allowed_bytes_growth(1020);
+ ASSERT_EQ(base::PLATFORM_FILE_OK, Truncate(from_file, 1020, 1020));
+ CheckUsage(1020, file_path_cost);
+
+ context.reset(NewContext(1020, Path(from_dir), Path(to_dir1)));
ASSERT_EQ(base::PLATFORM_FILE_OK,
QuotaFileUtil::GetInstance()->Move(context.get(),
Path(from_dir),
Path(to_dir1)));
- ASSERT_EQ(1020, quota_test_helper().GetCachedOriginUsage());
- ASSERT_EQ(quota_test_helper().ComputeCurrentOriginUsage(),
- quota_test_helper().GetCachedOriginUsage());
+ file_path_cost -= ComputeFilePathCost(from_dir);
+ file_path_cost += ComputeFilePathCost(to_dir1);
+ CheckUsage(1020, file_path_cost);
- context.reset(NewContext());
+ context.reset(NewContext(QuotaFileUtil::kNoLimit,
+ Path(from_dir), FilePath()));
ASSERT_EQ(base::PLATFORM_FILE_OK,
QuotaFileUtil::GetInstance()->CreateDirectory(context.get(),
Path(from_dir),
false, false));
+ file_path_cost += ComputeFilePathCost(from_dir);
ASSERT_EQ(base::PLATFORM_FILE_OK, EnsureFileExists(from_file, &created));
ASSERT_TRUE(created);
+ file_path_cost += ComputeFilePathCost(from_file);
- context.reset(NewContext());
- context->set_allowed_bytes_growth(QuotaFileUtil::kNoLimit);
- ASSERT_EQ(base::PLATFORM_FILE_OK,
- QuotaFileUtil::GetInstance()->Truncate(context.get(),
- Path(from_file),
- 1020));
- ASSERT_EQ(2040, quota_test_helper().GetCachedOriginUsage());
- ASSERT_EQ(quota_test_helper().ComputeCurrentOriginUsage(),
- quota_test_helper().GetCachedOriginUsage());
-
- context.reset(NewContext());
- context->set_allowed_bytes_growth(1019);
+ ASSERT_EQ(base::PLATFORM_FILE_OK, Truncate(from_file, 1020, 1020));
+ CheckUsage(2040, file_path_cost);
+
+ context.reset(NewContext(1019, Path(from_dir), Path(to_dir2)));
EXPECT_EQ(base::PLATFORM_FILE_OK,
QuotaFileUtil::GetInstance()->Move(context.get(),
Path(from_dir),
Path(to_dir2)));
- ASSERT_EQ(2040, quota_test_helper().GetCachedOriginUsage());
- ASSERT_EQ(quota_test_helper().ComputeCurrentOriginUsage(),
- quota_test_helper().GetCachedOriginUsage());
+ file_path_cost -= ComputeFilePathCost(from_dir);
+ file_path_cost += ComputeFilePathCost(to_dir2);
+ CheckUsage(2040, file_path_cost);
}
TEST_F(QuotaFileUtilTest, Remove) {
+ int64 file_path_cost = 0;
const char *dir = "dir";
const char *file = "file";
const char *dfile1 = "dir/dfile1";
@@ -407,65 +413,44 @@ TEST_F(QuotaFileUtilTest, Remove) {
ASSERT_EQ(base::PLATFORM_FILE_OK, EnsureFileExists(file, &created));
ASSERT_TRUE(created);
- context.reset(NewContext());
+ file_path_cost += ComputeFilePathCost(file);
+ context.reset(NewContext(QuotaFileUtil::kNoLimit, Path(dir), FilePath()));
ASSERT_EQ(base::PLATFORM_FILE_OK,
QuotaFileUtil::GetInstance()->CreateDirectory(context.get(),
Path(dir),
false, false));
+ file_path_cost += ComputeFilePathCost(dir);
ASSERT_EQ(base::PLATFORM_FILE_OK, EnsureFileExists(dfile1, &created));
ASSERT_TRUE(created);
+ file_path_cost += ComputeFilePathCost(dfile1);
ASSERT_EQ(base::PLATFORM_FILE_OK, EnsureFileExists(dfile2, &created));
ASSERT_TRUE(created);
+ file_path_cost += ComputeFilePathCost(dfile2);
- context.reset(NewContext());
- context->set_allowed_bytes_growth(QuotaFileUtil::kNoLimit);
- ASSERT_EQ(base::PLATFORM_FILE_OK,
- QuotaFileUtil::GetInstance()->Truncate(context.get(),
- Path(file),
- 340));
- ASSERT_EQ(340, quota_test_helper().GetCachedOriginUsage());
- ASSERT_EQ(quota_test_helper().ComputeCurrentOriginUsage(),
- quota_test_helper().GetCachedOriginUsage());
-
- context.reset(NewContext());
- context->set_allowed_bytes_growth(QuotaFileUtil::kNoLimit);
- ASSERT_EQ(base::PLATFORM_FILE_OK,
- QuotaFileUtil::GetInstance()->Truncate(context.get(),
- Path(dfile1),
- 1020));
- ASSERT_EQ(1360, quota_test_helper().GetCachedOriginUsage());
- ASSERT_EQ(quota_test_helper().ComputeCurrentOriginUsage(),
- quota_test_helper().GetCachedOriginUsage());
-
- context.reset(NewContext());
- context->set_allowed_bytes_growth(QuotaFileUtil::kNoLimit);
- ASSERT_EQ(base::PLATFORM_FILE_OK,
- QuotaFileUtil::GetInstance()->Truncate(context.get(),
- Path(dfile2),
- 120));
- ASSERT_EQ(1480, quota_test_helper().GetCachedOriginUsage());
- ASSERT_EQ(quota_test_helper().ComputeCurrentOriginUsage(),
- quota_test_helper().GetCachedOriginUsage());
-
- context.reset(NewContext());
- context->set_allowed_bytes_growth(QuotaFileUtil::kNoLimit);
+ ASSERT_EQ(base::PLATFORM_FILE_OK, Truncate(file, 340, 340));
+ CheckUsage(340, file_path_cost);
+
+ ASSERT_EQ(base::PLATFORM_FILE_OK, Truncate(dfile1, 1020, 1020));
+ CheckUsage(1360, file_path_cost);
+
+ ASSERT_EQ(base::PLATFORM_FILE_OK, Truncate(dfile2, 120, 120));
+ CheckUsage(1480, file_path_cost);
+
+ context.reset(NewContext(QuotaFileUtil::kNoLimit, Path(file), FilePath()));
ASSERT_EQ(base::PLATFORM_FILE_OK,
QuotaFileUtil::GetInstance()->Delete(context.get(),
Path(file),
false));
- ASSERT_EQ(1140, quota_test_helper().GetCachedOriginUsage());
- ASSERT_EQ(quota_test_helper().ComputeCurrentOriginUsage(),
- quota_test_helper().GetCachedOriginUsage());
+ file_path_cost -= ComputeFilePathCost(file);
+ CheckUsage(1140, file_path_cost);
- context.reset(NewContext());
- context->set_allowed_bytes_growth(QuotaFileUtil::kNoLimit);
+ context.reset(NewContext(QuotaFileUtil::kNoLimit, Path(dir), FilePath()));
ASSERT_EQ(base::PLATFORM_FILE_OK,
QuotaFileUtil::GetInstance()->Delete(context.get(),
Path(dir),
true));
- ASSERT_EQ(0, quota_test_helper().GetCachedOriginUsage());
- ASSERT_EQ(quota_test_helper().ComputeCurrentOriginUsage(),
- quota_test_helper().GetCachedOriginUsage());
+ file_path_cost = 0;
+ CheckUsage(0, 0);
}
} // namespace fileapi
diff --git a/webkit/fileapi/sandbox_mount_point_provider.cc b/webkit/fileapi/sandbox_mount_point_provider.cc
index 6414034..a9d4d13 100644
--- a/webkit/fileapi/sandbox_mount_point_provider.cc
+++ b/webkit/fileapi/sandbox_mount_point_provider.cc
@@ -279,10 +279,11 @@ SandboxMountPointProvider::SandboxMountPointProvider(
path_manager_(path_manager),
file_message_loop_(file_message_loop),
profile_path_(profile_path),
+ quota_file_util_(QuotaFileUtil::GetInstance()),
sandbox_file_util_(
new ObfuscatedFileSystemFileUtil(
profile_path.Append(kNewFileSystemDirectory),
- QuotaFileUtil::GetInstance())) {
+ quota_file_util_)) {
}
SandboxMountPointProvider::~SandboxMountPointProvider() {
@@ -562,7 +563,7 @@ int64 SandboxMountPointProvider::GetOriginUsageOnFileThread(
else
usage += file_info.size;
}
- // TODO(dmikurube): Add some cost as described at crbug.com/86114.
+ usage += quota_file_util_->ComputeFilePathCost(file_path_each);
}
// This clears the dirty flag too.
FileSystemUsageCache::UpdateUsage(usage_file_path, usage);
diff --git a/webkit/fileapi/sandbox_mount_point_provider.h b/webkit/fileapi/sandbox_mount_point_provider.h
index 2602280..199185d 100644
--- a/webkit/fileapi/sandbox_mount_point_provider.h
+++ b/webkit/fileapi/sandbox_mount_point_provider.h
@@ -26,6 +26,7 @@ class QuotaManagerProxy;
namespace fileapi {
class ObfuscatedFileSystemFileUtil;
+class QuotaFileUtil;
// An interface to construct or crack sandboxed filesystem paths.
// Currently each sandboxed filesystem path looks like (soon will be changed):
@@ -169,6 +170,7 @@ class SandboxMountPointProvider
const FilePath profile_path_;
+ QuotaFileUtil *quota_file_util_;
scoped_refptr<ObfuscatedFileSystemFileUtil> sandbox_file_util_;
// Acccessed only on the file thread.