| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ppapi/proxy/file_io_resource.h" | 5 #include "ppapi/proxy/file_io_resource.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/task_runner_util.h" | 8 #include "base/task_runner_util.h" |
| 9 #include "ipc/ipc_message.h" | 9 #include "ipc/ipc_message.h" |
| 10 #include "ppapi/c/pp_errors.h" | 10 #include "ppapi/c/pp_errors.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 // 32MB. This is OK since the API specifies that it may perform a partial read | 32 // 32MB. This is OK since the API specifies that it may perform a partial read |
| 33 // or write. | 33 // or write. |
| 34 static const int32_t kMaxReadWriteSize = 32 * 1024 * 1024; // 32MB | 34 static const int32_t kMaxReadWriteSize = 32 * 1024 * 1024; // 32MB |
| 35 | 35 |
| 36 // An adapter to let Read() share the same implementation with ReadToArray(). | 36 // An adapter to let Read() share the same implementation with ReadToArray(). |
| 37 void* DummyGetDataBuffer(void* user_data, uint32_t count, uint32_t size) { | 37 void* DummyGetDataBuffer(void* user_data, uint32_t count, uint32_t size) { |
| 38 return user_data; | 38 return user_data; |
| 39 } | 39 } |
| 40 | 40 |
| 41 // File thread task to close the file handle. | 41 // File thread task to close the file handle. |
| 42 void DoClose(base::PlatformFile file) { | 42 void DoClose(base::File auto_close_file) { |
| 43 base::ClosePlatformFile(file); | |
| 44 } | 43 } |
| 45 | 44 |
| 46 } // namespace | 45 } // namespace |
| 47 | 46 |
| 48 namespace ppapi { | 47 namespace ppapi { |
| 49 namespace proxy { | 48 namespace proxy { |
| 50 | 49 |
| 51 FileIOResource::QueryOp::QueryOp(scoped_refptr<FileHandleHolder> file_handle) | 50 FileIOResource::QueryOp::QueryOp(scoped_refptr<FileHolder> file_holder) |
| 52 : file_handle_(file_handle) { | 51 : file_holder_(file_holder) { |
| 53 DCHECK(file_handle_); | 52 DCHECK(file_holder_); |
| 54 } | 53 } |
| 55 | 54 |
| 56 FileIOResource::QueryOp::~QueryOp() { | 55 FileIOResource::QueryOp::~QueryOp() { |
| 57 } | 56 } |
| 58 | 57 |
| 59 int32_t FileIOResource::QueryOp::DoWork() { | 58 int32_t FileIOResource::QueryOp::DoWork() { |
| 60 // TODO(rvargas): Convert this code to use base::File. | 59 return file_holder_->file()->GetInfo(&file_info_) ? PP_OK : PP_ERROR_FAILED; |
| 61 base::File file(file_handle_->raw_handle()); | |
| 62 bool success = file.GetInfo(&file_info_); | |
| 63 file.TakePlatformFile(); | |
| 64 return success ? PP_OK : PP_ERROR_FAILED; | |
| 65 } | 60 } |
| 66 | 61 |
| 67 FileIOResource::ReadOp::ReadOp(scoped_refptr<FileHandleHolder> file_handle, | 62 FileIOResource::ReadOp::ReadOp(scoped_refptr<FileHolder> file_holder, |
| 68 int64_t offset, | 63 int64_t offset, |
| 69 int32_t bytes_to_read) | 64 int32_t bytes_to_read) |
| 70 : file_handle_(file_handle), | 65 : file_holder_(file_holder), |
| 71 offset_(offset), | 66 offset_(offset), |
| 72 bytes_to_read_(bytes_to_read) { | 67 bytes_to_read_(bytes_to_read) { |
| 73 DCHECK(file_handle_); | 68 DCHECK(file_holder_); |
| 74 } | 69 } |
| 75 | 70 |
| 76 FileIOResource::ReadOp::~ReadOp() { | 71 FileIOResource::ReadOp::~ReadOp() { |
| 77 } | 72 } |
| 78 | 73 |
| 79 int32_t FileIOResource::ReadOp::DoWork() { | 74 int32_t FileIOResource::ReadOp::DoWork() { |
| 80 DCHECK(!buffer_.get()); | 75 DCHECK(!buffer_.get()); |
| 81 buffer_.reset(new char[bytes_to_read_]); | 76 buffer_.reset(new char[bytes_to_read_]); |
| 82 return base::ReadPlatformFile( | 77 return file_holder_->file()->Read(offset_, buffer_.get(), bytes_to_read_); |
| 83 file_handle_->raw_handle(), offset_, buffer_.get(), bytes_to_read_); | |
| 84 } | 78 } |
| 85 | 79 |
| 86 FileIOResource::WriteOp::WriteOp(scoped_refptr<FileHandleHolder> file_handle, | 80 FileIOResource::WriteOp::WriteOp(scoped_refptr<FileHolder> file_holder, |
| 87 int64_t offset, | 81 int64_t offset, |
| 88 scoped_ptr<char[]> buffer, | 82 scoped_ptr<char[]> buffer, |
| 89 int32_t bytes_to_write, | 83 int32_t bytes_to_write, |
| 90 bool append) | 84 bool append) |
| 91 : file_handle_(file_handle), | 85 : file_holder_(file_holder), |
| 92 offset_(offset), | 86 offset_(offset), |
| 93 buffer_(buffer.Pass()), | 87 buffer_(buffer.Pass()), |
| 94 bytes_to_write_(bytes_to_write), | 88 bytes_to_write_(bytes_to_write), |
| 95 append_(append) { | 89 append_(append) { |
| 96 } | 90 } |
| 97 | 91 |
| 98 FileIOResource::WriteOp::~WriteOp() { | 92 FileIOResource::WriteOp::~WriteOp() { |
| 99 } | 93 } |
| 100 | 94 |
| 101 int32_t FileIOResource::WriteOp::DoWork() { | 95 int32_t FileIOResource::WriteOp::DoWork() { |
| 102 // In append mode, we can't call WritePlatformFile, since NaCl doesn't | 96 // In append mode, we can't call WritePlatformFile, since NaCl doesn't |
| 103 // implement fcntl, causing the function to call pwrite, which is incorrect. | 97 // implement fcntl, causing the function to call pwrite, which is incorrect. |
| 104 if (append_) { | 98 if (append_) { |
| 105 return base::WritePlatformFileAtCurrentPos( | 99 return file_holder_->file()->WriteAtCurrentPos(buffer_.get(), |
| 106 file_handle_->raw_handle(), buffer_.get(), bytes_to_write_); | 100 bytes_to_write_); |
| 107 } else { | 101 } else { |
| 108 return base::WritePlatformFile( | 102 return file_holder_->file()->Write(offset_, buffer_.get(), bytes_to_write_); |
| 109 file_handle_->raw_handle(), offset_, buffer_.get(), bytes_to_write_); | |
| 110 } | 103 } |
| 111 } | 104 } |
| 112 | 105 |
| 113 FileIOResource::FileIOResource(Connection connection, PP_Instance instance) | 106 FileIOResource::FileIOResource(Connection connection, PP_Instance instance) |
| 114 : PluginResource(connection, instance), | 107 : PluginResource(connection, instance), |
| 115 file_system_type_(PP_FILESYSTEMTYPE_INVALID), | 108 file_system_type_(PP_FILESYSTEMTYPE_INVALID), |
| 116 open_flags_(0), | 109 open_flags_(0), |
| 117 max_written_offset_(0), | 110 max_written_offset_(0), |
| 118 append_mode_write_amount_(0), | 111 append_mode_write_amount_(0), |
| 119 check_quota_(false), | 112 check_quota_(false), |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 } | 169 } |
| 177 | 170 |
| 178 int32_t FileIOResource::Query(PP_FileInfo* info, | 171 int32_t FileIOResource::Query(PP_FileInfo* info, |
| 179 scoped_refptr<TrackedCallback> callback) { | 172 scoped_refptr<TrackedCallback> callback) { |
| 180 int32_t rv = state_manager_.CheckOperationState( | 173 int32_t rv = state_manager_.CheckOperationState( |
| 181 FileIOStateManager::OPERATION_EXCLUSIVE, true); | 174 FileIOStateManager::OPERATION_EXCLUSIVE, true); |
| 182 if (rv != PP_OK) | 175 if (rv != PP_OK) |
| 183 return rv; | 176 return rv; |
| 184 if (!info) | 177 if (!info) |
| 185 return PP_ERROR_BADARGUMENT; | 178 return PP_ERROR_BADARGUMENT; |
| 186 if (!FileHandleHolder::IsValid(file_handle_)) | 179 if (!FileHolder::IsValid(file_holder_)) |
| 187 return PP_ERROR_FAILED; | 180 return PP_ERROR_FAILED; |
| 188 | 181 |
| 189 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); | 182 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); |
| 190 | 183 |
| 191 // If the callback is blocking, perform the task on the calling thread. | 184 // If the callback is blocking, perform the task on the calling thread. |
| 192 if (callback->is_blocking()) { | 185 if (callback->is_blocking()) { |
| 193 int32_t result = PP_ERROR_FAILED; | 186 int32_t result = PP_ERROR_FAILED; |
| 194 base::File::Info file_info; | 187 base::File::Info file_info; |
| 195 // The plugin could release its reference to this instance when we release | 188 // The plugin could release its reference to this instance when we release |
| 196 // the proxy lock below. | 189 // the proxy lock below. |
| 197 scoped_refptr<FileIOResource> protect(this); | 190 scoped_refptr<FileIOResource> protect(this); |
| 198 { | 191 { |
| 199 // Release the proxy lock while making a potentially slow file call. | 192 // Release the proxy lock while making a potentially slow file call. |
| 200 ProxyAutoUnlock unlock; | 193 ProxyAutoUnlock unlock; |
| 201 // TODO(rvargas): Convert this code to base::File. | 194 if (file_holder_->file()->GetInfo(&file_info)) |
| 202 base::File file(file_handle_->raw_handle()); | |
| 203 bool success = file.GetInfo(&file_info); | |
| 204 file.TakePlatformFile(); | |
| 205 if (success) | |
| 206 result = PP_OK; | 195 result = PP_OK; |
| 207 } | 196 } |
| 208 if (result == PP_OK) { | 197 if (result == PP_OK) { |
| 209 // This writes the file info into the plugin's PP_FileInfo struct. | 198 // This writes the file info into the plugin's PP_FileInfo struct. |
| 210 ppapi::FileInfoToPepperFileInfo(file_info, | 199 ppapi::FileInfoToPepperFileInfo(file_info, |
| 211 file_system_type_, | 200 file_system_type_, |
| 212 info); | 201 info); |
| 213 } | 202 } |
| 214 state_manager_.SetOperationFinished(); | 203 state_manager_.SetOperationFinished(); |
| 215 return result; | 204 return result; |
| 216 } | 205 } |
| 217 | 206 |
| 218 // For the non-blocking case, post a task to the file thread and add a | 207 // For the non-blocking case, post a task to the file thread and add a |
| 219 // completion task to write the result. | 208 // completion task to write the result. |
| 220 scoped_refptr<QueryOp> query_op(new QueryOp(file_handle_)); | 209 scoped_refptr<QueryOp> query_op(new QueryOp(file_holder_)); |
| 221 base::PostTaskAndReplyWithResult( | 210 base::PostTaskAndReplyWithResult( |
| 222 PpapiGlobals::Get()->GetFileTaskRunner(), | 211 PpapiGlobals::Get()->GetFileTaskRunner(), |
| 223 FROM_HERE, | 212 FROM_HERE, |
| 224 Bind(&FileIOResource::QueryOp::DoWork, query_op), | 213 Bind(&FileIOResource::QueryOp::DoWork, query_op), |
| 225 RunWhileLocked(Bind(&TrackedCallback::Run, callback))); | 214 RunWhileLocked(Bind(&TrackedCallback::Run, callback))); |
| 226 callback->set_completion_task( | 215 callback->set_completion_task( |
| 227 Bind(&FileIOResource::OnQueryComplete, this, query_op, info)); | 216 Bind(&FileIOResource::OnQueryComplete, this, query_op, info)); |
| 228 | 217 |
| 229 return PP_OK_COMPLETIONPENDING; | 218 return PP_OK_COMPLETIONPENDING; |
| 230 } | 219 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 } | 264 } |
| 276 | 265 |
| 277 int32_t FileIOResource::Write(int64_t offset, | 266 int32_t FileIOResource::Write(int64_t offset, |
| 278 const char* buffer, | 267 const char* buffer, |
| 279 int32_t bytes_to_write, | 268 int32_t bytes_to_write, |
| 280 scoped_refptr<TrackedCallback> callback) { | 269 scoped_refptr<TrackedCallback> callback) { |
| 281 if (!buffer) | 270 if (!buffer) |
| 282 return PP_ERROR_FAILED; | 271 return PP_ERROR_FAILED; |
| 283 if (offset < 0 || bytes_to_write < 0) | 272 if (offset < 0 || bytes_to_write < 0) |
| 284 return PP_ERROR_FAILED; | 273 return PP_ERROR_FAILED; |
| 285 if (!FileHandleHolder::IsValid(file_handle_)) | 274 if (!FileHolder::IsValid(file_holder_)) |
| 286 return PP_ERROR_FAILED; | 275 return PP_ERROR_FAILED; |
| 287 | 276 |
| 288 int32_t rv = state_manager_.CheckOperationState( | 277 int32_t rv = state_manager_.CheckOperationState( |
| 289 FileIOStateManager::OPERATION_WRITE, true); | 278 FileIOStateManager::OPERATION_WRITE, true); |
| 290 if (rv != PP_OK) | 279 if (rv != PP_OK) |
| 291 return rv; | 280 return rv; |
| 292 | 281 |
| 293 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_WRITE); | 282 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_WRITE); |
| 294 | 283 |
| 295 if (check_quota_) { | 284 if (check_quota_) { |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 if (called_close_) | 390 if (called_close_) |
| 402 return; | 391 return; |
| 403 | 392 |
| 404 called_close_ = true; | 393 called_close_ = true; |
| 405 if (check_quota_) { | 394 if (check_quota_) { |
| 406 check_quota_ = false; | 395 check_quota_ = false; |
| 407 file_system_resource_->AsPPB_FileSystem_API()->CloseQuotaFile( | 396 file_system_resource_->AsPPB_FileSystem_API()->CloseQuotaFile( |
| 408 pp_resource()); | 397 pp_resource()); |
| 409 } | 398 } |
| 410 | 399 |
| 411 if (file_handle_) | 400 if (file_holder_) |
| 412 file_handle_ = NULL; | 401 file_holder_ = NULL; |
| 413 | 402 |
| 414 Post(BROWSER, PpapiHostMsg_FileIO_Close( | 403 Post(BROWSER, PpapiHostMsg_FileIO_Close( |
| 415 FileGrowth(max_written_offset_, append_mode_write_amount_))); | 404 FileGrowth(max_written_offset_, append_mode_write_amount_))); |
| 416 } | 405 } |
| 417 | 406 |
| 418 int32_t FileIOResource::RequestOSFileHandle( | 407 int32_t FileIOResource::RequestOSFileHandle( |
| 419 PP_FileHandle* handle, | 408 PP_FileHandle* handle, |
| 420 scoped_refptr<TrackedCallback> callback) { | 409 scoped_refptr<TrackedCallback> callback) { |
| 421 int32_t rv = state_manager_.CheckOperationState( | 410 int32_t rv = state_manager_.CheckOperationState( |
| 422 FileIOStateManager::OPERATION_EXCLUSIVE, true); | 411 FileIOStateManager::OPERATION_EXCLUSIVE, true); |
| 423 if (rv != PP_OK) | 412 if (rv != PP_OK) |
| 424 return rv; | 413 return rv; |
| 425 | 414 |
| 426 Call<PpapiPluginMsg_FileIO_RequestOSFileHandleReply>(BROWSER, | 415 Call<PpapiPluginMsg_FileIO_RequestOSFileHandleReply>(BROWSER, |
| 427 PpapiHostMsg_FileIO_RequestOSFileHandle(), | 416 PpapiHostMsg_FileIO_RequestOSFileHandle(), |
| 428 base::Bind(&FileIOResource::OnPluginMsgRequestOSFileHandleComplete, this, | 417 base::Bind(&FileIOResource::OnPluginMsgRequestOSFileHandleComplete, this, |
| 429 callback, handle)); | 418 callback, handle)); |
| 430 | 419 |
| 431 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); | 420 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); |
| 432 return PP_OK_COMPLETIONPENDING; | 421 return PP_OK_COMPLETIONPENDING; |
| 433 } | 422 } |
| 434 | 423 |
| 435 FileIOResource::FileHandleHolder::FileHandleHolder(PP_FileHandle file_handle) | 424 FileIOResource::FileHolder::FileHolder(PP_FileHandle file_handle) |
| 436 : raw_handle_(file_handle) { | 425 : file_(file_handle) { |
| 437 } | 426 } |
| 438 | 427 |
| 439 // static | 428 // static |
| 440 bool FileIOResource::FileHandleHolder::IsValid( | 429 bool FileIOResource::FileHolder::IsValid( |
| 441 const scoped_refptr<FileIOResource::FileHandleHolder>& handle) { | 430 const scoped_refptr<FileIOResource::FileHolder>& handle) { |
| 442 return handle && (handle->raw_handle() != base::kInvalidPlatformFileValue); | 431 return handle && handle->file_.IsValid(); |
| 443 } | 432 } |
| 444 | 433 |
| 445 FileIOResource::FileHandleHolder::~FileHandleHolder() { | 434 FileIOResource::FileHolder::~FileHolder() { |
| 446 if (raw_handle_ != base::kInvalidPlatformFileValue) { | 435 if (file_.IsValid()) { |
| 447 base::TaskRunner* file_task_runner = | 436 base::TaskRunner* file_task_runner = |
| 448 PpapiGlobals::Get()->GetFileTaskRunner(); | 437 PpapiGlobals::Get()->GetFileTaskRunner(); |
| 449 file_task_runner->PostTask(FROM_HERE, | 438 file_task_runner->PostTask(FROM_HERE, |
| 450 base::Bind(&DoClose, raw_handle_)); | 439 base::Bind(&DoClose, Passed(&file_))); |
| 451 } | 440 } |
| 452 } | 441 } |
| 453 | 442 |
| 454 int32_t FileIOResource::ReadValidated(int64_t offset, | 443 int32_t FileIOResource::ReadValidated(int64_t offset, |
| 455 int32_t bytes_to_read, | 444 int32_t bytes_to_read, |
| 456 const PP_ArrayOutput& array_output, | 445 const PP_ArrayOutput& array_output, |
| 457 scoped_refptr<TrackedCallback> callback) { | 446 scoped_refptr<TrackedCallback> callback) { |
| 458 if (bytes_to_read < 0) | 447 if (bytes_to_read < 0) |
| 459 return PP_ERROR_FAILED; | 448 return PP_ERROR_FAILED; |
| 460 if (!FileHandleHolder::IsValid(file_handle_)) | 449 if (!FileHolder::IsValid(file_holder_)) |
| 461 return PP_ERROR_FAILED; | 450 return PP_ERROR_FAILED; |
| 462 | 451 |
| 463 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_READ); | 452 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_READ); |
| 464 | 453 |
| 465 bytes_to_read = std::min(bytes_to_read, kMaxReadWriteSize); | 454 bytes_to_read = std::min(bytes_to_read, kMaxReadWriteSize); |
| 466 if (callback->is_blocking()) { | 455 if (callback->is_blocking()) { |
| 467 char* buffer = static_cast<char*>( | 456 char* buffer = static_cast<char*>( |
| 468 array_output.GetDataBuffer(array_output.user_data, bytes_to_read, 1)); | 457 array_output.GetDataBuffer(array_output.user_data, bytes_to_read, 1)); |
| 469 int32_t result = PP_ERROR_FAILED; | 458 int32_t result = PP_ERROR_FAILED; |
| 470 // The plugin could release its reference to this instance when we release | 459 // The plugin could release its reference to this instance when we release |
| 471 // the proxy lock below. | 460 // the proxy lock below. |
| 472 scoped_refptr<FileIOResource> protect(this); | 461 scoped_refptr<FileIOResource> protect(this); |
| 473 if (buffer) { | 462 if (buffer) { |
| 474 // Release the proxy lock while making a potentially slow file call. | 463 // Release the proxy lock while making a potentially slow file call. |
| 475 ProxyAutoUnlock unlock; | 464 ProxyAutoUnlock unlock; |
| 476 result = base::ReadPlatformFile( | 465 result = file_holder_->file()->Read(offset, buffer, bytes_to_read); |
| 477 file_handle_->raw_handle(), offset, buffer, bytes_to_read); | |
| 478 if (result < 0) | 466 if (result < 0) |
| 479 result = PP_ERROR_FAILED; | 467 result = PP_ERROR_FAILED; |
| 480 } | 468 } |
| 481 state_manager_.SetOperationFinished(); | 469 state_manager_.SetOperationFinished(); |
| 482 return result; | 470 return result; |
| 483 } | 471 } |
| 484 | 472 |
| 485 // For the non-blocking case, post a task to the file thread. | 473 // For the non-blocking case, post a task to the file thread. |
| 486 scoped_refptr<ReadOp> read_op( | 474 scoped_refptr<ReadOp> read_op( |
| 487 new ReadOp(file_handle_, offset, bytes_to_read)); | 475 new ReadOp(file_holder_, offset, bytes_to_read)); |
| 488 base::PostTaskAndReplyWithResult( | 476 base::PostTaskAndReplyWithResult( |
| 489 PpapiGlobals::Get()->GetFileTaskRunner(), | 477 PpapiGlobals::Get()->GetFileTaskRunner(), |
| 490 FROM_HERE, | 478 FROM_HERE, |
| 491 Bind(&FileIOResource::ReadOp::DoWork, read_op), | 479 Bind(&FileIOResource::ReadOp::DoWork, read_op), |
| 492 RunWhileLocked(Bind(&TrackedCallback::Run, callback))); | 480 RunWhileLocked(Bind(&TrackedCallback::Run, callback))); |
| 493 callback->set_completion_task( | 481 callback->set_completion_task( |
| 494 Bind(&FileIOResource::OnReadComplete, this, read_op, array_output)); | 482 Bind(&FileIOResource::OnReadComplete, this, read_op, array_output)); |
| 495 | 483 |
| 496 return PP_OK_COMPLETIONPENDING; | 484 return PP_OK_COMPLETIONPENDING; |
| 497 } | 485 } |
| 498 | 486 |
| 499 int32_t FileIOResource::WriteValidated( | 487 int32_t FileIOResource::WriteValidated( |
| 500 int64_t offset, | 488 int64_t offset, |
| 501 const char* buffer, | 489 const char* buffer, |
| 502 int32_t bytes_to_write, | 490 int32_t bytes_to_write, |
| 503 scoped_refptr<TrackedCallback> callback) { | 491 scoped_refptr<TrackedCallback> callback) { |
| 504 bool append = (open_flags_ & PP_FILEOPENFLAG_APPEND) != 0; | 492 bool append = (open_flags_ & PP_FILEOPENFLAG_APPEND) != 0; |
| 505 if (callback->is_blocking()) { | 493 if (callback->is_blocking()) { |
| 506 int32_t result; | 494 int32_t result; |
| 507 { | 495 { |
| 508 // Release the proxy lock while making a potentially slow file call. | 496 // Release the proxy lock while making a potentially slow file call. |
| 509 ProxyAutoUnlock unlock; | 497 ProxyAutoUnlock unlock; |
| 510 if (append) { | 498 if (append) { |
| 511 result = base::WritePlatformFileAtCurrentPos( | 499 result = file_holder_->file()->WriteAtCurrentPos(buffer, |
| 512 file_handle_->raw_handle(), buffer, bytes_to_write); | 500 bytes_to_write); |
| 513 } else { | 501 } else { |
| 514 result = base::WritePlatformFile( | 502 result = file_holder_->file()->Write(offset, buffer, bytes_to_write); |
| 515 file_handle_->raw_handle(), offset, buffer, bytes_to_write); | |
| 516 } | 503 } |
| 517 } | 504 } |
| 518 if (result < 0) | 505 if (result < 0) |
| 519 result = PP_ERROR_FAILED; | 506 result = PP_ERROR_FAILED; |
| 520 | 507 |
| 521 state_manager_.SetOperationFinished(); | 508 state_manager_.SetOperationFinished(); |
| 522 return result; | 509 return result; |
| 523 } | 510 } |
| 524 | 511 |
| 525 // For the non-blocking case, post a task to the file thread. We must copy the | 512 // For the non-blocking case, post a task to the file thread. We must copy the |
| 526 // plugin's buffer at this point. | 513 // plugin's buffer at this point. |
| 527 scoped_ptr<char[]> copy(new char[bytes_to_write]); | 514 scoped_ptr<char[]> copy(new char[bytes_to_write]); |
| 528 memcpy(copy.get(), buffer, bytes_to_write); | 515 memcpy(copy.get(), buffer, bytes_to_write); |
| 529 scoped_refptr<WriteOp> write_op( | 516 scoped_refptr<WriteOp> write_op( |
| 530 new WriteOp(file_handle_, offset, copy.Pass(), bytes_to_write, append)); | 517 new WriteOp(file_holder_, offset, copy.Pass(), bytes_to_write, append)); |
| 531 base::PostTaskAndReplyWithResult( | 518 base::PostTaskAndReplyWithResult( |
| 532 PpapiGlobals::Get()->GetFileTaskRunner(), | 519 PpapiGlobals::Get()->GetFileTaskRunner(), |
| 533 FROM_HERE, | 520 FROM_HERE, |
| 534 Bind(&FileIOResource::WriteOp::DoWork, write_op), | 521 Bind(&FileIOResource::WriteOp::DoWork, write_op), |
| 535 RunWhileLocked(Bind(&TrackedCallback::Run, callback))); | 522 RunWhileLocked(Bind(&TrackedCallback::Run, callback))); |
| 536 callback->set_completion_task(Bind(&FileIOResource::OnWriteComplete, this)); | 523 callback->set_completion_task(Bind(&FileIOResource::OnWriteComplete, this)); |
| 537 | 524 |
| 538 return PP_OK_COMPLETIONPENDING; | 525 return PP_OK_COMPLETIONPENDING; |
| 539 } | 526 } |
| 540 | 527 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 612 } | 599 } |
| 613 | 600 |
| 614 if (callback->is_blocking()) { | 601 if (callback->is_blocking()) { |
| 615 int32_t result = | 602 int32_t result = |
| 616 WriteValidated(offset, buffer.get(), bytes_to_write, callback); | 603 WriteValidated(offset, buffer.get(), bytes_to_write, callback); |
| 617 DCHECK(result != PP_OK_COMPLETIONPENDING); | 604 DCHECK(result != PP_OK_COMPLETIONPENDING); |
| 618 callback->Run(result); | 605 callback->Run(result); |
| 619 } else { | 606 } else { |
| 620 bool append = (open_flags_ & PP_FILEOPENFLAG_APPEND) != 0; | 607 bool append = (open_flags_ & PP_FILEOPENFLAG_APPEND) != 0; |
| 621 scoped_refptr<WriteOp> write_op(new WriteOp( | 608 scoped_refptr<WriteOp> write_op(new WriteOp( |
| 622 file_handle_, offset, buffer.Pass(), bytes_to_write, append)); | 609 file_holder_, offset, buffer.Pass(), bytes_to_write, append)); |
| 623 base::PostTaskAndReplyWithResult( | 610 base::PostTaskAndReplyWithResult( |
| 624 PpapiGlobals::Get()->GetFileTaskRunner(), | 611 PpapiGlobals::Get()->GetFileTaskRunner(), |
| 625 FROM_HERE, | 612 FROM_HERE, |
| 626 Bind(&FileIOResource::WriteOp::DoWork, write_op), | 613 Bind(&FileIOResource::WriteOp::DoWork, write_op), |
| 627 RunWhileLocked(Bind(&TrackedCallback::Run, callback))); | 614 RunWhileLocked(Bind(&TrackedCallback::Run, callback))); |
| 628 callback->set_completion_task(Bind(&FileIOResource::OnWriteComplete, this)); | 615 callback->set_completion_task(Bind(&FileIOResource::OnWriteComplete, this)); |
| 629 } | 616 } |
| 630 } | 617 } |
| 631 | 618 |
| 632 void FileIOResource::OnRequestSetLengthQuotaComplete( | 619 void FileIOResource::OnRequestSetLengthQuotaComplete( |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 686 if (quota_file_system) { | 673 if (quota_file_system) { |
| 687 DCHECK(quota_file_system == file_system_resource_->pp_resource()); | 674 DCHECK(quota_file_system == file_system_resource_->pp_resource()); |
| 688 check_quota_ = true; | 675 check_quota_ = true; |
| 689 max_written_offset_ = max_written_offset; | 676 max_written_offset_ = max_written_offset; |
| 690 file_system_resource_->AsPPB_FileSystem_API()->OpenQuotaFile( | 677 file_system_resource_->AsPPB_FileSystem_API()->OpenQuotaFile( |
| 691 pp_resource()); | 678 pp_resource()); |
| 692 } | 679 } |
| 693 | 680 |
| 694 IPC::PlatformFileForTransit transit_file; | 681 IPC::PlatformFileForTransit transit_file; |
| 695 if (params.TakeFileHandleAtIndex(0, &transit_file)) { | 682 if (params.TakeFileHandleAtIndex(0, &transit_file)) { |
| 696 file_handle_ = new FileHandleHolder( | 683 file_holder_ = new FileHolder( |
| 697 IPC::PlatformFileForTransitToPlatformFile(transit_file)); | 684 IPC::PlatformFileForTransitToPlatformFile(transit_file)); |
| 698 } | 685 } |
| 699 } | 686 } |
| 700 // End this operation now, so the user's callback can execute another FileIO | 687 // End this operation now, so the user's callback can execute another FileIO |
| 701 // operation, assuming there are no other pending operations. | 688 // operation, assuming there are no other pending operations. |
| 702 state_manager_.SetOperationFinished(); | 689 state_manager_.SetOperationFinished(); |
| 703 callback->Run(result); | 690 callback->Run(result); |
| 704 } | 691 } |
| 705 | 692 |
| 706 void FileIOResource::OnPluginMsgRequestOSFileHandleComplete( | 693 void FileIOResource::OnPluginMsgRequestOSFileHandleComplete( |
| (...skipping 15 matching lines...) Expand all Loading... |
| 722 *output_handle = IPC::PlatformFileForTransitToPlatformFile(transit_file); | 709 *output_handle = IPC::PlatformFileForTransitToPlatformFile(transit_file); |
| 723 | 710 |
| 724 // End this operation now, so the user's callback can execute another FileIO | 711 // End this operation now, so the user's callback can execute another FileIO |
| 725 // operation, assuming there are no other pending operations. | 712 // operation, assuming there are no other pending operations. |
| 726 state_manager_.SetOperationFinished(); | 713 state_manager_.SetOperationFinished(); |
| 727 callback->Run(result); | 714 callback->Run(result); |
| 728 } | 715 } |
| 729 | 716 |
| 730 } // namespace proxy | 717 } // namespace proxy |
| 731 } // namespace ppapi | 718 } // namespace ppapi |
| OLD | NEW |