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

Side by Side Diff: webkit/glue/plugins/pepper_file_io.cc

Issue 2822031: File API boilerplate. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 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 | « webkit/glue/plugins/pepper_file_io.h ('k') | webkit/glue/plugins/pepper_file_ref.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2010 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 "webkit/glue/plugins/pepper_file_io.h"
6
7 #include "base/logging.h"
8 #include "third_party/ppapi/c/pp_completion_callback.h"
9 #include "third_party/ppapi/c/pp_errors.h"
10 #include "third_party/ppapi/c/ppb_file_io.h"
11 #include "third_party/ppapi/c/ppb_file_io_trusted.h"
12 #include "webkit/glue/plugins/pepper_file_ref.h"
13 #include "webkit/glue/plugins/pepper_plugin_module.h"
14 #include "webkit/glue/plugins/pepper_resource_tracker.h"
15
16 namespace pepper {
17
18 namespace {
19
20 PP_Resource Create(PP_Module module_id) {
21 PluginModule* module = PluginModule::FromPPModule(module_id);
22 if (!module)
23 return 0;
24
25 FileIO* file_io = new FileIO(module);
26 file_io->AddRef(); // AddRef for the caller.
27 return file_io->GetResource();
28 }
29
30 bool IsFileIO(PP_Resource resource) {
31 return !!ResourceTracker::Get()->GetAsFileIO(resource).get();
32 }
33
34 int32_t Open(PP_Resource file_io_id,
35 PP_Resource file_ref_id,
36 int32_t open_flags,
37 PP_CompletionCallback callback) {
38 scoped_refptr<FileIO> file_io(
39 ResourceTracker::Get()->GetAsFileIO(file_io_id));
40 if (!file_io.get())
41 return PP_Error_BadResource;
42
43 scoped_refptr<FileRef> file_ref(
44 ResourceTracker::Get()->GetAsFileRef(file_ref_id));
45 if (!file_ref.get())
46 return PP_Error_BadResource;
47
48 return file_io->Open(file_ref, open_flags, callback);
49 }
50
51 int32_t Query(PP_Resource file_io_id,
52 PP_FileInfo* info,
53 PP_CompletionCallback callback) {
54 scoped_refptr<FileIO> file_io(
55 ResourceTracker::Get()->GetAsFileIO(file_io_id));
56 if (!file_io.get())
57 return PP_Error_BadResource;
58
59 return file_io->Query(info, callback);
60 }
61
62 int32_t Touch(PP_Resource file_io_id,
63 PP_Time last_access_time,
64 PP_Time last_modified_time,
65 PP_CompletionCallback callback) {
66 scoped_refptr<FileIO> file_io(
67 ResourceTracker::Get()->GetAsFileIO(file_io_id));
68 if (!file_io.get())
69 return PP_Error_BadResource;
70
71 return file_io->Touch(last_access_time, last_modified_time, callback);
72 }
73
74 int32_t Read(PP_Resource file_io_id,
75 int64_t offset,
76 char* buffer,
77 int32_t bytes_to_read,
78 PP_CompletionCallback callback) {
79 scoped_refptr<FileIO> file_io(
80 ResourceTracker::Get()->GetAsFileIO(file_io_id));
81 if (!file_io.get())
82 return PP_Error_BadResource;
83
84 return file_io->Read(offset, buffer, bytes_to_read, callback);
85 }
86
87 int32_t Write(PP_Resource file_io_id,
88 int64_t offset,
89 const char* buffer,
90 int32_t bytes_to_write,
91 PP_CompletionCallback callback) {
92 scoped_refptr<FileIO> file_io(
93 ResourceTracker::Get()->GetAsFileIO(file_io_id));
94 if (!file_io.get())
95 return PP_Error_BadResource;
96
97 return file_io->Write(offset, buffer, bytes_to_write, callback);
98 }
99
100 int32_t SetLength(PP_Resource file_io_id,
101 int64_t length,
102 PP_CompletionCallback callback) {
103 scoped_refptr<FileIO> file_io(
104 ResourceTracker::Get()->GetAsFileIO(file_io_id));
105 if (!file_io.get())
106 return PP_Error_BadResource;
107
108 return file_io->SetLength(length, callback);
109 }
110
111 int32_t Flush(PP_Resource file_io_id,
112 PP_CompletionCallback callback) {
113 scoped_refptr<FileIO> file_io(
114 ResourceTracker::Get()->GetAsFileIO(file_io_id));
115 if (!file_io.get())
116 return PP_Error_BadResource;
117
118 return file_io->Flush(callback);
119 }
120
121 void Close(PP_Resource file_io_id) {
122 scoped_refptr<FileIO> file_io(
123 ResourceTracker::Get()->GetAsFileIO(file_io_id));
124 if (!file_io.get())
125 return;
126
127 file_io->Close();
128 }
129
130 const PPB_FileIO ppb_fileio = {
131 &Create,
132 &IsFileIO,
133 &Open,
134 &Query,
135 &Touch,
136 &Read,
137 &Write,
138 &SetLength,
139 &Flush,
140 &Close
141 };
142
143 int32_t GetOSFileDescriptor(PP_Resource file_io_id) {
144 scoped_refptr<FileIO> file_io(
145 ResourceTracker::Get()->GetAsFileIO(file_io_id));
146 if (!file_io.get())
147 return PP_Error_BadResource;
148
149 return file_io->GetOSFileDescriptor();
150 }
151
152 int32_t WillWrite(PP_Resource file_io_id,
153 int64_t offset,
154 int32_t bytes_to_write,
155 PP_CompletionCallback callback) {
156 scoped_refptr<FileIO> file_io(
157 ResourceTracker::Get()->GetAsFileIO(file_io_id));
158 if (!file_io.get())
159 return PP_Error_BadResource;
160
161 return file_io->WillWrite(offset, bytes_to_write, callback);
162 }
163
164 int32_t WillSetLength(PP_Resource file_io_id,
165 int64_t length,
166 PP_CompletionCallback callback) {
167 scoped_refptr<FileIO> file_io(
168 ResourceTracker::Get()->GetAsFileIO(file_io_id));
169 if (!file_io.get())
170 return PP_Error_BadResource;
171
172 return file_io->WillSetLength(length, callback);
173 }
174
175 const PPB_FileIOTrusted ppb_fileiotrusted = {
176 &GetOSFileDescriptor,
177 &WillWrite,
178 &WillSetLength
179 };
180
181 } // namespace
182
183 FileIO::FileIO(PluginModule* module) : Resource(module) {
184 }
185
186 FileIO::~FileIO() {
187 }
188
189 // static
190 const PPB_FileIO* FileIO::GetInterface() {
191 return &ppb_fileio;
192 }
193
194 // static
195 const PPB_FileIOTrusted* FileIO::GetTrustedInterface() {
196 return &ppb_fileiotrusted;
197 }
198
199 int32_t FileIO::Open(FileRef* file_ref,
200 int32_t open_flags,
201 PP_CompletionCallback callback) {
202 NOTIMPLEMENTED(); // TODO(darin): Implement me!
203 return PP_Error_Failed;
204 }
205
206 int32_t FileIO::Query(PP_FileInfo* info,
207 PP_CompletionCallback callback) {
208 NOTIMPLEMENTED(); // TODO(darin): Implement me!
209 return PP_Error_Failed;
210 }
211
212 int32_t FileIO::Touch(PP_Time last_access_time,
213 PP_Time last_modified_time,
214 PP_CompletionCallback callback) {
215 NOTIMPLEMENTED(); // TODO(darin): Implement me!
216 return PP_Error_Failed;
217 }
218
219 int32_t FileIO::Read(int64_t offset,
220 char* buffer,
221 int32_t bytes_to_read,
222 PP_CompletionCallback callback) {
223 NOTIMPLEMENTED(); // TODO(darin): Implement me!
224 return PP_Error_Failed;
225 }
226
227 int32_t FileIO::Write(int64_t offset,
228 const char* buffer,
229 int32_t bytes_to_write,
230 PP_CompletionCallback callback) {
231 NOTIMPLEMENTED(); // TODO(darin): Implement me!
232 return PP_Error_Failed;
233 }
234
235 int32_t FileIO::SetLength(int64_t length,
236 PP_CompletionCallback callback) {
237 NOTIMPLEMENTED(); // TODO(darin): Implement me!
238 return PP_Error_Failed;
239 }
240
241 int32_t FileIO::Flush(PP_CompletionCallback callback) {
242 NOTIMPLEMENTED(); // TODO(darin): Implement me!
243 return PP_Error_Failed;
244 }
245
246 void FileIO::Close() {
247 NOTIMPLEMENTED(); // TODO(darin): Implement me!
248 }
249
250 int32_t FileIO::GetOSFileDescriptor() {
251 NOTIMPLEMENTED(); // TODO(darin): Implement me!
252 return PP_Error_Failed;
253 }
254
255 int32_t FileIO::WillWrite(int64_t offset,
256 int32_t bytes_to_write,
257 PP_CompletionCallback callback) {
258 NOTIMPLEMENTED(); // TODO(darin): Implement me!
259 return PP_Error_Failed;
260 }
261
262 int32_t FileIO::WillSetLength(int64_t length,
263 PP_CompletionCallback callback) {
264 NOTIMPLEMENTED(); // TODO(darin): Implement me!
265 return PP_Error_Failed;
266 }
267
268 } // namespace pepper
OLDNEW
« no previous file with comments | « webkit/glue/plugins/pepper_file_io.h ('k') | webkit/glue/plugins/pepper_file_ref.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698