@@ -86,7 +86,7 @@ PepperFileIOHost::PepperFileIOHost(BrowserPpapiHostImpl* host,
86
86
: ResourceHost(host->GetPpapiHost (), instance, resource),
87
87
browser_ppapi_host_(host),
88
88
render_process_host_(NULL ),
89
- file_(base:: kInvalidPlatformFileValue ),
89
+ file_(BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE) ),
90
90
open_flags_(0 ),
91
91
file_system_type_(PP_FILESYSTEMTYPE_INVALID),
92
92
max_written_offset_(0 ),
@@ -97,8 +97,6 @@ PepperFileIOHost::PepperFileIOHost(BrowserPpapiHostImpl* host,
97
97
instance, &render_process_id_, &unused)) {
98
98
render_process_id_ = -1 ;
99
99
}
100
- file_message_loop_ =
101
- BrowserThread::GetMessageLoopProxyForThread (BrowserThread::FILE);
102
100
}
103
101
104
102
PepperFileIOHost::~PepperFileIOHost () {}
@@ -265,15 +263,14 @@ void PepperFileIOHost::DidOpenInternalFile(
265
263
void PepperFileIOHost::GotResolvedRenderProcessId (
266
264
ppapi::host::ReplyMessageContext reply_context,
267
265
base::FilePath path,
268
- int platform_file_flags ,
266
+ int file_flags ,
269
267
base::ProcessId resolved_render_process_id) {
270
268
DCHECK_CURRENTLY_ON (BrowserThread::IO);
271
269
resolved_render_process_id_ = resolved_render_process_id;
272
- base::FileUtilProxy::CreateOrOpen (
273
- file_message_loop_,
270
+ file_.CreateOrOpen (
274
271
path,
275
- platform_file_flags ,
276
- base::Bind (&PepperFileIOHost::ExecutePlatformOpenFileCallback ,
272
+ file_flags ,
273
+ base::Bind (&PepperFileIOHost::OnOpenProxyCallback ,
277
274
weak_factory_.GetWeakPtr (),
278
275
reply_context));
279
276
}
@@ -287,15 +284,14 @@ int32_t PepperFileIOHost::OnHostMsgTouch(
287
284
if (rv != PP_OK)
288
285
return rv;
289
286
290
- if (!base::FileUtilProxy::Touch (
291
- file_message_loop_,
292
- file_,
287
+ if (!file_.SetTimes (
293
288
PPTimeToTime (last_access_time),
294
289
PPTimeToTime (last_modified_time),
295
290
base::Bind (&PepperFileIOHost::ExecutePlatformGeneralCallback,
296
291
weak_factory_.GetWeakPtr (),
297
- context->MakeReplyMessageContext ())))
292
+ context->MakeReplyMessageContext ()))) {
298
293
return PP_ERROR_FAILED;
294
+ }
299
295
300
296
state_manager_.SetPendingOperation (FileIOStateManager::OPERATION_EXCLUSIVE);
301
297
return PP_OK_COMPLETIONPENDING;
@@ -314,14 +310,13 @@ int32_t PepperFileIOHost::OnHostMsgSetLength(
314
310
// Quota checks are performed on the plugin side, in order to use the same
315
311
// quota reservation and request system as Write.
316
312
317
- if (!base::FileUtilProxy::Truncate (
318
- file_message_loop_,
319
- file_,
313
+ if (!file_.SetLength (
320
314
length,
321
315
base::Bind (&PepperFileIOHost::ExecutePlatformGeneralCallback,
322
316
weak_factory_.GetWeakPtr (),
323
- context->MakeReplyMessageContext ())))
317
+ context->MakeReplyMessageContext ()))) {
324
318
return PP_ERROR_FAILED;
319
+ }
325
320
326
321
state_manager_.SetPendingOperation (FileIOStateManager::OPERATION_EXCLUSIVE);
327
322
return PP_OK_COMPLETIONPENDING;
@@ -334,13 +329,12 @@ int32_t PepperFileIOHost::OnHostMsgFlush(
334
329
if (rv != PP_OK)
335
330
return rv;
336
331
337
- if (!base::FileUtilProxy::Flush (
338
- file_message_loop_,
339
- file_,
332
+ if (!file_.Flush (
340
333
base::Bind (&PepperFileIOHost::ExecutePlatformGeneralCallback,
341
334
weak_factory_.GetWeakPtr (),
342
- context->MakeReplyMessageContext ())))
335
+ context->MakeReplyMessageContext ()))) {
343
336
return PP_ERROR_FAILED;
337
+ }
344
338
345
339
state_manager_.SetPendingOperation (FileIOStateManager::OPERATION_EXCLUSIVE);
346
340
return PP_OK_COMPLETIONPENDING;
@@ -354,12 +348,9 @@ int32_t PepperFileIOHost::OnHostMsgClose(
354
348
check_quota_ = false ;
355
349
}
356
350
357
- if (file_ != base::kInvalidPlatformFileValue ) {
358
- base::FileUtilProxy::Close (file_message_loop_,
359
- file_,
360
- base::Bind (&PepperFileIOHost::DidCloseFile,
361
- weak_factory_.GetWeakPtr ()));
362
- file_ = base::kInvalidPlatformFileValue ;
351
+ if (file_.IsValid ()) {
352
+ file_.Close (base::Bind (&PepperFileIOHost::DidCloseFile,
353
+ weak_factory_.GetWeakPtr ()));
363
354
}
364
355
return PP_OK;
365
356
}
@@ -425,17 +416,23 @@ void PepperFileIOHost::ExecutePlatformGeneralCallback(
425
416
state_manager_.SetOperationFinished ();
426
417
}
427
418
419
+ // TODO(rvargas): this method should go away when FileApi moves to use File.
428
420
void PepperFileIOHost::ExecutePlatformOpenFileCallback (
429
421
ppapi::host::ReplyMessageContext reply_context,
430
422
base::File::Error error_code,
431
423
base::PassPlatformFile file,
432
424
bool unused_created) {
433
- int32_t pp_error = ppapi::FileErrorToPepperError (error_code);
434
- DCHECK (file_ == base::kInvalidPlatformFileValue );
435
- file_ = file.ReleaseValue ();
425
+ DCHECK (!file_.IsValid ());
426
+ file_.SetFile (base::File (file.ReleaseValue ()));
436
427
437
- if (file_ != base::kInvalidPlatformFileValue &&
438
- !AddFileToReplyContext (open_flags_, &reply_context))
428
+ OnOpenProxyCallback (reply_context, error_code);
429
+ }
430
+
431
+ void PepperFileIOHost::OnOpenProxyCallback (
432
+ ppapi::host::ReplyMessageContext reply_context,
433
+ base::File::Error error_code) {
434
+ int32_t pp_error = ppapi::FileErrorToPepperError (error_code);
435
+ if (file_.IsValid () && !AddFileToReplyContext (open_flags_, &reply_context))
439
436
pp_error = PP_ERROR_FAILED;
440
437
441
438
PP_Resource quota_file_system = 0 ;
@@ -467,7 +464,8 @@ bool PepperFileIOHost::AddFileToReplyContext(
467
464
plugin_process_id = resolved_render_process_id_;
468
465
469
466
IPC::PlatformFileForTransit transit_file =
470
- BrokerGetFileHandleForProcess (file_, plugin_process_id, false );
467
+ BrokerGetFileHandleForProcess (file_.GetPlatformFile (), plugin_process_id,
468
+ false );
471
469
if (transit_file == IPC::InvalidPlatformFileForTransit ())
472
470
return false ;
473
471
0 commit comments