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_))) { | |
dmichael (off chromium)
2014/01/23 21:22:10
Please define & use an explicit conversion functio
rvargas (doing something else)
2014/01/24 03:14:54
fixed
| |
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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
181 if (!info) | 186 if (!info) |
182 return PP_ERROR_BADARGUMENT; | 187 return PP_ERROR_BADARGUMENT; |
183 if (!FileHandleHolder::IsValid(file_handle_)) | 188 if (!FileHandleHolder::IsValid(file_handle_)) |
184 return PP_ERROR_FAILED; | 189 return PP_ERROR_FAILED; |
185 | 190 |
186 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); | 191 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); |
187 | 192 |
188 // If the callback is blocking, perform the task on the calling thread. | 193 // If the callback is blocking, perform the task on the calling thread. |
189 if (callback->is_blocking()) { | 194 if (callback->is_blocking()) { |
190 int32_t result = PP_ERROR_FAILED; | 195 int32_t result = PP_ERROR_FAILED; |
191 base::PlatformFileInfo file_info; | 196 base::File::Info file_info; |
192 // The plugin could release its reference to this instance when we release | 197 // The plugin could release its reference to this instance when we release |
193 // the proxy lock below. | 198 // the proxy lock below. |
194 scoped_refptr<FileIOResource> protect(this); | 199 scoped_refptr<FileIOResource> protect(this); |
195 { | 200 { |
196 // Release the proxy lock while making a potentially slow file call. | 201 // Release the proxy lock while making a potentially slow file call. |
197 ProxyAutoUnlock unlock; | 202 ProxyAutoUnlock unlock; |
198 if (base::GetPlatformFileInfo(file_handle_->raw_handle(), &file_info)) | 203 // TODO(rvargas): Convert this code to base::File. |
204 if (base::GetPlatformFileInfo( | |
205 file_handle_->raw_handle(), | |
206 reinterpret_cast<base::PlatformFileInfo*>(&file_info))) { | |
dmichael (off chromium)
2014/01/23 21:22:10
ditto
rvargas (doing something else)
2014/01/24 03:14:54
fixed
| |
199 result = PP_OK; | 207 result = PP_OK; |
208 } | |
200 } | 209 } |
201 if (result == PP_OK) { | 210 if (result == PP_OK) { |
202 // This writes the file info into the plugin's PP_FileInfo struct. | 211 // This writes the file info into the plugin's PP_FileInfo struct. |
203 ppapi::PlatformFileInfoToPepperFileInfo(file_info, | 212 ppapi::FileInfoToPepperFileInfo(file_info, |
204 file_system_type_, | 213 file_system_type_, |
205 info); | 214 info); |
206 } | 215 } |
207 state_manager_.SetOperationFinished(); | 216 state_manager_.SetOperationFinished(); |
208 return result; | 217 return result; |
209 } | 218 } |
210 | 219 |
211 // For the non-blocking case, post a task to the file thread and add a | 220 // For the non-blocking case, post a task to the file thread and add a |
212 // completion task to write the result. | 221 // completion task to write the result. |
213 scoped_refptr<QueryOp> query_op(new QueryOp(file_handle_)); | 222 scoped_refptr<QueryOp> query_op(new QueryOp(file_handle_)); |
214 base::PostTaskAndReplyWithResult( | 223 base::PostTaskAndReplyWithResult( |
215 PpapiGlobals::Get()->GetFileTaskRunner(), | 224 PpapiGlobals::Get()->GetFileTaskRunner(), |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
540 } | 549 } |
541 | 550 |
542 int32_t FileIOResource::OnQueryComplete(scoped_refptr<QueryOp> query_op, | 551 int32_t FileIOResource::OnQueryComplete(scoped_refptr<QueryOp> query_op, |
543 PP_FileInfo* info, | 552 PP_FileInfo* info, |
544 int32_t result) { | 553 int32_t result) { |
545 DCHECK(state_manager_.get_pending_operation() == | 554 DCHECK(state_manager_.get_pending_operation() == |
546 FileIOStateManager::OPERATION_EXCLUSIVE); | 555 FileIOStateManager::OPERATION_EXCLUSIVE); |
547 | 556 |
548 if (result == PP_OK) { | 557 if (result == PP_OK) { |
549 // This writes the file info into the plugin's PP_FileInfo struct. | 558 // This writes the file info into the plugin's PP_FileInfo struct. |
550 ppapi::PlatformFileInfoToPepperFileInfo(query_op->file_info(), | 559 ppapi::FileInfoToPepperFileInfo(query_op->file_info(), |
551 file_system_type_, | 560 file_system_type_, |
552 info); | 561 info); |
553 } | 562 } |
554 state_manager_.SetOperationFinished(); | 563 state_manager_.SetOperationFinished(); |
555 return result; | 564 return result; |
556 } | 565 } |
557 | 566 |
558 int32_t FileIOResource::OnReadComplete(scoped_refptr<ReadOp> read_op, | 567 int32_t FileIOResource::OnReadComplete(scoped_refptr<ReadOp> read_op, |
559 PP_ArrayOutput array_output, | 568 PP_ArrayOutput array_output, |
560 int32_t result) { | 569 int32_t result) { |
561 DCHECK(state_manager_.get_pending_operation() == | 570 DCHECK(state_manager_.get_pending_operation() == |
562 FileIOStateManager::OPERATION_READ); | 571 FileIOStateManager::OPERATION_READ); |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
696 *output_handle = IPC::PlatformFileForTransitToPlatformFile(transit_file); | 705 *output_handle = IPC::PlatformFileForTransitToPlatformFile(transit_file); |
697 | 706 |
698 // End this operation now, so the user's callback can execute another FileIO | 707 // End this operation now, so the user's callback can execute another FileIO |
699 // operation, assuming there are no other pending operations. | 708 // operation, assuming there are no other pending operations. |
700 state_manager_.SetOperationFinished(); | 709 state_manager_.SetOperationFinished(); |
701 callback->Run(result); | 710 callback->Run(result); |
702 } | 711 } |
703 | 712 |
704 } // namespace proxy | 713 } // namespace proxy |
705 } // namespace ppapi | 714 } // namespace ppapi |
OLD | NEW |