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