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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 | 50 |
51 FileIOResource::QueryOp::QueryOp(scoped_refptr<FileHandleHolder> file_handle) | 51 FileIOResource::QueryOp::QueryOp(scoped_refptr<FileHandleHolder> file_handle) |
52 : file_handle_(file_handle) { | 52 : file_handle_(file_handle) { |
53 DCHECK(file_handle_); | 53 DCHECK(file_handle_); |
54 } | 54 } |
55 | 55 |
56 FileIOResource::QueryOp::~QueryOp() { | 56 FileIOResource::QueryOp::~QueryOp() { |
57 } | 57 } |
58 | 58 |
59 int32_t FileIOResource::QueryOp::DoWork() { | 59 int32_t FileIOResource::QueryOp::DoWork() { |
60 return base::GetPlatformFileInfo(file_handle_->raw_handle(), &file_info_) ? | 60 // TODO(rvargas): Convert this code to use base::File. |
61 PP_OK : PP_ERROR_FAILED; | 61 if (base::GetPlatformFileInfo( |
| 62 file_handle_->raw_handle(), |
| 63 reinterpret_cast<base::PlatformFileInfo*>(&file_info_))) { |
| 64 return PP_OK; |
| 65 } |
| 66 return PP_ERROR_FAILED; |
62 } | 67 } |
63 | 68 |
64 FileIOResource::ReadOp::ReadOp(scoped_refptr<FileHandleHolder> file_handle, | 69 FileIOResource::ReadOp::ReadOp(scoped_refptr<FileHandleHolder> file_handle, |
65 int64_t offset, | 70 int64_t offset, |
66 int32_t bytes_to_read) | 71 int32_t bytes_to_read) |
67 : file_handle_(file_handle), | 72 : file_handle_(file_handle), |
68 offset_(offset), | 73 offset_(offset), |
69 bytes_to_read_(bytes_to_read) { | 74 bytes_to_read_(bytes_to_read) { |
70 DCHECK(file_handle_); | 75 DCHECK(file_handle_); |
71 } | 76 } |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 if (!info) | 185 if (!info) |
181 return PP_ERROR_BADARGUMENT; | 186 return PP_ERROR_BADARGUMENT; |
182 if (!FileHandleHolder::IsValid(file_handle_)) | 187 if (!FileHandleHolder::IsValid(file_handle_)) |
183 return PP_ERROR_FAILED; | 188 return PP_ERROR_FAILED; |
184 | 189 |
185 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); | 190 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); |
186 | 191 |
187 // If the callback is blocking, perform the task on the calling thread. | 192 // If the callback is blocking, perform the task on the calling thread. |
188 if (callback->is_blocking()) { | 193 if (callback->is_blocking()) { |
189 int32_t result = PP_ERROR_FAILED; | 194 int32_t result = PP_ERROR_FAILED; |
190 base::PlatformFileInfo file_info; | 195 base::File::Info file_info; |
191 // The plugin could release its reference to this instance when we release | 196 // The plugin could release its reference to this instance when we release |
192 // the proxy lock below. | 197 // the proxy lock below. |
193 scoped_refptr<FileIOResource> protect(this); | 198 scoped_refptr<FileIOResource> protect(this); |
194 { | 199 { |
195 // Release the proxy lock while making a potentially slow file call. | 200 // Release the proxy lock while making a potentially slow file call. |
196 ProxyAutoUnlock unlock; | 201 ProxyAutoUnlock unlock; |
197 if (base::GetPlatformFileInfo(file_handle_->raw_handle(), &file_info)) | 202 // TODO(rvargas): Convert this code to base::File. |
| 203 if (base::GetPlatformFileInfo( |
| 204 file_handle_->raw_handle(), |
| 205 reinterpret_cast<base::PlatformFileInfo*>(&file_info))) { |
198 result = PP_OK; | 206 result = PP_OK; |
| 207 } |
199 } | 208 } |
200 if (result == PP_OK) { | 209 if (result == PP_OK) { |
201 // This writes the file info into the plugin's PP_FileInfo struct. | 210 // This writes the file info into the plugin's PP_FileInfo struct. |
202 ppapi::PlatformFileInfoToPepperFileInfo(file_info, | 211 ppapi::FileInfoToPepperFileInfo(file_info, |
203 file_system_type_, | 212 file_system_type_, |
204 info); | 213 info); |
205 } | 214 } |
206 state_manager_.SetOperationFinished(); | 215 state_manager_.SetOperationFinished(); |
207 return result; | 216 return result; |
208 } | 217 } |
209 | 218 |
210 // For the non-blocking case, post a task to the file thread and add a | 219 // For the non-blocking case, post a task to the file thread and add a |
211 // completion task to write the result. | 220 // completion task to write the result. |
212 scoped_refptr<QueryOp> query_op(new QueryOp(file_handle_)); | 221 scoped_refptr<QueryOp> query_op(new QueryOp(file_handle_)); |
213 base::PostTaskAndReplyWithResult( | 222 base::PostTaskAndReplyWithResult( |
214 PpapiGlobals::Get()->GetFileTaskRunner(), | 223 PpapiGlobals::Get()->GetFileTaskRunner(), |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 } | 523 } |
515 | 524 |
516 int32_t FileIOResource::OnQueryComplete(scoped_refptr<QueryOp> query_op, | 525 int32_t FileIOResource::OnQueryComplete(scoped_refptr<QueryOp> query_op, |
517 PP_FileInfo* info, | 526 PP_FileInfo* info, |
518 int32_t result) { | 527 int32_t result) { |
519 DCHECK(state_manager_.get_pending_operation() == | 528 DCHECK(state_manager_.get_pending_operation() == |
520 FileIOStateManager::OPERATION_EXCLUSIVE); | 529 FileIOStateManager::OPERATION_EXCLUSIVE); |
521 | 530 |
522 if (result == PP_OK) { | 531 if (result == PP_OK) { |
523 // This writes the file info into the plugin's PP_FileInfo struct. | 532 // This writes the file info into the plugin's PP_FileInfo struct. |
524 ppapi::PlatformFileInfoToPepperFileInfo(query_op->file_info(), | 533 ppapi::FileInfoToPepperFileInfo(query_op->file_info(), |
525 file_system_type_, | 534 file_system_type_, |
526 info); | 535 info); |
527 } | 536 } |
528 state_manager_.SetOperationFinished(); | 537 state_manager_.SetOperationFinished(); |
529 return result; | 538 return result; |
530 } | 539 } |
531 | 540 |
532 int32_t FileIOResource::OnReadComplete(scoped_refptr<ReadOp> read_op, | 541 int32_t FileIOResource::OnReadComplete(scoped_refptr<ReadOp> read_op, |
533 PP_ArrayOutput array_output, | 542 PP_ArrayOutput array_output, |
534 int32_t result) { | 543 int32_t result) { |
535 DCHECK(state_manager_.get_pending_operation() == | 544 DCHECK(state_manager_.get_pending_operation() == |
536 FileIOStateManager::OPERATION_READ); | 545 FileIOStateManager::OPERATION_READ); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
658 *output_handle = IPC::PlatformFileForTransitToPlatformFile(transit_file); | 667 *output_handle = IPC::PlatformFileForTransitToPlatformFile(transit_file); |
659 | 668 |
660 // End this operation now, so the user's callback can execute another FileIO | 669 // End this operation now, so the user's callback can execute another FileIO |
661 // operation, assuming there are no other pending operations. | 670 // operation, assuming there are no other pending operations. |
662 state_manager_.SetOperationFinished(); | 671 state_manager_.SetOperationFinished(); |
663 callback->Run(result); | 672 callback->Run(result); |
664 } | 673 } |
665 | 674 |
666 } // namespace proxy | 675 } // namespace proxy |
667 } // namespace ppapi | 676 } // namespace ppapi |
OLD | NEW |