Chromium Code Reviews| Index: webkit/fileapi/file_system_operation.cc |
| diff --git a/webkit/fileapi/file_system_operation.cc b/webkit/fileapi/file_system_operation.cc |
| index 4aa663c149b14c15bc5be2c0607f1cfece89c3e9..561c868e834eb15ef127a31c5090d8a181feeeaa 100644 |
| --- a/webkit/fileapi/file_system_operation.cc |
| +++ b/webkit/fileapi/file_system_operation.cc |
| @@ -23,6 +23,25 @@ |
| namespace fileapi { |
| +namespace { |
| + |
| +void SetQuotaForOperation(FileSystemOperationContext* op_context, |
| + const GURL& origin_url, |
| + quota::QuotaStatusCode status, |
| + int64 usage, int64 quota) { |
| + if (op_context->file_system_context()->IsStorageUnlimited(origin_url) || |
| + quota == QuotaFileUtil::kNoLimit) { |
| + op_context->set_allowed_bytes_growth(QuotaFileUtil::kNoLimit); |
| + } else { |
| + int64 avail = quota - usage; |
| + if (status != quota::kQuotaStatusOk || avail < 0) |
| + avail = 0; |
| + op_context->set_allowed_bytes_growth(avail); |
| + } |
| +} |
| + |
| +} // anonymous namespace |
|
brettw
2011/07/19 20:29:31
You don't need "anonymous" here, just "// namespac
kinuko
2011/07/20 13:39:35
Done.
|
| + |
| FileSystemOperation::FileSystemOperation( |
| FileSystemCallbackDispatcher* dispatcher, |
| scoped_refptr<base::MessageLoopProxy> proxy, |
| @@ -32,7 +51,9 @@ FileSystemOperation::FileSystemOperation( |
| dispatcher_(dispatcher), |
| file_system_operation_context_( |
| file_system_context, file_system_file_util), |
| - callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| + callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| + is_write_operation_(false) { |
| + DCHECK(file_system_context); |
| DCHECK(dispatcher); |
| #ifndef NDEBUG |
| pending_operation_ = kOperationNone; |
| @@ -161,20 +182,15 @@ void FileSystemOperation::Copy(const GURL& src_path, |
| file_system_operation_context_.set_dest_file_system_file_util( |
| dest_file_system_file_util); |
| - GetUsageAndQuotaThenCallback(dest_origin_url, callback_factory_.NewCallback( |
| - &FileSystemOperation::DelayedCopyForQuota)); |
| + GetUsageAndQuotaThenCallback(dest_origin_url, dest_type, |
| + callback_factory_.NewCallback(&FileSystemOperation::DelayedCopyForQuota)); |
| } |
| void FileSystemOperation::DelayedCopyForQuota(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); |
| - } |
| + SetQuotaForOperation(&file_system_operation_context_, |
| + file_system_operation_context_.dest_origin_url(), |
| + status, usage, quota); |
| FileSystemFileUtilProxy::Copy( |
| file_system_operation_context_, |
| proxy_, |
| @@ -220,20 +236,15 @@ void FileSystemOperation::Move(const GURL& src_path, |
| file_system_operation_context_.set_dest_file_system_file_util( |
| dest_file_system_file_util); |
| - GetUsageAndQuotaThenCallback(dest_origin_url, callback_factory_.NewCallback( |
| - &FileSystemOperation::DelayedMoveForQuota)); |
| + GetUsageAndQuotaThenCallback(dest_origin_url, dest_type, |
| + callback_factory_.NewCallback(&FileSystemOperation::DelayedMoveForQuota)); |
| } |
| void FileSystemOperation::DelayedMoveForQuota(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); |
| - } |
| + SetQuotaForOperation(&file_system_operation_context_, |
| + file_system_operation_context_.dest_origin_url(), |
| + status, usage, quota); |
| FileSystemFileUtilProxy::Move( |
| file_system_operation_context_, |
| proxy_, |
| @@ -403,21 +414,16 @@ void FileSystemOperation::Write( |
| new net::URLRequest(blob_url, file_writer_delegate_.get())); |
| blob_request_->set_context(url_request_context); |
| - GetUsageAndQuotaThenCallback(origin_url, callback_factory_.NewCallback( |
| + GetUsageAndQuotaThenCallback(origin_url, type, callback_factory_.NewCallback( |
| &FileSystemOperation::DelayedWriteForQuota)); |
| } |
| void FileSystemOperation::DelayedWriteForQuota(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( |
| + SetQuotaForOperation(&file_system_operation_context_, |
| + file_system_operation_context_.src_origin_url(), |
| + status, usage, quota); |
| + FileSystemFileUtilProxy::CreateOrOpenAndQuerySize( |
| file_system_operation_context_, |
| proxy_, |
| file_system_operation_context_.src_virtual_path(), |
| @@ -449,20 +455,15 @@ void FileSystemOperation::Truncate(const GURL& path, int64 length) { |
| file_system_file_util); |
| length_ = length; |
| - GetUsageAndQuotaThenCallback(origin_url, callback_factory_.NewCallback( |
| + GetUsageAndQuotaThenCallback(origin_url, type, callback_factory_.NewCallback( |
| &FileSystemOperation::DelayedTruncateForQuota)); |
| } |
| void FileSystemOperation::DelayedTruncateForQuota(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); |
| - } |
| + SetQuotaForOperation(&file_system_operation_context_, |
| + file_system_operation_context_.src_origin_url(), |
| + status, usage, quota); |
| FileSystemFileUtilProxy::Truncate( |
| file_system_operation_context_, |
| proxy_, |
| @@ -515,6 +516,7 @@ void FileSystemOperation::OpenFile(const GURL& path, |
| if (file_flags & ( |
| (base::PLATFORM_FILE_ENUMERATE | base::PLATFORM_FILE_TEMPORARY | |
| base::PLATFORM_FILE_HIDDEN))) { |
| + dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_INVALID_OPERATION); |
| delete this; |
| return; |
| } |
| @@ -541,7 +543,7 @@ void FileSystemOperation::OpenFile(const GURL& 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); |
| - FileSystemFileUtilProxy::CreateOrOpen( |
| + FileSystemFileUtilProxy::CreateOrOpenAndQuerySize( |
| file_system_operation_context_, |
| proxy_, |
| virtual_path, |
| @@ -586,15 +588,15 @@ void FileSystemOperation::Cancel(FileSystemOperation* cancel_operation_ptr) { |
| // TODO(ericu): Obfuscation integration. |
| bool FileSystemOperation::GetUsageAndQuotaThenCallback( |
| const GURL& origin_url, |
| + FileSystemType type, |
| quota::QuotaManager::GetUsageAndQuotaCallback* callback) { |
| quota::QuotaManagerProxy* quota_manager_proxy = |
| file_system_context()->quota_manager_proxy(); |
| if (quota_manager_proxy && quota_manager_proxy->quota_manager() && |
| file_system_operation_context_.src_type() != kFileSystemTypeExternal) { |
| quota_manager_proxy->quota_manager()->GetUsageAndQuota( |
| - file_system_operation_context_.src_origin_url(), |
| - FileSystemTypeToQuotaStorageType( |
| - file_system_operation_context_.src_type()), |
| + origin_url, |
| + FileSystemTypeToQuotaStorageType(type), |
| callback); |
| } else { |
| if (file_system_context()->IsStorageUnlimited(origin_url)) { |
| @@ -732,50 +734,34 @@ void FileSystemOperation::DidTouchFile(base::PlatformFileError rv) { |
| void FileSystemOperation::DidOpenFile( |
| base::PlatformFileError rv, |
| base::PassPlatformFile file, |
| - bool unused) { |
| - if (rv == base::PLATFORM_FILE_OK) |
| - dispatcher_->DidOpenFile(file.ReleaseValue(), peer_handle_); |
| - else |
| + bool unused, |
| + int64 file_size) { |
| + if (rv == base::PLATFORM_FILE_OK) { |
|
brettw
2011/07/19 20:29:31
This file doesn't usually use {} for single-line c
kinuko
2011/07/20 13:39:35
Done.
|
| + dispatcher_->DidOpenFile(file.ReleaseValue(), peer_handle_, file_size); |
| + } else { |
| dispatcher_->DidFail(rv); |
| + } |
| delete this; |
| } |
| void FileSystemOperation::OnFileOpenedForWrite( |
| base::PlatformFileError rv, |
| base::PassPlatformFile file, |
| - bool created) { |
| + bool created, |
| + int64 file_size) { |
| if (base::PLATFORM_FILE_OK != rv) { |
| dispatcher_->DidFail(rv); |
| delete this; |
| return; |
| } |
| - file_writer_delegate_->Start(file.ReleaseValue(), blob_request_.get()); |
| + file_writer_delegate_->Start(file.ReleaseValue(), file_size, |
| + blob_request_.get()); |
| } |
| bool FileSystemOperation::VerifyFileSystemPathForRead( |
| const GURL& path, GURL* origin_url, FileSystemType* type, |
| FilePath* virtual_path, FileSystemFileUtil** file_system_file_util) { |
| - |
| - // If we have no context, we just allow any operations, for testing. |
| - // TODO(ericu): Revisit this hack for security. |
| - if (!file_system_context()) { |
| -#ifdef OS_WIN |
| - // On Windows, the path will look like /C:/foo/bar; we need to remove the |
| - // leading slash to make it valid. But if it's empty, we shouldn't do |
| - // anything. |
| - std::string temp = UnescapeURLComponent(path.path(), |
| - UnescapeRule::SPACES | UnescapeRule::URL_SPECIAL_CHARS); |
| - if (temp.size()) |
| - temp = temp.substr(1); |
| - *virtual_path = FilePath(UTF8ToWide(temp)).NormalizeWindowsPathSeparators(); |
| -#else |
| - *virtual_path = FilePath(path.path()); |
| -#endif |
| - *type = file_system_operation_context_.src_type(); |
| - *origin_url = file_system_operation_context_.src_origin_url(); |
| - *file_system_file_util = NULL; |
| - return true; |
| - } |
| + DCHECK(file_system_context()); |
| // We may want do more checks, but for now it just checks if the given |
| // URL is valid. |
| @@ -811,27 +797,7 @@ bool FileSystemOperation::VerifyFileSystemPathForRead( |
| bool FileSystemOperation::VerifyFileSystemPathForWrite( |
| const GURL& path, bool create, GURL* origin_url, FileSystemType* type, |
| FilePath* virtual_path, FileSystemFileUtil** file_system_file_util) { |
| - |
| - // If we have no context, we just allow any operations, for testing. |
| - // TODO(ericu): Revisit this hack for security. |
| - if (!file_system_context()) { |
| -#ifdef OS_WIN |
| - // On Windows, the path will look like /C:/foo/bar; we need to remove the |
| - // leading slash to make it valid. But if it's empty, we shouldn't do |
| - // anything. |
| - std::string temp = UnescapeURLComponent(path.path(), |
| - UnescapeRule::SPACES | UnescapeRule::URL_SPECIAL_CHARS); |
| - if (temp.size()) |
| - temp = temp.substr(1); |
| - *virtual_path = FilePath(UTF8ToWide(temp)).NormalizeWindowsPathSeparators(); |
| -#else |
| - *virtual_path = FilePath(path.path()); |
| -#endif |
| - *type = file_system_operation_context_.dest_type(); |
| - *origin_url = file_system_operation_context_.dest_origin_url(); |
| - *file_system_file_util = NULL; |
| - return true; |
| - } |
| + DCHECK(file_system_context()); |
| if (!CrackFileSystemURL(path, origin_url, type, virtual_path)) { |
| dispatcher_->DidFail(base::PLATFORM_FILE_ERROR_INVALID_URL); |
| @@ -858,6 +824,7 @@ bool FileSystemOperation::VerifyFileSystemPathForWrite( |
| file_system_context()->path_manager()->GetFileSystemFileUtil(*type); |
| DCHECK(*file_system_file_util); |
| + is_write_operation_ = true; |
| return true; |
| } |