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

Side by Side Diff: ppapi/proxy/flash_file_resource.cc

Issue 11359097: Refactored the PPB_Flash_File_ModuleLocal/FileRef to the new ppapi resource model (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 1 month 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
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/proxy/flash_file_resource.h"
6
7 #include "ipc/ipc_message.h"
8 #include "ppapi/c/pp_errors.h"
9 #include "ppapi/proxy/ppapi_messages.h"
10 #include "ppapi/shared_impl/file_type_conversion.h"
11 #include "ppapi/shared_impl/time_conversion.h"
12 #include "ppapi/shared_impl/var.h"
13 #include "ppapi/thunk/enter.h"
14
15 namespace ppapi {
16 namespace proxy {
17
18 FlashFileResource::FlashFileResource(Connection connection,
19 PP_Instance instance)
20 : PluginResource(connection, instance) {
21 SendCreate(BROWSER, PpapiHostMsg_FlashFile_Create());
22 }
23
24 FlashFileResource::~FlashFileResource() {
25 }
26
27 thunk::PPB_Flash_File_API* FlashFileResource::AsPPB_Flash_File_API() {
28 return this;
29 }
30
31 int32_t FlashFileResource::OpenFile(PP_Instance instance,
32 const char* path,
33 int32_t mode,
34 PP_FileHandle* file) {
35 return OpenFileHelper(instance, path, PepperFilePath::DOMAIN_MODULE_LOCAL,
36 mode, file);
37 }
38
39 int32_t FlashFileResource::RenameFile(PP_Instance instance,
40 const char* path_from,
41 const char* path_to) {
42 PepperFilePath pepper_from(PepperFilePath::DOMAIN_MODULE_LOCAL,
43 FilePath::FromUTF8Unsafe(path_from));
yzshen1 2012/11/21 00:38:59 nit: explicitly include file_path.h
raymes 2012/11/21 22:44:53 Done.
44 PepperFilePath pepper_to(PepperFilePath::DOMAIN_MODULE_LOCAL,
45 FilePath::FromUTF8Unsafe(path_to));
46
47 int32_t error = SyncCall<IPC::Message>(
48 BROWSER, PpapiHostMsg_FlashFile_RenameFile(pepper_from, pepper_to));
49
50 return error;
51 }
52
53 int32_t FlashFileResource::DeleteFileOrDir(PP_Instance instance,
54 const char* path,
55 PP_Bool recursive) {
56 PepperFilePath pepper_path(PepperFilePath::DOMAIN_MODULE_LOCAL,
57 FilePath::FromUTF8Unsafe(path));
58
59 int32_t error = SyncCall<IPC::Message>(
yzshen1 2012/11/21 00:38:59 wrong indent.
raymes 2012/11/21 22:44:53 Done.
60 BROWSER, PpapiHostMsg_FlashFile_DeleteFileOrDir(pepper_path,
61 PP_ToBool(recursive)));
62
63 return error;
64 }
65
66 int32_t FlashFileResource::CreateDir(PP_Instance instance, const char* path) {
67 PepperFilePath pepper_path(PepperFilePath::DOMAIN_MODULE_LOCAL,
68 FilePath::FromUTF8Unsafe(path));
69
70 int32_t error = SyncCall<IPC::Message>(BROWSER,
71 PpapiHostMsg_FlashFile_CreateDir(pepper_path));
72
73 return error;
74 }
75
76 int32_t FlashFileResource::QueryFile(PP_Instance instance,
77 const char* path,
78 PP_FileInfo* info) {
79 return QueryFileHelper(instance, path, PepperFilePath::DOMAIN_MODULE_LOCAL,
80 info);
81 }
82
83 int32_t FlashFileResource::GetDirContents(PP_Instance instance,
84 const char* path,
85 PP_DirContents_Dev** contents) {
86 ppapi::DirContents entries;
87 PepperFilePath pepper_path(PepperFilePath::DOMAIN_MODULE_LOCAL,
88 FilePath::FromUTF8Unsafe(path));
89
90 int32_t error = SyncCall<PpapiPluginMsg_FlashFile_GetDirContentsReply>(
91 BROWSER, PpapiHostMsg_FlashFile_GetDirContents(pepper_path), &entries);
92
93 if (error == PP_OK) {
94 // Copy the serialized dir entries to the output struct.
95 *contents = new PP_DirContents_Dev;
96 (*contents)->count = static_cast<int32_t>(entries.size());
97 (*contents)->entries = new PP_DirEntry_Dev[entries.size()];
98 for (size_t i = 0; i < entries.size(); i++) {
99 const ppapi::DirEntry& source = entries[i];
100 PP_DirEntry_Dev* dest = &(*contents)->entries[i];
101 std::string name = source.name.AsUTF8Unsafe();
102 char* name_copy = new char[name.size() + 1];
103 memcpy(name_copy, name.c_str(), name.size() + 1);
104 dest->name = name_copy;
105 dest->is_dir = PP_FromBool(source.is_dir);
106 }
107 }
108
109 return error;
110 }
111
112 void FlashFileResource::FreeDirContents(PP_Instance instance,
113 PP_DirContents_Dev* contents) {
114 for (int32_t i = 0; i < contents->count; ++i)
115 delete[] contents->entries[i].name;
116 delete[] contents->entries;
117 delete contents;
118 }
119
120 int32_t FlashFileResource::CreateTemporaryFile(PP_Instance instance,
121 PP_FileHandle* file) {
122 if (!file)
123 return PP_ERROR_BADARGUMENT;
124
125 IPC::Message unused;
126 ResourceMessageReplyParams reply_params;
127 int32_t error = GenericSyncCall(BROWSER,
128 PpapiHostMsg_FlashFile_CreateTemporaryFile(), &unused, &reply_params);
129 if (error != PP_OK)
130 return error;
131
132 IPC::PlatformFileForTransit transit_file;
133 if (!reply_params.TakeFileHandleAtIndex(0, &transit_file))
134 return PP_ERROR_FAILED;
135
136 *file = IPC::PlatformFileForTransitToPlatformFile(transit_file);
137 return PP_OK;
138 }
139
140 int32_t FlashFileResource::OpenFileRef(PP_Instance instance,
141 PP_Resource file_ref,
142 int32_t mode,
143 PP_FileHandle* file) {
144 thunk::EnterResourceNoLock<thunk::PPB_FileRef_API> enter(file_ref, true);
145 if (enter.failed())
146 return PP_ERROR_BADRESOURCE;
147 if (enter.object()->GetFileSystemType() != PP_FILESYSTEMTYPE_EXTERNAL)
148 return PP_ERROR_BADARGUMENT;
149 StringVar* string_var =
150 StringVar::FromPPVar(enter.object()->GetAbsolutePath());
yzshen1 2012/11/21 00:38:59 the PP_Var is leaked.
raymes 2012/11/21 22:44:53 Done.
151 if (!string_var)
152 return PP_ERROR_BADARGUMENT;
153 std::string path = string_var->value();
154
155 return OpenFileHelper(instance, path, PepperFilePath::DOMAIN_ABSOLUTE, mode,
156 file);
157 }
158
159 int32_t FlashFileResource::QueryFileRef(PP_Instance instance,
160 PP_Resource file_ref,
161 PP_FileInfo* info) {
162 thunk::EnterResourceNoLock<thunk::PPB_FileRef_API> enter(file_ref, true);
163 if (enter.failed())
164 return PP_ERROR_BADRESOURCE;
165 if (enter.object()->GetFileSystemType() != PP_FILESYSTEMTYPE_EXTERNAL)
166 return PP_ERROR_BADARGUMENT;
167 StringVar* string_var =
168 StringVar::FromPPVar(enter.object()->GetAbsolutePath());
yzshen1 2012/11/21 00:38:59 - the PP_Var is leaked. - Is it possible the reuse
raymes 2012/11/21 22:44:53 Done.
169 if (!string_var)
170 return PP_ERROR_BADARGUMENT;
171 std::string path = string_var->value();
172
173 return QueryFileHelper(instance, path, PepperFilePath::DOMAIN_ABSOLUTE, info);
174 }
175
176 int32_t FlashFileResource::OpenFileHelper(PP_Instance instance,
yzshen1 2012/11/21 00:38:59 instance is not used.
raymes 2012/11/21 22:44:53 Done.
177 const std::string& path,
178 PepperFilePath::Domain domain_type,
179 int32_t mode,
180 PP_FileHandle* file) {
181 int flags = 0;
182 if (path.empty() ||
183 !ppapi::PepperFileOpenFlagsToPlatformFileFlags(mode, &flags) ||
184 !file)
185 return PP_ERROR_BADARGUMENT;
186
187 PepperFilePath pepper_path(domain_type, FilePath::FromUTF8Unsafe(path));
yzshen1 2012/11/21 00:38:59 [I don't know the answer. Just to make sure you ha
raymes 2012/11/21 22:44:53 If the plugin provides a non-UTF8 string, a best-e
188
189 IPC::Message unused;
190 ResourceMessageReplyParams reply_params;
191 int32_t error = GenericSyncCall(BROWSER,
192 PpapiHostMsg_FlashFile_OpenFile(pepper_path, flags), &unused,
193 &reply_params);
194 if (error != PP_OK)
195 return error;
196
197 IPC::PlatformFileForTransit transit_file;
198 if (!reply_params.TakeFileHandleAtIndex(0, &transit_file))
199 return PP_ERROR_FAILED;
200
201 *file = IPC::PlatformFileForTransitToPlatformFile(transit_file);
202 return PP_OK;
203 }
204
205 int32_t FlashFileResource::QueryFileHelper(PP_Instance instance,
yzshen1 2012/11/21 00:38:59 instance is not used.
raymes 2012/11/21 22:44:53 Done.
206 const std::string& path,
207 PepperFilePath::Domain domain_type,
208 PP_FileInfo* info) {
209 if (path.empty() || !info)
210 return PP_ERROR_BADARGUMENT;
211
212 base::PlatformFileInfo file_info;
213 PepperFilePath pepper_path(domain_type, FilePath::FromUTF8Unsafe(path));
214
215 int32_t error = SyncCall<PpapiPluginMsg_FlashFile_QueryFileReply>(BROWSER,
216 PpapiHostMsg_FlashFile_QueryFile(pepper_path), &file_info);
217
218 if (error == PP_OK) {
219 info->size = file_info.size;
220 info->creation_time = TimeToPPTime(file_info.creation_time);
221 info->last_access_time = TimeToPPTime(file_info.last_accessed);
222 info->last_modified_time = TimeToPPTime(file_info.last_modified);
223 info->system_type = PP_FILESYSTEMTYPE_EXTERNAL;
224 if (file_info.is_directory)
225 info->type = PP_FILETYPE_DIRECTORY;
226 else
227 info->type = PP_FILETYPE_REGULAR;
228 }
229
230 return error;
231 }
232
233 } // namespace proxy
234 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698