Chromium Code Reviews| 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 | |
| 94 void GetFileInfoCallback(scoped_refptr<PluginInstance> plugin_instance, | |
| 95 base::PlatformFile file, | |
| 96 PP_FileInfo* info, | |
| 97 scoped_refptr<TrackedCallback> callback, | |
| 98 base::PlatformFileError error_code, | |
| 99 const base::PlatformFileInfo& file_info) { | |
| 100 base::FileUtilProxy::Close( | |
| 101 plugin_instance->delegate()->GetFileThreadMessageLoopProxy(), | |
| 102 file, base::Bind(&IgnoreCloseCallback)); | |
| 103 | |
| 104 if (!TrackedCallback::IsPending(callback)) | |
| 105 return; | |
| 106 | |
| 107 int32_t pp_error = ::ppapi::PlatformFileErrorToPepperError(error_code); | |
| 108 if (pp_error != PP_OK) | |
| 109 callback->Run(pp_error); | |
| 110 | |
| 111 info->size = file_info.size; | |
| 112 if (file_info.is_symbolic_link) | |
| 113 info->type = PP_FILETYPE_OTHER; | |
| 114 else if (file_info.is_directory) | |
| 115 info->type = PP_FILETYPE_DIRECTORY; | |
| 116 else | |
| 117 info->type = PP_FILETYPE_REGULAR; | |
| 118 | |
| 119 info->system_type = PP_FILESYSTEMTYPE_EXTERNAL; | |
| 120 info->creation_time = file_info.creation_time.ToDoubleT(); | |
| 121 info->last_access_time = file_info.last_accessed.ToDoubleT(); | |
| 122 info->last_modified_time = file_info.last_modified.ToDoubleT(); | |
| 123 callback->Run(PP_OK); | |
| 124 } | |
| 125 | |
| 126 void QueryCallback(scoped_refptr<PluginInstance> plugin_instance, | |
| 127 PP_FileInfo* info, | |
| 128 scoped_refptr<TrackedCallback> callback, | |
| 129 base::PlatformFileError error_code, | |
| 130 base::PassPlatformFile passed_file) { | |
| 131 if (!TrackedCallback::IsPending(callback)) | |
| 132 return; | |
| 133 | |
| 134 int32_t pp_error = ::ppapi::PlatformFileErrorToPepperError(error_code); | |
| 135 if (pp_error != PP_OK) | |
| 136 callback->Run(pp_error); | |
| 137 base::PlatformFile file = passed_file.ReleaseValue(); | |
| 138 | |
| 139 if (!base::FileUtilProxy::GetFileInfoFromPlatformFile( | |
| 140 plugin_instance->delegate()->GetFileThreadMessageLoopProxy(), file, | |
|
dmichael (off chromium)
2013/03/27 20:20:06
nit: 4-space indent
| |
| 141 base::Bind(&GetFileInfoCallback, plugin_instance, file, info, callback))) | |
|
yzshen1
2013/03/27 19:41:22
nit: I think the reply won't be run when it return
| |
| 142 callback->Run(PP_ERROR_FAILED); | |
| 143 } | |
| 144 | |
| 89 } // namespace | 145 } // namespace |
| 90 | 146 |
| 91 PPB_FileRef_Impl::PPB_FileRef_Impl(const PPB_FileRef_CreateInfo& info, | 147 PPB_FileRef_Impl::PPB_FileRef_Impl(const PPB_FileRef_CreateInfo& info, |
| 92 PPB_FileSystem_Impl* file_system) | 148 PPB_FileSystem_Impl* file_system) |
| 93 : PPB_FileRef_Shared(::ppapi::OBJECT_IS_IMPL, info), | 149 : PPB_FileRef_Shared(::ppapi::OBJECT_IS_IMPL, info), |
| 94 file_system_(file_system), | 150 file_system_(file_system), |
| 95 external_file_system_path_() { | 151 external_file_system_path_() { |
| 96 } | 152 } |
| 97 | 153 |
| 98 PPB_FileRef_Impl::PPB_FileRef_Impl(const PPB_FileRef_CreateInfo& info, | 154 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 | 342 |
| 287 bool PPB_FileRef_Impl::HasValidFileSystem() const { | 343 bool PPB_FileRef_Impl::HasValidFileSystem() const { |
| 288 return file_system_ && file_system_->opened(); | 344 return file_system_ && file_system_->opened(); |
| 289 } | 345 } |
| 290 | 346 |
| 291 bool PPB_FileRef_Impl::IsValidNonExternalFileSystem() const { | 347 bool PPB_FileRef_Impl::IsValidNonExternalFileSystem() const { |
| 292 return file_system_ && file_system_->opened() && | 348 return file_system_ && file_system_->opened() && |
| 293 file_system_->type() != PP_FILESYSTEMTYPE_EXTERNAL; | 349 file_system_->type() != PP_FILESYSTEMTYPE_EXTERNAL; |
| 294 } | 350 } |
| 295 | 351 |
| 352 int32_t PPB_FileRef_Impl::Query(PP_FileInfo* info, | |
| 353 scoped_refptr<TrackedCallback> callback) { | |
| 354 scoped_refptr<PluginInstance> plugin_instance = | |
| 355 ResourceHelper::GetPluginInstance(this); | |
| 356 if (!plugin_instance.get()) | |
| 357 return PP_ERROR_FAILED; | |
| 358 | |
| 359 if (!file_system_) { | |
| 360 // External file system | |
| 361 // We have to do something totally different for external file systems. | |
| 362 if (!plugin_instance->delegate()->AsyncOpenFile( | |
| 363 GetSystemPath(), base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ, | |
|
dmichael (off chromium)
2013/03/27 20:20:06
nit: 4-space indent
| |
| 364 base::Bind(&QueryCallback, plugin_instance, info, callback))) | |
|
yzshen1
2013/03/27 19:41:22
PPB_FileRef_Impl itself is ref-counted, maybe hold
dmichael (off chromium)
2013/03/27 20:20:06
+1... those callbacks could just be members, I th
| |
| 365 return PP_ERROR_FAILED; | |
| 366 } else { | |
| 367 // Non-external file system | |
| 368 if (!HasValidFileSystem()) | |
| 369 return PP_ERROR_NOACCESS; | |
| 370 | |
| 371 if (!plugin_instance->delegate()->Query( | |
| 372 GetFileSystemURL(), | |
| 373 new FileCallbacks(this, callback, info, file_system_))) | |
| 374 return PP_ERROR_FAILED; | |
| 375 | |
| 376 } | |
| 377 return PP_OK_COMPLETIONPENDING; | |
| 378 } | |
| 379 | |
| 296 } // namespace ppapi | 380 } // namespace ppapi |
| 297 } // namespace webkit | 381 } // namespace webkit |
| OLD | NEW |