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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 |
89 } // namespace | 91 } // namespace |
90 | 92 |
91 PPB_FileRef_Impl::PPB_FileRef_Impl(const PPB_FileRef_CreateInfo& info, | 93 PPB_FileRef_Impl::PPB_FileRef_Impl(const PPB_FileRef_CreateInfo& info, |
92 PPB_FileSystem_Impl* file_system) | 94 PPB_FileSystem_Impl* file_system) |
93 : PPB_FileRef_Shared(::ppapi::OBJECT_IS_IMPL, info), | 95 : PPB_FileRef_Shared(::ppapi::OBJECT_IS_IMPL, info), |
94 file_system_(file_system), | 96 file_system_(file_system), |
95 external_file_system_path_() { | 97 external_file_system_path_(), |
98 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | |
96 } | 99 } |
97 | 100 |
98 PPB_FileRef_Impl::PPB_FileRef_Impl(const PPB_FileRef_CreateInfo& info, | 101 PPB_FileRef_Impl::PPB_FileRef_Impl(const PPB_FileRef_CreateInfo& info, |
99 const base::FilePath& external_file_path) | 102 const base::FilePath& external_file_path) |
100 : PPB_FileRef_Shared(::ppapi::OBJECT_IS_IMPL, info), | 103 : PPB_FileRef_Shared(::ppapi::OBJECT_IS_IMPL, info), |
101 file_system_(), | 104 file_system_(), |
102 external_file_system_path_(external_file_path) { | 105 external_file_system_path_(external_file_path), |
106 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | |
103 } | 107 } |
104 | 108 |
105 PPB_FileRef_Impl::~PPB_FileRef_Impl() { | 109 PPB_FileRef_Impl::~PPB_FileRef_Impl() { |
106 } | 110 } |
107 | 111 |
108 // static | 112 // static |
109 PPB_FileRef_Impl* PPB_FileRef_Impl::CreateInternal(PP_Resource pp_file_system, | 113 PPB_FileRef_Impl* PPB_FileRef_Impl::CreateInternal(PP_Resource pp_file_system, |
110 const std::string& path) { | 114 const std::string& path) { |
111 EnterResourceNoLock<PPB_FileSystem_API> enter(pp_file_system, true); | 115 EnterResourceNoLock<PPB_FileSystem_API> enter(pp_file_system, true); |
112 if (enter.failed()) | 116 if (enter.failed()) |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
286 | 290 |
287 bool PPB_FileRef_Impl::HasValidFileSystem() const { | 291 bool PPB_FileRef_Impl::HasValidFileSystem() const { |
288 return file_system_ && file_system_->opened(); | 292 return file_system_ && file_system_->opened(); |
289 } | 293 } |
290 | 294 |
291 bool PPB_FileRef_Impl::IsValidNonExternalFileSystem() const { | 295 bool PPB_FileRef_Impl::IsValidNonExternalFileSystem() const { |
292 return file_system_ && file_system_->opened() && | 296 return file_system_ && file_system_->opened() && |
293 file_system_->type() != PP_FILESYSTEMTYPE_EXTERNAL; | 297 file_system_->type() != PP_FILESYSTEMTYPE_EXTERNAL; |
294 } | 298 } |
295 | 299 |
300 int32_t PPB_FileRef_Impl::Query(PP_FileInfo* info, | |
301 scoped_refptr<TrackedCallback> callback) { | |
302 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); | |
303 if (!plugin_instance) | |
304 return PP_ERROR_FAILED; | |
305 | |
306 if (!file_system_) { | |
307 // External filesystem | |
308 // We have to do something totally different for external filesystems. | |
yzshen1
2013/03/26 23:32:42
nit: file systems.
| |
309 if (!plugin_instance->delegate()->AsyncOpenFile( | |
310 GetSystemPath(), base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ, | |
311 base::Bind(&PPB_FileRef_Impl::QueryCallback, | |
312 weak_factory_.GetWeakPtr(), info, callback))) | |
313 return PP_ERROR_FAILED; | |
314 } else { | |
315 // Non-external filesystem | |
yzshen1
2013/03/26 23:32:42
Just out of curiosity: I wonder why we have IsVali
| |
316 if (!HasValidFileSystem()) | |
317 return PP_ERROR_NOACCESS; | |
318 | |
319 if (!plugin_instance->delegate()->Query( | |
320 GetFileSystemURL(), | |
321 new FileCallbacks(this, callback, info, file_system_))) | |
322 return PP_ERROR_FAILED; | |
323 | |
324 } | |
325 return PP_OK_COMPLETIONPENDING; | |
326 } | |
327 | |
328 void PPB_FileRef_Impl::QueryCallback(PP_FileInfo* info, | |
329 scoped_refptr<TrackedCallback> callback, | |
330 base::PlatformFileError error_code, | |
331 base::PassPlatformFile passed_file) { | |
332 int32_t pp_error = ::ppapi::PlatformFileErrorToPepperError(error_code); | |
yzshen1
2013/03/26 23:32:42
Please test that whether |callback| is still pendi
| |
333 if (pp_error != PP_OK) | |
334 callback->Run(pp_error); | |
335 base::PlatformFile file = passed_file.ReleaseValue(); | |
yzshen1
2013/03/26 23:32:42
It seems the file handle is leaked?
(Besides, beca
| |
336 | |
337 PluginInstance* plugin_instance = ResourceHelper::GetPluginInstance(this); | |
338 if (!plugin_instance) | |
339 callback->Run(PP_ERROR_FAILED); | |
340 | |
341 if (!base::FileUtilProxy::GetFileInfoFromPlatformFile( | |
342 plugin_instance->delegate()->GetFileThreadMessageLoopProxy(), file, | |
343 base::Bind(&PPB_FileRef_Impl::GetFileInfoCallback, | |
344 weak_factory_.GetWeakPtr(), info, callback))) | |
345 callback->Run(PP_ERROR_FAILED); | |
346 } | |
347 | |
348 void PPB_FileRef_Impl::GetFileInfoCallback( | |
349 PP_FileInfo* info, | |
350 scoped_refptr<TrackedCallback> callback, | |
351 base::PlatformFileError error_code, | |
352 const base::PlatformFileInfo& file_info) { | |
353 int32_t pp_error = ::ppapi::PlatformFileErrorToPepperError(error_code); | |
yzshen1
2013/03/26 23:32:42
Same here, please test whether |callback| is still
| |
354 if (pp_error != PP_OK) | |
355 callback->Run(pp_error); | |
356 | |
357 info->size = file_info.size; | |
358 if (file_info.is_symbolic_link) | |
359 info->type = PP_FILETYPE_OTHER; | |
360 else if (file_info.is_directory) | |
361 info->type = PP_FILETYPE_DIRECTORY; | |
362 else | |
363 info->type = PP_FILETYPE_REGULAR; | |
364 | |
365 info->system_type = PP_FILESYSTEMTYPE_EXTERNAL; | |
366 info->creation_time = file_info.creation_time.ToDoubleT(); | |
367 info->last_access_time = file_info.last_accessed.ToDoubleT(); | |
368 info->last_modified_time = file_info.last_modified.ToDoubleT(); | |
369 callback->Run(PP_OK); | |
370 } | |
371 | |
372 | |
296 } // namespace ppapi | 373 } // namespace ppapi |
297 } // namespace webkit | 374 } // namespace webkit |
OLD | NEW |