| 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 int32_t FileIOResource::ReadOp::DoWork() { | 71 int32_t FileIOResource::ReadOp::DoWork() { |
| 72 DCHECK(!buffer_.get()); | 72 DCHECK(!buffer_.get()); |
| 73 buffer_.reset(new char[bytes_to_read_]); | 73 buffer_.reset(new char[bytes_to_read_]); |
| 74 return base::ReadPlatformFile( | 74 return base::ReadPlatformFile( |
| 75 file_handle_->raw_handle(), offset_, buffer_.get(), bytes_to_read_); | 75 file_handle_->raw_handle(), offset_, buffer_.get(), bytes_to_read_); |
| 76 } | 76 } |
| 77 | 77 |
| 78 FileIOResource::FileIOResource(Connection connection, PP_Instance instance) | 78 FileIOResource::FileIOResource(Connection connection, PP_Instance instance) |
| 79 : PluginResource(connection, instance), | 79 : PluginResource(connection, instance), |
| 80 file_system_type_(PP_FILESYSTEMTYPE_INVALID) { | 80 file_system_type_(PP_FILESYSTEMTYPE_INVALID) { |
| 81 SendCreate(BROWSER, PpapiHostMsg_FileIO_Create()); | 81 SendCreate(RENDERER, PpapiHostMsg_FileIO_Create()); |
| 82 } | 82 } |
| 83 | 83 |
| 84 FileIOResource::~FileIOResource() { | 84 FileIOResource::~FileIOResource() { |
| 85 } | 85 } |
| 86 | 86 |
| 87 PPB_FileIO_API* FileIOResource::AsPPB_FileIO_API() { | 87 PPB_FileIO_API* FileIOResource::AsPPB_FileIO_API() { |
| 88 return this; | 88 return this; |
| 89 } | 89 } |
| 90 | 90 |
| 91 int32_t FileIOResource::Open(PP_Resource file_ref, | 91 int32_t FileIOResource::Open(PP_Resource file_ref, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 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 | 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. | 115 // don't want the plugin destroying it during the Open operation. |
| 116 file_ref_ = enter.resource(); | 116 file_ref_ = enter.resource(); |
| 117 | 117 |
| 118 Call<PpapiPluginMsg_FileIO_OpenReply>(BROWSER, | 118 Call<PpapiPluginMsg_FileIO_OpenReply>(RENDERER, |
| 119 PpapiHostMsg_FileIO_Open( | 119 PpapiHostMsg_FileIO_Open( |
| 120 file_ref, | 120 file_ref, |
| 121 open_flags), | 121 open_flags), |
| 122 base::Bind(&FileIOResource::OnPluginMsgOpenFileComplete, this, | 122 base::Bind(&FileIOResource::OnPluginMsgOpenFileComplete, this, |
| 123 callback)); | 123 callback)); |
| 124 | 124 |
| 125 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); | 125 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); |
| 126 return PP_OK_COMPLETIONPENDING; | 126 return PP_OK_COMPLETIONPENDING; |
| 127 } | 127 } |
| 128 | 128 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 } | 177 } |
| 178 | 178 |
| 179 int32_t FileIOResource::Touch(PP_Time last_access_time, | 179 int32_t FileIOResource::Touch(PP_Time last_access_time, |
| 180 PP_Time last_modified_time, | 180 PP_Time last_modified_time, |
| 181 scoped_refptr<TrackedCallback> callback) { | 181 scoped_refptr<TrackedCallback> callback) { |
| 182 int32_t rv = state_manager_.CheckOperationState( | 182 int32_t rv = state_manager_.CheckOperationState( |
| 183 FileIOStateManager::OPERATION_EXCLUSIVE, true); | 183 FileIOStateManager::OPERATION_EXCLUSIVE, true); |
| 184 if (rv != PP_OK) | 184 if (rv != PP_OK) |
| 185 return rv; | 185 return rv; |
| 186 | 186 |
| 187 Call<PpapiPluginMsg_FileIO_GeneralReply>(BROWSER, | 187 Call<PpapiPluginMsg_FileIO_GeneralReply>(RENDERER, |
| 188 PpapiHostMsg_FileIO_Touch(last_access_time, last_modified_time), | 188 PpapiHostMsg_FileIO_Touch(last_access_time, last_modified_time), |
| 189 base::Bind(&FileIOResource::OnPluginMsgGeneralComplete, this, | 189 base::Bind(&FileIOResource::OnPluginMsgGeneralComplete, this, |
| 190 callback)); | 190 callback)); |
| 191 | 191 |
| 192 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); | 192 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); |
| 193 return PP_OK_COMPLETIONPENDING; | 193 return PP_OK_COMPLETIONPENDING; |
| 194 } | 194 } |
| 195 | 195 |
| 196 int32_t FileIOResource::Read(int64_t offset, | 196 int32_t FileIOResource::Read(int64_t offset, |
| 197 char* buffer, | 197 char* buffer, |
| (...skipping 28 matching lines...) Expand all Loading... |
| 226 int32_t bytes_to_write, | 226 int32_t bytes_to_write, |
| 227 scoped_refptr<TrackedCallback> callback) { | 227 scoped_refptr<TrackedCallback> callback) { |
| 228 int32_t rv = state_manager_.CheckOperationState( | 228 int32_t rv = state_manager_.CheckOperationState( |
| 229 FileIOStateManager::OPERATION_WRITE, true); | 229 FileIOStateManager::OPERATION_WRITE, true); |
| 230 if (rv != PP_OK) | 230 if (rv != PP_OK) |
| 231 return rv; | 231 return rv; |
| 232 | 232 |
| 233 // TODO(brettw) it would be nice to use a shared memory buffer for large | 233 // TODO(brettw) it would be nice to use a shared memory buffer for large |
| 234 // writes rather than having to copy to a string (which will involve a number | 234 // writes rather than having to copy to a string (which will involve a number |
| 235 // of extra copies to serialize over IPC). | 235 // of extra copies to serialize over IPC). |
| 236 Call<PpapiPluginMsg_FileIO_GeneralReply>(BROWSER, | 236 Call<PpapiPluginMsg_FileIO_GeneralReply>(RENDERER, |
| 237 PpapiHostMsg_FileIO_Write(offset, std::string(buffer, bytes_to_write)), | 237 PpapiHostMsg_FileIO_Write(offset, std::string(buffer, bytes_to_write)), |
| 238 base::Bind(&FileIOResource::OnPluginMsgGeneralComplete, this, | 238 base::Bind(&FileIOResource::OnPluginMsgGeneralComplete, this, |
| 239 callback)); | 239 callback)); |
| 240 | 240 |
| 241 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_WRITE); | 241 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_WRITE); |
| 242 return PP_OK_COMPLETIONPENDING; | 242 return PP_OK_COMPLETIONPENDING; |
| 243 } | 243 } |
| 244 | 244 |
| 245 int32_t FileIOResource::SetLength(int64_t length, | 245 int32_t FileIOResource::SetLength(int64_t length, |
| 246 scoped_refptr<TrackedCallback> callback) { | 246 scoped_refptr<TrackedCallback> callback) { |
| 247 int32_t rv = state_manager_.CheckOperationState( | 247 int32_t rv = state_manager_.CheckOperationState( |
| 248 FileIOStateManager::OPERATION_EXCLUSIVE, true); | 248 FileIOStateManager::OPERATION_EXCLUSIVE, true); |
| 249 if (rv != PP_OK) | 249 if (rv != PP_OK) |
| 250 return rv; | 250 return rv; |
| 251 | 251 |
| 252 Call<PpapiPluginMsg_FileIO_GeneralReply>(BROWSER, | 252 Call<PpapiPluginMsg_FileIO_GeneralReply>(RENDERER, |
| 253 PpapiHostMsg_FileIO_SetLength(length), | 253 PpapiHostMsg_FileIO_SetLength(length), |
| 254 base::Bind(&FileIOResource::OnPluginMsgGeneralComplete, this, | 254 base::Bind(&FileIOResource::OnPluginMsgGeneralComplete, this, |
| 255 callback)); | 255 callback)); |
| 256 | 256 |
| 257 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); | 257 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); |
| 258 return PP_OK_COMPLETIONPENDING; | 258 return PP_OK_COMPLETIONPENDING; |
| 259 } | 259 } |
| 260 | 260 |
| 261 int32_t FileIOResource::Flush(scoped_refptr<TrackedCallback> callback) { | 261 int32_t FileIOResource::Flush(scoped_refptr<TrackedCallback> callback) { |
| 262 int32_t rv = state_manager_.CheckOperationState( | 262 int32_t rv = state_manager_.CheckOperationState( |
| 263 FileIOStateManager::OPERATION_EXCLUSIVE, true); | 263 FileIOStateManager::OPERATION_EXCLUSIVE, true); |
| 264 if (rv != PP_OK) | 264 if (rv != PP_OK) |
| 265 return rv; | 265 return rv; |
| 266 | 266 |
| 267 Call<PpapiPluginMsg_FileIO_GeneralReply>(BROWSER, | 267 Call<PpapiPluginMsg_FileIO_GeneralReply>(RENDERER, |
| 268 PpapiHostMsg_FileIO_Flush(), | 268 PpapiHostMsg_FileIO_Flush(), |
| 269 base::Bind(&FileIOResource::OnPluginMsgGeneralComplete, this, | 269 base::Bind(&FileIOResource::OnPluginMsgGeneralComplete, this, |
| 270 callback)); | 270 callback)); |
| 271 | 271 |
| 272 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); | 272 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); |
| 273 return PP_OK_COMPLETIONPENDING; | 273 return PP_OK_COMPLETIONPENDING; |
| 274 } | 274 } |
| 275 | 275 |
| 276 void FileIOResource::Close() { | 276 void FileIOResource::Close() { |
| 277 if (file_handle_) { | 277 if (file_handle_) { |
| 278 file_handle_ = NULL; | 278 file_handle_ = NULL; |
| 279 } | 279 } |
| 280 Post(BROWSER, PpapiHostMsg_FileIO_Close()); | 280 Post(RENDERER, PpapiHostMsg_FileIO_Close()); |
| 281 } | 281 } |
| 282 | 282 |
| 283 int32_t FileIOResource::RequestOSFileHandle( | 283 int32_t FileIOResource::RequestOSFileHandle( |
| 284 PP_FileHandle* handle, | 284 PP_FileHandle* handle, |
| 285 scoped_refptr<TrackedCallback> callback) { | 285 scoped_refptr<TrackedCallback> callback) { |
| 286 int32_t rv = state_manager_.CheckOperationState( | 286 int32_t rv = state_manager_.CheckOperationState( |
| 287 FileIOStateManager::OPERATION_EXCLUSIVE, true); | 287 FileIOStateManager::OPERATION_EXCLUSIVE, true); |
| 288 if (rv != PP_OK) | 288 if (rv != PP_OK) |
| 289 return rv; | 289 return rv; |
| 290 | 290 |
| 291 Call<PpapiPluginMsg_FileIO_RequestOSFileHandleReply>(BROWSER, | 291 Call<PpapiPluginMsg_FileIO_RequestOSFileHandleReply>(RENDERER, |
| 292 PpapiHostMsg_FileIO_RequestOSFileHandle(), | 292 PpapiHostMsg_FileIO_RequestOSFileHandle(), |
| 293 base::Bind(&FileIOResource::OnPluginMsgRequestOSFileHandleComplete, this, | 293 base::Bind(&FileIOResource::OnPluginMsgRequestOSFileHandleComplete, this, |
| 294 callback, handle)); | 294 callback, handle)); |
| 295 | 295 |
| 296 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); | 296 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); |
| 297 return PP_OK_COMPLETIONPENDING; | 297 return PP_OK_COMPLETIONPENDING; |
| 298 } | 298 } |
| 299 | 299 |
| 300 FileIOResource::FileHandleHolder::FileHandleHolder(PP_FileHandle file_handle) | 300 FileIOResource::FileHandleHolder::FileHandleHolder(PP_FileHandle file_handle) |
| 301 : raw_handle_(file_handle) { | 301 : raw_handle_(file_handle) { |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 *output_handle = IPC::PlatformFileForTransitToPlatformFile(transit_file); | 452 *output_handle = IPC::PlatformFileForTransitToPlatformFile(transit_file); |
| 453 | 453 |
| 454 // End this operation now, so the user's callback can execute another FileIO | 454 // End this operation now, so the user's callback can execute another FileIO |
| 455 // operation, assuming there are no other pending operations. | 455 // operation, assuming there are no other pending operations. |
| 456 state_manager_.SetOperationFinished(); | 456 state_manager_.SetOperationFinished(); |
| 457 callback->Run(result); | 457 callback->Run(result); |
| 458 } | 458 } |
| 459 | 459 |
| 460 } // namespace proxy | 460 } // namespace proxy |
| 461 } // namespace ppapi | 461 } // namespace ppapi |
| OLD | NEW |