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

Unified Diff: ppapi/cpp/private/flash_file.cc

Issue 10638007: Pepper Flash: Add trivial C++ wrappers for PPB_Flash_File_{ModuleLocal,FileRef}. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ffffuuuuuuuuuuuuuuuuuuuuuuuuuuu Created 8 years, 6 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
« no previous file with comments | « ppapi/cpp/private/flash_file.h ('k') | ppapi/ppapi_sources.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ppapi/cpp/private/flash_file.cc
diff --git a/ppapi/cpp/private/flash_file.cc b/ppapi/cpp/private/flash_file.cc
new file mode 100644
index 0000000000000000000000000000000000000000..0f0ee077ee2dd7b3bbd95c96ac3a7ae524f3d5bb
--- /dev/null
+++ b/ppapi/cpp/private/flash_file.cc
@@ -0,0 +1,237 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ppapi/cpp/private/flash_file.h"
+
+#include "ppapi/c/pp_bool.h"
+#include "ppapi/c/pp_errors.h"
+#include "ppapi/cpp/file_ref.h"
+#include "ppapi/cpp/instance_handle.h"
+#include "ppapi/cpp/module_impl.h"
+
+namespace pp {
+
+// FileModuleLocal -------------------------------------------------------------
+
+namespace {
+
+template <> const char* interface_name<PPB_Flash_File_ModuleLocal_3_0>() {
+ return PPB_FLASH_FILE_MODULELOCAL_INTERFACE_3_0;
+}
+
+template <> const char* interface_name<PPB_Flash_File_ModuleLocal_2_0>() {
+ return PPB_FLASH_FILE_MODULELOCAL_INTERFACE_2_0;
+}
+
+} // namespace
+
+namespace flash {
+
+// static
+bool FileModuleLocal::IsAvailable() {
+ return has_interface<PPB_Flash_File_ModuleLocal_3_0>() ||
+ has_interface<PPB_Flash_File_ModuleLocal_2_0>();
+}
+
+// static
+bool FileModuleLocal::CreateThreadAdapterForInstance(
+ const InstanceHandle& instance) {
+ bool rv = false;
+ if (has_interface<PPB_Flash_File_ModuleLocal_3_0>()) {
+ rv = get_interface<PPB_Flash_File_ModuleLocal_3_0>()->
+ CreateThreadAdapterForInstance(instance.pp_instance());
+ } else if (has_interface<PPB_Flash_File_ModuleLocal_2_0>()) {
+ rv = get_interface<PPB_Flash_File_ModuleLocal_2_0>()->
+ CreateThreadAdapterForInstance( instance.pp_instance());
+ }
+ return rv;
+}
+
+// static
+void FileModuleLocal::ClearThreadAdapterForInstance(
+ const InstanceHandle& instance) {
+ if (has_interface<PPB_Flash_File_ModuleLocal_3_0>()) {
+ get_interface<PPB_Flash_File_ModuleLocal_3_0>()->
+ ClearThreadAdapterForInstance(instance.pp_instance());
+ } else if (has_interface<PPB_Flash_File_ModuleLocal_2_0>()) {
+ get_interface<PPB_Flash_File_ModuleLocal_2_0>()->
+ ClearThreadAdapterForInstance(instance.pp_instance());
+ }
+}
+
+// static
+PP_FileHandle FileModuleLocal::OpenFile(const InstanceHandle& instance,
+ const std::string& path,
+ int32_t mode) {
+ PP_FileHandle file_handle = PP_kInvalidFileHandle;
+ int32_t result = PP_ERROR_FAILED;
+ if (has_interface<PPB_Flash_File_ModuleLocal_3_0>()) {
+ result = get_interface<PPB_Flash_File_ModuleLocal_3_0>()->
+ OpenFile(instance.pp_instance(), path.c_str(), mode, &file_handle);
+ } else if (has_interface<PPB_Flash_File_ModuleLocal_2_0>()) {
+ result = get_interface<PPB_Flash_File_ModuleLocal_2_0>()->
+ OpenFile(instance.pp_instance(), path.c_str(), mode, &file_handle);
+ }
+ return (result == PP_OK) ? file_handle : PP_kInvalidFileHandle;
+}
+
+// static
+bool FileModuleLocal::RenameFile(const InstanceHandle& instance,
+ const std::string& path_from,
+ const std::string& path_to) {
+ int32_t result = PP_ERROR_FAILED;
+ if (has_interface<PPB_Flash_File_ModuleLocal_3_0>()) {
+ result = get_interface<PPB_Flash_File_ModuleLocal_3_0>()->
+ RenameFile(instance.pp_instance(), path_from.c_str(), path_to.c_str());
+ } else if (has_interface<PPB_Flash_File_ModuleLocal_2_0>()) {
+ result = get_interface<PPB_Flash_File_ModuleLocal_2_0>()->
+ RenameFile(instance.pp_instance(), path_from.c_str(), path_to.c_str());
+ }
+ return result == PP_OK;
+}
+
+// static
+bool FileModuleLocal::DeleteFileOrDir(const InstanceHandle& instance,
+ const std::string& path,
+ bool recursive) {
+ int32_t result = PP_ERROR_FAILED;
+ if (has_interface<PPB_Flash_File_ModuleLocal_3_0>()) {
+ result = get_interface<PPB_Flash_File_ModuleLocal_3_0>()->
+ DeleteFileOrDir(instance.pp_instance(), path.c_str(),
+ PP_FromBool(recursive));
+ } else if (has_interface<PPB_Flash_File_ModuleLocal_2_0>()) {
+ result = get_interface<PPB_Flash_File_ModuleLocal_2_0>()->
+ DeleteFileOrDir(instance.pp_instance(), path.c_str(),
+ PP_FromBool(recursive));
+ }
+ return result == PP_OK;
+}
+
+// static
+bool FileModuleLocal::CreateDir(const InstanceHandle& instance,
+ const std::string& path) {
+ int32_t result = PP_ERROR_FAILED;
+ if (has_interface<PPB_Flash_File_ModuleLocal_3_0>()) {
+ result = get_interface<PPB_Flash_File_ModuleLocal_3_0>()->
+ CreateDir(instance.pp_instance(), path.c_str());
+ } else if (has_interface<PPB_Flash_File_ModuleLocal_2_0>()) {
+ result = get_interface<PPB_Flash_File_ModuleLocal_2_0>()->
+ CreateDir(instance.pp_instance(), path.c_str());
+ }
+ return result == PP_OK;
+}
+
+// static
+bool FileModuleLocal::QueryFile(const InstanceHandle& instance,
+ const std::string& path,
+ PP_FileInfo* info) {
+ int32_t result = PP_ERROR_FAILED;
+ if (has_interface<PPB_Flash_File_ModuleLocal_3_0>()) {
+ result = get_interface<PPB_Flash_File_ModuleLocal_3_0>()->
+ QueryFile(instance.pp_instance(), path.c_str(), info);
+ } else if (has_interface<PPB_Flash_File_ModuleLocal_2_0>()) {
+ result = get_interface<PPB_Flash_File_ModuleLocal_2_0>()->
+ QueryFile(instance.pp_instance(), path.c_str(), info);
+ }
+ return result == PP_OK;
+}
+
+// static
+bool FileModuleLocal::GetDirContents(
+ const InstanceHandle& instance,
+ const std::string& path,
+ std::vector<PP_DirEntry_Dev>* dir_contents) {
+ dir_contents->clear();
+
+ int32_t result = PP_ERROR_FAILED;
+ if (has_interface<PPB_Flash_File_ModuleLocal_3_0>()) {
+ PP_DirContents_Dev* contents = NULL;
+ result = get_interface<PPB_Flash_File_ModuleLocal_3_0>()->
+ GetDirContents(instance.pp_instance(), path.c_str(), &contents);
+ if (result == PP_OK && contents) {
+ for (int32_t i = 0; i < contents->count; i++)
+ dir_contents->push_back(contents->entries[i]);
+ }
+ if (contents) {
+ get_interface<PPB_Flash_File_ModuleLocal_3_0>()->
+ FreeDirContents(instance.pp_instance(), contents);
+ }
+ } else if (has_interface<PPB_Flash_File_ModuleLocal_2_0>()) {
+ PP_DirContents_Dev* contents = NULL;
+ result = get_interface<PPB_Flash_File_ModuleLocal_2_0>()->
+ GetDirContents(instance.pp_instance(), path.c_str(), &contents);
+ if (result == PP_OK && contents) {
+ for (int32_t i = 0; i < contents->count; i++)
+ dir_contents->push_back(contents->entries[i]);
+ }
+ if (contents) {
+ get_interface<PPB_Flash_File_ModuleLocal_2_0>()->
+ FreeDirContents(instance.pp_instance(), contents);
+ }
+ }
+ return result == PP_OK;
+}
+
+// static
+bool FileModuleLocal::IsCreateTemporaryFileAvailable() {
+ return has_interface<PPB_Flash_File_ModuleLocal_3_0>();
+}
+
+// static
+PP_FileHandle FileModuleLocal::CreateTemporaryFile(
+ const InstanceHandle& instance) {
+ PP_FileHandle file_handle = PP_kInvalidFileHandle;
+ int32_t result = PP_ERROR_FAILED;
+ if (has_interface<PPB_Flash_File_ModuleLocal_3_0>()) {
+ result = get_interface<PPB_Flash_File_ModuleLocal_3_0>()->
+ CreateTemporaryFile(instance.pp_instance(), &file_handle);
+ }
+ return (result == PP_OK) ? file_handle : PP_kInvalidFileHandle;
+}
+
+} // namespace flash
+
+// FileFileRef -----------------------------------------------------------------
+
+namespace {
+
+template <> const char* interface_name<PPB_Flash_File_FileRef>() {
+ return PPB_FLASH_FILE_FILEREF_INTERFACE;
+}
+
+} // namespace
+
+namespace flash {
+
+// static
+bool FileFileRef::IsAvailable() {
+ return has_interface<PPB_Flash_File_FileRef>();
+}
+
+// static
+PP_FileHandle FileFileRef::OpenFile(const pp::FileRef& resource,
+ int32_t mode) {
+ PP_FileHandle file_handle = PP_kInvalidFileHandle;
+ int32_t result = PP_ERROR_FAILED;
+ if (has_interface<PPB_Flash_File_FileRef>()) {
+ result = get_interface<PPB_Flash_File_FileRef>()->
+ OpenFile(resource.pp_resource(), mode, &file_handle);
+ }
+ return (result == PP_OK) ? file_handle : PP_kInvalidFileHandle;
+}
+
+// static
+bool FileFileRef::QueryFile(const pp::FileRef& resource,
+ PP_FileInfo* info) {
+ int32_t result = PP_ERROR_FAILED;
+ if (has_interface<PPB_Flash_File_FileRef>()) {
+ result = get_interface<PPB_Flash_File_FileRef>()->
+ QueryFile(resource.pp_resource(), info);
+ }
+ return result == PP_OK;
+}
+
+} // namespace flash
+
+} // namespace pp
« no previous file with comments | « ppapi/cpp/private/flash_file.h ('k') | ppapi/ppapi_sources.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698