| 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" |
| 11 #include "base/files/file_util_proxy.h" | 11 #include "base/files/file_util_proxy.h" |
| 12 #include "content/child/child_thread.h" | 12 #include "content/child/child_thread.h" |
| 13 #include "content/child/fileapi/file_system_dispatcher.h" | 13 #include "content/child/fileapi/file_system_dispatcher.h" |
| 14 #include "content/child/quota_dispatcher.h" | 14 #include "content/child/quota_dispatcher.h" |
| 15 #include "content/common/fileapi/file_system_messages.h" | 15 #include "content/common/fileapi/file_system_messages.h" |
| 16 #include "content/public/common/content_client.h" | 16 #include "content/public/common/content_client.h" |
| 17 #include "content/public/renderer/content_renderer_client.h" | 17 #include "content/public/renderer/content_renderer_client.h" |
| 18 #include "content/renderer/pepper/host_globals.h" | 18 #include "content/renderer/pepper/host_globals.h" |
| 19 #include "content/renderer/pepper/pepper_plugin_delegate_impl.h" |
| 19 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" | 20 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" |
| 20 #include "content/renderer/pepper/ppb_file_ref_impl.h" | 21 #include "content/renderer/pepper/ppb_file_ref_impl.h" |
| 21 #include "content/renderer/pepper/quota_file_io.h" | 22 #include "content/renderer/pepper/quota_file_io.h" |
| 23 #include "content/renderer/pepper/resource_helper.h" |
| 22 #include "content/renderer/render_thread_impl.h" | 24 #include "content/renderer/render_thread_impl.h" |
| 23 #include "ppapi/c/pp_errors.h" | 25 #include "ppapi/c/pp_errors.h" |
| 24 #include "ppapi/host/dispatch_host_message.h" | 26 #include "ppapi/host/dispatch_host_message.h" |
| 25 #include "ppapi/host/ppapi_host.h" | 27 #include "ppapi/host/ppapi_host.h" |
| 26 #include "ppapi/proxy/ppapi_messages.h" | 28 #include "ppapi/proxy/ppapi_messages.h" |
| 27 #include "ppapi/shared_impl/file_type_conversion.h" | 29 #include "ppapi/shared_impl/file_type_conversion.h" |
| 28 #include "ppapi/shared_impl/time_conversion.h" | 30 #include "ppapi/shared_impl/time_conversion.h" |
| 29 #include "ppapi/thunk/enter.h" | 31 #include "ppapi/thunk/enter.h" |
| 30 #include "third_party/WebKit/public/web/WebPluginContainer.h" | 32 #include "third_party/WebKit/public/web/WebPluginContainer.h" |
| 31 | 33 |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 quota::kQuotaLimitTypeUnknown, | 136 quota::kQuotaLimitTypeUnknown, |
| 135 PepperFileIOHost::NotifyCloseFileCallback()); | 137 PepperFileIOHost::NotifyCloseFileCallback()); |
| 136 } | 138 } |
| 137 | 139 |
| 138 } // namespace | 140 } // namespace |
| 139 | 141 |
| 140 PepperFileIOHost::PepperFileIOHost(RendererPpapiHost* host, | 142 PepperFileIOHost::PepperFileIOHost(RendererPpapiHost* host, |
| 141 PP_Instance instance, | 143 PP_Instance instance, |
| 142 PP_Resource resource) | 144 PP_Resource resource) |
| 143 : ResourceHost(host->GetPpapiHost(), instance, resource), | 145 : ResourceHost(host->GetPpapiHost(), instance, resource), |
| 144 plugin_delegate_(NULL), | |
| 145 file_(base::kInvalidPlatformFileValue), | 146 file_(base::kInvalidPlatformFileValue), |
| 146 file_system_type_(PP_FILESYSTEMTYPE_INVALID), | 147 file_system_type_(PP_FILESYSTEMTYPE_INVALID), |
| 147 quota_policy_(quota::kQuotaLimitTypeUnknown), | 148 quota_policy_(quota::kQuotaLimitTypeUnknown), |
| 148 is_running_in_process_(host->IsRunningInProcess()), | 149 is_running_in_process_(host->IsRunningInProcess()), |
| 149 open_flags_(0), | 150 open_flags_(0), |
| 150 weak_factory_(this) { | 151 weak_factory_(this) { |
| 151 // TODO(victorhsieh): eliminate plugin_delegate_ as it's no longer needed. | |
| 152 PepperPluginInstanceImpl* plugin_instance = | |
| 153 HostGlobals::Get()->GetInstance(instance); | |
| 154 plugin_delegate_ = plugin_instance ? plugin_instance->delegate() : NULL; | |
| 155 } | 152 } |
| 156 | 153 |
| 157 PepperFileIOHost::~PepperFileIOHost() { | 154 PepperFileIOHost::~PepperFileIOHost() { |
| 158 OnHostMsgClose(NULL); | 155 OnHostMsgClose(NULL); |
| 159 } | 156 } |
| 160 | 157 |
| 161 int32_t PepperFileIOHost::OnResourceMessageReceived( | 158 int32_t PepperFileIOHost::OnResourceMessageReceived( |
| 162 const IPC::Message& msg, | 159 const IPC::Message& msg, |
| 163 ppapi::host::HostMessageContext* context) { | 160 ppapi::host::HostMessageContext* context) { |
| 164 IPC_BEGIN_MESSAGE_MAP(PepperFileIOHost, msg) | 161 IPC_BEGIN_MESSAGE_MAP(PepperFileIOHost, msg) |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 | 207 |
| 211 PPB_FileRef_API* file_ref_api = enter.object(); | 208 PPB_FileRef_API* file_ref_api = enter.object(); |
| 212 PP_FileSystemType type = file_ref_api->GetFileSystemType(); | 209 PP_FileSystemType type = file_ref_api->GetFileSystemType(); |
| 213 if (type != PP_FILESYSTEMTYPE_LOCALPERSISTENT && | 210 if (type != PP_FILESYSTEMTYPE_LOCALPERSISTENT && |
| 214 type != PP_FILESYSTEMTYPE_LOCALTEMPORARY && | 211 type != PP_FILESYSTEMTYPE_LOCALTEMPORARY && |
| 215 type != PP_FILESYSTEMTYPE_EXTERNAL && | 212 type != PP_FILESYSTEMTYPE_EXTERNAL && |
| 216 type != PP_FILESYSTEMTYPE_ISOLATED) | 213 type != PP_FILESYSTEMTYPE_ISOLATED) |
| 217 return PP_ERROR_FAILED; | 214 return PP_ERROR_FAILED; |
| 218 file_system_type_ = type; | 215 file_system_type_ = type; |
| 219 | 216 |
| 220 if (!plugin_delegate_) | |
| 221 return PP_ERROR_FAILED; | |
| 222 | |
| 223 PPB_FileRef_Impl* file_ref = static_cast<PPB_FileRef_Impl*>(file_ref_api); | 217 PPB_FileRef_Impl* file_ref = static_cast<PPB_FileRef_Impl*>(file_ref_api); |
| 224 if (file_ref->HasValidFileSystem()) { | 218 if (file_ref->HasValidFileSystem()) { |
| 225 file_system_url_ = file_ref->GetFileSystemURL(); | 219 file_system_url_ = file_ref->GetFileSystemURL(); |
| 226 | 220 |
| 227 FileSystemDispatcher* file_system_dispatcher = | 221 FileSystemDispatcher* file_system_dispatcher = |
| 228 ChildThread::current()->file_system_dispatcher(); | 222 ChildThread::current()->file_system_dispatcher(); |
| 229 AsyncOpenFileSystemURLCallback callback = base::Bind( | 223 AsyncOpenFileSystemURLCallback callback = base::Bind( |
| 230 &PepperFileIOHost::ExecutePlatformOpenFileSystemURLCallback, | 224 &PepperFileIOHost::ExecutePlatformOpenFileSystemURLCallback, |
| 231 weak_factory_.GetWeakPtr(), | 225 weak_factory_.GetWeakPtr(), |
| 232 context->MakeReplyMessageContext()); | 226 context->MakeReplyMessageContext()); |
| 233 file_system_dispatcher->OpenFile( | 227 file_system_dispatcher->OpenFile( |
| 234 file_system_url_, flags, | 228 file_system_url_, flags, |
| 235 base::Bind(&DidOpenFileSystemURL, callback), | 229 base::Bind(&DidOpenFileSystemURL, callback), |
| 236 base::Bind(&DidFailOpenFileSystemURL, callback)); | 230 base::Bind(&DidFailOpenFileSystemURL, callback)); |
| 237 } else { | 231 } else { |
| 238 if (file_system_type_ != PP_FILESYSTEMTYPE_EXTERNAL) | 232 PepperPluginDelegateImpl* plugin_delegate = |
| 233 static_cast<PepperPluginInstanceImpl*>( |
| 234 PepperPluginInstance::Get(pp_instance()))->delegate(); |
| 235 if (file_system_type_ != PP_FILESYSTEMTYPE_EXTERNAL || !plugin_delegate) |
| 239 return PP_ERROR_FAILED; | 236 return PP_ERROR_FAILED; |
| 240 if (!plugin_delegate_->AsyncOpenFile( | 237 if (!plugin_delegate->AsyncOpenFile( |
| 241 file_ref->GetSystemPath(), flags, | 238 file_ref->GetSystemPath(), flags, |
| 242 base::Bind(&PepperFileIOHost::ExecutePlatformOpenFileCallback, | 239 base::Bind(&PepperFileIOHost::ExecutePlatformOpenFileCallback, |
| 243 weak_factory_.GetWeakPtr(), | 240 weak_factory_.GetWeakPtr(), |
| 244 context->MakeReplyMessageContext()))) | 241 context->MakeReplyMessageContext()))) |
| 245 return PP_ERROR_FAILED; | 242 return PP_ERROR_FAILED; |
| 246 } | 243 } |
| 247 | 244 |
| 248 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); | 245 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); |
| 249 return PP_OK_COMPLETIONPENDING; | 246 return PP_OK_COMPLETIONPENDING; |
| 250 } | 247 } |
| 251 | 248 |
| 252 int32_t PepperFileIOHost::OnHostMsgQuery( | 249 int32_t PepperFileIOHost::OnHostMsgQuery( |
| 253 ppapi::host::HostMessageContext* context) { | 250 ppapi::host::HostMessageContext* context) { |
| 254 int32_t rv = state_manager_.CheckOperationState( | 251 int32_t rv = state_manager_.CheckOperationState( |
| 255 FileIOStateManager::OPERATION_EXCLUSIVE, true); | 252 FileIOStateManager::OPERATION_EXCLUSIVE, true); |
| 256 if (rv != PP_OK) | 253 if (rv != PP_OK) |
| 257 return rv; | 254 return rv; |
| 258 | 255 |
| 259 if (!plugin_delegate_) | |
| 260 return PP_ERROR_FAILED; | |
| 261 | |
| 262 if (!base::FileUtilProxy::GetFileInfoFromPlatformFile( | 256 if (!base::FileUtilProxy::GetFileInfoFromPlatformFile( |
| 263 plugin_delegate_->GetFileThreadMessageLoopProxy().get(), | 257 RenderThreadImpl::current()->GetFileThreadMessageLoopProxy().get(), |
| 264 file_, | 258 file_, |
| 265 base::Bind(&PepperFileIOHost::ExecutePlatformQueryCallback, | 259 base::Bind(&PepperFileIOHost::ExecutePlatformQueryCallback, |
| 266 weak_factory_.GetWeakPtr(), | 260 weak_factory_.GetWeakPtr(), |
| 267 context->MakeReplyMessageContext()))) | 261 context->MakeReplyMessageContext()))) |
| 268 return PP_ERROR_FAILED; | 262 return PP_ERROR_FAILED; |
| 269 | 263 |
| 270 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); | 264 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); |
| 271 return PP_OK_COMPLETIONPENDING; | 265 return PP_OK_COMPLETIONPENDING; |
| 272 } | 266 } |
| 273 | 267 |
| 274 int32_t PepperFileIOHost::OnHostMsgTouch( | 268 int32_t PepperFileIOHost::OnHostMsgTouch( |
| 275 ppapi::host::HostMessageContext* context, | 269 ppapi::host::HostMessageContext* context, |
| 276 PP_Time last_access_time, | 270 PP_Time last_access_time, |
| 277 PP_Time last_modified_time) { | 271 PP_Time last_modified_time) { |
| 278 int32_t rv = state_manager_.CheckOperationState( | 272 int32_t rv = state_manager_.CheckOperationState( |
| 279 FileIOStateManager::OPERATION_EXCLUSIVE, true); | 273 FileIOStateManager::OPERATION_EXCLUSIVE, true); |
| 280 if (rv != PP_OK) | 274 if (rv != PP_OK) |
| 281 return rv; | 275 return rv; |
| 282 | 276 |
| 283 if (!plugin_delegate_) | |
| 284 return PP_ERROR_FAILED; | |
| 285 | |
| 286 if (file_system_type_ != PP_FILESYSTEMTYPE_EXTERNAL) { | 277 if (file_system_type_ != PP_FILESYSTEMTYPE_EXTERNAL) { |
| 287 FileSystemDispatcher* file_system_dispatcher = | 278 FileSystemDispatcher* file_system_dispatcher = |
| 288 ChildThread::current()->file_system_dispatcher(); | 279 ChildThread::current()->file_system_dispatcher(); |
| 289 file_system_dispatcher->TouchFile( | 280 file_system_dispatcher->TouchFile( |
| 290 file_system_url_, | 281 file_system_url_, |
| 291 PPTimeToTime(last_access_time), | 282 PPTimeToTime(last_access_time), |
| 292 PPTimeToTime(last_modified_time), | 283 PPTimeToTime(last_modified_time), |
| 293 base::Bind(&PepperFileIOHost::ExecutePlatformGeneralCallback, | 284 base::Bind(&PepperFileIOHost::ExecutePlatformGeneralCallback, |
| 294 weak_factory_.GetWeakPtr(), | 285 weak_factory_.GetWeakPtr(), |
| 295 context->MakeReplyMessageContext())); | 286 context->MakeReplyMessageContext())); |
| 296 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); | 287 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); |
| 297 return PP_OK_COMPLETIONPENDING; | 288 return PP_OK_COMPLETIONPENDING; |
| 298 } | 289 } |
| 299 | 290 |
| 300 // TODO(nhiroki): fix a failure of FileIO.Touch for an external filesystem on | 291 // TODO(nhiroki): fix a failure of FileIO.Touch for an external filesystem on |
| 301 // Mac and Linux due to sandbox restrictions (http://crbug.com/101128). | 292 // Mac and Linux due to sandbox restrictions (http://crbug.com/101128). |
| 302 if (!base::FileUtilProxy::Touch( | 293 if (!base::FileUtilProxy::Touch( |
| 303 plugin_delegate_->GetFileThreadMessageLoopProxy().get(), | 294 RenderThreadImpl::current()->GetFileThreadMessageLoopProxy().get(), |
| 304 file_, | 295 file_, |
| 305 PPTimeToTime(last_access_time), | 296 PPTimeToTime(last_access_time), |
| 306 PPTimeToTime(last_modified_time), | 297 PPTimeToTime(last_modified_time), |
| 307 base::Bind(&PepperFileIOHost::ExecutePlatformGeneralCallback, | 298 base::Bind(&PepperFileIOHost::ExecutePlatformGeneralCallback, |
| 308 weak_factory_.GetWeakPtr(), | 299 weak_factory_.GetWeakPtr(), |
| 309 context->MakeReplyMessageContext()))) | 300 context->MakeReplyMessageContext()))) |
| 310 return PP_ERROR_FAILED; | 301 return PP_ERROR_FAILED; |
| 311 | 302 |
| 312 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); | 303 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); |
| 313 return PP_OK_COMPLETIONPENDING; | 304 return PP_OK_COMPLETIONPENDING; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 325 // Validate max_read_length before allocating below. This value is coming from | 316 // Validate max_read_length before allocating below. This value is coming from |
| 326 // the untrusted plugin. | 317 // the untrusted plugin. |
| 327 if (max_read_length < 0) { | 318 if (max_read_length < 0) { |
| 328 ReplyMessageContext reply_context = context->MakeReplyMessageContext(); | 319 ReplyMessageContext reply_context = context->MakeReplyMessageContext(); |
| 329 reply_context.params.set_result(PP_ERROR_FAILED); | 320 reply_context.params.set_result(PP_ERROR_FAILED); |
| 330 host()->SendReply(reply_context, | 321 host()->SendReply(reply_context, |
| 331 PpapiPluginMsg_FileIO_ReadReply(std::string())); | 322 PpapiPluginMsg_FileIO_ReadReply(std::string())); |
| 332 return PP_OK_COMPLETIONPENDING; | 323 return PP_OK_COMPLETIONPENDING; |
| 333 } | 324 } |
| 334 | 325 |
| 335 if (!plugin_delegate_) | |
| 336 return PP_ERROR_FAILED; | |
| 337 | |
| 338 if (!base::FileUtilProxy::Read( | 326 if (!base::FileUtilProxy::Read( |
| 339 plugin_delegate_->GetFileThreadMessageLoopProxy().get(), | 327 RenderThreadImpl::current()->GetFileThreadMessageLoopProxy().get(), |
| 340 file_, | 328 file_, |
| 341 offset, | 329 offset, |
| 342 max_read_length, | 330 max_read_length, |
| 343 base::Bind(&PepperFileIOHost::ExecutePlatformReadCallback, | 331 base::Bind(&PepperFileIOHost::ExecutePlatformReadCallback, |
| 344 weak_factory_.GetWeakPtr(), | 332 weak_factory_.GetWeakPtr(), |
| 345 context->MakeReplyMessageContext()))) | 333 context->MakeReplyMessageContext()))) |
| 346 return PP_ERROR_FAILED; | 334 return PP_ERROR_FAILED; |
| 347 | 335 |
| 348 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_READ); | 336 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_READ); |
| 349 return PP_OK_COMPLETIONPENDING; | 337 return PP_OK_COMPLETIONPENDING; |
| 350 } | 338 } |
| 351 | 339 |
| 352 int32_t PepperFileIOHost::OnHostMsgWrite( | 340 int32_t PepperFileIOHost::OnHostMsgWrite( |
| 353 ppapi::host::HostMessageContext* context, | 341 ppapi::host::HostMessageContext* context, |
| 354 int64_t offset, | 342 int64_t offset, |
| 355 const std::string& buffer) { | 343 const std::string& buffer) { |
| 356 int32_t rv = state_manager_.CheckOperationState( | 344 int32_t rv = state_manager_.CheckOperationState( |
| 357 FileIOStateManager::OPERATION_WRITE, true); | 345 FileIOStateManager::OPERATION_WRITE, true); |
| 358 if (rv != PP_OK) | 346 if (rv != PP_OK) |
| 359 return rv; | 347 return rv; |
| 360 | 348 |
| 361 if (quota_file_io_) { | 349 if (quota_file_io_) { |
| 362 if (!quota_file_io_->Write( | 350 if (!quota_file_io_->Write( |
| 363 offset, buffer.c_str(), buffer.size(), | 351 offset, buffer.c_str(), buffer.size(), |
| 364 base::Bind(&PepperFileIOHost::ExecutePlatformWriteCallback, | 352 base::Bind(&PepperFileIOHost::ExecutePlatformWriteCallback, |
| 365 weak_factory_.GetWeakPtr(), | 353 weak_factory_.GetWeakPtr(), |
| 366 context->MakeReplyMessageContext()))) | 354 context->MakeReplyMessageContext()))) |
| 367 return PP_ERROR_FAILED; | 355 return PP_ERROR_FAILED; |
| 368 } else { | 356 } else { |
| 369 if (!plugin_delegate_) | |
| 370 return PP_ERROR_FAILED; | |
| 371 | |
| 372 if (!base::FileUtilProxy::Write( | 357 if (!base::FileUtilProxy::Write( |
| 373 plugin_delegate_->GetFileThreadMessageLoopProxy().get(), | 358 RenderThreadImpl::current()->GetFileThreadMessageLoopProxy().get(), |
| 374 file_, | 359 file_, |
| 375 offset, | 360 offset, |
| 376 buffer.c_str(), | 361 buffer.c_str(), |
| 377 buffer.size(), | 362 buffer.size(), |
| 378 base::Bind(&PepperFileIOHost::ExecutePlatformWriteCallback, | 363 base::Bind(&PepperFileIOHost::ExecutePlatformWriteCallback, |
| 379 weak_factory_.GetWeakPtr(), | 364 weak_factory_.GetWeakPtr(), |
| 380 context->MakeReplyMessageContext()))) | 365 context->MakeReplyMessageContext()))) |
| 381 return PP_ERROR_FAILED; | 366 return PP_ERROR_FAILED; |
| 382 } | 367 } |
| 383 | 368 |
| 384 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_WRITE); | 369 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_WRITE); |
| 385 return PP_OK_COMPLETIONPENDING; | 370 return PP_OK_COMPLETIONPENDING; |
| 386 } | 371 } |
| 387 | 372 |
| 388 int32_t PepperFileIOHost::OnHostMsgSetLength( | 373 int32_t PepperFileIOHost::OnHostMsgSetLength( |
| 389 ppapi::host::HostMessageContext* context, | 374 ppapi::host::HostMessageContext* context, |
| 390 int64_t length) { | 375 int64_t length) { |
| 391 int32_t rv = state_manager_.CheckOperationState( | 376 int32_t rv = state_manager_.CheckOperationState( |
| 392 FileIOStateManager::OPERATION_EXCLUSIVE, true); | 377 FileIOStateManager::OPERATION_EXCLUSIVE, true); |
| 393 if (rv != PP_OK) | 378 if (rv != PP_OK) |
| 394 return rv; | 379 return rv; |
| 395 | 380 |
| 396 if (!plugin_delegate_) | |
| 397 return PP_ERROR_FAILED; | |
| 398 | |
| 399 if (file_system_type_ != PP_FILESYSTEMTYPE_EXTERNAL) { | 381 if (file_system_type_ != PP_FILESYSTEMTYPE_EXTERNAL) { |
| 400 FileSystemDispatcher* file_system_dispatcher = | 382 FileSystemDispatcher* file_system_dispatcher = |
| 401 ChildThread::current()->file_system_dispatcher(); | 383 ChildThread::current()->file_system_dispatcher(); |
| 402 file_system_dispatcher->Truncate( | 384 file_system_dispatcher->Truncate( |
| 403 file_system_url_, length, NULL, | 385 file_system_url_, length, NULL, |
| 404 base::Bind(&PepperFileIOHost::ExecutePlatformGeneralCallback, | 386 base::Bind(&PepperFileIOHost::ExecutePlatformGeneralCallback, |
| 405 weak_factory_.GetWeakPtr(), | 387 weak_factory_.GetWeakPtr(), |
| 406 context->MakeReplyMessageContext())); | 388 context->MakeReplyMessageContext())); |
| 407 } else { | 389 } else { |
| 408 // TODO(nhiroki): fix a failure of FileIO.SetLength for an external | 390 // TODO(nhiroki): fix a failure of FileIO.SetLength for an external |
| 409 // filesystem on Mac due to sandbox restrictions (http://crbug.com/156077). | 391 // filesystem on Mac due to sandbox restrictions (http://crbug.com/156077). |
| 410 if (!base::FileUtilProxy::Truncate( | 392 if (!base::FileUtilProxy::Truncate( |
| 411 plugin_delegate_->GetFileThreadMessageLoopProxy().get(), | 393 RenderThreadImpl::current()->GetFileThreadMessageLoopProxy().get(), |
| 412 file_, | 394 file_, |
| 413 length, | 395 length, |
| 414 base::Bind(&PepperFileIOHost::ExecutePlatformGeneralCallback, | 396 base::Bind(&PepperFileIOHost::ExecutePlatformGeneralCallback, |
| 415 weak_factory_.GetWeakPtr(), | 397 weak_factory_.GetWeakPtr(), |
| 416 context->MakeReplyMessageContext()))) | 398 context->MakeReplyMessageContext()))) |
| 417 return PP_ERROR_FAILED; | 399 return PP_ERROR_FAILED; |
| 418 } | 400 } |
| 419 | 401 |
| 420 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); | 402 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); |
| 421 return PP_OK_COMPLETIONPENDING; | 403 return PP_OK_COMPLETIONPENDING; |
| 422 } | 404 } |
| 423 | 405 |
| 424 int32_t PepperFileIOHost::OnHostMsgFlush( | 406 int32_t PepperFileIOHost::OnHostMsgFlush( |
| 425 ppapi::host::HostMessageContext* context) { | 407 ppapi::host::HostMessageContext* context) { |
| 426 int32_t rv = state_manager_.CheckOperationState( | 408 int32_t rv = state_manager_.CheckOperationState( |
| 427 FileIOStateManager::OPERATION_EXCLUSIVE, true); | 409 FileIOStateManager::OPERATION_EXCLUSIVE, true); |
| 428 if (rv != PP_OK) | 410 if (rv != PP_OK) |
| 429 return rv; | 411 return rv; |
| 430 | 412 |
| 431 if (!plugin_delegate_) | |
| 432 return PP_ERROR_FAILED; | |
| 433 | |
| 434 if (!base::FileUtilProxy::Flush( | 413 if (!base::FileUtilProxy::Flush( |
| 435 plugin_delegate_->GetFileThreadMessageLoopProxy().get(), | 414 RenderThreadImpl::current()->GetFileThreadMessageLoopProxy().get(), |
| 436 file_, | 415 file_, |
| 437 base::Bind(&PepperFileIOHost::ExecutePlatformGeneralCallback, | 416 base::Bind(&PepperFileIOHost::ExecutePlatformGeneralCallback, |
| 438 weak_factory_.GetWeakPtr(), | 417 weak_factory_.GetWeakPtr(), |
| 439 context->MakeReplyMessageContext()))) | 418 context->MakeReplyMessageContext()))) |
| 440 return PP_ERROR_FAILED; | 419 return PP_ERROR_FAILED; |
| 441 | 420 |
| 442 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); | 421 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); |
| 443 return PP_OK_COMPLETIONPENDING; | 422 return PP_OK_COMPLETIONPENDING; |
| 444 } | 423 } |
| 445 | 424 |
| 446 int32_t PepperFileIOHost::OnHostMsgClose( | 425 int32_t PepperFileIOHost::OnHostMsgClose( |
| 447 ppapi::host::HostMessageContext* context) { | 426 ppapi::host::HostMessageContext* context) { |
| 448 if (file_ != base::kInvalidPlatformFileValue && plugin_delegate_) { | 427 if (file_ != base::kInvalidPlatformFileValue) { |
| 449 base::FileUtilProxy::Close( | 428 base::FileUtilProxy::Close( |
| 450 plugin_delegate_->GetFileThreadMessageLoopProxy().get(), | 429 RenderThreadImpl::current()->GetFileThreadMessageLoopProxy().get(), |
| 451 file_, | 430 file_, |
| 452 base::ResetAndReturn(¬ify_close_file_callback_)); | 431 base::ResetAndReturn(¬ify_close_file_callback_)); |
| 453 file_ = base::kInvalidPlatformFileValue; | 432 file_ = base::kInvalidPlatformFileValue; |
| 454 quota_file_io_.reset(); | 433 quota_file_io_.reset(); |
| 455 } | 434 } |
| 456 return PP_OK; | 435 return PP_OK; |
| 457 } | 436 } |
| 458 | 437 |
| 459 int32_t PepperFileIOHost::OnHostMsgWillWrite( | 438 int32_t PepperFileIOHost::OnHostMsgWillWrite( |
| 460 ppapi::host::HostMessageContext* context, | 439 ppapi::host::HostMessageContext* context, |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 // On the plugin side, the callback expects a parameter with different meaning | 609 // On the plugin side, the callback expects a parameter with different meaning |
| 631 // depends on whether is negative or not. It is the result here. We translate | 610 // depends on whether is negative or not. It is the result here. We translate |
| 632 // for the callback. | 611 // for the callback. |
| 633 int32_t pp_error = ::ppapi::PlatformFileErrorToPepperError(error_code); | 612 int32_t pp_error = ::ppapi::PlatformFileErrorToPepperError(error_code); |
| 634 reply_context.params.set_result(ErrorOrByteNumber(pp_error, bytes_written)); | 613 reply_context.params.set_result(ErrorOrByteNumber(pp_error, bytes_written)); |
| 635 host()->SendReply(reply_context, PpapiPluginMsg_FileIO_GeneralReply()); | 614 host()->SendReply(reply_context, PpapiPluginMsg_FileIO_GeneralReply()); |
| 636 state_manager_.SetOperationFinished(); | 615 state_manager_.SetOperationFinished(); |
| 637 } | 616 } |
| 638 | 617 |
| 639 } // namespace content | 618 } // namespace content |
| OLD | NEW |