Android NTP: Most visited tile clicks should have PageTransition.AUTO_BOOKMARK
[chromium-blink-merge.git] / ppapi / cpp / private / flash_file.cc
blob7004b985b1a3a99dabd7e40fde89353c3f4ab02c
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
3 // found in the LICENSE file.
5 #include "ppapi/cpp/private/flash_file.h"
7 #include "ppapi/c/pp_bool.h"
8 #include "ppapi/c/pp_errors.h"
9 #include "ppapi/cpp/file_ref.h"
10 #include "ppapi/cpp/instance_handle.h"
11 #include "ppapi/cpp/module_impl.h"
13 namespace pp {
15 // FileModuleLocal -------------------------------------------------------------
17 namespace {
19 template <> const char* interface_name<PPB_Flash_File_ModuleLocal_3_0>() {
20 return PPB_FLASH_FILE_MODULELOCAL_INTERFACE_3_0;
23 } // namespace
25 namespace flash {
27 static FileModuleLocal::DirEntry ConvertDirEntry(const PP_DirEntry_Dev& entry) {
28 FileModuleLocal::DirEntry rv = { entry.name, PP_ToBool(entry.is_dir) };
29 return rv;
32 // static
33 bool FileModuleLocal::IsAvailable() {
34 return has_interface<PPB_Flash_File_ModuleLocal_3_0>();
37 // static
38 PP_FileHandle FileModuleLocal::OpenFile(const InstanceHandle& instance,
39 const std::string& path,
40 int32_t mode) {
41 PP_FileHandle file_handle = PP_kInvalidFileHandle;
42 int32_t result = PP_ERROR_FAILED;
43 if (has_interface<PPB_Flash_File_ModuleLocal_3_0>()) {
44 result = get_interface<PPB_Flash_File_ModuleLocal_3_0>()->
45 OpenFile(instance.pp_instance(), path.c_str(), mode, &file_handle);
47 return (result == PP_OK) ? file_handle : PP_kInvalidFileHandle;
50 // static
51 bool FileModuleLocal::RenameFile(const InstanceHandle& instance,
52 const std::string& path_from,
53 const std::string& path_to) {
54 int32_t result = PP_ERROR_FAILED;
55 if (has_interface<PPB_Flash_File_ModuleLocal_3_0>()) {
56 result = get_interface<PPB_Flash_File_ModuleLocal_3_0>()->
57 RenameFile(instance.pp_instance(), path_from.c_str(), path_to.c_str());
59 return result == PP_OK;
62 // static
63 bool FileModuleLocal::DeleteFileOrDir(const InstanceHandle& instance,
64 const std::string& path,
65 bool recursive) {
66 int32_t result = PP_ERROR_FAILED;
67 if (has_interface<PPB_Flash_File_ModuleLocal_3_0>()) {
68 result = get_interface<PPB_Flash_File_ModuleLocal_3_0>()->
69 DeleteFileOrDir(instance.pp_instance(), path.c_str(),
70 PP_FromBool(recursive));
72 return result == PP_OK;
75 // static
76 bool FileModuleLocal::CreateDir(const InstanceHandle& instance,
77 const std::string& path) {
78 int32_t result = PP_ERROR_FAILED;
79 if (has_interface<PPB_Flash_File_ModuleLocal_3_0>()) {
80 result = get_interface<PPB_Flash_File_ModuleLocal_3_0>()->
81 CreateDir(instance.pp_instance(), path.c_str());
83 return result == PP_OK;
86 // static
87 bool FileModuleLocal::QueryFile(const InstanceHandle& instance,
88 const std::string& path,
89 PP_FileInfo* info) {
90 int32_t result = PP_ERROR_FAILED;
91 if (has_interface<PPB_Flash_File_ModuleLocal_3_0>()) {
92 result = get_interface<PPB_Flash_File_ModuleLocal_3_0>()->
93 QueryFile(instance.pp_instance(), path.c_str(), info);
95 return result == PP_OK;
98 // static
99 bool FileModuleLocal::GetDirContents(
100 const InstanceHandle& instance,
101 const std::string& path,
102 std::vector<DirEntry>* dir_contents) {
103 dir_contents->clear();
105 int32_t result = PP_ERROR_FAILED;
106 if (has_interface<PPB_Flash_File_ModuleLocal_3_0>()) {
107 PP_DirContents_Dev* contents = NULL;
108 result = get_interface<PPB_Flash_File_ModuleLocal_3_0>()->
109 GetDirContents(instance.pp_instance(), path.c_str(), &contents);
110 if (result == PP_OK && contents) {
111 for (int32_t i = 0; i < contents->count; i++)
112 dir_contents->push_back(ConvertDirEntry(contents->entries[i]));
114 if (contents) {
115 get_interface<PPB_Flash_File_ModuleLocal_3_0>()->
116 FreeDirContents(instance.pp_instance(), contents);
119 return result == PP_OK;
122 // static
123 PP_FileHandle FileModuleLocal::CreateTemporaryFile(
124 const InstanceHandle& instance) {
125 PP_FileHandle file_handle = PP_kInvalidFileHandle;
126 int32_t result = PP_ERROR_FAILED;
127 if (has_interface<PPB_Flash_File_ModuleLocal_3_0>()) {
128 result = get_interface<PPB_Flash_File_ModuleLocal_3_0>()->
129 CreateTemporaryFile(instance.pp_instance(), &file_handle);
131 return (result == PP_OK) ? file_handle : PP_kInvalidFileHandle;
134 } // namespace flash
136 // FileFileRef -----------------------------------------------------------------
138 namespace {
140 template <> const char* interface_name<PPB_Flash_File_FileRef>() {
141 return PPB_FLASH_FILE_FILEREF_INTERFACE;
144 } // namespace
146 namespace flash {
148 // static
149 bool FileFileRef::IsAvailable() {
150 return has_interface<PPB_Flash_File_FileRef>();
153 // static
154 PP_FileHandle FileFileRef::OpenFile(const pp::FileRef& resource,
155 int32_t mode) {
156 PP_FileHandle file_handle = PP_kInvalidFileHandle;
157 int32_t result = PP_ERROR_FAILED;
158 if (has_interface<PPB_Flash_File_FileRef>()) {
159 result = get_interface<PPB_Flash_File_FileRef>()->
160 OpenFile(resource.pp_resource(), mode, &file_handle);
162 return (result == PP_OK) ? file_handle : PP_kInvalidFileHandle;
165 // static
166 bool FileFileRef::QueryFile(const pp::FileRef& resource,
167 PP_FileInfo* info) {
168 int32_t result = PP_ERROR_FAILED;
169 if (has_interface<PPB_Flash_File_FileRef>()) {
170 result = get_interface<PPB_Flash_File_FileRef>()->
171 QueryFile(resource.pp_resource(), info);
173 return result == PP_OK;
176 } // namespace flash
178 } // namespace pp