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 "content/renderer/pepper/pepper_file_io_host.h" | 5 #include "content/renderer/pepper/pepper_file_io_host.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 ppapi::host::HostMessageContext* context) { | 164 ppapi::host::HostMessageContext* context) { |
165 int32_t rv = state_manager_.CheckOperationState( | 165 int32_t rv = state_manager_.CheckOperationState( |
166 FileIOStateManager::OPERATION_EXCLUSIVE, true); | 166 FileIOStateManager::OPERATION_EXCLUSIVE, true); |
167 if (rv != PP_OK) | 167 if (rv != PP_OK) |
168 return rv; | 168 return rv; |
169 | 169 |
170 if (!plugin_delegate_) | 170 if (!plugin_delegate_) |
171 return PP_ERROR_FAILED; | 171 return PP_ERROR_FAILED; |
172 | 172 |
173 if (!base::FileUtilProxy::GetFileInfoFromPlatformFile( | 173 if (!base::FileUtilProxy::GetFileInfoFromPlatformFile( |
174 plugin_delegate_->GetFileThreadMessageLoopProxy(), file_, | 174 plugin_delegate_->GetFileThreadMessageLoopProxy().get(), |
| 175 file_, |
175 base::Bind(&PepperFileIOHost::ExecutePlatformQueryCallback, | 176 base::Bind(&PepperFileIOHost::ExecutePlatformQueryCallback, |
176 weak_factory_.GetWeakPtr(), | 177 weak_factory_.GetWeakPtr(), |
177 context->MakeReplyMessageContext()))) | 178 context->MakeReplyMessageContext()))) |
178 return PP_ERROR_FAILED; | 179 return PP_ERROR_FAILED; |
179 | 180 |
180 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); | 181 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); |
181 return PP_OK_COMPLETIONPENDING; | 182 return PP_OK_COMPLETIONPENDING; |
182 } | 183 } |
183 | 184 |
184 int32_t PepperFileIOHost::OnHostMsgTouch( | 185 int32_t PepperFileIOHost::OnHostMsgTouch( |
(...skipping 17 matching lines...) Expand all Loading... |
202 weak_factory_.GetWeakPtr(), | 203 weak_factory_.GetWeakPtr(), |
203 context->MakeReplyMessageContext()))) | 204 context->MakeReplyMessageContext()))) |
204 return PP_ERROR_FAILED; | 205 return PP_ERROR_FAILED; |
205 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); | 206 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); |
206 return PP_OK_COMPLETIONPENDING; | 207 return PP_OK_COMPLETIONPENDING; |
207 } | 208 } |
208 | 209 |
209 // TODO(nhiroki): fix a failure of FileIO.Touch for an external filesystem on | 210 // TODO(nhiroki): fix a failure of FileIO.Touch for an external filesystem on |
210 // Mac and Linux due to sandbox restrictions (http://crbug.com/101128). | 211 // Mac and Linux due to sandbox restrictions (http://crbug.com/101128). |
211 if (!base::FileUtilProxy::Touch( | 212 if (!base::FileUtilProxy::Touch( |
212 plugin_delegate_->GetFileThreadMessageLoopProxy(), | 213 plugin_delegate_->GetFileThreadMessageLoopProxy().get(), |
213 file_, PPTimeToTime(last_access_time), | 214 file_, |
| 215 PPTimeToTime(last_access_time), |
214 PPTimeToTime(last_modified_time), | 216 PPTimeToTime(last_modified_time), |
215 base::Bind(&PepperFileIOHost::ExecutePlatformGeneralCallback, | 217 base::Bind(&PepperFileIOHost::ExecutePlatformGeneralCallback, |
216 weak_factory_.GetWeakPtr(), | 218 weak_factory_.GetWeakPtr(), |
217 context->MakeReplyMessageContext()))) | 219 context->MakeReplyMessageContext()))) |
218 return PP_ERROR_FAILED; | 220 return PP_ERROR_FAILED; |
219 | 221 |
220 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); | 222 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); |
221 return PP_OK_COMPLETIONPENDING; | 223 return PP_OK_COMPLETIONPENDING; |
222 } | 224 } |
223 | 225 |
(...skipping 13 matching lines...) Expand all Loading... |
237 reply_context.params.set_result(PP_ERROR_FAILED); | 239 reply_context.params.set_result(PP_ERROR_FAILED); |
238 host()->SendReply(reply_context, | 240 host()->SendReply(reply_context, |
239 PpapiPluginMsg_FileIO_ReadReply(std::string())); | 241 PpapiPluginMsg_FileIO_ReadReply(std::string())); |
240 return PP_OK_COMPLETIONPENDING; | 242 return PP_OK_COMPLETIONPENDING; |
241 } | 243 } |
242 | 244 |
243 if (!plugin_delegate_) | 245 if (!plugin_delegate_) |
244 return PP_ERROR_FAILED; | 246 return PP_ERROR_FAILED; |
245 | 247 |
246 if (!base::FileUtilProxy::Read( | 248 if (!base::FileUtilProxy::Read( |
247 plugin_delegate_->GetFileThreadMessageLoopProxy(), file_, offset, | 249 plugin_delegate_->GetFileThreadMessageLoopProxy().get(), |
| 250 file_, |
| 251 offset, |
248 max_read_length, | 252 max_read_length, |
249 base::Bind(&PepperFileIOHost::ExecutePlatformReadCallback, | 253 base::Bind(&PepperFileIOHost::ExecutePlatformReadCallback, |
250 weak_factory_.GetWeakPtr(), | 254 weak_factory_.GetWeakPtr(), |
251 context->MakeReplyMessageContext()))) | 255 context->MakeReplyMessageContext()))) |
252 return PP_ERROR_FAILED; | 256 return PP_ERROR_FAILED; |
253 | 257 |
254 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_READ); | 258 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_READ); |
255 return PP_OK_COMPLETIONPENDING; | 259 return PP_OK_COMPLETIONPENDING; |
256 } | 260 } |
257 | 261 |
(...skipping 11 matching lines...) Expand all Loading... |
269 offset, buffer.c_str(), buffer.size(), | 273 offset, buffer.c_str(), buffer.size(), |
270 base::Bind(&PepperFileIOHost::ExecutePlatformWriteCallback, | 274 base::Bind(&PepperFileIOHost::ExecutePlatformWriteCallback, |
271 weak_factory_.GetWeakPtr(), | 275 weak_factory_.GetWeakPtr(), |
272 context->MakeReplyMessageContext()))) | 276 context->MakeReplyMessageContext()))) |
273 return PP_ERROR_FAILED; | 277 return PP_ERROR_FAILED; |
274 } else { | 278 } else { |
275 if (!plugin_delegate_) | 279 if (!plugin_delegate_) |
276 return PP_ERROR_FAILED; | 280 return PP_ERROR_FAILED; |
277 | 281 |
278 if (!base::FileUtilProxy::Write( | 282 if (!base::FileUtilProxy::Write( |
279 plugin_delegate_->GetFileThreadMessageLoopProxy(), file_, offset, | 283 plugin_delegate_->GetFileThreadMessageLoopProxy().get(), |
280 buffer.c_str(), buffer.size(), | 284 file_, |
| 285 offset, |
| 286 buffer.c_str(), |
| 287 buffer.size(), |
281 base::Bind(&PepperFileIOHost::ExecutePlatformWriteCallback, | 288 base::Bind(&PepperFileIOHost::ExecutePlatformWriteCallback, |
282 weak_factory_.GetWeakPtr(), | 289 weak_factory_.GetWeakPtr(), |
283 context->MakeReplyMessageContext()))) | 290 context->MakeReplyMessageContext()))) |
284 return PP_ERROR_FAILED; | 291 return PP_ERROR_FAILED; |
285 } | 292 } |
286 | 293 |
287 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_WRITE); | 294 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_WRITE); |
288 return PP_OK_COMPLETIONPENDING; | 295 return PP_OK_COMPLETIONPENDING; |
289 } | 296 } |
290 | 297 |
(...skipping 12 matching lines...) Expand all Loading... |
303 if (!plugin_delegate_->SetLength( | 310 if (!plugin_delegate_->SetLength( |
304 file_system_url_, length, | 311 file_system_url_, length, |
305 base::Bind(&PepperFileIOHost::ExecutePlatformGeneralCallback, | 312 base::Bind(&PepperFileIOHost::ExecutePlatformGeneralCallback, |
306 weak_factory_.GetWeakPtr(), | 313 weak_factory_.GetWeakPtr(), |
307 context->MakeReplyMessageContext()))) | 314 context->MakeReplyMessageContext()))) |
308 return PP_ERROR_FAILED; | 315 return PP_ERROR_FAILED; |
309 } else { | 316 } else { |
310 // TODO(nhiroki): fix a failure of FileIO.SetLength for an external | 317 // TODO(nhiroki): fix a failure of FileIO.SetLength for an external |
311 // filesystem on Mac due to sandbox restrictions (http://crbug.com/156077). | 318 // filesystem on Mac due to sandbox restrictions (http://crbug.com/156077). |
312 if (!base::FileUtilProxy::Truncate( | 319 if (!base::FileUtilProxy::Truncate( |
313 plugin_delegate_->GetFileThreadMessageLoopProxy(), file_, length, | 320 plugin_delegate_->GetFileThreadMessageLoopProxy().get(), |
| 321 file_, |
| 322 length, |
314 base::Bind(&PepperFileIOHost::ExecutePlatformGeneralCallback, | 323 base::Bind(&PepperFileIOHost::ExecutePlatformGeneralCallback, |
315 weak_factory_.GetWeakPtr(), | 324 weak_factory_.GetWeakPtr(), |
316 context->MakeReplyMessageContext()))) | 325 context->MakeReplyMessageContext()))) |
317 return PP_ERROR_FAILED; | 326 return PP_ERROR_FAILED; |
318 } | 327 } |
319 | 328 |
320 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); | 329 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); |
321 return PP_OK_COMPLETIONPENDING; | 330 return PP_OK_COMPLETIONPENDING; |
322 } | 331 } |
323 | 332 |
324 int32_t PepperFileIOHost::OnHostMsgFlush( | 333 int32_t PepperFileIOHost::OnHostMsgFlush( |
325 ppapi::host::HostMessageContext* context) { | 334 ppapi::host::HostMessageContext* context) { |
326 int32_t rv = state_manager_.CheckOperationState( | 335 int32_t rv = state_manager_.CheckOperationState( |
327 FileIOStateManager::OPERATION_EXCLUSIVE, true); | 336 FileIOStateManager::OPERATION_EXCLUSIVE, true); |
328 if (rv != PP_OK) | 337 if (rv != PP_OK) |
329 return rv; | 338 return rv; |
330 | 339 |
331 if (!plugin_delegate_) | 340 if (!plugin_delegate_) |
332 return PP_ERROR_FAILED; | 341 return PP_ERROR_FAILED; |
333 | 342 |
334 if (!base::FileUtilProxy::Flush( | 343 if (!base::FileUtilProxy::Flush( |
335 plugin_delegate_->GetFileThreadMessageLoopProxy(), file_, | 344 plugin_delegate_->GetFileThreadMessageLoopProxy().get(), |
| 345 file_, |
336 base::Bind(&PepperFileIOHost::ExecutePlatformGeneralCallback, | 346 base::Bind(&PepperFileIOHost::ExecutePlatformGeneralCallback, |
337 weak_factory_.GetWeakPtr(), | 347 weak_factory_.GetWeakPtr(), |
338 context->MakeReplyMessageContext()))) | 348 context->MakeReplyMessageContext()))) |
339 return PP_ERROR_FAILED; | 349 return PP_ERROR_FAILED; |
340 | 350 |
341 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); | 351 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); |
342 return PP_OK_COMPLETIONPENDING; | 352 return PP_OK_COMPLETIONPENDING; |
343 } | 353 } |
344 | 354 |
345 int32_t PepperFileIOHost::OnHostMsgClose( | 355 int32_t PepperFileIOHost::OnHostMsgClose( |
346 ppapi::host::HostMessageContext* context) { | 356 ppapi::host::HostMessageContext* context) { |
347 if (file_ != base::kInvalidPlatformFileValue && plugin_delegate_) { | 357 if (file_ != base::kInvalidPlatformFileValue && plugin_delegate_) { |
348 base::FileUtilProxy::Close( | 358 base::FileUtilProxy::Close( |
349 plugin_delegate_->GetFileThreadMessageLoopProxy(), | 359 plugin_delegate_->GetFileThreadMessageLoopProxy().get(), |
350 file_, | 360 file_, |
351 base::ResetAndReturn(¬ify_close_file_callback_)); | 361 base::ResetAndReturn(¬ify_close_file_callback_)); |
352 file_ = base::kInvalidPlatformFileValue; | 362 file_ = base::kInvalidPlatformFileValue; |
353 quota_file_io_.reset(); | 363 quota_file_io_.reset(); |
354 } | 364 } |
355 return PP_OK; | 365 return PP_OK; |
356 } | 366 } |
357 | 367 |
358 int32_t PepperFileIOHost::OnHostMsgWillWrite( | 368 int32_t PepperFileIOHost::OnHostMsgWillWrite( |
359 ppapi::host::HostMessageContext* context, | 369 ppapi::host::HostMessageContext* context, |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
524 // On the plugin side, the callback expects a parameter with different meaning | 534 // On the plugin side, the callback expects a parameter with different meaning |
525 // depends on whether is negative or not. It is the result here. We translate | 535 // depends on whether is negative or not. It is the result here. We translate |
526 // for the callback. | 536 // for the callback. |
527 int32_t pp_error = ::ppapi::PlatformFileErrorToPepperError(error_code); | 537 int32_t pp_error = ::ppapi::PlatformFileErrorToPepperError(error_code); |
528 reply_context.params.set_result(ErrorOrByteNumber(pp_error, bytes_written)); | 538 reply_context.params.set_result(ErrorOrByteNumber(pp_error, bytes_written)); |
529 host()->SendReply(reply_context, PpapiPluginMsg_FileIO_GeneralReply()); | 539 host()->SendReply(reply_context, PpapiPluginMsg_FileIO_GeneralReply()); |
530 state_manager_.SetOperationFinished(); | 540 state_manager_.SetOperationFinished(); |
531 } | 541 } |
532 | 542 |
533 } // namespace content | 543 } // namespace content |
OLD | NEW |