OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "webkit/plugins/ppapi/ppb_file_ref_impl.h" | 5 #include "webkit/plugins/ppapi/ppb_file_ref_impl.h" |
6 | 6 |
7 #include "base/platform_file.h" | |
7 #include "base/string_util.h" | 8 #include "base/string_util.h" |
8 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
9 #include "googleurl/src/gurl.h" | 10 #include "googleurl/src/gurl.h" |
10 #include "net/base/escape.h" | 11 #include "net/base/escape.h" |
11 #include "ppapi/c/pp_errors.h" | 12 #include "ppapi/c/pp_errors.h" |
13 #include "ppapi/shared_impl/file_type_conversion.h" | |
14 #include "ppapi/shared_impl/time_conversion.h" | |
15 #include "ppapi/shared_impl/var.h" | |
12 #include "ppapi/thunk/enter.h" | 16 #include "ppapi/thunk/enter.h" |
13 #include "ppapi/thunk/ppb_file_system_api.h" | 17 #include "ppapi/thunk/ppb_file_system_api.h" |
14 #include "ppapi/shared_impl/time_conversion.h" | |
15 #include "ppapi/shared_impl/var.h" | |
16 #include "webkit/plugins/ppapi/common.h" | 18 #include "webkit/plugins/ppapi/common.h" |
17 #include "webkit/plugins/ppapi/file_callbacks.h" | 19 #include "webkit/plugins/ppapi/file_callbacks.h" |
18 #include "webkit/plugins/ppapi/plugin_delegate.h" | 20 #include "webkit/plugins/ppapi/plugin_delegate.h" |
19 #include "webkit/plugins/ppapi/plugin_module.h" | 21 #include "webkit/plugins/ppapi/plugin_module.h" |
20 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 22 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
21 #include "webkit/plugins/ppapi/ppb_file_system_impl.h" | 23 #include "webkit/plugins/ppapi/ppb_file_system_impl.h" |
22 #include "webkit/plugins/ppapi/resource_helper.h" | 24 #include "webkit/plugins/ppapi/resource_helper.h" |
23 | 25 |
24 using ppapi::HostResource; | 26 using ppapi::HostResource; |
25 using ppapi::PPB_FileRef_CreateInfo; | 27 using ppapi::PPB_FileRef_CreateInfo; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
79 std::string GetNameForVirtualFilePath(const std::string& path) { | 81 std::string GetNameForVirtualFilePath(const std::string& path) { |
80 if (path.size() == 1 && path[0] == '/') | 82 if (path.size() == 1 && path[0] == '/') |
81 return path; | 83 return path; |
82 | 84 |
83 // There should always be a leading slash at least! | 85 // There should always be a leading slash at least! |
84 size_t pos = path.rfind('/'); | 86 size_t pos = path.rfind('/'); |
85 CHECK(pos != std::string::npos); | 87 CHECK(pos != std::string::npos); |
86 return path.substr(pos + 1); | 88 return path.substr(pos + 1); |
87 } | 89 } |
88 | 90 |
91 void IgnoreCloseCallback(base::PlatformFileError error_code) { | |
92 } | |
93 | |
89 } // namespace | 94 } // namespace |
90 | 95 |
91 PPB_FileRef_Impl::PPB_FileRef_Impl(const PPB_FileRef_CreateInfo& info, | 96 PPB_FileRef_Impl::PPB_FileRef_Impl(const PPB_FileRef_CreateInfo& info, |
92 PPB_FileSystem_Impl* file_system) | 97 PPB_FileSystem_Impl* file_system) |
93 : PPB_FileRef_Shared(::ppapi::OBJECT_IS_IMPL, info), | 98 : PPB_FileRef_Shared(::ppapi::OBJECT_IS_IMPL, info), |
94 file_system_(file_system), | 99 file_system_(file_system), |
95 external_file_system_path_() { | 100 external_file_system_path_() { |
96 } | 101 } |
97 | 102 |
98 PPB_FileRef_Impl::PPB_FileRef_Impl(const PPB_FileRef_CreateInfo& info, | 103 PPB_FileRef_Impl::PPB_FileRef_Impl(const PPB_FileRef_CreateInfo& info, |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
286 | 291 |
287 bool PPB_FileRef_Impl::HasValidFileSystem() const { | 292 bool PPB_FileRef_Impl::HasValidFileSystem() const { |
288 return file_system_ && file_system_->opened(); | 293 return file_system_ && file_system_->opened(); |
289 } | 294 } |
290 | 295 |
291 bool PPB_FileRef_Impl::IsValidNonExternalFileSystem() const { | 296 bool PPB_FileRef_Impl::IsValidNonExternalFileSystem() const { |
292 return file_system_ && file_system_->opened() && | 297 return file_system_ && file_system_->opened() && |
293 file_system_->type() != PP_FILESYSTEMTYPE_EXTERNAL; | 298 file_system_->type() != PP_FILESYSTEMTYPE_EXTERNAL; |
294 } | 299 } |
295 | 300 |
301 int32_t PPB_FileRef_Impl::Query(PP_FileInfo* info, | |
302 scoped_refptr<TrackedCallback> callback) { | |
303 scoped_refptr<PluginInstance> plugin_instance = | |
304 ResourceHelper::GetPluginInstance(this); | |
305 if (!plugin_instance.get()) | |
306 return PP_ERROR_FAILED; | |
307 | |
308 if (!file_system_) { | |
309 // External file system | |
310 // We have to do something totally different for external file systems. | |
311 if (!plugin_instance->delegate()->AsyncOpenFile( | |
312 GetSystemPath(), | |
313 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ, | |
314 base::Bind(&PPB_FileRef_Impl::QueryCallback, this, info, callback))) | |
315 return PP_ERROR_FAILED; | |
316 } else { | |
317 // Non-external file system | |
318 if (!HasValidFileSystem()) | |
319 return PP_ERROR_NOACCESS; | |
320 | |
321 if (!plugin_instance->delegate()->Query( | |
322 GetFileSystemURL(), | |
323 new FileCallbacks(this, callback, info, file_system_))) | |
324 return PP_ERROR_FAILED; | |
325 | |
326 } | |
327 return PP_OK_COMPLETIONPENDING; | |
328 } | |
329 | |
330 void PPB_FileRef_Impl::QueryCallback(PP_FileInfo* info, | |
331 scoped_refptr<TrackedCallback> callback, | |
332 base::PlatformFileError error_code, | |
333 base::PassPlatformFile passed_file) { | |
334 if (!TrackedCallback::IsPending(callback)) | |
335 return; | |
dmichael (off chromium)
2013/03/27 22:13:55
Do you need to close passed_file here?
| |
336 | |
337 scoped_refptr<PluginInstance> plugin_instance = | |
338 ResourceHelper::GetPluginInstance(this); | |
339 if (!plugin_instance.get()) | |
340 callback->Run(PP_ERROR_FAILED); | |
dmichael (off chromium)
2013/03/27 22:13:55
I think callback->Abort() is more appropriate here
| |
341 | |
342 int32_t pp_error = ::ppapi::PlatformFileErrorToPepperError(error_code); | |
343 if (pp_error != PP_OK) | |
344 callback->Run(pp_error); | |
345 base::PlatformFile file = passed_file.ReleaseValue(); | |
346 | |
347 if (!base::FileUtilProxy::GetFileInfoFromPlatformFile( | |
348 plugin_instance->delegate()->GetFileThreadMessageLoopProxy(), file, | |
349 base::Bind(&PPB_FileRef_Impl::GetFileInfoCallback, this, file, info, | |
350 callback))) { | |
351 base::FileUtilProxy::Close( | |
352 plugin_instance->delegate()->GetFileThreadMessageLoopProxy(), | |
353 file, base::Bind(&IgnoreCloseCallback)); | |
354 callback->Run(PP_ERROR_FAILED); | |
355 } | |
356 } | |
357 | |
358 void PPB_FileRef_Impl::GetFileInfoCallback( | |
359 base::PlatformFile file, | |
360 PP_FileInfo* info, | |
361 scoped_refptr<TrackedCallback> callback, | |
362 base::PlatformFileError error_code, | |
363 const base::PlatformFileInfo& file_info) { | |
364 scoped_refptr<PluginInstance> plugin_instance = | |
365 ResourceHelper::GetPluginInstance(this); | |
366 if (plugin_instance.get()) { | |
dmichael (off chromium)
2013/03/27 22:13:55
nit: You don't need to say ".get()"
| |
367 base::FileUtilProxy::Close( | |
368 plugin_instance->delegate()->GetFileThreadMessageLoopProxy(), | |
369 file, base::Bind(&IgnoreCloseCallback)); | |
dmichael (off chromium)
2013/03/27 22:13:55
Hmm, in the rare case that the instance is gone by
| |
370 } | |
371 | |
372 if (!TrackedCallback::IsPending(callback)) | |
373 return; | |
374 | |
375 int32_t pp_error = ::ppapi::PlatformFileErrorToPepperError(error_code); | |
376 if (pp_error != PP_OK) | |
377 callback->Run(pp_error); | |
378 | |
379 info->size = file_info.size; | |
380 if (file_info.is_symbolic_link) | |
381 info->type = PP_FILETYPE_OTHER; | |
382 else if (file_info.is_directory) | |
383 info->type = PP_FILETYPE_DIRECTORY; | |
384 else | |
385 info->type = PP_FILETYPE_REGULAR; | |
386 | |
387 info->system_type = PP_FILESYSTEMTYPE_EXTERNAL; | |
388 info->creation_time = file_info.creation_time.ToDoubleT(); | |
389 info->last_access_time = file_info.last_accessed.ToDoubleT(); | |
390 info->last_modified_time = file_info.last_modified.ToDoubleT(); | |
391 callback->Run(PP_OK); | |
392 } | |
393 | |
296 } // namespace ppapi | 394 } // namespace ppapi |
297 } // namespace webkit | 395 } // namespace webkit |
OLD | NEW |