OLD | NEW |
---|---|
(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 <string> | |
raymes
2012/11/27 06:54:28
This should probably be in the header instead
victorhsieh
2012/11/27 09:44:42
Done.
raymes
2012/11/27 16:41:30
I think you forgot to upload a patch set because I
victorhsieh
2012/11/28 04:11:55
Oops, done.
| |
8 | |
9 #include "base/bind.h" | |
10 #include "base/callback_helpers.h" | |
11 #include "base/file_util_proxy.h" | |
12 #include "ppapi/c/pp_errors.h" | |
13 #include "ppapi/host/dispatch_host_message.h" | |
14 #include "ppapi/host/ppapi_host.h" | |
15 #include "ppapi/proxy/ppapi_messages.h" | |
16 #include "ppapi/shared_impl/file_type_conversion.h" | |
17 #include "ppapi/shared_impl/file_type_conversion.h" | |
raymes
2012/11/27 06:54:28
you've included this twice
victorhsieh
2012/11/27 09:44:42
Done.
| |
18 #include "ppapi/shared_impl/time_conversion.h" | |
19 #include "ppapi/shared_impl/time_conversion.h" | |
raymes
2012/11/27 06:54:28
you've included this twice
victorhsieh
2012/11/27 09:44:42
Done.
| |
20 #include "webkit/fileapi/file_system_callback_dispatcher.h" | |
21 #include "webkit/plugins/ppapi/file_callbacks.h" | |
22 #include "webkit/plugins/ppapi/ppb_file_ref_impl.h" | |
23 #include "webkit/plugins/ppapi/quota_file_io.h" | |
24 | |
25 namespace content { | |
26 | |
27 using ppapi::PPTimeToTime; | |
28 using ppapi::TimeToPPTime; | |
29 using ppapi::thunk::PPB_FileRef_API; | |
30 using webkit::ppapi::PPB_FileRef_Impl; | |
31 using webkit::ppapi::PluginDelegate; | |
raymes
2012/11/27 06:54:28
I think this list is slightly out of order (at lea
victorhsieh
2012/11/27 09:44:42
How should I sort them? Capital letter shouldn't
raymes
2012/11/27 16:41:30
Oh sorry you're right the order is good.
| |
32 | |
33 namespace { | |
34 | |
35 // The maximum size we'll support reading in one chunk. The renderer process | |
36 // must allocate a buffer sized according to the request of the plugin. To | |
37 // keep things from getting out of control, we cap the read size to this value. | |
38 // This should generally be OK since the API specifies that it may perform a | |
39 // partial read. | |
40 static const int32_t kMaxReadSize = 32 * 1024 * 1024; // 32MB | |
41 | |
42 typedef base::Callback<void (base::PlatformFileError)> PlatformGeneralCallback; | |
43 | |
44 class PlatformGeneralCallbackTranslator | |
45 : public fileapi::FileSystemCallbackDispatcher { | |
46 public: | |
47 PlatformGeneralCallbackTranslator( | |
48 const PlatformGeneralCallback& callback) | |
raymes
2012/11/27 06:54:28
nit: push this onto the previous line
victorhsieh
2012/11/27 09:44:42
Done.
| |
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( | |
58 const base::PlatformFileInfo& file_info, | |
raymes
2012/11/27 06:54:28
nit: Push this onto the previous line
victorhsieh
2012/11/27 09:44:42
Done.
| |
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 } // namespace | |
91 | |
92 PepperFileIOHost::PepperFileIOHost(RendererPpapiHost* host, | |
93 PP_Instance instance, | |
94 PP_Resource resource) | |
95 : ResourceHost(host->GetPpapiHost(), instance, resource), | |
96 ppapi::PPB_FileIO_Shared(), | |
97 plugin_delegate_(host->GetDelegateForInstance(instance)), | |
98 file_(base::kInvalidPlatformFileValue), | |
99 file_system_type_(PP_FILESYSTEMTYPE_INVALID), | |
100 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | |
101 } | |
102 | |
103 PepperFileIOHost::~PepperFileIOHost() { | |
raymes
2012/11/27 06:54:28
Should this call into the same code as OnHostMsgCl
victorhsieh
2012/11/27 09:44:42
Yes, the old implementation does, so I made it the
| |
104 } | |
105 | |
106 int32_t PepperFileIOHost::OnResourceMessageReceived( | |
107 const IPC::Message& msg, | |
108 ppapi::host::HostMessageContext* context) { | |
109 IPC_BEGIN_MESSAGE_MAP(PepperFileIOHost, msg) | |
110 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_FileIO_Open, | |
111 OnHostMsgOpen) | |
112 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_FileIO_Query, | |
113 OnHostMsgQuery) | |
114 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_FileIO_Touch, | |
115 OnHostMsgTouch) | |
116 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_FileIO_Read, | |
117 OnHostMsgRead) | |
118 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_FileIO_Write, | |
119 OnHostMsgWrite) | |
120 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_FileIO_SetLength, | |
121 OnHostMsgSetLength) | |
122 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_FileIO_Flush, | |
123 OnHostMsgFlush) | |
124 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_FileIO_Close, | |
125 OnHostMsgClose) | |
126 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_FileIO_WillWrite, | |
127 OnHostMsgWillWrite) | |
128 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_FileIO_WillSetLength, | |
129 OnHostMsgWillSetLength) | |
130 IPC_END_MESSAGE_MAP() | |
131 return PP_ERROR_FAILED; | |
132 } | |
133 | |
134 int32_t PepperFileIOHost::OnHostMsgOpen( | |
135 ppapi::host::HostMessageContext* context, | |
136 PP_Resource file_ref_resource, | |
137 int32_t open_flags) { | |
138 temp_reply_context_ = context->MakeReplyMessageContext(); | |
139 return DoOpen(file_ref_resource, open_flags); | |
140 } | |
141 | |
142 int32_t PepperFileIOHost::OnHostMsgQuery( | |
143 ppapi::host::HostMessageContext* context) { | |
144 temp_reply_context_ = context->MakeReplyMessageContext(); | |
145 return DoQuery(); | |
146 } | |
147 | |
148 int32_t PepperFileIOHost::OnHostMsgTouch( | |
149 ppapi::host::HostMessageContext* context, | |
150 PP_Time last_access_time, | |
151 PP_Time last_modified_time) { | |
152 temp_reply_context_ = context->MakeReplyMessageContext(); | |
153 return DoTouch(last_access_time, last_modified_time); | |
154 } | |
155 | |
156 int32_t PepperFileIOHost::OnHostMsgRead( | |
157 ppapi::host::HostMessageContext* context, | |
158 int64_t offset, | |
159 int32_t bytes_to_read) { | |
160 | |
raymes
2012/11/27 06:54:28
uneeded newline
victorhsieh
2012/11/27 09:44:42
Done.
| |
161 // Validate bytes_to_read before allocating below. This value is coming from | |
162 // the untrusted plugin. | |
163 if (bytes_to_read < 0) { | |
164 ppapi::host::ReplyMessageContext reply_context = | |
165 context->MakeReplyMessageContext(); | |
166 reply_context.params.set_result(PP_ERROR_FAILED); | |
167 host()->SendReply(reply_context, | |
168 PpapiPluginMsg_FileIO_ReadComplete(std::string())); | |
169 return PP_OK_COMPLETIONPENDING; | |
170 } | |
171 | |
172 temp_reply_context_ = context->MakeReplyMessageContext(); | |
173 return DoRead(offset, std::min(bytes_to_read, kMaxReadSize)); | |
174 } | |
175 | |
176 int32_t PepperFileIOHost::OnHostMsgWrite( | |
177 ppapi::host::HostMessageContext* context, | |
178 int64_t offset, | |
179 const std::string& buffer) { | |
180 temp_reply_context_ = context->MakeReplyMessageContext(); | |
181 return DoWrite(offset, buffer.c_str(), buffer.size()); | |
182 } | |
183 | |
184 int32_t PepperFileIOHost::OnHostMsgSetLength( | |
185 ppapi::host::HostMessageContext* context, | |
186 int64_t length) { | |
187 temp_reply_context_ = context->MakeReplyMessageContext(); | |
188 return DoSetLength(length); | |
189 } | |
190 | |
191 int32_t PepperFileIOHost::OnHostMsgFlush( | |
192 ppapi::host::HostMessageContext* context) { | |
193 temp_reply_context_ = context->MakeReplyMessageContext(); | |
194 return DoFlush(); | |
195 } | |
196 | |
197 int32_t PepperFileIOHost::OnHostMsgClose( | |
198 ppapi::host::HostMessageContext* context) { | |
199 if (file_ != base::kInvalidPlatformFileValue && plugin_delegate_) { | |
200 base::FileUtilProxy::Close( | |
201 plugin_delegate_->GetFileThreadMessageLoopProxy(), | |
raymes
2012/11/27 06:54:28
Please look at the code for this function in the d
victorhsieh
2012/11/27 09:44:42
Done. Leave a TODO.
| |
202 file_, | |
203 base::ResetAndReturn(¬ify_close_file_callback_)); | |
204 file_ = base::kInvalidPlatformFileValue; | |
205 quota_file_io_.reset(); | |
206 } | |
207 return PP_OK; | |
208 } | |
209 | |
210 int32_t PepperFileIOHost::OnHostMsgWillWrite( | |
211 ppapi::host::HostMessageContext* context, | |
212 int64_t offset, | |
213 int32_t bytes_to_write) { | |
214 int32_t rv = CommonPreCondition(true, OPERATION_EXCLUSIVE); | |
215 if (rv != PP_OK) | |
216 return rv; | |
217 | |
218 if (!quota_file_io_.get()) | |
219 return PP_OK; | |
220 | |
221 if (!quota_file_io_->WillWrite( | |
222 offset, bytes_to_write, | |
223 base::Bind(&PepperFileIOHost::ExecutePlatformWillWriteCallback, | |
224 weak_factory_.GetWeakPtr(), | |
225 context->MakeReplyMessageContext()))) | |
226 return PP_ERROR_FAILED; | |
227 | |
228 return PP_OK_COMPLETIONPENDING; | |
229 } | |
230 | |
231 int32_t PepperFileIOHost::OnHostMsgWillSetLength( | |
232 ppapi::host::HostMessageContext* context, | |
233 int64_t length) { | |
234 int32_t rv = CommonPreCondition(true, OPERATION_EXCLUSIVE); | |
235 if (rv != PP_OK) | |
236 return rv; | |
237 | |
238 if (!quota_file_io_.get()) | |
239 return PP_OK; | |
240 | |
241 if (!quota_file_io_->WillSetLength( | |
242 length, | |
243 base::Bind(&PepperFileIOHost::ExecutePlatformGeneralCallback, | |
244 weak_factory_.GetWeakPtr(), | |
245 context->MakeReplyMessageContext()))) | |
246 return PP_ERROR_FAILED; | |
247 | |
248 return PP_OK_COMPLETIONPENDING; | |
249 } | |
250 | |
251 int32_t PepperFileIOHost::CommonPreCondition(bool should_be_open, | |
252 OperationType new_op) { | |
253 if (!plugin_delegate_ || !CheckOpenState(should_be_open)) | |
254 return PP_ERROR_FAILED; | |
255 return PP_OK; | |
256 } | |
257 | |
258 void PepperFileIOHost::CommonPostCondition(OperationType new_op) { | |
259 } | |
260 | |
261 int32_t PepperFileIOHost::OpenValidated( | |
262 PP_Resource file_ref_resource, | |
263 PPB_FileRef_API* file_ref_api, | |
264 int32_t open_flags) { | |
265 int flags = 0; | |
266 if (!::ppapi::PepperFileOpenFlagsToPlatformFileFlags(open_flags, &flags)) | |
267 return PP_ERROR_BADARGUMENT; | |
268 | |
269 PP_FileSystemType type = file_ref_api->GetFileSystemType(); | |
270 if (type != PP_FILESYSTEMTYPE_LOCALPERSISTENT && | |
271 type != PP_FILESYSTEMTYPE_LOCALTEMPORARY && | |
272 type != PP_FILESYSTEMTYPE_EXTERNAL) | |
273 return PP_ERROR_FAILED; | |
274 file_system_type_ = type; | |
275 | |
276 PPB_FileRef_Impl* file_ref = static_cast<PPB_FileRef_Impl*>(file_ref_api); | |
277 if (file_ref->HasValidFileSystem()) { | |
278 file_system_url_ = file_ref->GetFileSystemURL(); | |
279 if (!plugin_delegate_->AsyncOpenFileSystemURL( | |
280 file_system_url_, flags, | |
281 base::Bind( | |
282 &PepperFileIOHost::ExecutePlatformOpenFileSystemURLCallback, | |
283 weak_factory_.GetWeakPtr(), | |
284 temp_reply_context_))) | |
285 return PP_ERROR_FAILED; | |
286 } else { | |
287 if (file_system_type_ != PP_FILESYSTEMTYPE_EXTERNAL) | |
288 return PP_ERROR_FAILED; | |
289 if (!plugin_delegate_->AsyncOpenFile( | |
290 file_ref->GetSystemPath(), flags, | |
291 base::Bind(&PepperFileIOHost::ExecutePlatformOpenFileCallback, | |
292 weak_factory_.GetWeakPtr(), | |
293 temp_reply_context_))) | |
294 return PP_ERROR_FAILED; | |
295 } | |
296 | |
297 return PP_OK_COMPLETIONPENDING; | |
298 } | |
299 | |
300 int32_t PepperFileIOHost::QueryValidated() { | |
301 if (!base::FileUtilProxy::GetFileInfoFromPlatformFile( | |
302 plugin_delegate_->GetFileThreadMessageLoopProxy(), file_, | |
303 base::Bind(&PepperFileIOHost::ExecutePlatformQueryCallback, | |
304 weak_factory_.GetWeakPtr(), | |
305 temp_reply_context_))) | |
306 return PP_ERROR_FAILED; | |
307 | |
308 return PP_OK_COMPLETIONPENDING; | |
309 } | |
310 | |
311 int32_t PepperFileIOHost::TouchValidated( | |
312 PP_Time last_access_time, | |
313 PP_Time last_modified_time) { | |
314 if (file_system_type_ != PP_FILESYSTEMTYPE_EXTERNAL) { | |
315 if (!plugin_delegate_->Touch( | |
316 file_system_url_, | |
317 PPTimeToTime(last_access_time), | |
318 PPTimeToTime(last_modified_time), | |
319 new PlatformGeneralCallbackTranslator( | |
320 base::Bind(&PepperFileIOHost::ExecutePlatformGeneralCallback, | |
321 weak_factory_.GetWeakPtr(), | |
322 temp_reply_context_)))) | |
323 return PP_ERROR_FAILED; | |
324 return PP_OK_COMPLETIONPENDING; | |
325 } | |
326 | |
327 // TODO(nhiroki): fix a failure of FileIO.Touch for an external filesystem on | |
328 // Mac and Linux due to sandbox restrictions (http://crbug.com/101128). | |
329 if (!base::FileUtilProxy::Touch( | |
330 plugin_delegate_->GetFileThreadMessageLoopProxy(), | |
331 file_, PPTimeToTime(last_access_time), | |
332 PPTimeToTime(last_modified_time), | |
333 base::Bind(&PepperFileIOHost::ExecutePlatformGeneralCallback, | |
334 weak_factory_.GetWeakPtr(), | |
335 temp_reply_context_))) | |
336 return PP_ERROR_FAILED; | |
337 | |
338 return PP_OK_COMPLETIONPENDING; | |
339 } | |
340 | |
341 int32_t PepperFileIOHost::ReadValidated( | |
342 int64_t offset, | |
343 int32_t max_read_length) { | |
344 if (!base::FileUtilProxy::Read( | |
345 plugin_delegate_->GetFileThreadMessageLoopProxy(), file_, offset, | |
346 max_read_length, | |
347 base::Bind(&PepperFileIOHost::ExecutePlatformReadCallback, | |
348 weak_factory_.GetWeakPtr(), | |
349 temp_reply_context_))) | |
350 return PP_ERROR_FAILED; | |
351 | |
352 return PP_OK_COMPLETIONPENDING; | |
353 } | |
354 | |
355 int32_t PepperFileIOHost::WriteValidated( | |
356 int64_t offset, | |
357 const char* buffer, | |
358 int32_t bytes_to_write) { | |
359 if (quota_file_io_.get()) { | |
360 if (!quota_file_io_->Write( | |
361 offset, buffer, bytes_to_write, | |
362 base::Bind(&PepperFileIOHost::ExecutePlatformWriteCallback, | |
363 weak_factory_.GetWeakPtr(), | |
364 temp_reply_context_))) | |
365 return PP_ERROR_FAILED; | |
366 } else { | |
367 if (!base::FileUtilProxy::Write( | |
368 plugin_delegate_->GetFileThreadMessageLoopProxy(), file_, offset, | |
369 buffer, bytes_to_write, | |
370 base::Bind(&PepperFileIOHost::ExecutePlatformWriteCallback, | |
371 weak_factory_.GetWeakPtr(), | |
372 temp_reply_context_))) | |
373 return PP_ERROR_FAILED; | |
374 } | |
375 | |
376 return PP_OK_COMPLETIONPENDING; | |
377 } | |
378 | |
379 int32_t PepperFileIOHost::SetLengthValidated( | |
380 int64_t length) { | |
381 if (quota_file_io_.get()) { | |
382 if (!quota_file_io_->SetLength( | |
raymes
2012/11/27 06:54:28
Why does the existing implementation call plugin_d
victorhsieh
2012/11/27 09:44:42
Thanks for catching! A change (http://crrev.com/1
| |
383 length, | |
384 base::Bind(&PepperFileIOHost::ExecutePlatformGeneralCallback, | |
385 weak_factory_.GetWeakPtr(), | |
386 temp_reply_context_))) | |
387 return PP_ERROR_FAILED; | |
388 } else { | |
389 if (!base::FileUtilProxy::Truncate( | |
raymes
2012/11/27 06:54:28
You've erased a TODO here. Is http://crbug.com/156
victorhsieh
2012/11/27 09:44:42
Oops! Have put it back.
| |
390 plugin_delegate_->GetFileThreadMessageLoopProxy(), file_, length, | |
391 base::Bind(&PepperFileIOHost::ExecutePlatformGeneralCallback, | |
392 weak_factory_.GetWeakPtr(), | |
393 temp_reply_context_))) | |
394 return PP_ERROR_FAILED; | |
395 } | |
396 | |
397 return PP_OK_COMPLETIONPENDING; | |
398 } | |
399 | |
400 int32_t PepperFileIOHost::FlushValidated() { | |
401 if (!base::FileUtilProxy::Flush( | |
402 plugin_delegate_->GetFileThreadMessageLoopProxy(), file_, | |
403 base::Bind(&PepperFileIOHost::ExecutePlatformGeneralCallback, | |
404 weak_factory_.GetWeakPtr(), | |
405 temp_reply_context_))) | |
406 return PP_ERROR_FAILED; | |
407 | |
408 return PP_OK_COMPLETIONPENDING; | |
409 } | |
410 | |
411 void PepperFileIOHost::ExecutePlatformGeneralCallback( | |
412 ppapi::host::ReplyMessageContext reply_context, | |
413 base::PlatformFileError error_code) { | |
414 reply_context.params.set_result( | |
415 ::ppapi::PlatformFileErrorToPepperError(error_code)); | |
416 host()->SendReply(reply_context, PpapiPluginMsg_FileIO_GeneralComplete()); | |
417 } | |
418 | |
419 void PepperFileIOHost::ExecutePlatformOpenFileCallback( | |
420 ppapi::host::ReplyMessageContext reply_context, | |
421 base::PlatformFileError error_code, | |
422 base::PassPlatformFile file) { | |
423 int32_t pp_error = ::ppapi::PlatformFileErrorToPepperError(error_code); | |
424 if (pp_error == PP_OK) | |
425 SetOpenSucceed(); | |
426 | |
427 DCHECK(file_ == base::kInvalidPlatformFileValue); | |
428 file_ = file.ReleaseValue(); | |
429 | |
430 DCHECK(!quota_file_io_.get()); | |
431 if (file_ != base::kInvalidPlatformFileValue && | |
432 (file_system_type_ == PP_FILESYSTEMTYPE_LOCALTEMPORARY || | |
433 file_system_type_ == PP_FILESYSTEMTYPE_LOCALPERSISTENT)) { | |
434 quota_file_io_.reset(new webkit::ppapi::QuotaFileIO( | |
435 pp_instance(), file_, file_system_url_, file_system_type_)); | |
436 } | |
437 | |
438 reply_context.params.set_result(pp_error); | |
439 host()->SendReply(reply_context, PpapiPluginMsg_FileIO_OpenFileComplete()); | |
440 } | |
441 | |
442 void PepperFileIOHost::ExecutePlatformOpenFileSystemURLCallback( | |
443 ppapi::host::ReplyMessageContext reply_context, | |
444 base::PlatformFileError error_code, | |
445 base::PassPlatformFile file, | |
446 const PluginDelegate::NotifyCloseFileCallback& callback) { | |
447 if (error_code == base::PLATFORM_FILE_OK) | |
448 notify_close_file_callback_ = callback; | |
449 ExecutePlatformOpenFileCallback(reply_context, error_code, file); | |
450 } | |
451 | |
452 void PepperFileIOHost::ExecutePlatformQueryCallback( | |
453 ppapi::host::ReplyMessageContext reply_context, | |
454 base::PlatformFileError error_code, | |
455 const base::PlatformFileInfo& file_info) { | |
456 PP_FileInfo pp_info; | |
457 pp_info.size = file_info.size; | |
458 pp_info.creation_time = TimeToPPTime(file_info.creation_time); | |
459 pp_info.last_access_time = TimeToPPTime(file_info.last_accessed); | |
460 pp_info.last_modified_time = TimeToPPTime(file_info.last_modified); | |
461 pp_info.system_type = file_system_type_; | |
462 if (file_info.is_directory) | |
463 pp_info.type = PP_FILETYPE_DIRECTORY; | |
464 else | |
465 pp_info.type = PP_FILETYPE_REGULAR; | |
466 | |
467 int32_t pp_error = ::ppapi::PlatformFileErrorToPepperError(error_code); | |
468 reply_context.params.set_result(pp_error); | |
469 host()->SendReply(reply_context, | |
470 PpapiPluginMsg_FileIO_QueryComplete(pp_info)); | |
471 } | |
472 | |
473 void PepperFileIOHost::ExecutePlatformReadCallback( | |
474 ppapi::host::ReplyMessageContext reply_context, | |
475 base::PlatformFileError error_code, | |
476 const char* data, int bytes_read) { | |
477 // Map the error code, OK getting mapped to the # of bytes read. | |
478 int32_t pp_error = ::ppapi::PlatformFileErrorToPepperError(error_code); | |
479 pp_error = pp_error == PP_OK ? bytes_read : pp_error; | |
raymes
2012/11/27 06:54:28
I think it would be better to avoid doing funny st
victorhsieh
2012/11/27 09:44:42
The callback still expect a parameter that is byte
| |
480 | |
481 // Debug checks | |
raymes
2012/11/27 06:54:28
I would get rid of these checks as well.
victorhsieh
2012/11/27 09:44:42
Done.
| |
482 if (pp_error >= 0) | |
483 DCHECK(pp_error <= bytes_read); | |
484 else | |
485 DCHECK(bytes_read == 0); | |
486 | |
487 // Only send the amount of data in the string that was actually read. | |
488 std::string buffer(data, pp_error > 0 ? pp_error : 0); | |
raymes
2012/11/27 06:54:28
Just change this to:
std::string buffer;
if (pp_er
victorhsieh
2012/11/27 09:44:42
Done.
| |
489 reply_context.params.set_result(pp_error); | |
490 host()->SendReply(reply_context, | |
491 PpapiPluginMsg_FileIO_ReadComplete(buffer)); | |
492 } | |
493 | |
494 void PepperFileIOHost::ExecutePlatformWriteCallback( | |
495 ppapi::host::ReplyMessageContext reply_context, | |
496 base::PlatformFileError error_code, | |
497 int bytes_written) { | |
498 int32_t pp_error = ::ppapi::PlatformFileErrorToPepperError(error_code); | |
499 reply_context.params.set_result(pp_error == PP_OK ? bytes_written : pp_error); | |
raymes
2012/11/27 06:54:28
It would be better to set the result to pp_error a
victorhsieh
2012/11/27 09:44:42
Same as read. Leave a comment for now. I'm happy
| |
500 host()->SendReply(reply_context, PpapiPluginMsg_FileIO_GeneralComplete()); | |
501 } | |
502 | |
503 void PepperFileIOHost::ExecutePlatformWillWriteCallback( | |
504 ppapi::host::ReplyMessageContext reply_context, | |
505 base::PlatformFileError error_code, | |
506 int bytes_written) { | |
507 if (error_code != base::PLATFORM_FILE_OK) | |
508 reply_context.params.set_result( | |
509 ::ppapi::PlatformFileErrorToPepperError(error_code)); | |
510 else | |
511 reply_context.params.set_result(bytes_written); | |
raymes
2012/11/27 06:54:28
Same here
victorhsieh
2012/11/27 09:44:42
Done.
| |
512 host()->SendReply(reply_context, | |
513 PpapiPluginMsg_FileIO_GeneralComplete()); | |
514 } | |
515 | |
516 } // namespace content | |
OLD | NEW |