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( |
| 95 scoped_refptr<base::TaskRunner> task_runner, |
| 96 base::PlatformFile file, |
| 97 PP_FileInfo* info, |
| 98 scoped_refptr<TrackedCallback> callback, |
| 99 base::PlatformFileError error_code, |
| 100 const base::PlatformFileInfo& file_info) { |
| 101 base::FileUtilProxy::Close( |
| 102 task_runner, 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<base::TaskRunner> task_runner, |
| 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 task_runner, file, |
| 141 base::Bind(&GetFileInfoCallback, task_runner, file, info, |
| 142 callback))) { |
| 143 base::FileUtilProxy::Close( |
| 144 task_runner, file, base::Bind(&IgnoreCloseCallback)); |
| 145 callback->Run(PP_ERROR_FAILED); |
| 146 } |
| 147 } |
| 148 |
89 } // namespace | 149 } // namespace |
90 | 150 |
91 PPB_FileRef_Impl::PPB_FileRef_Impl(const PPB_FileRef_CreateInfo& info, | 151 PPB_FileRef_Impl::PPB_FileRef_Impl(const PPB_FileRef_CreateInfo& info, |
92 PPB_FileSystem_Impl* file_system) | 152 PPB_FileSystem_Impl* file_system) |
93 : PPB_FileRef_Shared(::ppapi::OBJECT_IS_IMPL, info), | 153 : PPB_FileRef_Shared(::ppapi::OBJECT_IS_IMPL, info), |
94 file_system_(file_system), | 154 file_system_(file_system), |
95 external_file_system_path_() { | 155 external_file_system_path_() { |
96 } | 156 } |
97 | 157 |
98 PPB_FileRef_Impl::PPB_FileRef_Impl(const PPB_FileRef_CreateInfo& info, | 158 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 | 346 |
287 bool PPB_FileRef_Impl::HasValidFileSystem() const { | 347 bool PPB_FileRef_Impl::HasValidFileSystem() const { |
288 return file_system_ && file_system_->opened(); | 348 return file_system_ && file_system_->opened(); |
289 } | 349 } |
290 | 350 |
291 bool PPB_FileRef_Impl::IsValidNonExternalFileSystem() const { | 351 bool PPB_FileRef_Impl::IsValidNonExternalFileSystem() const { |
292 return file_system_ && file_system_->opened() && | 352 return file_system_ && file_system_->opened() && |
293 file_system_->type() != PP_FILESYSTEMTYPE_EXTERNAL; | 353 file_system_->type() != PP_FILESYSTEMTYPE_EXTERNAL; |
294 } | 354 } |
295 | 355 |
| 356 int32_t PPB_FileRef_Impl::Query(PP_FileInfo* info, |
| 357 scoped_refptr<TrackedCallback> callback) { |
| 358 scoped_refptr<PluginInstance> plugin_instance = |
| 359 ResourceHelper::GetPluginInstance(this); |
| 360 if (!plugin_instance.get()) |
| 361 return PP_ERROR_FAILED; |
| 362 |
| 363 if (!file_system_) { |
| 364 // External file system |
| 365 // We have to do something totally different for external file systems. |
| 366 |
| 367 // TODO(teravest): Use the SequencedWorkerPool instead. |
| 368 scoped_refptr<base::TaskRunner> task_runner = |
| 369 plugin_instance->delegate()->GetFileThreadMessageLoopProxy(); |
| 370 if (!plugin_instance->delegate()->AsyncOpenFile( |
| 371 GetSystemPath(), |
| 372 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ, |
| 373 base::Bind(&QueryCallback, task_runner, info, callback))) |
| 374 return PP_ERROR_FAILED; |
| 375 } else { |
| 376 // Non-external file system |
| 377 if (!HasValidFileSystem()) |
| 378 return PP_ERROR_NOACCESS; |
| 379 |
| 380 if (!plugin_instance->delegate()->Query( |
| 381 GetFileSystemURL(), |
| 382 new FileCallbacks(this, callback, info, file_system_))) |
| 383 return PP_ERROR_FAILED; |
| 384 |
| 385 } |
| 386 return PP_OK_COMPLETIONPENDING; |
| 387 } |
| 388 |
296 } // namespace ppapi | 389 } // namespace ppapi |
297 } // namespace webkit | 390 } // namespace webkit |
OLD | NEW |