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