diff options
author | tzik@chromium.org <tzik@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-22 10:31:12 +0000 |
---|---|---|
committer | tzik@chromium.org <tzik@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-22 10:31:12 +0000 |
commit | 304875dd89f326d20dcf6c85639592365f126c71 (patch) | |
tree | ef944efd7bc34134b2dc9b7874d3b69b66473195 /ppapi | |
parent | 516009142bfa85a27b5c50a700bd3fa1e02f8dc6 (diff) | |
download | chromium_src-304875dd89f326d20dcf6c85639592365f126c71.zip chromium_src-304875dd89f326d20dcf6c85639592365f126c71.tar.gz chromium_src-304875dd89f326d20dcf6c85639592365f126c71.tar.bz2 |
[Pepper] Refine append mode write handling on FileIOResource
* Count written amount in append mode separately.
* Make the values robust to multiple job.
BUG=334171
Review URL: https://codereview.chromium.org/140853002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@246273 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi')
-rw-r--r-- | ppapi/proxy/file_io_resource.cc | 62 | ||||
-rw-r--r-- | ppapi/proxy/file_io_resource.h | 4 | ||||
-rw-r--r-- | ppapi/proxy/file_system_resource.cc | 1 | ||||
-rw-r--r-- | ppapi/thunk/ppb_file_io_api.h | 2 |
4 files changed, 57 insertions, 12 deletions
diff --git a/ppapi/proxy/file_io_resource.cc b/ppapi/proxy/file_io_resource.cc index e86c321..f4fa6a5 100644 --- a/ppapi/proxy/file_io_resource.cc +++ b/ppapi/proxy/file_io_resource.cc @@ -112,6 +112,7 @@ FileIOResource::FileIOResource(Connection connection, PP_Instance instance) file_system_type_(PP_FILESYSTEMTYPE_INVALID), open_flags_(0), max_written_offset_(0), + append_mode_write_amount_(0), check_quota_(false), called_close_(false) { SendCreate(BROWSER, PpapiHostMsg_FileIO_Create()); @@ -272,7 +273,7 @@ int32_t FileIOResource::Write(int64_t offset, scoped_refptr<TrackedCallback> callback) { if (!buffer) return PP_ERROR_FAILED; - if (bytes_to_write < 0) + if (offset < 0 || bytes_to_write < 0) return PP_ERROR_FAILED; if (!FileHandleHolder::IsValid(file_handle_)) return PP_ERROR_FAILED; @@ -285,13 +286,18 @@ int32_t FileIOResource::Write(int64_t offset, state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_WRITE); if (check_quota_) { - int64_t actual_offset = - (open_flags_ & PP_FILEOPENFLAG_APPEND) ? max_written_offset_ : offset; + int64_t increase = 0; + uint64_t max_offset = 0; + bool append = (open_flags_ & PP_FILEOPENFLAG_APPEND) != 0; + if (append) { + increase = bytes_to_write; + } else { + uint64_t max_offset = offset + bytes_to_write; + if (max_offset > static_cast<uint64_t>(kint64max)) + return PP_ERROR_FAILED; // amount calculation would overflow. + increase = static_cast<int64_t>(max_offset) - max_written_offset_; + } - uint64_t max_offset = actual_offset + bytes_to_write; - if (max_offset > static_cast<uint64_t>(std::numeric_limits<int64_t>::max())) - return PP_ERROR_FAILED; // amount calculation would overflow. - int64_t increase = static_cast<int64_t>(max_offset) - max_written_offset_; if (increase > 0) { int64_t result = file_system_resource_->AsPPB_FileSystem_API()->RequestQuota( @@ -302,7 +308,11 @@ int32_t FileIOResource::Write(int64_t offset, if (result == PP_OK_COMPLETIONPENDING) return PP_OK_COMPLETIONPENDING; DCHECK(result == increase); - max_written_offset_ = max_offset; + + if (append) + append_mode_write_amount_ += bytes_to_write; + else + max_written_offset_ = max_offset; } } return WriteValidated(offset, buffer, bytes_to_write, callback); @@ -360,10 +370,19 @@ int64_t FileIOResource::GetMaxWrittenOffset() const { return max_written_offset_; } +int64_t FileIOResource::GetAppendModeWriteAmount() const { + return append_mode_write_amount_; +} + void FileIOResource::SetMaxWrittenOffset(int64_t max_written_offset) { max_written_offset_ = max_written_offset; } +void FileIOResource::SetAppendModeWriteAmount( + int64_t append_mode_write_amount) { + append_mode_write_amount_ = append_mode_write_amount; +} + void FileIOResource::Close() { if (called_close_) return; @@ -378,7 +397,10 @@ void FileIOResource::Close() { if (file_handle_) file_handle_ = NULL; - Post(BROWSER, PpapiHostMsg_FileIO_Close(max_written_offset_)); + // TODO(tzik): Post |max_written_offset_| and |append_mode_write_amount_| + // separately by using FileGrowth after the IPC signature changed. + Post(BROWSER, PpapiHostMsg_FileIO_Close( + max_written_offset_ + append_mode_write_amount_)); } int32_t FileIOResource::RequestOSFileHandle( @@ -510,7 +532,11 @@ void FileIOResource::SetLengthValidated( base::Bind(&FileIOResource::OnPluginMsgGeneralComplete, this, callback)); - max_written_offset_ = length; + // On the browser side we grow |max_written_offset_| monotonically, due to the + // unpredictable ordering of plugin side Write and SetLength calls. Match that + // behavior here. + if (max_written_offset_ < length) + max_written_offset_ = length; } int32_t FileIOResource::OnQueryComplete(scoped_refptr<QueryOp> query_op, @@ -560,7 +586,17 @@ void FileIOResource::OnRequestWriteQuotaComplete( callback->Run(PP_ERROR_NOQUOTA); return; } - max_written_offset_ += granted; + if (open_flags_ & PP_FILEOPENFLAG_APPEND) { + DCHECK_LE(bytes_to_write, granted); + append_mode_write_amount_ += bytes_to_write; + } else { + DCHECK_LE(offset + bytes_to_write - max_written_offset_, granted); + + int64_t max_offset = offset + bytes_to_write; + if (max_written_offset_ < max_offset) + max_written_offset_ = max_offset; + } + int32_t result = WriteValidated(offset, buffer, bytes_to_write, callback); if (result != PP_OK_COMPLETIONPENDING) callback->Run(result); @@ -576,7 +612,9 @@ void FileIOResource::OnRequestSetLengthQuotaComplete( return; } - max_written_offset_ = length; + DCHECK_LE(length - max_written_offset_, granted); + if (max_written_offset_ < length) + max_written_offset_ = length; SetLengthValidated(length, callback); } diff --git a/ppapi/proxy/file_io_resource.h b/ppapi/proxy/file_io_resource.h index 23df0e6..38ac683 100644 --- a/ppapi/proxy/file_io_resource.h +++ b/ppapi/proxy/file_io_resource.h @@ -58,7 +58,10 @@ class PPAPI_PROXY_EXPORT FileIOResource virtual int32_t SetLength(int64_t length, scoped_refptr<TrackedCallback> callback) OVERRIDE; virtual int64_t GetMaxWrittenOffset() const OVERRIDE; + virtual int64_t GetAppendModeWriteAmount() const OVERRIDE; virtual void SetMaxWrittenOffset(int64_t max_written_offset) OVERRIDE; + virtual void SetAppendModeWriteAmount( + int64_t append_mode_write_amount) OVERRIDE; virtual int32_t Flush(scoped_refptr<TrackedCallback> callback) OVERRIDE; virtual void Close() OVERRIDE; virtual int32_t RequestOSFileHandle( @@ -216,6 +219,7 @@ class PPAPI_PROXY_EXPORT FileIOResource int32_t open_flags_; int64_t max_written_offset_; + int64_t append_mode_write_amount_; bool check_quota_; bool called_close_; diff --git a/ppapi/proxy/file_system_resource.cc b/ppapi/proxy/file_system_resource.cc index 8061189..8a8bf49 100644 --- a/ppapi/proxy/file_system_resource.cc +++ b/ppapi/proxy/file_system_resource.cc @@ -203,6 +203,7 @@ void FileSystemResource::ReserveQuotaComplete( DCHECK(!enter.failed()); PPB_FileIO_API* file_io_api = enter.object(); file_io_api->SetMaxWrittenOffset(it->second); + file_io_api->SetAppendModeWriteAmount(0); } DCHECK(!pending_quota_requests_.empty()); diff --git a/ppapi/thunk/ppb_file_io_api.h b/ppapi/thunk/ppb_file_io_api.h index 830b140..c1e78d4 100644 --- a/ppapi/thunk/ppb_file_io_api.h +++ b/ppapi/thunk/ppb_file_io_api.h @@ -43,7 +43,9 @@ class PPAPI_THUNK_EXPORT PPB_FileIO_API { virtual int32_t SetLength(int64_t length, scoped_refptr<TrackedCallback> callback) = 0; virtual int64_t GetMaxWrittenOffset() const = 0; + virtual int64_t GetAppendModeWriteAmount() const = 0; virtual void SetMaxWrittenOffset(int64_t max_written_offset) = 0; + virtual void SetAppendModeWriteAmount(int64_t append_mode_write_amount) = 0; virtual int32_t Flush(scoped_refptr<TrackedCallback> callback) = 0; virtual void Close() = 0; |