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

Side by Side Diff: content/renderer/pepper/pepper_file_io_host.cc

Issue 11419131: Refactor FileIO to the new design (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "content/renderer/pepper/pepper_file_io_host.h"
6
7 #include "base/bind.h"
8 #include "base/callback_helpers.h"
9 #include "base/file_util_proxy.h"
10 #include "ppapi/c/pp_errors.h"
11 #include "ppapi/host/dispatch_host_message.h"
12 #include "ppapi/host/ppapi_host.h"
13 #include "ppapi/proxy/ppapi_messages.h"
14 #include "ppapi/shared_impl/file_type_conversion.h"
15 #include "ppapi/shared_impl/time_conversion.h"
16 #include "ppapi/thunk/enter.h"
17 #include "webkit/fileapi/file_system_callback_dispatcher.h"
18 #include "webkit/plugins/ppapi/file_callbacks.h"
19 #include "webkit/plugins/ppapi/host_globals.h"
20 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
21 #include "webkit/plugins/ppapi/ppb_file_ref_impl.h"
22 #include "webkit/plugins/ppapi/quota_file_io.h"
23
24 namespace content {
25
26 using ppapi::PPTimeToTime;
27 using ppapi::TimeToPPTime;
28 using ppapi::host::ReplyMessageContext;
29 using ppapi::thunk::EnterResourceNoLock;
30 using ppapi::thunk::PPB_FileRef_API;
31 using webkit::ppapi::PPB_FileRef_Impl;
32 using webkit::ppapi::PluginDelegate;
33
34 namespace {
35
36 // The maximum size we'll support reading in one chunk. The renderer process
37 // must allocate a buffer sized according to the request of the plugin. To
38 // keep things from getting out of control, we cap the read size to this value.
39 // This should generally be OK since the API specifies that it may perform a
40 // partial read.
41 static const int32_t kMaxReadSize = 32 * 1024 * 1024; // 32MB
42
43 typedef base::Callback<void (base::PlatformFileError)> PlatformGeneralCallback;
44
45 class PlatformGeneralCallbackTranslator
46 : public fileapi::FileSystemCallbackDispatcher {
47 public:
48 PlatformGeneralCallbackTranslator(const PlatformGeneralCallback& callback)
49 : callback_(callback) {}
50
51 virtual ~PlatformGeneralCallbackTranslator() {}
52
53 virtual void DidSucceed() OVERRIDE {
54 callback_.Run(base::PLATFORM_FILE_OK);
55 }
56
57 virtual void DidReadMetadata(const base::PlatformFileInfo& file_info,
58 const FilePath& platform_path) OVERRIDE {
59 NOTREACHED();
60 }
61
62 virtual void DidReadDirectory(
63 const std::vector<base::FileUtilProxy::Entry>& entries,
64 bool has_more) OVERRIDE {
65 NOTREACHED();
66 }
67
68 virtual void DidOpenFileSystem(const std::string& name,
69 const GURL& root) OVERRIDE {
70 NOTREACHED();
71 }
72
73 virtual void DidFail(base::PlatformFileError error_code) OVERRIDE {
74 callback_.Run(error_code);
75 }
76
77 virtual void DidWrite(int64 bytes, bool complete) OVERRIDE {
78 NOTREACHED();
79 }
80
81 virtual void DidOpenFile(base::PlatformFile file) OVERRIDE {
82 NOTREACHED();
83 }
84
85 private:
86 PlatformGeneralCallback callback_;
87 };
88
89 int32_t ErrorOrByteNumber(int32_t pp_error, int32_t byte_number) {
90 // On the plugin side, some callbacks expect a parameter that means different
91 // things depending on whether is negative or not. We translate for those
92 // callbacks here.
93 return pp_error == PP_OK ? byte_number : pp_error;
94 }
95
96 } // namespace
97
98 PepperFileIOHost::PepperFileIOHost(RendererPpapiHost* host,
99 PP_Instance instance,
100 PP_Resource resource)
101 : ResourceHost(host->GetPpapiHost(), instance, resource),
102 ppapi::PPB_FileIO_Shared(),
103 file_(base::kInvalidPlatformFileValue),
104 file_system_type_(PP_FILESYSTEMTYPE_INVALID),
105 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
106 // TODO(victorhsieh): eliminate plugin_delegate_ as it's no longer needed.
107 webkit::ppapi::PluginInstance* plugin_instance =
108 webkit::ppapi::HostGlobals::Get()->GetInstance(instance);
109 plugin_delegate_ = plugin_instance ? plugin_instance->delegate() : NULL;
110 }
111
112 PepperFileIOHost::~PepperFileIOHost() {
113 OnHostMsgClose(NULL);
114 }
115
116 int32_t PepperFileIOHost::OnResourceMessageReceived(
117 const IPC::Message& msg,
118 ppapi::host::HostMessageContext* context) {
119 IPC_BEGIN_MESSAGE_MAP(PepperFileIOHost, msg)
120 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_FileIO_Open,
121 OnHostMsgOpen)
122 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_FileIO_Query,
123 OnHostMsgQuery)
124 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_FileIO_Touch,
125 OnHostMsgTouch)
126 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_FileIO_Read,
127 OnHostMsgRead)
128 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_FileIO_Write,
129 OnHostMsgWrite)
130 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_FileIO_SetLength,
131 OnHostMsgSetLength)
132 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_FileIO_Flush,
133 OnHostMsgFlush)
134 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_FileIO_Close,
135 OnHostMsgClose)
136 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_FileIO_WillWrite,
137 OnHostMsgWillWrite)
138 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_FileIO_WillSetLength,
139 OnHostMsgWillSetLength)
140 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_FileIO_GetOSFileDescriptor,
141 OnHostMsgGetOSFileDescriptor)
142 IPC_END_MESSAGE_MAP()
143 return PP_ERROR_FAILED;
144 }
145
146 int32_t PepperFileIOHost::OnHostMsgOpen(
147 ppapi::host::HostMessageContext* context,
148 PP_Resource file_ref_resource,
149 int32_t open_flags) {
150 EnterResourceNoLock<PPB_FileRef_API> enter(file_ref_resource, true);
151 if (enter.failed())
152 return PP_ERROR_BADRESOURCE;
153
154 int32_t rv = CommonPreCondition(false, OPERATION_EXCLUSIVE);
raymes 2012/11/28 18:39:35 If we make the PPB_FileIO_Shared a helper class (m
victorhsieh 2012/11/29 06:34:55 Done.
155 if (rv != PP_OK)
156 return rv;
157
158 CommonPostCondition(OPERATION_EXCLUSIVE);
159 return OpenValidated(context->MakeReplyMessageContext(),
raymes 2012/11/28 18:39:35 We can get rid of the "Validated" functions here a
victorhsieh 2012/11/29 06:34:55 Done.
160 enter.object(), open_flags);
161 }
162
163 int32_t PepperFileIOHost::OnHostMsgQuery(
164 ppapi::host::HostMessageContext* context) {
165 int32_t rv = CommonPreCondition(true, OPERATION_EXCLUSIVE);
166 if (rv != PP_OK)
167 return rv;
168
169 CommonPostCondition(OPERATION_EXCLUSIVE);
170 return QueryValidated(context->MakeReplyMessageContext());
171 }
172
173 int32_t PepperFileIOHost::OnHostMsgTouch(
174 ppapi::host::HostMessageContext* context,
175 PP_Time last_access_time,
176 PP_Time last_modified_time) {
177 int32_t rv = CommonPreCondition(true, OPERATION_EXCLUSIVE);
178 if (rv != PP_OK)
179 return rv;
180
181 CommonPostCondition(OPERATION_EXCLUSIVE);
182 return TouchValidated(context->MakeReplyMessageContext(),
183 last_access_time, last_modified_time);
184 }
185
186 int32_t PepperFileIOHost::OnHostMsgRead(
187 ppapi::host::HostMessageContext* context,
188 int64_t offset,
189 int32_t bytes_to_read) {
190 int32_t rv = CommonPreCondition(true, OPERATION_READ);
191 if (rv != PP_OK)
192 return rv;
193
194 // Validate bytes_to_read before allocating below. This value is coming from
195 // the untrusted plugin.
196 if (bytes_to_read < 0) {
197 ReplyMessageContext reply_context = context->MakeReplyMessageContext();
198 reply_context.params.set_result(PP_ERROR_FAILED);
199 host()->SendReply(reply_context,
200 PpapiPluginMsg_FileIO_ReadComplete(std::string()));
201 return PP_OK_COMPLETIONPENDING;
202 }
203
204 CommonPostCondition(OPERATION_READ);
205 return ReadValidated(context->MakeReplyMessageContext(),
206 offset, bytes_to_read);
207 }
208
209 int32_t PepperFileIOHost::OnHostMsgWrite(
210 ppapi::host::HostMessageContext* context,
211 int64_t offset,
212 const std::string& buffer) {
213 int32_t rv = CommonPreCondition(true, OPERATION_WRITE);
214 if (rv != PP_OK)
215 return rv;
216
217 CommonPostCondition(OPERATION_WRITE);
218 return WriteValidated(context->MakeReplyMessageContext(),
219 offset, buffer.c_str(), buffer.size());
220 }
221
222 int32_t PepperFileIOHost::OnHostMsgSetLength(
223 ppapi::host::HostMessageContext* context,
224 int64_t length) {
225 int32_t rv = CommonPreCondition(true, OPERATION_EXCLUSIVE);
226 if (rv != PP_OK)
227 return rv;
228
229 CommonPostCondition(OPERATION_EXCLUSIVE);
230 return SetLengthValidated(context->MakeReplyMessageContext(), length);
231 }
232
233 int32_t PepperFileIOHost::OnHostMsgFlush(
234 ppapi::host::HostMessageContext* context) {
235 int32_t rv = CommonPreCondition(true, OPERATION_EXCLUSIVE);
236 if (rv != PP_OK)
237 return rv;
238
239 CommonPostCondition(OPERATION_EXCLUSIVE);
240 return FlushValidated(context->MakeReplyMessageContext());
241 }
242
243 int32_t PepperFileIOHost::OnHostMsgClose(
244 ppapi::host::HostMessageContext* context) {
245 if (file_ != base::kInvalidPlatformFileValue && plugin_delegate_) {
246 base::FileUtilProxy::Close(
247 plugin_delegate_->GetFileThreadMessageLoopProxy(),
248 file_,
249 base::ResetAndReturn(&notify_close_file_callback_));
250 file_ = base::kInvalidPlatformFileValue;
251 quota_file_io_.reset();
252 }
253 return PP_OK;
254 }
255
256 int32_t PepperFileIOHost::OnHostMsgWillWrite(
257 ppapi::host::HostMessageContext* context,
258 int64_t offset,
259 int32_t bytes_to_write) {
260 int32_t rv = CommonPreCondition(true, OPERATION_EXCLUSIVE);
261 if (rv != PP_OK)
262 return rv;
263
264 if (!quota_file_io_.get())
265 return PP_OK;
266
267 if (!quota_file_io_->WillWrite(
268 offset, bytes_to_write,
269 base::Bind(&PepperFileIOHost::ExecutePlatformWillWriteCallback,
270 weak_factory_.GetWeakPtr(),
271 context->MakeReplyMessageContext())))
272 return PP_ERROR_FAILED;
273
274 CommonPostCondition(OPERATION_EXCLUSIVE);
275 return PP_OK_COMPLETIONPENDING;
276 }
277
278 int32_t PepperFileIOHost::OnHostMsgWillSetLength(
279 ppapi::host::HostMessageContext* context,
280 int64_t length) {
281 int32_t rv = CommonPreCondition(true, OPERATION_EXCLUSIVE);
282 if (rv != PP_OK)
283 return rv;
284
285 if (!quota_file_io_.get())
286 return PP_OK;
287
288 if (!quota_file_io_->WillSetLength(
289 length,
290 base::Bind(&PepperFileIOHost::ExecutePlatformGeneralCallback,
291 weak_factory_.GetWeakPtr(),
292 context->MakeReplyMessageContext())))
293 return PP_ERROR_FAILED;
294
295 CommonPostCondition(OPERATION_EXCLUSIVE);
296 return PP_OK_COMPLETIONPENDING;
297 }
298
299 int32_t PepperFileIOHost::OnHostMsgGetOSFileDescriptor(
300 ppapi::host::HostMessageContext* context) {
301 //if (!host()->IsRunningInProcess())
302 // return PP_ERROR_FAILED;
303 int32_t fd =
304 #if defined(OS_POSIX)
305 file_;
306 #elif defined(OS_WIN)
307 reinterpret_cast<uintptr_t>(file_);
308 #else
309 -1; // Platform not supported.
310 #endif
311 // TODO(victorhsieh): Pass the file handle in the reply params once this works
312 // in-process.
313 host()->SendReply(context->MakeReplyMessageContext(),
314 PpapiPluginMsg_FileIO_GetOSFileDescriptorReply(fd));
315 return PP_OK_COMPLETIONPENDING;
316 }
317
318 int32_t PepperFileIOHost::OpenValidated(
319 const ReplyMessageContext& reply_context,
320 PPB_FileRef_API* file_ref_api,
321 int32_t open_flags) {
322 if (!plugin_delegate_)
323 return PP_ERROR_FAILED;
324
325 int flags = 0;
326 if (!::ppapi::PepperFileOpenFlagsToPlatformFileFlags(open_flags, &flags))
327 return PP_ERROR_BADARGUMENT;
328
329 PP_FileSystemType type = file_ref_api->GetFileSystemType();
330 if (type != PP_FILESYSTEMTYPE_LOCALPERSISTENT &&
331 type != PP_FILESYSTEMTYPE_LOCALTEMPORARY &&
332 type != PP_FILESYSTEMTYPE_EXTERNAL)
333 return PP_ERROR_FAILED;
334 file_system_type_ = type;
335
336 PPB_FileRef_Impl* file_ref = static_cast<PPB_FileRef_Impl*>(file_ref_api);
337 if (file_ref->HasValidFileSystem()) {
338 file_system_url_ = file_ref->GetFileSystemURL();
339 if (!plugin_delegate_->AsyncOpenFileSystemURL(
340 file_system_url_, flags,
341 base::Bind(
342 &PepperFileIOHost::ExecutePlatformOpenFileSystemURLCallback,
343 weak_factory_.GetWeakPtr(),
344 reply_context)))
345 return PP_ERROR_FAILED;
346 } else {
347 if (file_system_type_ != PP_FILESYSTEMTYPE_EXTERNAL)
348 return PP_ERROR_FAILED;
349 if (!plugin_delegate_->AsyncOpenFile(
350 file_ref->GetSystemPath(), flags,
351 base::Bind(&PepperFileIOHost::ExecutePlatformOpenFileCallback,
352 weak_factory_.GetWeakPtr(),
353 reply_context)))
354 return PP_ERROR_FAILED;
355 }
356
357 return PP_OK_COMPLETIONPENDING;
358 }
359
360 int32_t PepperFileIOHost::QueryValidated(
361 const ReplyMessageContext& reply_context) {
362 if (!plugin_delegate_)
363 return PP_ERROR_FAILED;
364
365 if (!base::FileUtilProxy::GetFileInfoFromPlatformFile(
366 plugin_delegate_->GetFileThreadMessageLoopProxy(), file_,
367 base::Bind(&PepperFileIOHost::ExecutePlatformQueryCallback,
368 weak_factory_.GetWeakPtr(),
369 reply_context)))
370 return PP_ERROR_FAILED;
371
372 return PP_OK_COMPLETIONPENDING;
373 }
374
375 int32_t PepperFileIOHost::TouchValidated(
376 const ReplyMessageContext& reply_context,
377 PP_Time last_access_time,
378 PP_Time last_modified_time) {
379 if (!plugin_delegate_)
380 return PP_ERROR_FAILED;
381
382 if (file_system_type_ != PP_FILESYSTEMTYPE_EXTERNAL) {
383 if (!plugin_delegate_->Touch(
384 file_system_url_,
385 PPTimeToTime(last_access_time),
386 PPTimeToTime(last_modified_time),
387 new PlatformGeneralCallbackTranslator(
388 base::Bind(&PepperFileIOHost::ExecutePlatformGeneralCallback,
389 weak_factory_.GetWeakPtr(),
390 reply_context))))
391 return PP_ERROR_FAILED;
392 return PP_OK_COMPLETIONPENDING;
393 }
394
395 // TODO(nhiroki): fix a failure of FileIO.Touch for an external filesystem on
396 // Mac and Linux due to sandbox restrictions (http://crbug.com/101128).
397 if (!base::FileUtilProxy::Touch(
398 plugin_delegate_->GetFileThreadMessageLoopProxy(),
399 file_, PPTimeToTime(last_access_time),
400 PPTimeToTime(last_modified_time),
401 base::Bind(&PepperFileIOHost::ExecutePlatformGeneralCallback,
402 weak_factory_.GetWeakPtr(),
403 reply_context)))
404 return PP_ERROR_FAILED;
405
406 return PP_OK_COMPLETIONPENDING;
407 }
408
409 int32_t PepperFileIOHost::ReadValidated(
410 const ReplyMessageContext& reply_context,
411 int64_t offset,
412 int32_t max_read_length) {
413 if (!plugin_delegate_)
414 return PP_ERROR_FAILED;
415
416 if (!base::FileUtilProxy::Read(
417 plugin_delegate_->GetFileThreadMessageLoopProxy(), file_, offset,
418 max_read_length,
419 base::Bind(&PepperFileIOHost::ExecutePlatformReadCallback,
420 weak_factory_.GetWeakPtr(),
421 reply_context)))
422 return PP_ERROR_FAILED;
423
424 return PP_OK_COMPLETIONPENDING;
425 }
426
427 int32_t PepperFileIOHost::WriteValidated(
428 const ReplyMessageContext& reply_context,
429 int64_t offset,
430 const char* buffer,
431 int32_t bytes_to_write) {
432 if (quota_file_io_.get()) {
433 if (!quota_file_io_->Write(
434 offset, buffer, bytes_to_write,
435 base::Bind(&PepperFileIOHost::ExecutePlatformWriteCallback,
436 weak_factory_.GetWeakPtr(),
437 reply_context)))
438 return PP_ERROR_FAILED;
439 } else {
440 if (!plugin_delegate_)
441 return PP_ERROR_FAILED;
442
443 if (!base::FileUtilProxy::Write(
444 plugin_delegate_->GetFileThreadMessageLoopProxy(), file_, offset,
445 buffer, bytes_to_write,
446 base::Bind(&PepperFileIOHost::ExecutePlatformWriteCallback,
447 weak_factory_.GetWeakPtr(),
448 reply_context)))
449 return PP_ERROR_FAILED;
450 }
451
452 return PP_OK_COMPLETIONPENDING;
453 }
454
455 int32_t PepperFileIOHost::SetLengthValidated(
456 const ReplyMessageContext& reply_context,
457 int64_t length) {
458 if (!plugin_delegate_)
459 return PP_ERROR_FAILED;
460
461 if (file_system_type_ != PP_FILESYSTEMTYPE_EXTERNAL) {
462 if (!plugin_delegate_->SetLength(
463 file_system_url_, length,
464 new PlatformGeneralCallbackTranslator(
465 base::Bind(&PepperFileIOHost::ExecutePlatformGeneralCallback,
466 weak_factory_.GetWeakPtr(),
467 reply_context))))
468 return PP_ERROR_FAILED;
469 } else {
470 // TODO(nhiroki): fix a failure of FileIO.SetLength for an external
471 // filesystem on Mac due to sandbox restrictions (http://crbug.com/156077).
472 if (!base::FileUtilProxy::Truncate(
473 plugin_delegate_->GetFileThreadMessageLoopProxy(), file_, length,
474 base::Bind(&PepperFileIOHost::ExecutePlatformGeneralCallback,
475 weak_factory_.GetWeakPtr(),
476 reply_context)))
477 return PP_ERROR_FAILED;
478 }
479
480 return PP_OK_COMPLETIONPENDING;
481 }
482
483 int32_t PepperFileIOHost::FlushValidated(
484 const ReplyMessageContext& reply_context) {
485 if (!plugin_delegate_)
486 return PP_ERROR_FAILED;
487
488 if (!base::FileUtilProxy::Flush(
489 plugin_delegate_->GetFileThreadMessageLoopProxy(), file_,
490 base::Bind(&PepperFileIOHost::ExecutePlatformGeneralCallback,
491 weak_factory_.GetWeakPtr(),
492 reply_context)))
493 return PP_ERROR_FAILED;
494
495 return PP_OK_COMPLETIONPENDING;
496 }
497
498 void PepperFileIOHost::ExecutePlatformGeneralCallback(
499 ppapi::host::ReplyMessageContext reply_context,
500 base::PlatformFileError error_code) {
501 reply_context.params.set_result(
502 ::ppapi::PlatformFileErrorToPepperError(error_code));
503 host()->SendReply(reply_context, PpapiPluginMsg_FileIO_GeneralComplete());
504 SetOpFinished();
505 }
506
507 void PepperFileIOHost::ExecutePlatformOpenFileCallback(
508 ppapi::host::ReplyMessageContext reply_context,
509 base::PlatformFileError error_code,
510 base::PassPlatformFile file) {
511 int32_t pp_error = ::ppapi::PlatformFileErrorToPepperError(error_code);
512 if (pp_error == PP_OK)
513 SetOpenSucceed();
514
515 DCHECK(file_ == base::kInvalidPlatformFileValue);
516 file_ = file.ReleaseValue();
517
518 DCHECK(!quota_file_io_.get());
519 if (file_ != base::kInvalidPlatformFileValue &&
520 (file_system_type_ == PP_FILESYSTEMTYPE_LOCALTEMPORARY ||
521 file_system_type_ == PP_FILESYSTEMTYPE_LOCALPERSISTENT)) {
522 quota_file_io_.reset(new webkit::ppapi::QuotaFileIO(
523 pp_instance(), file_, file_system_url_, file_system_type_));
524 }
525
526 reply_context.params.set_result(pp_error);
527 host()->SendReply(reply_context, PpapiPluginMsg_FileIO_OpenFileComplete());
528 SetOpFinished();
529 }
530
531 void PepperFileIOHost::ExecutePlatformOpenFileSystemURLCallback(
532 ppapi::host::ReplyMessageContext reply_context,
533 base::PlatformFileError error_code,
534 base::PassPlatformFile file,
535 const PluginDelegate::NotifyCloseFileCallback& callback) {
536 if (error_code == base::PLATFORM_FILE_OK)
537 notify_close_file_callback_ = callback;
538 ExecutePlatformOpenFileCallback(reply_context, error_code, file);
539 }
540
541 void PepperFileIOHost::ExecutePlatformQueryCallback(
542 ppapi::host::ReplyMessageContext reply_context,
543 base::PlatformFileError error_code,
544 const base::PlatformFileInfo& file_info) {
545 PP_FileInfo pp_info;
546 pp_info.size = file_info.size;
547 pp_info.creation_time = TimeToPPTime(file_info.creation_time);
548 pp_info.last_access_time = TimeToPPTime(file_info.last_accessed);
549 pp_info.last_modified_time = TimeToPPTime(file_info.last_modified);
550 pp_info.system_type = file_system_type_;
551 if (file_info.is_directory)
552 pp_info.type = PP_FILETYPE_DIRECTORY;
553 else
554 pp_info.type = PP_FILETYPE_REGULAR;
555
556 int32_t pp_error = ::ppapi::PlatformFileErrorToPepperError(error_code);
557 reply_context.params.set_result(pp_error);
558 host()->SendReply(reply_context,
559 PpapiPluginMsg_FileIO_QueryComplete(pp_info));
560 SetOpFinished();
561 }
562
563 void PepperFileIOHost::ExecutePlatformReadCallback(
564 ppapi::host::ReplyMessageContext reply_context,
565 base::PlatformFileError error_code,
566 const char* data, int bytes_read) {
567 int32_t pp_error = ::ppapi::PlatformFileErrorToPepperError(error_code);
568
569 // Only send the amount of data in the string that was actually read.
570 std::string buffer;
571 if (pp_error == PP_OK)
572 buffer.append(data, bytes_read);
573 reply_context.params.set_result(ErrorOrByteNumber(pp_error, bytes_read));
574 host()->SendReply(reply_context, PpapiPluginMsg_FileIO_ReadComplete(buffer));
575 SetOpFinished();
576 }
577
578 void PepperFileIOHost::ExecutePlatformWriteCallback(
579 ppapi::host::ReplyMessageContext reply_context,
580 base::PlatformFileError error_code,
581 int bytes_written) {
582 int32_t pp_error = ::ppapi::PlatformFileErrorToPepperError(error_code);
583 reply_context.params.set_result(ErrorOrByteNumber(pp_error, bytes_written));
584 host()->SendReply(reply_context, PpapiPluginMsg_FileIO_GeneralComplete());
585 SetOpFinished();
586 }
587
588 void PepperFileIOHost::ExecutePlatformWillWriteCallback(
589 ppapi::host::ReplyMessageContext reply_context,
590 base::PlatformFileError error_code,
591 int bytes_written) {
592 // On the plugin side, the callback expects a parameter with different meaning
593 // depends on whether is negative or not. It is the result here. We
594 // translate for the callback.
595 int32_t pp_error = ::ppapi::PlatformFileErrorToPepperError(error_code);
596 reply_context.params.set_result(ErrorOrByteNumber(pp_error, bytes_written));
597 host()->SendReply(reply_context, PpapiPluginMsg_FileIO_GeneralComplete());
598 SetOpFinished();
599 }
600
601 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698