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

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

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

Powered by Google App Engine
This is Rietveld 408576698