Chromium Code Reviews| 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 "ipc/ipc_message.h" | 8 #include "ipc/ipc_message.h" |
| 9 #include "ppapi/c/pp_errors.h" | 9 #include "ppapi/c/pp_errors.h" |
| 10 #include "ppapi/proxy/ppapi_messages.h" | 10 #include "ppapi/proxy/ppapi_messages.h" |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 178 | 178 |
| 179 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); | 179 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); |
| 180 return PP_OK_COMPLETIONPENDING; | 180 return PP_OK_COMPLETIONPENDING; |
| 181 } | 181 } |
| 182 | 182 |
| 183 void FileIOResource::Close() { | 183 void FileIOResource::Close() { |
| 184 Post(RENDERER, PpapiHostMsg_FileIO_Close()); | 184 Post(RENDERER, PpapiHostMsg_FileIO_Close()); |
| 185 } | 185 } |
| 186 | 186 |
| 187 int32_t FileIOResource::GetOSFileDescriptor() { | 187 int32_t FileIOResource::GetOSFileDescriptor() { |
| 188 int32_t file_descriptor; | 188 IPC::Message reply; |
| 189 // Only available when running in process. | 189 ResourceMessageReplyParams reply_params; |
| 190 SyncCall<PpapiPluginMsg_FileIO_GetOSFileDescriptorReply>( | 190 int32_t error = GenericSyncCall(RENDERER, |
| 191 RENDERER, PpapiHostMsg_FileIO_GetOSFileDescriptor(), &file_descriptor); | 191 PpapiHostMsg_FileIO_GetOSFileDescriptor(), &reply, &reply_params); |
| 192 return file_descriptor; | 192 if (error != PP_OK) |
| 193 return error; | |
| 194 | |
| 195 IPC::PlatformFileForTransit transit_file; | |
| 196 if (!reply_params.TakeFileHandleAtIndex(0, &transit_file)) | |
| 197 return PP_ERROR_FAILED; | |
| 198 base::PlatformFile file = | |
| 199 IPC::PlatformFileForTransitToPlatformFile(transit_file); | |
| 200 #if defined(OS_POSIX) | |
| 201 return file; | |
| 202 #elif defined(OS_WIN) | |
| 203 return reinterpret_cast<uintptr_t>(file); | |
| 204 #else | |
| 205 return -1; // Platform not supported. | |
| 206 #endif | |
| 193 } | 207 } |
| 194 | 208 |
| 195 int32_t FileIOResource::WillWrite(int64_t offset, | 209 int32_t FileIOResource::WillWrite(int64_t offset, |
| 196 int32_t bytes_to_write, | 210 int32_t bytes_to_write, |
| 197 scoped_refptr<TrackedCallback> callback) { | 211 scoped_refptr<TrackedCallback> callback) { |
| 198 Call<PpapiPluginMsg_FileIO_GeneralReply>(RENDERER, | 212 Call<PpapiPluginMsg_FileIO_GeneralReply>(RENDERER, |
| 199 PpapiHostMsg_FileIO_WillWrite(offset, bytes_to_write), | 213 PpapiHostMsg_FileIO_WillWrite(offset, bytes_to_write), |
| 200 base::Bind(&FileIOResource::OnPluginMsgGeneralComplete, this, | 214 base::Bind(&FileIOResource::OnPluginMsgGeneralComplete, this, |
| 201 callback)); | 215 callback)); |
| 202 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); | 216 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 217 int32_t bytes_to_read, | 231 int32_t bytes_to_read, |
| 218 const PP_ArrayOutput& array_output, | 232 const PP_ArrayOutput& array_output, |
| 219 scoped_refptr<TrackedCallback> callback) { | 233 scoped_refptr<TrackedCallback> callback) { |
| 220 Call<PpapiPluginMsg_FileIO_ReadReply>(RENDERER, | 234 Call<PpapiPluginMsg_FileIO_ReadReply>(RENDERER, |
| 221 PpapiHostMsg_FileIO_Read(offset, bytes_to_read), | 235 PpapiHostMsg_FileIO_Read(offset, bytes_to_read), |
| 222 base::Bind(&FileIOResource::OnPluginMsgReadComplete, this, | 236 base::Bind(&FileIOResource::OnPluginMsgReadComplete, this, |
| 223 callback, array_output)); | 237 callback, array_output)); |
| 224 return PP_OK_COMPLETIONPENDING; | 238 return PP_OK_COMPLETIONPENDING; |
| 225 } | 239 } |
| 226 | 240 |
| 241 int32_t FileIOResource::GetOSFileHandle( | |
|
dmichael (off chromium)
2013/03/27 19:40:53
Maybe RequestOSFileHandle? I think synchronous whe
hamaji
2013/03/28 00:17:29
Done.
| |
| 242 PP_FileHandle* handle, | |
| 243 scoped_refptr<TrackedCallback> callback) { | |
| 244 int32_t rv = state_manager_.CheckOperationState( | |
| 245 FileIOStateManager::OPERATION_EXCLUSIVE, true); | |
| 246 if (rv != PP_OK) | |
| 247 return rv; | |
| 248 | |
| 249 Call<PpapiPluginMsg_FileIO_GetOSFileDescriptorReply>(RENDERER, | |
| 250 PpapiHostMsg_FileIO_GetOSFileDescriptor(), | |
| 251 base::Bind(&FileIOResource::OnPluginMsgGetOSFileHandleComplete, this, | |
| 252 callback, handle)); | |
| 253 | |
| 254 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); | |
| 255 return PP_OK_COMPLETIONPENDING; | |
| 256 } | |
| 257 | |
| 227 void FileIOResource::OnPluginMsgGeneralComplete( | 258 void FileIOResource::OnPluginMsgGeneralComplete( |
| 228 scoped_refptr<TrackedCallback> callback, | 259 scoped_refptr<TrackedCallback> callback, |
| 229 const ResourceMessageReplyParams& params) { | 260 const ResourceMessageReplyParams& params) { |
| 230 DCHECK(state_manager_.get_pending_operation() == | 261 DCHECK(state_manager_.get_pending_operation() == |
| 231 FileIOStateManager::OPERATION_EXCLUSIVE || | 262 FileIOStateManager::OPERATION_EXCLUSIVE || |
| 232 state_manager_.get_pending_operation() == | 263 state_manager_.get_pending_operation() == |
| 233 FileIOStateManager::OPERATION_WRITE); | 264 FileIOStateManager::OPERATION_WRITE); |
| 234 // End the operation now. The callback may perform another file operation. | 265 // End the operation now. The callback may perform another file operation. |
| 235 state_manager_.SetOperationFinished(); | 266 state_manager_.SetOperationFinished(); |
| 236 callback->Run(params.result()); | 267 callback->Run(params.result()); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 279 if (output.is_valid()) | 310 if (output.is_valid()) |
| 280 output.StoreArray(data.data(), std::max(0, result)); | 311 output.StoreArray(data.data(), std::max(0, result)); |
| 281 else | 312 else |
| 282 result = PP_ERROR_FAILED; | 313 result = PP_ERROR_FAILED; |
| 283 | 314 |
| 284 // End the operation now. The callback may perform another file operation. | 315 // End the operation now. The callback may perform another file operation. |
| 285 state_manager_.SetOperationFinished(); | 316 state_manager_.SetOperationFinished(); |
| 286 callback->Run(result); | 317 callback->Run(result); |
| 287 } | 318 } |
| 288 | 319 |
| 320 void FileIOResource::OnPluginMsgGetOSFileHandleComplete( | |
| 321 scoped_refptr<TrackedCallback> callback, | |
| 322 PP_FileHandle* output_handle, | |
| 323 const ResourceMessageReplyParams& params) { | |
| 324 DCHECK(state_manager_.get_pending_operation() == | |
| 325 FileIOStateManager::OPERATION_EXCLUSIVE); | |
|
yzshen1
2013/03/27 20:47:58
Please check whether |callback| is pending. It is
hamaji
2013/03/28 00:17:29
Done. I'm not 100% sure if I understood your comme
yzshen1
2013/03/28 20:59:49
Yes.
What I was talking about is that the plugin
hamaji
2013/03/28 21:37:15
Thanks for your explanation!
On 2013/03/28 20:59:
| |
| 326 | |
| 327 int32_t result = params.result(); | |
| 328 IPC::PlatformFileForTransit transit_file; | |
| 329 if (!params.TakeFileHandleAtIndex(0, &transit_file)) | |
| 330 result = PP_ERROR_FAILED; | |
| 331 *output_handle = IPC::PlatformFileForTransitToPlatformFile(transit_file); | |
| 332 | |
| 333 // End the operation now. The callback may perform another file operation. | |
| 334 state_manager_.SetOperationFinished(); | |
| 335 callback->Run(result); | |
| 336 } | |
| 337 | |
| 289 } // namespace proxy | 338 } // namespace proxy |
| 290 } // namespace ppapi | 339 } // namespace ppapi |
| 291 | |
| OLD | NEW |