| 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 "ppapi/cpp/private/flash_file.h" | 5 #include "ppapi/cpp/private/flash_file.h" |
| 6 | 6 |
| 7 #include "ppapi/c/pp_bool.h" | 7 #include "ppapi/c/pp_bool.h" |
| 8 #include "ppapi/c/pp_errors.h" | 8 #include "ppapi/c/pp_errors.h" |
| 9 #include "ppapi/cpp/file_ref.h" | 9 #include "ppapi/cpp/file_ref.h" |
| 10 #include "ppapi/cpp/instance_handle.h" | 10 #include "ppapi/cpp/instance_handle.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 } | 21 } |
| 22 | 22 |
| 23 template <> const char* interface_name<PPB_Flash_File_ModuleLocal_2_0>() { | 23 template <> const char* interface_name<PPB_Flash_File_ModuleLocal_2_0>() { |
| 24 return PPB_FLASH_FILE_MODULELOCAL_INTERFACE_2_0; | 24 return PPB_FLASH_FILE_MODULELOCAL_INTERFACE_2_0; |
| 25 } | 25 } |
| 26 | 26 |
| 27 } // namespace | 27 } // namespace |
| 28 | 28 |
| 29 namespace flash { | 29 namespace flash { |
| 30 | 30 |
| 31 static FileModuleLocal::DirEntry ConvertDirEntry(const PP_DirEntry_Dev& entry) { |
| 32 FileModuleLocal::DirEntry rv = { entry.name, PP_ToBool(entry.is_dir) }; |
| 33 return rv; |
| 34 } |
| 35 |
| 31 // static | 36 // static |
| 32 bool FileModuleLocal::IsAvailable() { | 37 bool FileModuleLocal::IsAvailable() { |
| 33 return has_interface<PPB_Flash_File_ModuleLocal_3_0>() || | 38 return has_interface<PPB_Flash_File_ModuleLocal_3_0>() || |
| 34 has_interface<PPB_Flash_File_ModuleLocal_2_0>(); | 39 has_interface<PPB_Flash_File_ModuleLocal_2_0>(); |
| 35 } | 40 } |
| 36 | 41 |
| 37 // static | 42 // static |
| 38 bool FileModuleLocal::CreateThreadAdapterForInstance( | 43 bool FileModuleLocal::CreateThreadAdapterForInstance( |
| 39 const InstanceHandle& instance) { | 44 const InstanceHandle& instance) { |
| 40 bool rv = false; | 45 bool rv = false; |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 result = get_interface<PPB_Flash_File_ModuleLocal_2_0>()-> | 139 result = get_interface<PPB_Flash_File_ModuleLocal_2_0>()-> |
| 135 QueryFile(instance.pp_instance(), path.c_str(), info); | 140 QueryFile(instance.pp_instance(), path.c_str(), info); |
| 136 } | 141 } |
| 137 return result == PP_OK; | 142 return result == PP_OK; |
| 138 } | 143 } |
| 139 | 144 |
| 140 // static | 145 // static |
| 141 bool FileModuleLocal::GetDirContents( | 146 bool FileModuleLocal::GetDirContents( |
| 142 const InstanceHandle& instance, | 147 const InstanceHandle& instance, |
| 143 const std::string& path, | 148 const std::string& path, |
| 144 std::vector<PP_DirEntry_Dev>* dir_contents) { | 149 std::vector<DirEntry>* dir_contents) { |
| 145 dir_contents->clear(); | 150 dir_contents->clear(); |
| 146 | 151 |
| 147 int32_t result = PP_ERROR_FAILED; | 152 int32_t result = PP_ERROR_FAILED; |
| 148 if (has_interface<PPB_Flash_File_ModuleLocal_3_0>()) { | 153 if (has_interface<PPB_Flash_File_ModuleLocal_3_0>()) { |
| 149 PP_DirContents_Dev* contents = NULL; | 154 PP_DirContents_Dev* contents = NULL; |
| 150 result = get_interface<PPB_Flash_File_ModuleLocal_3_0>()-> | 155 result = get_interface<PPB_Flash_File_ModuleLocal_3_0>()-> |
| 151 GetDirContents(instance.pp_instance(), path.c_str(), &contents); | 156 GetDirContents(instance.pp_instance(), path.c_str(), &contents); |
| 152 if (result == PP_OK && contents) { | 157 if (result == PP_OK && contents) { |
| 153 for (int32_t i = 0; i < contents->count; i++) | 158 for (int32_t i = 0; i < contents->count; i++) |
| 154 dir_contents->push_back(contents->entries[i]); | 159 dir_contents->push_back(ConvertDirEntry(contents->entries[i])); |
| 155 } | 160 } |
| 156 if (contents) { | 161 if (contents) { |
| 157 get_interface<PPB_Flash_File_ModuleLocal_3_0>()-> | 162 get_interface<PPB_Flash_File_ModuleLocal_3_0>()-> |
| 158 FreeDirContents(instance.pp_instance(), contents); | 163 FreeDirContents(instance.pp_instance(), contents); |
| 159 } | 164 } |
| 160 } else if (has_interface<PPB_Flash_File_ModuleLocal_2_0>()) { | 165 } else if (has_interface<PPB_Flash_File_ModuleLocal_2_0>()) { |
| 161 PP_DirContents_Dev* contents = NULL; | 166 PP_DirContents_Dev* contents = NULL; |
| 162 result = get_interface<PPB_Flash_File_ModuleLocal_2_0>()-> | 167 result = get_interface<PPB_Flash_File_ModuleLocal_2_0>()-> |
| 163 GetDirContents(instance.pp_instance(), path.c_str(), &contents); | 168 GetDirContents(instance.pp_instance(), path.c_str(), &contents); |
| 164 if (result == PP_OK && contents) { | 169 if (result == PP_OK && contents) { |
| 165 for (int32_t i = 0; i < contents->count; i++) | 170 for (int32_t i = 0; i < contents->count; i++) |
| 166 dir_contents->push_back(contents->entries[i]); | 171 dir_contents->push_back(ConvertDirEntry(contents->entries[i])); |
| 167 } | 172 } |
| 168 if (contents) { | 173 if (contents) { |
| 169 get_interface<PPB_Flash_File_ModuleLocal_2_0>()-> | 174 get_interface<PPB_Flash_File_ModuleLocal_2_0>()-> |
| 170 FreeDirContents(instance.pp_instance(), contents); | 175 FreeDirContents(instance.pp_instance(), contents); |
| 171 } | 176 } |
| 172 } | 177 } |
| 173 return result == PP_OK; | 178 return result == PP_OK; |
| 174 } | 179 } |
| 175 | 180 |
| 176 // static | 181 // static |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 if (has_interface<PPB_Flash_File_FileRef>()) { | 233 if (has_interface<PPB_Flash_File_FileRef>()) { |
| 229 result = get_interface<PPB_Flash_File_FileRef>()-> | 234 result = get_interface<PPB_Flash_File_FileRef>()-> |
| 230 QueryFile(resource.pp_resource(), info); | 235 QueryFile(resource.pp_resource(), info); |
| 231 } | 236 } |
| 232 return result == PP_OK; | 237 return result == PP_OK; |
| 233 } | 238 } |
| 234 | 239 |
| 235 } // namespace flash | 240 } // namespace flash |
| 236 | 241 |
| 237 } // namespace pp | 242 } // namespace pp |
| OLD | NEW |