Count-up/down the dirty count in the usage cache at FileSystemOperation, not at QuotaFU.


BUG=none
TEST=none


Review URL: http://codereview.chromium.org/7671039

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@98942 0039d316-1c4b-4281-b951-d872f2087c98
parent 530a3385
......@@ -23,6 +23,39 @@
namespace fileapi {
class FileSystemOperation::ScopedQuotaUtilHelper {
public:
ScopedQuotaUtilHelper(FileSystemContext* context,
const GURL& origin_url,
FileSystemType type);
~ScopedQuotaUtilHelper();
private:
FileSystemQuotaUtil* quota_util_;
const GURL& origin_url_;
FileSystemType type_;
DISALLOW_COPY_AND_ASSIGN(ScopedQuotaUtilHelper);
};
FileSystemOperation::ScopedQuotaUtilHelper::ScopedQuotaUtilHelper(
FileSystemContext* context, const GURL& origin_url, FileSystemType type)
: origin_url_(origin_url), type_(type) {
DCHECK(context);
DCHECK(type != kFileSystemTypeUnknown);
quota_util_ = context->GetQuotaUtil(type_);
if (quota_util_) {
DCHECK(quota_util_->proxy());
quota_util_->proxy()->StartUpdateOrigin(origin_url_, type_);
}
}
FileSystemOperation::ScopedQuotaUtilHelper::~ScopedQuotaUtilHelper() {
if (quota_util_) {
DCHECK(quota_util_->proxy());
quota_util_->proxy()->EndUpdateOrigin(origin_url_, type_);
}
}
FileSystemOperation::FileSystemOperation(
FileSystemCallbackDispatcher* dispatcher,
scoped_refptr<base::MessageLoopProxy> proxy,
......@@ -104,6 +137,12 @@ void FileSystemOperation::DelayedCreateFileForQuota(
} else {
file_system_operation_context_.set_allowed_bytes_growth(quota - usage);
}
quota_util_helper_.reset(new ScopedQuotaUtilHelper(
file_system_context(),
file_system_operation_context_.src_origin_url(),
file_system_operation_context_.src_type()));
FileSystemFileUtilProxy::EnsureFileExists(
file_system_operation_context_,
proxy_,
......@@ -152,6 +191,12 @@ void FileSystemOperation::DelayedCreateDirectoryForQuota(
} else {
file_system_operation_context_.set_allowed_bytes_growth(quota - usage);
}
quota_util_helper_.reset(new ScopedQuotaUtilHelper(
file_system_context(),
file_system_operation_context_.src_origin_url(),
file_system_operation_context_.src_type()));
FileSystemFileUtilProxy::CreateDirectory(
file_system_operation_context_,
proxy_,
......@@ -208,6 +253,12 @@ void FileSystemOperation::DelayedCopyForQuota(quota::QuotaStatusCode status,
} else {
file_system_operation_context_.set_allowed_bytes_growth(quota - usage);
}
quota_util_helper_.reset(new ScopedQuotaUtilHelper(
file_system_context(),
file_system_operation_context_.dest_origin_url(),
file_system_operation_context_.dest_type()));
FileSystemFileUtilProxy::Copy(
file_system_operation_context_,
proxy_,
......@@ -263,6 +314,12 @@ void FileSystemOperation::DelayedMoveForQuota(quota::QuotaStatusCode status,
} else {
file_system_operation_context_.set_allowed_bytes_growth(quota - usage);
}
quota_util_helper_.reset(new ScopedQuotaUtilHelper(
file_system_context(),
file_system_operation_context_.dest_origin_url(),
file_system_operation_context_.dest_type()));
FileSystemFileUtilProxy::Move(
file_system_operation_context_,
proxy_,
......@@ -444,6 +501,12 @@ void FileSystemOperation::DelayedWriteForQuota(quota::QuotaStatusCode status,
} else {
file_system_operation_context_.set_allowed_bytes_growth(quota - usage);
}
quota_util_helper_.reset(new ScopedQuotaUtilHelper(
file_system_context(),
file_system_operation_context_.src_origin_url(),
file_system_operation_context_.src_type()));
FileSystemFileUtilProxy::CreateOrOpen(
file_system_operation_context_,
proxy_,
......@@ -488,6 +551,12 @@ void FileSystemOperation::DelayedTruncateForQuota(quota::QuotaStatusCode status,
} else {
file_system_operation_context_.set_allowed_bytes_growth(quota - usage);
}
quota_util_helper_.reset(new ScopedQuotaUtilHelper(
file_system_context(),
file_system_operation_context_.src_origin_url(),
file_system_operation_context_.src_type()));
FileSystemFileUtilProxy::Truncate(
file_system_operation_context_,
proxy_,
......@@ -582,6 +651,11 @@ void FileSystemOperation::DelayedOpenFileForQuota(quota::QuotaStatusCode status,
file_system_operation_context_.set_allowed_bytes_growth(quota - usage);
}
quota_util_helper_.reset(new ScopedQuotaUtilHelper(
file_system_context(),
file_system_operation_context_.src_origin_url(),
file_system_operation_context_.src_type()));
FileSystemFileUtilProxy::CreateOrOpen(
file_system_operation_context_,
proxy_,
......
......@@ -17,8 +17,8 @@
#include "base/platform_file.h"
#include "base/process.h"
#include "googleurl/src/gurl.h"
#include "webkit/fileapi/file_system_types.h"
#include "webkit/fileapi/file_system_operation_context.h"
#include "webkit/fileapi/file_system_types.h"
#include "webkit/quota/quota_manager.h"
namespace base {
......@@ -38,6 +38,7 @@ class FileSystemCallbackDispatcher;
class FileSystemContext;
class FileWriterDelegate;
class FileSystemOperationTest;
class FileSystemQuotaUtil;
// This class is designed to serve one-time file system operation per instance.
// Only one method(CreateFile, CreateDirectory, Copy, Move, DirectoryExists,
......@@ -92,6 +93,8 @@ class FileSystemOperation {
void Cancel(FileSystemOperation* cancel_operation);
private:
class ScopedQuotaUtilHelper;
FileSystemContext* file_system_context() const {
return file_system_operation_context_.file_system_context();
}
......@@ -239,6 +242,8 @@ class FileSystemOperation {
base::ScopedCallbackFactory<FileSystemOperation> callback_factory_;
scoped_ptr<ScopedQuotaUtilHelper> quota_util_helper_;
// These are all used only by Write().
friend class FileWriterDelegate;
scoped_ptr<FileWriterDelegate> file_writer_delegate_;
......
......@@ -45,48 +45,25 @@ bool CanCopy(
return true;
}
// A helper class to hook quota_util() methods before and after modifications.
class ScopedOriginUpdateHelper {
public:
explicit ScopedOriginUpdateHelper(
FileSystemOperationContext* operation_context,
const GURL& origin_url,
FileSystemType type)
: operation_context_(operation_context),
origin_url_(origin_url),
type_(type) {
DCHECK(operation_context_);
DCHECK(operation_context_->file_system_context());
DCHECK(type != kFileSystemTypeUnknown);
quota_util_ =
operation_context_->file_system_context()->GetQuotaUtil(type_);
quota_manager_proxy_ =
operation_context_->file_system_context()->quota_manager_proxy();
if (quota_util_)
quota_util_->StartUpdateOriginOnFileThread(origin_url_, type_);
}
~ScopedOriginUpdateHelper() {
if (quota_util_)
quota_util_->EndUpdateOriginOnFileThread(origin_url_, type_);
}
void NotifyUpdate(int64 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);
}
private:
FileSystemOperationContext* operation_context_;
FileSystemQuotaUtil* quota_util_;
QuotaManagerProxy* quota_manager_proxy_;
const GURL& origin_url_;
FileSystemType type_;
DISALLOW_COPY_AND_ASSIGN(ScopedOriginUpdateHelper);
};
void NotifyUpdate(FileSystemOperationContext* operation_context,
const GURL& origin_url,
FileSystemType type,
int64 growth) {
DCHECK(operation_context);
DCHECK(operation_context->file_system_context());
DCHECK(type != kFileSystemTypeUnknown);
FileSystemQuotaUtil* quota_util =
operation_context->file_system_context()->GetQuotaUtil(type);
QuotaManagerProxy* quota_manager_proxy =
operation_context->file_system_context()->quota_manager_proxy();
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);
}
} // namespace (anonymous)
......@@ -109,13 +86,6 @@ base::PlatformFileError QuotaFileUtil::CopyOrMoveFile(
bool copy) {
DCHECK(fs_context);
// TODO(kinuko): For cross-filesystem move case we need 2 helpers, one for
// src and one for dest.
ScopedOriginUpdateHelper helper(
fs_context,
fs_context->dest_origin_url(),
fs_context->dest_type());
int64 growth = 0;
// It assumes copy/move operations are always in the same fs currently.
......@@ -138,7 +108,10 @@ base::PlatformFileError QuotaFileUtil::CopyOrMoveFile(
if (error == base::PLATFORM_FILE_OK) {
// TODO(kinuko): For cross-filesystem move case, call this with -growth
// for source and growth for dest.
helper.NotifyUpdate(growth);
NotifyUpdate(fs_context,
fs_context->dest_origin_url(),
fs_context->dest_type(),
growth);
}
return error;
......@@ -148,10 +121,6 @@ base::PlatformFileError QuotaFileUtil::DeleteFile(
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;
base::PlatformFileInfo file_info;
......@@ -163,7 +132,10 @@ base::PlatformFileError QuotaFileUtil::DeleteFile(
fs_context, file_path);
if (error == base::PLATFORM_FILE_OK)
helper.NotifyUpdate(growth);
NotifyUpdate(fs_context,
fs_context->src_origin_url(),
fs_context->src_type(),
growth);
return error;
}
......@@ -173,10 +145,6 @@ base::PlatformFileError QuotaFileUtil::Truncate(
const FilePath& path,
int64 length) {
int64 allowed_bytes_growth = fs_context->allowed_bytes_growth();
ScopedOriginUpdateHelper helper(
fs_context,
fs_context->src_origin_url(),
fs_context->src_type());
int64 growth = 0;
base::PlatformFileInfo file_info;
......@@ -192,7 +160,10 @@ base::PlatformFileError QuotaFileUtil::Truncate(
fs_context, path, length);
if (error == base::PLATFORM_FILE_OK)
helper.NotifyUpdate(growth);
NotifyUpdate(fs_context,
fs_context->src_origin_url(),
fs_context->src_type(),
growth);
return error;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment