Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(393)

Unified Diff: webkit/plugins/ppapi/ppb_file_ref_impl.cc

Issue 12817009: Add Query() support to FileRef (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Don't leak file handles, fix nits Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« ppapi/tests/test_file_ref.cc ('K') | « webkit/plugins/ppapi/ppb_file_ref_impl.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/plugins/ppapi/ppb_file_ref_impl.cc
diff --git a/webkit/plugins/ppapi/ppb_file_ref_impl.cc b/webkit/plugins/ppapi/ppb_file_ref_impl.cc
index aacc016a8860384b75056349f637a36ab5d0187d..dc808b3a0dfcfd34e834a5846793e05755bcf3cc 100644
--- a/webkit/plugins/ppapi/ppb_file_ref_impl.cc
+++ b/webkit/plugins/ppapi/ppb_file_ref_impl.cc
@@ -4,15 +4,17 @@
#include "webkit/plugins/ppapi/ppb_file_ref_impl.h"
+#include "base/platform_file.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
#include "googleurl/src/gurl.h"
#include "net/base/escape.h"
#include "ppapi/c/pp_errors.h"
-#include "ppapi/thunk/enter.h"
-#include "ppapi/thunk/ppb_file_system_api.h"
+#include "ppapi/shared_impl/file_type_conversion.h"
#include "ppapi/shared_impl/time_conversion.h"
#include "ppapi/shared_impl/var.h"
+#include "ppapi/thunk/enter.h"
+#include "ppapi/thunk/ppb_file_system_api.h"
#include "webkit/plugins/ppapi/common.h"
#include "webkit/plugins/ppapi/file_callbacks.h"
#include "webkit/plugins/ppapi/plugin_delegate.h"
@@ -86,6 +88,60 @@ std::string GetNameForVirtualFilePath(const std::string& path) {
return path.substr(pos + 1);
}
+void IgnoreCloseCallback(base::PlatformFileError error_code) {
+}
+
+void GetFileInfoCallback(scoped_refptr<PluginInstance> plugin_instance,
+ base::PlatformFile file,
+ PP_FileInfo* info,
+ scoped_refptr<TrackedCallback> callback,
+ base::PlatformFileError error_code,
+ const base::PlatformFileInfo& file_info) {
+ base::FileUtilProxy::Close(
+ plugin_instance->delegate()->GetFileThreadMessageLoopProxy(),
+ file, base::Bind(&IgnoreCloseCallback));
+
+ if (!TrackedCallback::IsPending(callback))
+ return;
+
+ int32_t pp_error = ::ppapi::PlatformFileErrorToPepperError(error_code);
+ if (pp_error != PP_OK)
+ callback->Run(pp_error);
+
+ info->size = file_info.size;
+ if (file_info.is_symbolic_link)
+ info->type = PP_FILETYPE_OTHER;
+ else if (file_info.is_directory)
+ info->type = PP_FILETYPE_DIRECTORY;
+ else
+ info->type = PP_FILETYPE_REGULAR;
+
+ info->system_type = PP_FILESYSTEMTYPE_EXTERNAL;
+ info->creation_time = file_info.creation_time.ToDoubleT();
+ info->last_access_time = file_info.last_accessed.ToDoubleT();
+ info->last_modified_time = file_info.last_modified.ToDoubleT();
+ callback->Run(PP_OK);
+}
+
+void QueryCallback(scoped_refptr<PluginInstance> plugin_instance,
+ PP_FileInfo* info,
+ scoped_refptr<TrackedCallback> callback,
+ base::PlatformFileError error_code,
+ base::PassPlatformFile passed_file) {
+ if (!TrackedCallback::IsPending(callback))
+ return;
+
+ int32_t pp_error = ::ppapi::PlatformFileErrorToPepperError(error_code);
+ if (pp_error != PP_OK)
+ callback->Run(pp_error);
+ base::PlatformFile file = passed_file.ReleaseValue();
+
+ if (!base::FileUtilProxy::GetFileInfoFromPlatformFile(
+ plugin_instance->delegate()->GetFileThreadMessageLoopProxy(), file,
dmichael (off chromium) 2013/03/27 20:20:06 nit: 4-space indent
+ 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
+ callback->Run(PP_ERROR_FAILED);
+}
+
} // namespace
PPB_FileRef_Impl::PPB_FileRef_Impl(const PPB_FileRef_CreateInfo& info,
@@ -293,5 +349,33 @@ bool PPB_FileRef_Impl::IsValidNonExternalFileSystem() const {
file_system_->type() != PP_FILESYSTEMTYPE_EXTERNAL;
}
+int32_t PPB_FileRef_Impl::Query(PP_FileInfo* info,
+ scoped_refptr<TrackedCallback> callback) {
+ scoped_refptr<PluginInstance> plugin_instance =
+ ResourceHelper::GetPluginInstance(this);
+ if (!plugin_instance.get())
+ return PP_ERROR_FAILED;
+
+ if (!file_system_) {
+ // External file system
+ // We have to do something totally different for external file systems.
+ if (!plugin_instance->delegate()->AsyncOpenFile(
+ GetSystemPath(), base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ,
dmichael (off chromium) 2013/03/27 20:20:06 nit: 4-space indent
+ 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
+ return PP_ERROR_FAILED;
+ } else {
+ // Non-external file system
+ if (!HasValidFileSystem())
+ return PP_ERROR_NOACCESS;
+
+ if (!plugin_instance->delegate()->Query(
+ GetFileSystemURL(),
+ new FileCallbacks(this, callback, info, file_system_)))
+ return PP_ERROR_FAILED;
+
+ }
+ return PP_OK_COMPLETIONPENDING;
+}
+
} // namespace ppapi
} // namespace webkit
« ppapi/tests/test_file_ref.cc ('K') | « webkit/plugins/ppapi/ppb_file_ref_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698