| 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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 NOTREACHED(); | 104 NOTREACHED(); |
| 105 return PP_ERROR_FAILED; | 105 return PP_ERROR_FAILED; |
| 106 } | 106 } |
| 107 file_system_type_ = type; | 107 file_system_type_ = type; |
| 108 | 108 |
| 109 int32_t rv = state_manager_.CheckOperationState( | 109 int32_t rv = state_manager_.CheckOperationState( |
| 110 FileIOStateManager::OPERATION_EXCLUSIVE, false); | 110 FileIOStateManager::OPERATION_EXCLUSIVE, false); |
| 111 if (rv != PP_OK) | 111 if (rv != PP_OK) |
| 112 return rv; | 112 return rv; |
| 113 | 113 |
| 114 // Take a reference on the FileRef resource while we're opening the file; we | |
| 115 // don't want the plugin destroying it during the Open operation. | |
| 116 file_ref_ = file_ref; | |
| 117 | |
| 118 Call<PpapiPluginMsg_FileIO_OpenReply>(RENDERER, | 114 Call<PpapiPluginMsg_FileIO_OpenReply>(RENDERER, |
| 119 PpapiHostMsg_FileIO_Open( | 115 PpapiHostMsg_FileIO_Open( |
| 120 file_ref, | 116 enter.resource()->host_resource().host_resource(), |
| 121 open_flags), | 117 open_flags), |
| 122 base::Bind(&FileIOResource::OnPluginMsgOpenFileComplete, this, | 118 base::Bind(&FileIOResource::OnPluginMsgOpenFileComplete, this, |
| 123 callback)); | 119 callback)); |
| 124 | 120 |
| 125 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); | 121 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); |
| 126 return PP_OK_COMPLETIONPENDING; | 122 return PP_OK_COMPLETIONPENDING; |
| 127 } | 123 } |
| 128 | 124 |
| 129 int32_t FileIOResource::Query(PP_FileInfo* info, | 125 int32_t FileIOResource::Query(PP_FileInfo* info, |
| 130 scoped_refptr<TrackedCallback> callback) { | 126 scoped_refptr<TrackedCallback> callback) { |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 // operation, assuming there are no other pending operations. | 403 // operation, assuming there are no other pending operations. |
| 408 state_manager_.SetOperationFinished(); | 404 state_manager_.SetOperationFinished(); |
| 409 callback->Run(params.result()); | 405 callback->Run(params.result()); |
| 410 } | 406 } |
| 411 | 407 |
| 412 void FileIOResource::OnPluginMsgOpenFileComplete( | 408 void FileIOResource::OnPluginMsgOpenFileComplete( |
| 413 scoped_refptr<TrackedCallback> callback, | 409 scoped_refptr<TrackedCallback> callback, |
| 414 const ResourceMessageReplyParams& params) { | 410 const ResourceMessageReplyParams& params) { |
| 415 DCHECK(state_manager_.get_pending_operation() == | 411 DCHECK(state_manager_.get_pending_operation() == |
| 416 FileIOStateManager::OPERATION_EXCLUSIVE); | 412 FileIOStateManager::OPERATION_EXCLUSIVE); |
| 417 | |
| 418 // Release the FileRef resource. | |
| 419 file_ref_ = 0; | |
| 420 if (params.result() == PP_OK) | 413 if (params.result() == PP_OK) |
| 421 state_manager_.SetOpenSucceed(); | 414 state_manager_.SetOpenSucceed(); |
| 422 | 415 |
| 423 int32_t result = params.result(); | 416 int32_t result = params.result(); |
| 424 IPC::PlatformFileForTransit transit_file; | 417 IPC::PlatformFileForTransit transit_file; |
| 425 if ((result == PP_OK) && params.TakeFileHandleAtIndex(0, &transit_file)) | 418 if ((result == PP_OK) && params.TakeFileHandleAtIndex(0, &transit_file)) |
| 426 file_handle_ = IPC::PlatformFileForTransitToPlatformFile(transit_file); | 419 file_handle_ = IPC::PlatformFileForTransitToPlatformFile(transit_file); |
| 427 // End this operation now, so the user's callback can execute another FileIO | 420 // End this operation now, so the user's callback can execute another FileIO |
| 428 // operation, assuming there are no other pending operations. | 421 // operation, assuming there are no other pending operations. |
| 429 state_manager_.SetOperationFinished(); | 422 state_manager_.SetOperationFinished(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 449 *output_handle = IPC::PlatformFileForTransitToPlatformFile(transit_file); | 442 *output_handle = IPC::PlatformFileForTransitToPlatformFile(transit_file); |
| 450 | 443 |
| 451 // End this operation now, so the user's callback can execute another FileIO | 444 // End this operation now, so the user's callback can execute another FileIO |
| 452 // operation, assuming there are no other pending operations. | 445 // operation, assuming there are no other pending operations. |
| 453 state_manager_.SetOperationFinished(); | 446 state_manager_.SetOperationFinished(); |
| 454 callback->Run(result); | 447 callback->Run(result); |
| 455 } | 448 } |
| 456 | 449 |
| 457 } // namespace proxy | 450 } // namespace proxy |
| 458 } // namespace ppapi | 451 } // namespace ppapi |
| OLD | NEW |