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

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