OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 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 "webkit/glue/plugins/pepper_file_io.h" | 5 #include "webkit/glue/plugins/pepper_file_io.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "third_party/ppapi/c/pp_completion_callback.h" | 8 #include "third_party/ppapi/c/pp_completion_callback.h" |
9 #include "third_party/ppapi/c/pp_errors.h" | 9 #include "third_party/ppapi/c/pp_errors.h" |
10 #include "third_party/ppapi/c/ppb_file_io.h" | 10 #include "third_party/ppapi/c/ppb_file_io.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 bool IsFileIO(PP_Resource resource) { | 30 bool IsFileIO(PP_Resource resource) { |
31 return !!Resource::GetAs<FileIO>(resource).get(); | 31 return !!Resource::GetAs<FileIO>(resource).get(); |
32 } | 32 } |
33 | 33 |
34 int32_t Open(PP_Resource file_io_id, | 34 int32_t Open(PP_Resource file_io_id, |
35 PP_Resource file_ref_id, | 35 PP_Resource file_ref_id, |
36 int32_t open_flags, | 36 int32_t open_flags, |
37 PP_CompletionCallback callback) { | 37 PP_CompletionCallback callback) { |
38 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); | 38 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); |
39 if (!file_io.get()) | 39 if (!file_io.get()) |
40 return PP_Error_BadResource; | 40 return PP_ERROR_BADRESOURCE; |
41 | 41 |
42 scoped_refptr<FileRef> file_ref(Resource::GetAs<FileRef>(file_ref_id)); | 42 scoped_refptr<FileRef> file_ref(Resource::GetAs<FileRef>(file_ref_id)); |
43 if (!file_ref.get()) | 43 if (!file_ref.get()) |
44 return PP_Error_BadResource; | 44 return PP_ERROR_BADRESOURCE; |
45 | 45 |
46 return file_io->Open(file_ref, open_flags, callback); | 46 return file_io->Open(file_ref, open_flags, callback); |
47 } | 47 } |
48 | 48 |
49 int32_t Query(PP_Resource file_io_id, | 49 int32_t Query(PP_Resource file_io_id, |
50 PP_FileInfo* info, | 50 PP_FileInfo* info, |
51 PP_CompletionCallback callback) { | 51 PP_CompletionCallback callback) { |
52 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); | 52 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); |
53 if (!file_io.get()) | 53 if (!file_io.get()) |
54 return PP_Error_BadResource; | 54 return PP_ERROR_BADRESOURCE; |
55 | 55 |
56 return file_io->Query(info, callback); | 56 return file_io->Query(info, callback); |
57 } | 57 } |
58 | 58 |
59 int32_t Touch(PP_Resource file_io_id, | 59 int32_t Touch(PP_Resource file_io_id, |
60 PP_Time last_access_time, | 60 PP_Time last_access_time, |
61 PP_Time last_modified_time, | 61 PP_Time last_modified_time, |
62 PP_CompletionCallback callback) { | 62 PP_CompletionCallback callback) { |
63 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); | 63 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); |
64 if (!file_io.get()) | 64 if (!file_io.get()) |
65 return PP_Error_BadResource; | 65 return PP_ERROR_BADRESOURCE; |
66 | 66 |
67 return file_io->Touch(last_access_time, last_modified_time, callback); | 67 return file_io->Touch(last_access_time, last_modified_time, callback); |
68 } | 68 } |
69 | 69 |
70 int32_t Read(PP_Resource file_io_id, | 70 int32_t Read(PP_Resource file_io_id, |
71 int64_t offset, | 71 int64_t offset, |
72 char* buffer, | 72 char* buffer, |
73 int32_t bytes_to_read, | 73 int32_t bytes_to_read, |
74 PP_CompletionCallback callback) { | 74 PP_CompletionCallback callback) { |
75 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); | 75 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); |
76 if (!file_io.get()) | 76 if (!file_io.get()) |
77 return PP_Error_BadResource; | 77 return PP_ERROR_BADRESOURCE; |
78 | 78 |
79 return file_io->Read(offset, buffer, bytes_to_read, callback); | 79 return file_io->Read(offset, buffer, bytes_to_read, callback); |
80 } | 80 } |
81 | 81 |
82 int32_t Write(PP_Resource file_io_id, | 82 int32_t Write(PP_Resource file_io_id, |
83 int64_t offset, | 83 int64_t offset, |
84 const char* buffer, | 84 const char* buffer, |
85 int32_t bytes_to_write, | 85 int32_t bytes_to_write, |
86 PP_CompletionCallback callback) { | 86 PP_CompletionCallback callback) { |
87 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); | 87 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); |
88 if (!file_io.get()) | 88 if (!file_io.get()) |
89 return PP_Error_BadResource; | 89 return PP_ERROR_BADRESOURCE; |
90 | 90 |
91 return file_io->Write(offset, buffer, bytes_to_write, callback); | 91 return file_io->Write(offset, buffer, bytes_to_write, callback); |
92 } | 92 } |
93 | 93 |
94 int32_t SetLength(PP_Resource file_io_id, | 94 int32_t SetLength(PP_Resource file_io_id, |
95 int64_t length, | 95 int64_t length, |
96 PP_CompletionCallback callback) { | 96 PP_CompletionCallback callback) { |
97 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); | 97 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); |
98 if (!file_io.get()) | 98 if (!file_io.get()) |
99 return PP_Error_BadResource; | 99 return PP_ERROR_BADRESOURCE; |
100 | 100 |
101 return file_io->SetLength(length, callback); | 101 return file_io->SetLength(length, callback); |
102 } | 102 } |
103 | 103 |
104 int32_t Flush(PP_Resource file_io_id, | 104 int32_t Flush(PP_Resource file_io_id, |
105 PP_CompletionCallback callback) { | 105 PP_CompletionCallback callback) { |
106 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); | 106 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); |
107 if (!file_io.get()) | 107 if (!file_io.get()) |
108 return PP_Error_BadResource; | 108 return PP_ERROR_BADRESOURCE; |
109 | 109 |
110 return file_io->Flush(callback); | 110 return file_io->Flush(callback); |
111 } | 111 } |
112 | 112 |
113 void Close(PP_Resource file_io_id) { | 113 void Close(PP_Resource file_io_id) { |
114 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); | 114 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); |
115 if (!file_io.get()) | 115 if (!file_io.get()) |
116 return; | 116 return; |
117 | 117 |
118 file_io->Close(); | 118 file_io->Close(); |
119 } | 119 } |
120 | 120 |
121 const PPB_FileIO ppb_fileio = { | 121 const PPB_FileIO ppb_fileio = { |
122 &Create, | 122 &Create, |
123 &IsFileIO, | 123 &IsFileIO, |
124 &Open, | 124 &Open, |
125 &Query, | 125 &Query, |
126 &Touch, | 126 &Touch, |
127 &Read, | 127 &Read, |
128 &Write, | 128 &Write, |
129 &SetLength, | 129 &SetLength, |
130 &Flush, | 130 &Flush, |
131 &Close | 131 &Close |
132 }; | 132 }; |
133 | 133 |
134 int32_t GetOSFileDescriptor(PP_Resource file_io_id) { | 134 int32_t GetOSFileDescriptor(PP_Resource file_io_id) { |
135 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); | 135 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); |
136 if (!file_io.get()) | 136 if (!file_io.get()) |
137 return PP_Error_BadResource; | 137 return PP_ERROR_BADRESOURCE; |
138 | 138 |
139 return file_io->GetOSFileDescriptor(); | 139 return file_io->GetOSFileDescriptor(); |
140 } | 140 } |
141 | 141 |
142 int32_t WillWrite(PP_Resource file_io_id, | 142 int32_t WillWrite(PP_Resource file_io_id, |
143 int64_t offset, | 143 int64_t offset, |
144 int32_t bytes_to_write, | 144 int32_t bytes_to_write, |
145 PP_CompletionCallback callback) { | 145 PP_CompletionCallback callback) { |
146 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); | 146 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); |
147 if (!file_io.get()) | 147 if (!file_io.get()) |
148 return PP_Error_BadResource; | 148 return PP_ERROR_BADRESOURCE; |
149 | 149 |
150 return file_io->WillWrite(offset, bytes_to_write, callback); | 150 return file_io->WillWrite(offset, bytes_to_write, callback); |
151 } | 151 } |
152 | 152 |
153 int32_t WillSetLength(PP_Resource file_io_id, | 153 int32_t WillSetLength(PP_Resource file_io_id, |
154 int64_t length, | 154 int64_t length, |
155 PP_CompletionCallback callback) { | 155 PP_CompletionCallback callback) { |
156 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); | 156 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); |
157 if (!file_io.get()) | 157 if (!file_io.get()) |
158 return PP_Error_BadResource; | 158 return PP_ERROR_BADRESOURCE; |
159 | 159 |
160 return file_io->WillSetLength(length, callback); | 160 return file_io->WillSetLength(length, callback); |
161 } | 161 } |
162 | 162 |
163 const PPB_FileIOTrusted ppb_fileiotrusted = { | 163 const PPB_FileIOTrusted ppb_fileiotrusted = { |
164 &GetOSFileDescriptor, | 164 &GetOSFileDescriptor, |
165 &WillWrite, | 165 &WillWrite, |
166 &WillSetLength | 166 &WillSetLength |
167 }; | 167 }; |
168 | 168 |
(...skipping 12 matching lines...) Expand all Loading... |
181 | 181 |
182 // static | 182 // static |
183 const PPB_FileIOTrusted* FileIO::GetTrustedInterface() { | 183 const PPB_FileIOTrusted* FileIO::GetTrustedInterface() { |
184 return &ppb_fileiotrusted; | 184 return &ppb_fileiotrusted; |
185 } | 185 } |
186 | 186 |
187 int32_t FileIO::Open(FileRef* file_ref, | 187 int32_t FileIO::Open(FileRef* file_ref, |
188 int32_t open_flags, | 188 int32_t open_flags, |
189 PP_CompletionCallback callback) { | 189 PP_CompletionCallback callback) { |
190 NOTIMPLEMENTED(); // TODO(darin): Implement me! | 190 NOTIMPLEMENTED(); // TODO(darin): Implement me! |
191 return PP_Error_Failed; | 191 return PP_ERROR_FAILED; |
192 } | 192 } |
193 | 193 |
194 int32_t FileIO::Query(PP_FileInfo* info, | 194 int32_t FileIO::Query(PP_FileInfo* info, |
195 PP_CompletionCallback callback) { | 195 PP_CompletionCallback callback) { |
196 NOTIMPLEMENTED(); // TODO(darin): Implement me! | 196 NOTIMPLEMENTED(); // TODO(darin): Implement me! |
197 return PP_Error_Failed; | 197 return PP_ERROR_FAILED; |
198 } | 198 } |
199 | 199 |
200 int32_t FileIO::Touch(PP_Time last_access_time, | 200 int32_t FileIO::Touch(PP_Time last_access_time, |
201 PP_Time last_modified_time, | 201 PP_Time last_modified_time, |
202 PP_CompletionCallback callback) { | 202 PP_CompletionCallback callback) { |
203 NOTIMPLEMENTED(); // TODO(darin): Implement me! | 203 NOTIMPLEMENTED(); // TODO(darin): Implement me! |
204 return PP_Error_Failed; | 204 return PP_ERROR_FAILED; |
205 } | 205 } |
206 | 206 |
207 int32_t FileIO::Read(int64_t offset, | 207 int32_t FileIO::Read(int64_t offset, |
208 char* buffer, | 208 char* buffer, |
209 int32_t bytes_to_read, | 209 int32_t bytes_to_read, |
210 PP_CompletionCallback callback) { | 210 PP_CompletionCallback callback) { |
211 NOTIMPLEMENTED(); // TODO(darin): Implement me! | 211 NOTIMPLEMENTED(); // TODO(darin): Implement me! |
212 return PP_Error_Failed; | 212 return PP_ERROR_FAILED; |
213 } | 213 } |
214 | 214 |
215 int32_t FileIO::Write(int64_t offset, | 215 int32_t FileIO::Write(int64_t offset, |
216 const char* buffer, | 216 const char* buffer, |
217 int32_t bytes_to_write, | 217 int32_t bytes_to_write, |
218 PP_CompletionCallback callback) { | 218 PP_CompletionCallback callback) { |
219 NOTIMPLEMENTED(); // TODO(darin): Implement me! | 219 NOTIMPLEMENTED(); // TODO(darin): Implement me! |
220 return PP_Error_Failed; | 220 return PP_ERROR_FAILED; |
221 } | 221 } |
222 | 222 |
223 int32_t FileIO::SetLength(int64_t length, | 223 int32_t FileIO::SetLength(int64_t length, |
224 PP_CompletionCallback callback) { | 224 PP_CompletionCallback callback) { |
225 NOTIMPLEMENTED(); // TODO(darin): Implement me! | 225 NOTIMPLEMENTED(); // TODO(darin): Implement me! |
226 return PP_Error_Failed; | 226 return PP_ERROR_FAILED; |
227 } | 227 } |
228 | 228 |
229 int32_t FileIO::Flush(PP_CompletionCallback callback) { | 229 int32_t FileIO::Flush(PP_CompletionCallback callback) { |
230 NOTIMPLEMENTED(); // TODO(darin): Implement me! | 230 NOTIMPLEMENTED(); // TODO(darin): Implement me! |
231 return PP_Error_Failed; | 231 return PP_ERROR_FAILED; |
232 } | 232 } |
233 | 233 |
234 void FileIO::Close() { | 234 void FileIO::Close() { |
235 NOTIMPLEMENTED(); // TODO(darin): Implement me! | 235 NOTIMPLEMENTED(); // TODO(darin): Implement me! |
236 } | 236 } |
237 | 237 |
238 int32_t FileIO::GetOSFileDescriptor() { | 238 int32_t FileIO::GetOSFileDescriptor() { |
239 NOTIMPLEMENTED(); // TODO(darin): Implement me! | 239 NOTIMPLEMENTED(); // TODO(darin): Implement me! |
240 return PP_Error_Failed; | 240 return PP_ERROR_FAILED; |
241 } | 241 } |
242 | 242 |
243 int32_t FileIO::WillWrite(int64_t offset, | 243 int32_t FileIO::WillWrite(int64_t offset, |
244 int32_t bytes_to_write, | 244 int32_t bytes_to_write, |
245 PP_CompletionCallback callback) { | 245 PP_CompletionCallback callback) { |
246 NOTIMPLEMENTED(); // TODO(darin): Implement me! | 246 NOTIMPLEMENTED(); // TODO(darin): Implement me! |
247 return PP_Error_Failed; | 247 return PP_ERROR_FAILED; |
248 } | 248 } |
249 | 249 |
250 int32_t FileIO::WillSetLength(int64_t length, | 250 int32_t FileIO::WillSetLength(int64_t length, |
251 PP_CompletionCallback callback) { | 251 PP_CompletionCallback callback) { |
252 NOTIMPLEMENTED(); // TODO(darin): Implement me! | 252 NOTIMPLEMENTED(); // TODO(darin): Implement me! |
253 return PP_Error_Failed; | 253 return PP_ERROR_FAILED; |
254 } | 254 } |
255 | 255 |
256 } // namespace pepper | 256 } // namespace pepper |
OLD | NEW |