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

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: Take ref on PPB_FileRef_Impl instead of PluginInstance. 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_utils.h ('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..232d0cc5093a6a7b669644ba17668a15f89e354c 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,9 @@ std::string GetNameForVirtualFilePath(const std::string& path) {
return path.substr(pos + 1);
}
+void IgnoreCloseCallback(base::PlatformFileError error_code) {
+}
+
} // namespace
PPB_FileRef_Impl::PPB_FileRef_Impl(const PPB_FileRef_CreateInfo& info,
@@ -293,5 +298,98 @@ 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,
+ base::Bind(&PPB_FileRef_Impl::QueryCallback, this, info, callback)))
+ 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;
+}
+
+void PPB_FileRef_Impl::QueryCallback(PP_FileInfo* info,
+ scoped_refptr<TrackedCallback> callback,
+ base::PlatformFileError error_code,
+ base::PassPlatformFile passed_file) {
+ if (!TrackedCallback::IsPending(callback))
+ return;
dmichael (off chromium) 2013/03/27 22:13:55 Do you need to close passed_file here?
+
+ scoped_refptr<PluginInstance> plugin_instance =
+ ResourceHelper::GetPluginInstance(this);
+ if (!plugin_instance.get())
+ callback->Run(PP_ERROR_FAILED);
dmichael (off chromium) 2013/03/27 22:13:55 I think callback->Abort() is more appropriate here
+
+ 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,
+ base::Bind(&PPB_FileRef_Impl::GetFileInfoCallback, this, file, info,
+ callback))) {
+ base::FileUtilProxy::Close(
+ plugin_instance->delegate()->GetFileThreadMessageLoopProxy(),
+ file, base::Bind(&IgnoreCloseCallback));
+ callback->Run(PP_ERROR_FAILED);
+ }
+}
+
+void PPB_FileRef_Impl::GetFileInfoCallback(
+ base::PlatformFile file,
+ PP_FileInfo* info,
+ scoped_refptr<TrackedCallback> callback,
+ base::PlatformFileError error_code,
+ const base::PlatformFileInfo& file_info) {
+ scoped_refptr<PluginInstance> plugin_instance =
+ ResourceHelper::GetPluginInstance(this);
+ if (plugin_instance.get()) {
dmichael (off chromium) 2013/03/27 22:13:55 nit: You don't need to say ".get()"
+ base::FileUtilProxy::Close(
+ plugin_instance->delegate()->GetFileThreadMessageLoopProxy(),
+ file, base::Bind(&IgnoreCloseCallback));
dmichael (off chromium) 2013/03/27 22:13:55 Hmm, in the rare case that the instance is gone by
+ }
+
+ 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);
+}
+
} // namespace ppapi
} // namespace webkit
« ppapi/tests/test_utils.h ('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