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

Side by Side 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, 5 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ppapi/cpp/private/flash_file.h ('k') | ppapi/ppapi_sources.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "ppapi/cpp/private/flash_file.h"
6
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"
12
13 namespace pp {
14
15 // FileModuleLocal -------------------------------------------------------------
16
17 namespace {
18
19 template <> const char* interface_name<PPB_Flash_File_ModuleLocal_3_0>() {
20 return PPB_FLASH_FILE_MODULELOCAL_INTERFACE_3_0;
21 }
22
23 template <> const char* interface_name<PPB_Flash_File_ModuleLocal_2_0>() {
24 return PPB_FLASH_FILE_MODULELOCAL_INTERFACE_2_0;
25 }
26
27 } // namespace
28
29 namespace flash {
30
31 // static
32 bool FileModuleLocal::IsAvailable() {
33 return has_interface<PPB_Flash_File_ModuleLocal_3_0>() ||
34 has_interface<PPB_Flash_File_ModuleLocal_2_0>();
35 }
36
37 // static
38 bool FileModuleLocal::CreateThreadAdapterForInstance(
39 const InstanceHandle& instance) {
40 bool rv = false;
41 if (has_interface<PPB_Flash_File_ModuleLocal_3_0>()) {
42 rv = get_interface<PPB_Flash_File_ModuleLocal_3_0>()->
43 CreateThreadAdapterForInstance(instance.pp_instance());
44 } else if (has_interface<PPB_Flash_File_ModuleLocal_2_0>()) {
45 rv = get_interface<PPB_Flash_File_ModuleLocal_2_0>()->
46 CreateThreadAdapterForInstance( instance.pp_instance());
47 }
48 return rv;
49 }
50
51 // static
52 void FileModuleLocal::ClearThreadAdapterForInstance(
53 const InstanceHandle& instance) {
54 if (has_interface<PPB_Flash_File_ModuleLocal_3_0>()) {
55 get_interface<PPB_Flash_File_ModuleLocal_3_0>()->
56 ClearThreadAdapterForInstance(instance.pp_instance());
57 } else if (has_interface<PPB_Flash_File_ModuleLocal_2_0>()) {
58 get_interface<PPB_Flash_File_ModuleLocal_2_0>()->
59 ClearThreadAdapterForInstance(instance.pp_instance());
60 }
61 }
62
63 // static
64 PP_FileHandle FileModuleLocal::OpenFile(const InstanceHandle& instance,
65 const std::string& path,
66 int32_t mode) {
67 PP_FileHandle file_handle = PP_kInvalidFileHandle;
68 int32_t result = PP_ERROR_FAILED;
69 if (has_interface<PPB_Flash_File_ModuleLocal_3_0>()) {
70 result = get_interface<PPB_Flash_File_ModuleLocal_3_0>()->
71 OpenFile(instance.pp_instance(), path.c_str(), mode, &file_handle);
72 } else if (has_interface<PPB_Flash_File_ModuleLocal_2_0>()) {
73 result = get_interface<PPB_Flash_File_ModuleLocal_2_0>()->
74 OpenFile(instance.pp_instance(), path.c_str(), mode, &file_handle);
75 }
76 return (result == PP_OK) ? file_handle : PP_kInvalidFileHandle;
77 }
78
79 // static
80 bool FileModuleLocal::RenameFile(const InstanceHandle& instance,
81 const std::string& path_from,
82 const std::string& path_to) {
83 int32_t result = PP_ERROR_FAILED;
84 if (has_interface<PPB_Flash_File_ModuleLocal_3_0>()) {
85 result = get_interface<PPB_Flash_File_ModuleLocal_3_0>()->
86 RenameFile(instance.pp_instance(), path_from.c_str(), path_to.c_str());
87 } else if (has_interface<PPB_Flash_File_ModuleLocal_2_0>()) {
88 result = get_interface<PPB_Flash_File_ModuleLocal_2_0>()->
89 RenameFile(instance.pp_instance(), path_from.c_str(), path_to.c_str());
90 }
91 return result == PP_OK;
92 }
93
94 // static
95 bool FileModuleLocal::DeleteFileOrDir(const InstanceHandle& instance,
96 const std::string& path,
97 bool recursive) {
98 int32_t result = PP_ERROR_FAILED;
99 if (has_interface<PPB_Flash_File_ModuleLocal_3_0>()) {
100 result = get_interface<PPB_Flash_File_ModuleLocal_3_0>()->
101 DeleteFileOrDir(instance.pp_instance(), path.c_str(),
102 PP_FromBool(recursive));
103 } else if (has_interface<PPB_Flash_File_ModuleLocal_2_0>()) {
104 result = get_interface<PPB_Flash_File_ModuleLocal_2_0>()->
105 DeleteFileOrDir(instance.pp_instance(), path.c_str(),
106 PP_FromBool(recursive));
107 }
108 return result == PP_OK;
109 }
110
111 // static
112 bool FileModuleLocal::CreateDir(const InstanceHandle& instance,
113 const std::string& path) {
114 int32_t result = PP_ERROR_FAILED;
115 if (has_interface<PPB_Flash_File_ModuleLocal_3_0>()) {
116 result = get_interface<PPB_Flash_File_ModuleLocal_3_0>()->
117 CreateDir(instance.pp_instance(), path.c_str());
118 } else if (has_interface<PPB_Flash_File_ModuleLocal_2_0>()) {
119 result = get_interface<PPB_Flash_File_ModuleLocal_2_0>()->
120 CreateDir(instance.pp_instance(), path.c_str());
121 }
122 return result == PP_OK;
123 }
124
125 // static
126 bool FileModuleLocal::QueryFile(const InstanceHandle& instance,
127 const std::string& path,
128 PP_FileInfo* info) {
129 int32_t result = PP_ERROR_FAILED;
130 if (has_interface<PPB_Flash_File_ModuleLocal_3_0>()) {
131 result = get_interface<PPB_Flash_File_ModuleLocal_3_0>()->
132 QueryFile(instance.pp_instance(), path.c_str(), info);
133 } else if (has_interface<PPB_Flash_File_ModuleLocal_2_0>()) {
134 result = get_interface<PPB_Flash_File_ModuleLocal_2_0>()->
135 QueryFile(instance.pp_instance(), path.c_str(), info);
136 }
137 return result == PP_OK;
138 }
139
140 // static
141 bool FileModuleLocal::GetDirContents(
142 const InstanceHandle& instance,
143 const std::string& path,
144 std::vector<PP_DirEntry_Dev>* dir_contents) {
145 dir_contents->clear();
146
147 int32_t result = PP_ERROR_FAILED;
148 if (has_interface<PPB_Flash_File_ModuleLocal_3_0>()) {
149 PP_DirContents_Dev* contents = NULL;
150 result = get_interface<PPB_Flash_File_ModuleLocal_3_0>()->
151 GetDirContents(instance.pp_instance(), path.c_str(), &contents);
152 if (result == PP_OK && contents) {
153 for (int32_t i = 0; i < contents->count; i++)
154 dir_contents->push_back(contents->entries[i]);
155 }
156 if (contents) {
157 get_interface<PPB_Flash_File_ModuleLocal_3_0>()->
158 FreeDirContents(instance.pp_instance(), contents);
159 }
160 } else if (has_interface<PPB_Flash_File_ModuleLocal_2_0>()) {
161 PP_DirContents_Dev* contents = NULL;
162 result = get_interface<PPB_Flash_File_ModuleLocal_2_0>()->
163 GetDirContents(instance.pp_instance(), path.c_str(), &contents);
164 if (result == PP_OK && contents) {
165 for (int32_t i = 0; i < contents->count; i++)
166 dir_contents->push_back(contents->entries[i]);
167 }
168 if (contents) {
169 get_interface<PPB_Flash_File_ModuleLocal_2_0>()->
170 FreeDirContents(instance.pp_instance(), contents);
171 }
172 }
173 return result == PP_OK;
174 }
175
176 // static
177 bool FileModuleLocal::IsCreateTemporaryFileAvailable() {
178 return has_interface<PPB_Flash_File_ModuleLocal_3_0>();
179 }
180
181 // static
182 PP_FileHandle FileModuleLocal::CreateTemporaryFile(
183 const InstanceHandle& instance) {
184 PP_FileHandle file_handle = PP_kInvalidFileHandle;
185 int32_t result = PP_ERROR_FAILED;
186 if (has_interface<PPB_Flash_File_ModuleLocal_3_0>()) {
187 result = get_interface<PPB_Flash_File_ModuleLocal_3_0>()->
188 CreateTemporaryFile(instance.pp_instance(), &file_handle);
189 }
190 return (result == PP_OK) ? file_handle : PP_kInvalidFileHandle;
191 }
192
193 } // namespace flash
194
195 // FileFileRef -----------------------------------------------------------------
196
197 namespace {
198
199 template <> const char* interface_name<PPB_Flash_File_FileRef>() {
200 return PPB_FLASH_FILE_FILEREF_INTERFACE;
201 }
202
203 } // namespace
204
205 namespace flash {
206
207 // static
208 bool FileFileRef::IsAvailable() {
209 return has_interface<PPB_Flash_File_FileRef>();
210 }
211
212 // static
213 PP_FileHandle FileFileRef::OpenFile(const pp::FileRef& resource,
214 int32_t mode) {
215 PP_FileHandle file_handle = PP_kInvalidFileHandle;
216 int32_t result = PP_ERROR_FAILED;
217 if (has_interface<PPB_Flash_File_FileRef>()) {
218 result = get_interface<PPB_Flash_File_FileRef>()->
219 OpenFile(resource.pp_resource(), mode, &file_handle);
220 }
221 return (result == PP_OK) ? file_handle : PP_kInvalidFileHandle;
222 }
223
224 // static
225 bool FileFileRef::QueryFile(const pp::FileRef& resource,
226 PP_FileInfo* info) {
227 int32_t result = PP_ERROR_FAILED;
228 if (has_interface<PPB_Flash_File_FileRef>()) {
229 result = get_interface<PPB_Flash_File_FileRef>()->
230 QueryFile(resource.pp_resource(), info);
231 }
232 return result == PP_OK;
233 }
234
235 } // namespace flash
236
237 } // namespace pp
OLDNEW
« 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