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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
42 void DoClose(base::File auto_close_file) { | 42 void DoClose(base::File auto_close_file) { |
43 } | 43 } |
44 | 44 |
45 } // namespace | 45 } // namespace |
46 | 46 |
47 namespace ppapi { | 47 namespace ppapi { |
48 namespace proxy { | 48 namespace proxy { |
49 | 49 |
50 FileIOResource::QueryOp::QueryOp(scoped_refptr<FileHolder> file_holder) | 50 FileIOResource::QueryOp::QueryOp(scoped_refptr<FileHolder> file_holder) |
51 : file_holder_(file_holder) { | 51 : file_holder_(file_holder) { |
52 DCHECK(file_holder_); | 52 DCHECK(file_holder_.get()); |
dmichael (off chromium)
2014/08/25 19:55:12
I thought there was (or would be) a reasonable con
dcheng
2014/08/25 19:56:39
Unfortunately, it's not possible to add a boolean
| |
53 } | 53 } |
54 | 54 |
55 FileIOResource::QueryOp::~QueryOp() { | 55 FileIOResource::QueryOp::~QueryOp() { |
56 } | 56 } |
57 | 57 |
58 int32_t FileIOResource::QueryOp::DoWork() { | 58 int32_t FileIOResource::QueryOp::DoWork() { |
59 return file_holder_->file()->GetInfo(&file_info_) ? PP_OK : PP_ERROR_FAILED; | 59 return file_holder_->file()->GetInfo(&file_info_) ? PP_OK : PP_ERROR_FAILED; |
60 } | 60 } |
61 | 61 |
62 FileIOResource::ReadOp::ReadOp(scoped_refptr<FileHolder> file_holder, | 62 FileIOResource::ReadOp::ReadOp(scoped_refptr<FileHolder> file_holder, |
63 int64_t offset, | 63 int64_t offset, |
64 int32_t bytes_to_read) | 64 int32_t bytes_to_read) |
65 : file_holder_(file_holder), | 65 : file_holder_(file_holder), |
66 offset_(offset), | 66 offset_(offset), |
67 bytes_to_read_(bytes_to_read) { | 67 bytes_to_read_(bytes_to_read) { |
68 DCHECK(file_holder_); | 68 DCHECK(file_holder_.get()); |
69 } | 69 } |
70 | 70 |
71 FileIOResource::ReadOp::~ReadOp() { | 71 FileIOResource::ReadOp::~ReadOp() { |
72 } | 72 } |
73 | 73 |
74 int32_t FileIOResource::ReadOp::DoWork() { | 74 int32_t FileIOResource::ReadOp::DoWork() { |
75 DCHECK(!buffer_.get()); | 75 DCHECK(!buffer_.get()); |
76 buffer_.reset(new char[bytes_to_read_]); | 76 buffer_.reset(new char[bytes_to_read_]); |
77 return file_holder_->file()->Read(offset_, buffer_.get(), bytes_to_read_); | 77 return file_holder_->file()->Read(offset_, buffer_.get(), bytes_to_read_); |
78 } | 78 } |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
390 if (called_close_) | 390 if (called_close_) |
391 return; | 391 return; |
392 | 392 |
393 called_close_ = true; | 393 called_close_ = true; |
394 if (check_quota_) { | 394 if (check_quota_) { |
395 check_quota_ = false; | 395 check_quota_ = false; |
396 file_system_resource_->AsPPB_FileSystem_API()->CloseQuotaFile( | 396 file_system_resource_->AsPPB_FileSystem_API()->CloseQuotaFile( |
397 pp_resource()); | 397 pp_resource()); |
398 } | 398 } |
399 | 399 |
400 if (file_holder_) | 400 if (file_holder_.get()) |
401 file_holder_ = NULL; | 401 file_holder_ = NULL; |
402 | 402 |
403 Post(BROWSER, PpapiHostMsg_FileIO_Close( | 403 Post(BROWSER, PpapiHostMsg_FileIO_Close( |
404 FileGrowth(max_written_offset_, append_mode_write_amount_))); | 404 FileGrowth(max_written_offset_, append_mode_write_amount_))); |
405 } | 405 } |
406 | 406 |
407 int32_t FileIOResource::RequestOSFileHandle( | 407 int32_t FileIOResource::RequestOSFileHandle( |
408 PP_FileHandle* handle, | 408 PP_FileHandle* handle, |
409 scoped_refptr<TrackedCallback> callback) { | 409 scoped_refptr<TrackedCallback> callback) { |
410 int32_t rv = state_manager_.CheckOperationState( | 410 int32_t rv = state_manager_.CheckOperationState( |
(...skipping 10 matching lines...) Expand all Loading... | |
421 return PP_OK_COMPLETIONPENDING; | 421 return PP_OK_COMPLETIONPENDING; |
422 } | 422 } |
423 | 423 |
424 FileIOResource::FileHolder::FileHolder(PP_FileHandle file_handle) | 424 FileIOResource::FileHolder::FileHolder(PP_FileHandle file_handle) |
425 : file_(file_handle) { | 425 : file_(file_handle) { |
426 } | 426 } |
427 | 427 |
428 // static | 428 // static |
429 bool FileIOResource::FileHolder::IsValid( | 429 bool FileIOResource::FileHolder::IsValid( |
430 const scoped_refptr<FileIOResource::FileHolder>& handle) { | 430 const scoped_refptr<FileIOResource::FileHolder>& handle) { |
431 return handle && handle->file_.IsValid(); | 431 return handle.get() && handle->file_.IsValid(); |
432 } | 432 } |
433 | 433 |
434 FileIOResource::FileHolder::~FileHolder() { | 434 FileIOResource::FileHolder::~FileHolder() { |
435 if (file_.IsValid()) { | 435 if (file_.IsValid()) { |
436 base::TaskRunner* file_task_runner = | 436 base::TaskRunner* file_task_runner = |
437 PpapiGlobals::Get()->GetFileTaskRunner(); | 437 PpapiGlobals::Get()->GetFileTaskRunner(); |
438 file_task_runner->PostTask(FROM_HERE, | 438 file_task_runner->PostTask(FROM_HERE, |
439 base::Bind(&DoClose, Passed(&file_))); | 439 base::Bind(&DoClose, Passed(&file_))); |
440 } | 440 } |
441 } | 441 } |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
709 *output_handle = IPC::PlatformFileForTransitToPlatformFile(transit_file); | 709 *output_handle = IPC::PlatformFileForTransitToPlatformFile(transit_file); |
710 | 710 |
711 // 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 |
712 // operation, assuming there are no other pending operations. | 712 // operation, assuming there are no other pending operations. |
713 state_manager_.SetOperationFinished(); | 713 state_manager_.SetOperationFinished(); |
714 callback->Run(result); | 714 callback->Run(result); |
715 } | 715 } |
716 | 716 |
717 } // namespace proxy | 717 } // namespace proxy |
718 } // namespace ppapi | 718 } // namespace ppapi |
OLD | NEW |