Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(732)

Side by Side Diff: content/browser/renderer_host/pepper/pepper_file_io_host.cc

Issue 252583007: Replace FileUtilProxy with FileProxy in renderer_host/pepper (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: For review Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/browser/renderer_host/pepper/pepper_file_io_host.h" 5 #include "content/browser/renderer_host/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/files/file_util_proxy.h" 10 #include "base/files/file_util_proxy.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 } 79 }
80 80
81 } // namespace 81 } // namespace
82 82
83 PepperFileIOHost::PepperFileIOHost(BrowserPpapiHostImpl* host, 83 PepperFileIOHost::PepperFileIOHost(BrowserPpapiHostImpl* host,
84 PP_Instance instance, 84 PP_Instance instance,
85 PP_Resource resource) 85 PP_Resource resource)
86 : ResourceHost(host->GetPpapiHost(), instance, resource), 86 : ResourceHost(host->GetPpapiHost(), instance, resource),
87 browser_ppapi_host_(host), 87 browser_ppapi_host_(host),
88 render_process_host_(NULL), 88 render_process_host_(NULL),
89 file_(base::kInvalidPlatformFileValue), 89 file_(BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)),
90 open_flags_(0), 90 open_flags_(0),
91 file_system_type_(PP_FILESYSTEMTYPE_INVALID), 91 file_system_type_(PP_FILESYSTEMTYPE_INVALID),
92 max_written_offset_(0), 92 max_written_offset_(0),
93 check_quota_(false), 93 check_quota_(false),
94 weak_factory_(this) { 94 weak_factory_(this) {
95 int unused; 95 int unused;
96 if (!host->GetRenderFrameIDsForInstance( 96 if (!host->GetRenderFrameIDsForInstance(
97 instance, &render_process_id_, &unused)) { 97 instance, &render_process_id_, &unused)) {
98 render_process_id_ = -1; 98 render_process_id_ = -1;
99 } 99 }
100 file_message_loop_ =
101 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE);
102 } 100 }
103 101
104 PepperFileIOHost::~PepperFileIOHost() {} 102 PepperFileIOHost::~PepperFileIOHost() {}
105 103
106 int32_t PepperFileIOHost::OnResourceMessageReceived( 104 int32_t PepperFileIOHost::OnResourceMessageReceived(
107 const IPC::Message& msg, 105 const IPC::Message& msg,
108 ppapi::host::HostMessageContext* context) { 106 ppapi::host::HostMessageContext* context) {
109 IPC_BEGIN_MESSAGE_MAP(PepperFileIOHost, msg) 107 IPC_BEGIN_MESSAGE_MAP(PepperFileIOHost, msg)
110 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_FileIO_Open, OnHostMsgOpen) 108 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_FileIO_Open, OnHostMsgOpen)
111 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_FileIO_Touch, OnHostMsgTouch) 109 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_FileIO_Touch, OnHostMsgTouch)
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 } 255 }
258 } 256 }
259 257
260 ExecutePlatformOpenFileCallback( 258 ExecutePlatformOpenFileCallback(
261 reply_context, result, base::PassPlatformFile(&file), true); 259 reply_context, result, base::PassPlatformFile(&file), true);
262 } 260 }
263 261
264 void PepperFileIOHost::GotResolvedRenderProcessId( 262 void PepperFileIOHost::GotResolvedRenderProcessId(
265 ppapi::host::ReplyMessageContext reply_context, 263 ppapi::host::ReplyMessageContext reply_context,
266 base::FilePath path, 264 base::FilePath path,
267 int platform_file_flags, 265 int file_flags,
268 base::ProcessId resolved_render_process_id) { 266 base::ProcessId resolved_render_process_id) {
269 DCHECK_CURRENTLY_ON(BrowserThread::IO); 267 DCHECK_CURRENTLY_ON(BrowserThread::IO);
270 resolved_render_process_id_ = resolved_render_process_id; 268 resolved_render_process_id_ = resolved_render_process_id;
271 base::FileUtilProxy::CreateOrOpen( 269 file_.CreateOrOpen(
272 file_message_loop_,
273 path, 270 path,
274 platform_file_flags, 271 file_flags,
275 base::Bind(&PepperFileIOHost::ExecutePlatformOpenFileCallback, 272 base::Bind(&PepperFileIOHost::OnOpenProxyCallback,
276 weak_factory_.GetWeakPtr(), 273 weak_factory_.GetWeakPtr(),
277 reply_context)); 274 reply_context));
278 } 275 }
279 276
280 int32_t PepperFileIOHost::OnHostMsgTouch( 277 int32_t PepperFileIOHost::OnHostMsgTouch(
281 ppapi::host::HostMessageContext* context, 278 ppapi::host::HostMessageContext* context,
282 PP_Time last_access_time, 279 PP_Time last_access_time,
283 PP_Time last_modified_time) { 280 PP_Time last_modified_time) {
284 int32_t rv = state_manager_.CheckOperationState( 281 int32_t rv = state_manager_.CheckOperationState(
285 FileIOStateManager::OPERATION_EXCLUSIVE, true); 282 FileIOStateManager::OPERATION_EXCLUSIVE, true);
286 if (rv != PP_OK) 283 if (rv != PP_OK)
287 return rv; 284 return rv;
288 285
289 if (!base::FileUtilProxy::Touch( 286 if (!file_.SetTimes(
290 file_message_loop_,
291 file_,
292 PPTimeToTime(last_access_time), 287 PPTimeToTime(last_access_time),
293 PPTimeToTime(last_modified_time), 288 PPTimeToTime(last_modified_time),
294 base::Bind(&PepperFileIOHost::ExecutePlatformGeneralCallback, 289 base::Bind(&PepperFileIOHost::ExecutePlatformGeneralCallback,
295 weak_factory_.GetWeakPtr(), 290 weak_factory_.GetWeakPtr(),
296 context->MakeReplyMessageContext()))) 291 context->MakeReplyMessageContext()))) {
297 return PP_ERROR_FAILED; 292 return PP_ERROR_FAILED;
293 }
298 294
299 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); 295 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE);
300 return PP_OK_COMPLETIONPENDING; 296 return PP_OK_COMPLETIONPENDING;
301 } 297 }
302 298
303 int32_t PepperFileIOHost::OnHostMsgSetLength( 299 int32_t PepperFileIOHost::OnHostMsgSetLength(
304 ppapi::host::HostMessageContext* context, 300 ppapi::host::HostMessageContext* context,
305 int64_t length) { 301 int64_t length) {
306 int32_t rv = state_manager_.CheckOperationState( 302 int32_t rv = state_manager_.CheckOperationState(
307 FileIOStateManager::OPERATION_EXCLUSIVE, true); 303 FileIOStateManager::OPERATION_EXCLUSIVE, true);
308 if (rv != PP_OK) 304 if (rv != PP_OK)
309 return rv; 305 return rv;
310 if (length < 0) 306 if (length < 0)
311 return PP_ERROR_BADARGUMENT; 307 return PP_ERROR_BADARGUMENT;
312 308
313 // Quota checks are performed on the plugin side, in order to use the same 309 // Quota checks are performed on the plugin side, in order to use the same
314 // quota reservation and request system as Write. 310 // quota reservation and request system as Write.
315 311
316 if (!base::FileUtilProxy::Truncate( 312 if (!file_.SetLength(
317 file_message_loop_,
318 file_,
319 length, 313 length,
320 base::Bind(&PepperFileIOHost::ExecutePlatformGeneralCallback, 314 base::Bind(&PepperFileIOHost::ExecutePlatformGeneralCallback,
321 weak_factory_.GetWeakPtr(), 315 weak_factory_.GetWeakPtr(),
322 context->MakeReplyMessageContext()))) 316 context->MakeReplyMessageContext()))) {
323 return PP_ERROR_FAILED; 317 return PP_ERROR_FAILED;
318 }
324 319
325 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); 320 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE);
326 return PP_OK_COMPLETIONPENDING; 321 return PP_OK_COMPLETIONPENDING;
327 } 322 }
328 323
329 int32_t PepperFileIOHost::OnHostMsgFlush( 324 int32_t PepperFileIOHost::OnHostMsgFlush(
330 ppapi::host::HostMessageContext* context) { 325 ppapi::host::HostMessageContext* context) {
331 int32_t rv = state_manager_.CheckOperationState( 326 int32_t rv = state_manager_.CheckOperationState(
332 FileIOStateManager::OPERATION_EXCLUSIVE, true); 327 FileIOStateManager::OPERATION_EXCLUSIVE, true);
333 if (rv != PP_OK) 328 if (rv != PP_OK)
334 return rv; 329 return rv;
335 330
336 if (!base::FileUtilProxy::Flush( 331 if (!file_.Flush(
337 file_message_loop_,
338 file_,
339 base::Bind(&PepperFileIOHost::ExecutePlatformGeneralCallback, 332 base::Bind(&PepperFileIOHost::ExecutePlatformGeneralCallback,
340 weak_factory_.GetWeakPtr(), 333 weak_factory_.GetWeakPtr(),
341 context->MakeReplyMessageContext()))) 334 context->MakeReplyMessageContext()))) {
342 return PP_ERROR_FAILED; 335 return PP_ERROR_FAILED;
336 }
343 337
344 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE); 338 state_manager_.SetPendingOperation(FileIOStateManager::OPERATION_EXCLUSIVE);
345 return PP_OK_COMPLETIONPENDING; 339 return PP_OK_COMPLETIONPENDING;
346 } 340 }
347 341
348 int32_t PepperFileIOHost::OnHostMsgClose( 342 int32_t PepperFileIOHost::OnHostMsgClose(
349 ppapi::host::HostMessageContext* context, 343 ppapi::host::HostMessageContext* context,
350 const ppapi::FileGrowth& file_growth) { 344 const ppapi::FileGrowth& file_growth) {
351 if (check_quota_) { 345 if (check_quota_) {
352 file_system_host_->CloseQuotaFile(this, file_growth); 346 file_system_host_->CloseQuotaFile(this, file_growth);
353 check_quota_ = false; 347 check_quota_ = false;
354 } 348 }
355 349
356 if (file_ != base::kInvalidPlatformFileValue) { 350 if (file_.IsValid()) {
357 base::FileUtilProxy::Close(file_message_loop_, 351 file_.Close(base::Bind(&PepperFileIOHost::DidCloseFile,
358 file_, 352 weak_factory_.GetWeakPtr()));
359 base::Bind(&PepperFileIOHost::DidCloseFile,
360 weak_factory_.GetWeakPtr()));
361 file_ = base::kInvalidPlatformFileValue;
362 } 353 }
363 return PP_OK; 354 return PP_OK;
364 } 355 }
365 356
366 void PepperFileIOHost::DidOpenQuotaFile( 357 void PepperFileIOHost::DidOpenQuotaFile(
367 ppapi::host::ReplyMessageContext reply_context, 358 ppapi::host::ReplyMessageContext reply_context,
368 base::PlatformFile file, 359 base::PlatformFile file,
369 int64_t max_written_offset) { 360 int64_t max_written_offset) {
370 max_written_offset_ = max_written_offset; 361 max_written_offset_ = max_written_offset;
371 362
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 } 408 }
418 409
419 void PepperFileIOHost::ExecutePlatformGeneralCallback( 410 void PepperFileIOHost::ExecutePlatformGeneralCallback(
420 ppapi::host::ReplyMessageContext reply_context, 411 ppapi::host::ReplyMessageContext reply_context,
421 base::File::Error error_code) { 412 base::File::Error error_code) {
422 reply_context.params.set_result(ppapi::FileErrorToPepperError(error_code)); 413 reply_context.params.set_result(ppapi::FileErrorToPepperError(error_code));
423 host()->SendReply(reply_context, PpapiPluginMsg_FileIO_GeneralReply()); 414 host()->SendReply(reply_context, PpapiPluginMsg_FileIO_GeneralReply());
424 state_manager_.SetOperationFinished(); 415 state_manager_.SetOperationFinished();
425 } 416 }
426 417
418 // TODO(rvargas): this method should go away when FileApi moves to use File.
427 void PepperFileIOHost::ExecutePlatformOpenFileCallback( 419 void PepperFileIOHost::ExecutePlatformOpenFileCallback(
428 ppapi::host::ReplyMessageContext reply_context, 420 ppapi::host::ReplyMessageContext reply_context,
429 base::File::Error error_code, 421 base::File::Error error_code,
430 base::PassPlatformFile file, 422 base::PassPlatformFile file,
431 bool unused_created) { 423 bool unused_created) {
424 DCHECK(!file_.IsValid());
425 file_.SetFile(base::File(file.ReleaseValue()));
426
427 OnOpenProxyCallback(reply_context, error_code);
428 }
429
430 void PepperFileIOHost::OnOpenProxyCallback(
431 ppapi::host::ReplyMessageContext reply_context,
432 base::File::Error error_code) {
432 int32_t pp_error = ppapi::FileErrorToPepperError(error_code); 433 int32_t pp_error = ppapi::FileErrorToPepperError(error_code);
433 DCHECK(file_ == base::kInvalidPlatformFileValue); 434 if (file_.IsValid() && !AddFileToReplyContext(open_flags_, &reply_context))
434 file_ = file.ReleaseValue();
435
436 if (file_ != base::kInvalidPlatformFileValue &&
437 !AddFileToReplyContext(open_flags_, &reply_context))
438 pp_error = PP_ERROR_FAILED; 435 pp_error = PP_ERROR_FAILED;
439 436
440 PP_Resource quota_file_system = 0; 437 PP_Resource quota_file_system = 0;
441 if (pp_error == PP_OK) { 438 if (pp_error == PP_OK) {
442 state_manager_.SetOpenSucceed(); 439 state_manager_.SetOpenSucceed();
443 // A non-zero resource id signals the plugin side to check quota. 440 // A non-zero resource id signals the plugin side to check quota.
444 if (check_quota_) 441 if (check_quota_)
445 quota_file_system = file_system_host_->pp_resource(); 442 quota_file_system = file_system_host_->pp_resource();
446 } 443 }
447 444
(...skipping 11 matching lines...) Expand all
459 456
460 bool PepperFileIOHost::AddFileToReplyContext( 457 bool PepperFileIOHost::AddFileToReplyContext(
461 int32_t open_flags, 458 int32_t open_flags,
462 ppapi::host::ReplyMessageContext* reply_context) const { 459 ppapi::host::ReplyMessageContext* reply_context) const {
463 base::ProcessId plugin_process_id = 460 base::ProcessId plugin_process_id =
464 base::GetProcId(browser_ppapi_host_->GetPluginProcessHandle()); 461 base::GetProcId(browser_ppapi_host_->GetPluginProcessHandle());
465 if (plugin_process_id == base::kNullProcessId) 462 if (plugin_process_id == base::kNullProcessId)
466 plugin_process_id = resolved_render_process_id_; 463 plugin_process_id = resolved_render_process_id_;
467 464
468 IPC::PlatformFileForTransit transit_file = 465 IPC::PlatformFileForTransit transit_file =
469 BrokerGetFileHandleForProcess(file_, plugin_process_id, false); 466 BrokerGetFileHandleForProcess(file_.GetPlatformFile(), plugin_process_id,
467 false);
470 if (transit_file == IPC::InvalidPlatformFileForTransit()) 468 if (transit_file == IPC::InvalidPlatformFileForTransit())
471 return false; 469 return false;
472 470
473 ppapi::proxy::SerializedHandle file_handle; 471 ppapi::proxy::SerializedHandle file_handle;
474 // A non-zero resource id signals NaClIPCAdapter to create a NaClQuotaDesc. 472 // A non-zero resource id signals NaClIPCAdapter to create a NaClQuotaDesc.
475 PP_Resource quota_file_io = check_quota_ ? pp_resource() : 0; 473 PP_Resource quota_file_io = check_quota_ ? pp_resource() : 0;
476 file_handle.set_file_handle(transit_file, open_flags, quota_file_io); 474 file_handle.set_file_handle(transit_file, open_flags, quota_file_io);
477 reply_context->params.AppendHandle(file_handle); 475 reply_context->params.AppendHandle(file_handle);
478 return true; 476 return true;
479 } 477 }
480 478
481 } // namespace content 479 } // namespace content
OLDNEW
« base/files/file_proxy.h ('K') | « content/browser/renderer_host/pepper/pepper_file_io_host.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698