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/plugins/ppapi/ppb_file_io_impl.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/file_util_proxy.h" | 9 #include "base/file_util_proxy.h" |
10 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
11 #include "base/platform_file.h" | 11 #include "base/platform_file.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/time.h" | 13 #include "base/time.h" |
14 #include "ppapi/c/dev/ppb_file_io_dev.h" | 14 #include "ppapi/c/dev/ppb_file_io_dev.h" |
15 #include "ppapi/c/dev/ppb_file_io_trusted_dev.h" | 15 #include "ppapi/c/dev/ppb_file_io_trusted_dev.h" |
16 #include "ppapi/c/pp_completion_callback.h" | 16 #include "ppapi/c/pp_completion_callback.h" |
17 #include "ppapi/c/pp_errors.h" | 17 #include "ppapi/c/pp_errors.h" |
18 #include "webkit/glue/plugins/pepper_common.h" | 18 #include "webkit/plugins/ppapi/common.h" |
19 #include "webkit/glue/plugins/pepper_file_ref.h" | 19 #include "webkit/plugins/ppapi/plugin_instance.h" |
20 #include "webkit/glue/plugins/pepper_plugin_instance.h" | 20 #include "webkit/plugins/ppapi/plugin_module.h" |
21 #include "webkit/glue/plugins/pepper_plugin_module.h" | 21 #include "webkit/plugins/ppapi/ppb_file_ref_impl.h" |
22 #include "webkit/glue/plugins/pepper_resource_tracker.h" | 22 #include "webkit/plugins/ppapi/resource_tracker.h" |
23 | 23 |
24 namespace pepper { | 24 namespace webkit { |
| 25 namespace ppapi { |
25 | 26 |
26 namespace { | 27 namespace { |
27 | 28 |
28 PP_Resource Create(PP_Module module_id) { | 29 PP_Resource Create(PP_Module module_id) { |
29 PluginModule* module = ResourceTracker::Get()->GetModule(module_id); | 30 PluginModule* module = ResourceTracker::Get()->GetModule(module_id); |
30 if (!module) | 31 if (!module) |
31 return 0; | 32 return 0; |
32 | 33 |
33 FileIO* file_io = new FileIO(module); | 34 PPB_FileIO_Impl* file_io = new PPB_FileIO_Impl(module); |
34 return file_io->GetReference(); | 35 return file_io->GetReference(); |
35 } | 36 } |
36 | 37 |
37 PP_Bool IsFileIO(PP_Resource resource) { | 38 PP_Bool IsFileIO(PP_Resource resource) { |
38 return BoolToPPBool(!!Resource::GetAs<FileIO>(resource)); | 39 return BoolToPPBool(!!Resource::GetAs<PPB_FileIO_Impl>(resource)); |
39 } | 40 } |
40 | 41 |
41 int32_t Open(PP_Resource file_io_id, | 42 int32_t Open(PP_Resource file_io_id, |
42 PP_Resource file_ref_id, | 43 PP_Resource file_ref_id, |
43 int32_t open_flags, | 44 int32_t open_flags, |
44 PP_CompletionCallback callback) { | 45 PP_CompletionCallback callback) { |
45 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); | 46 scoped_refptr<PPB_FileIO_Impl> file_io(Resource::GetAs<PPB_FileIO_Impl>(file_i
o_id)); |
46 if (!file_io) | 47 if (!file_io) |
47 return PP_ERROR_BADRESOURCE; | 48 return PP_ERROR_BADRESOURCE; |
48 | 49 |
49 scoped_refptr<FileRef> file_ref(Resource::GetAs<FileRef>(file_ref_id)); | 50 scoped_refptr<PPB_FileRef_Impl> file_ref( |
| 51 Resource::GetAs<PPB_FileRef_Impl>(file_ref_id)); |
50 if (!file_ref) | 52 if (!file_ref) |
51 return PP_ERROR_BADRESOURCE; | 53 return PP_ERROR_BADRESOURCE; |
52 | 54 |
53 return file_io->Open(file_ref, open_flags, callback); | 55 return file_io->Open(file_ref, open_flags, callback); |
54 } | 56 } |
55 | 57 |
56 int32_t Query(PP_Resource file_io_id, | 58 int32_t Query(PP_Resource file_io_id, |
57 PP_FileInfo_Dev* info, | 59 PP_FileInfo_Dev* info, |
58 PP_CompletionCallback callback) { | 60 PP_CompletionCallback callback) { |
59 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); | 61 scoped_refptr<PPB_FileIO_Impl> file_io(Resource::GetAs<PPB_FileIO_Impl>(file_i
o_id)); |
60 if (!file_io) | 62 if (!file_io) |
61 return PP_ERROR_BADRESOURCE; | 63 return PP_ERROR_BADRESOURCE; |
62 return file_io->Query(info, callback); | 64 return file_io->Query(info, callback); |
63 } | 65 } |
64 | 66 |
65 int32_t Touch(PP_Resource file_io_id, | 67 int32_t Touch(PP_Resource file_io_id, |
66 PP_Time last_access_time, | 68 PP_Time last_access_time, |
67 PP_Time last_modified_time, | 69 PP_Time last_modified_time, |
68 PP_CompletionCallback callback) { | 70 PP_CompletionCallback callback) { |
69 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); | 71 scoped_refptr<PPB_FileIO_Impl> file_io(Resource::GetAs<PPB_FileIO_Impl>(file_i
o_id)); |
70 if (!file_io) | 72 if (!file_io) |
71 return PP_ERROR_BADRESOURCE; | 73 return PP_ERROR_BADRESOURCE; |
72 return file_io->Touch(last_access_time, last_modified_time, callback); | 74 return file_io->Touch(last_access_time, last_modified_time, callback); |
73 } | 75 } |
74 | 76 |
75 int32_t Read(PP_Resource file_io_id, | 77 int32_t Read(PP_Resource file_io_id, |
76 int64_t offset, | 78 int64_t offset, |
77 char* buffer, | 79 char* buffer, |
78 int32_t bytes_to_read, | 80 int32_t bytes_to_read, |
79 PP_CompletionCallback callback) { | 81 PP_CompletionCallback callback) { |
80 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); | 82 scoped_refptr<PPB_FileIO_Impl> file_io(Resource::GetAs<PPB_FileIO_Impl>(file_i
o_id)); |
81 if (!file_io) | 83 if (!file_io) |
82 return PP_ERROR_BADRESOURCE; | 84 return PP_ERROR_BADRESOURCE; |
83 return file_io->Read(offset, buffer, bytes_to_read, callback); | 85 return file_io->Read(offset, buffer, bytes_to_read, callback); |
84 } | 86 } |
85 | 87 |
86 int32_t Write(PP_Resource file_io_id, | 88 int32_t Write(PP_Resource file_io_id, |
87 int64_t offset, | 89 int64_t offset, |
88 const char* buffer, | 90 const char* buffer, |
89 int32_t bytes_to_write, | 91 int32_t bytes_to_write, |
90 PP_CompletionCallback callback) { | 92 PP_CompletionCallback callback) { |
91 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); | 93 scoped_refptr<PPB_FileIO_Impl> file_io(Resource::GetAs<PPB_FileIO_Impl>(file_i
o_id)); |
92 if (!file_io) | 94 if (!file_io) |
93 return PP_ERROR_BADRESOURCE; | 95 return PP_ERROR_BADRESOURCE; |
94 return file_io->Write(offset, buffer, bytes_to_write, callback); | 96 return file_io->Write(offset, buffer, bytes_to_write, callback); |
95 } | 97 } |
96 | 98 |
97 int32_t SetLength(PP_Resource file_io_id, | 99 int32_t SetLength(PP_Resource file_io_id, |
98 int64_t length, | 100 int64_t length, |
99 PP_CompletionCallback callback) { | 101 PP_CompletionCallback callback) { |
100 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); | 102 scoped_refptr<PPB_FileIO_Impl> file_io(Resource::GetAs<PPB_FileIO_Impl>(file_i
o_id)); |
101 if (!file_io) | 103 if (!file_io) |
102 return PP_ERROR_BADRESOURCE; | 104 return PP_ERROR_BADRESOURCE; |
103 return file_io->SetLength(length, callback); | 105 return file_io->SetLength(length, callback); |
104 } | 106 } |
105 | 107 |
106 int32_t Flush(PP_Resource file_io_id, | 108 int32_t Flush(PP_Resource file_io_id, |
107 PP_CompletionCallback callback) { | 109 PP_CompletionCallback callback) { |
108 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); | 110 scoped_refptr<PPB_FileIO_Impl> file_io(Resource::GetAs<PPB_FileIO_Impl>(file_i
o_id)); |
109 if (!file_io) | 111 if (!file_io) |
110 return PP_ERROR_BADRESOURCE; | 112 return PP_ERROR_BADRESOURCE; |
111 return file_io->Flush(callback); | 113 return file_io->Flush(callback); |
112 } | 114 } |
113 | 115 |
114 void Close(PP_Resource file_io_id) { | 116 void Close(PP_Resource file_io_id) { |
115 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); | 117 scoped_refptr<PPB_FileIO_Impl> file_io(Resource::GetAs<PPB_FileIO_Impl>(file_i
o_id)); |
116 if (!file_io) | 118 if (!file_io) |
117 return; | 119 return; |
118 file_io->Close(); | 120 file_io->Close(); |
119 } | 121 } |
120 | 122 |
121 const PPB_FileIO_Dev ppb_fileio = { | 123 const PPB_FileIO_Dev ppb_fileio = { |
122 &Create, | 124 &Create, |
123 &IsFileIO, | 125 &IsFileIO, |
124 &Open, | 126 &Open, |
125 &Query, | 127 &Query, |
126 &Touch, | 128 &Touch, |
127 &Read, | 129 &Read, |
128 &Write, | 130 &Write, |
129 &SetLength, | 131 &SetLength, |
130 &Flush, | 132 &Flush, |
131 &Close | 133 &Close |
132 }; | 134 }; |
133 | 135 |
134 int32_t GetOSFileDescriptor(PP_Resource file_io_id) { | 136 int32_t GetOSFileDescriptor(PP_Resource file_io_id) { |
135 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); | 137 scoped_refptr<PPB_FileIO_Impl> file_io(Resource::GetAs<PPB_FileIO_Impl>(file_i
o_id)); |
136 if (!file_io) | 138 if (!file_io) |
137 return PP_ERROR_BADRESOURCE; | 139 return PP_ERROR_BADRESOURCE; |
138 return file_io->GetOSFileDescriptor(); | 140 return file_io->GetOSFileDescriptor(); |
139 } | 141 } |
140 | 142 |
141 int32_t WillWrite(PP_Resource file_io_id, | 143 int32_t WillWrite(PP_Resource file_io_id, |
142 int64_t offset, | 144 int64_t offset, |
143 int32_t bytes_to_write, | 145 int32_t bytes_to_write, |
144 PP_CompletionCallback callback) { | 146 PP_CompletionCallback callback) { |
145 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); | 147 scoped_refptr<PPB_FileIO_Impl> file_io(Resource::GetAs<PPB_FileIO_Impl>(file_i
o_id)); |
146 if (!file_io) | 148 if (!file_io) |
147 return PP_ERROR_BADRESOURCE; | 149 return PP_ERROR_BADRESOURCE; |
148 return file_io->WillWrite(offset, bytes_to_write, callback); | 150 return file_io->WillWrite(offset, bytes_to_write, callback); |
149 } | 151 } |
150 | 152 |
151 int32_t WillSetLength(PP_Resource file_io_id, | 153 int32_t WillSetLength(PP_Resource file_io_id, |
152 int64_t length, | 154 int64_t length, |
153 PP_CompletionCallback callback) { | 155 PP_CompletionCallback callback) { |
154 scoped_refptr<FileIO> file_io(Resource::GetAs<FileIO>(file_io_id)); | 156 scoped_refptr<PPB_FileIO_Impl> file_io(Resource::GetAs<PPB_FileIO_Impl>(file_i
o_id)); |
155 if (!file_io) | 157 if (!file_io) |
156 return PP_ERROR_BADRESOURCE; | 158 return PP_ERROR_BADRESOURCE; |
157 return file_io->WillSetLength(length, callback); | 159 return file_io->WillSetLength(length, callback); |
158 } | 160 } |
159 | 161 |
160 const PPB_FileIOTrusted_Dev ppb_fileiotrusted = { | 162 const PPB_FileIOTrusted_Dev ppb_fileiotrusted = { |
161 &GetOSFileDescriptor, | 163 &GetOSFileDescriptor, |
162 &WillWrite, | 164 &WillWrite, |
163 &WillSetLength | 165 &WillSetLength |
164 }; | 166 }; |
(...skipping 15 matching lines...) Expand all Loading... |
180 case base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY: | 182 case base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY: |
181 NOTREACHED(); | 183 NOTREACHED(); |
182 return PP_ERROR_FAILED; | 184 return PP_ERROR_FAILED; |
183 default: | 185 default: |
184 return PP_ERROR_FAILED; | 186 return PP_ERROR_FAILED; |
185 } | 187 } |
186 } | 188 } |
187 | 189 |
188 } // namespace | 190 } // namespace |
189 | 191 |
190 FileIO::FileIO(PluginModule* module) | 192 PPB_FileIO_Impl::PPB_FileIO_Impl(PluginModule* module) |
191 : Resource(module), | 193 : Resource(module), |
192 delegate_(module->GetSomeInstance()->delegate()), | 194 delegate_(module->GetSomeInstance()->delegate()), |
193 ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)), | 195 ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)), |
194 file_(base::kInvalidPlatformFileValue), | 196 file_(base::kInvalidPlatformFileValue), |
195 callback_(), | 197 callback_(), |
196 info_(NULL) { | 198 info_(NULL) { |
197 } | 199 } |
198 | 200 |
199 FileIO::~FileIO() { | 201 PPB_FileIO_Impl::~PPB_FileIO_Impl() { |
200 Close(); | 202 Close(); |
201 } | 203 } |
202 | 204 |
203 // static | 205 // static |
204 const PPB_FileIO_Dev* FileIO::GetInterface() { | 206 const PPB_FileIO_Dev* PPB_FileIO_Impl::GetInterface() { |
205 return &ppb_fileio; | 207 return &ppb_fileio; |
206 } | 208 } |
207 | 209 |
208 // static | 210 // static |
209 const PPB_FileIOTrusted_Dev* FileIO::GetTrustedInterface() { | 211 const PPB_FileIOTrusted_Dev* PPB_FileIO_Impl::GetTrustedInterface() { |
210 return &ppb_fileiotrusted; | 212 return &ppb_fileiotrusted; |
211 } | 213 } |
212 | 214 |
213 FileIO* FileIO::AsFileIO() { | 215 PPB_FileIO_Impl* PPB_FileIO_Impl::AsPPB_FileIO_Impl() { |
214 return this; | 216 return this; |
215 } | 217 } |
216 | 218 |
217 int32_t FileIO::Open(FileRef* file_ref, | 219 int32_t PPB_FileIO_Impl::Open(PPB_FileRef_Impl* file_ref, |
218 int32_t open_flags, | 220 int32_t open_flags, |
219 PP_CompletionCallback callback) { | 221 PP_CompletionCallback callback) { |
220 if (file_ != base::kInvalidPlatformFileValue) | 222 if (file_ != base::kInvalidPlatformFileValue) |
221 return PP_ERROR_FAILED; | 223 return PP_ERROR_FAILED; |
222 | 224 |
223 DCHECK(!callback_.func); | 225 DCHECK(!callback_.func); |
224 callback_ = callback; | 226 callback_ = callback; |
225 | 227 |
226 int flags = 0; | 228 int flags = 0; |
227 if (open_flags & PP_FILEOPENFLAG_READ) | 229 if (open_flags & PP_FILEOPENFLAG_READ) |
228 flags |= base::PLATFORM_FILE_READ; | 230 flags |= base::PLATFORM_FILE_READ; |
229 if (open_flags & PP_FILEOPENFLAG_WRITE) { | 231 if (open_flags & PP_FILEOPENFLAG_WRITE) { |
230 flags |= base::PLATFORM_FILE_WRITE; | 232 flags |= base::PLATFORM_FILE_WRITE; |
231 flags |= base::PLATFORM_FILE_WRITE_ATTRIBUTES; | 233 flags |= base::PLATFORM_FILE_WRITE_ATTRIBUTES; |
232 } | 234 } |
233 | 235 |
234 if (open_flags & PP_FILEOPENFLAG_TRUNCATE) { | 236 if (open_flags & PP_FILEOPENFLAG_TRUNCATE) { |
235 DCHECK(open_flags & PP_FILEOPENFLAG_WRITE); | 237 DCHECK(open_flags & PP_FILEOPENFLAG_WRITE); |
236 flags |= base::PLATFORM_FILE_TRUNCATE; | 238 flags |= base::PLATFORM_FILE_TRUNCATE; |
237 } else if (open_flags & PP_FILEOPENFLAG_CREATE) { | 239 } else if (open_flags & PP_FILEOPENFLAG_CREATE) { |
238 if (open_flags & PP_FILEOPENFLAG_EXCLUSIVE) | 240 if (open_flags & PP_FILEOPENFLAG_EXCLUSIVE) |
239 flags |= base::PLATFORM_FILE_CREATE; | 241 flags |= base::PLATFORM_FILE_CREATE; |
240 else | 242 else |
241 flags |= base::PLATFORM_FILE_OPEN_ALWAYS; | 243 flags |= base::PLATFORM_FILE_OPEN_ALWAYS; |
242 } else | 244 } else |
243 flags |= base::PLATFORM_FILE_OPEN; | 245 flags |= base::PLATFORM_FILE_OPEN; |
244 | 246 |
245 file_system_type_ = file_ref->GetFileSystemType(); | 247 file_system_type_ = file_ref->GetFileSystemType(); |
246 if (!delegate_->AsyncOpenFile( | 248 if (!delegate_->AsyncOpenFile( |
247 file_ref->GetSystemPath(), flags, | 249 file_ref->GetSystemPath(), flags, |
248 callback_factory_.NewCallback(&FileIO::AsyncOpenFileCallback))) | 250 callback_factory_.NewCallback(&PPB_FileIO_Impl::AsyncOpenFileCallback)
)) |
249 return PP_ERROR_FAILED; | 251 return PP_ERROR_FAILED; |
250 | 252 |
251 return PP_ERROR_WOULDBLOCK; | 253 return PP_ERROR_WOULDBLOCK; |
252 } | 254 } |
253 | 255 |
254 int32_t FileIO::Query(PP_FileInfo_Dev* info, | 256 int32_t PPB_FileIO_Impl::Query(PP_FileInfo_Dev* info, |
255 PP_CompletionCallback callback) { | 257 PP_CompletionCallback callback) { |
256 if (file_ == base::kInvalidPlatformFileValue) | 258 if (file_ == base::kInvalidPlatformFileValue) |
257 return PP_ERROR_FAILED; | 259 return PP_ERROR_FAILED; |
258 | 260 |
259 DCHECK(!callback_.func); | 261 DCHECK(!callback_.func); |
260 callback_ = callback; | 262 callback_ = callback; |
261 | 263 |
262 DCHECK(!info_); | 264 DCHECK(!info_); |
263 DCHECK(info); | 265 DCHECK(info); |
264 info_ = info; | 266 info_ = info; |
265 | 267 |
266 if (!base::FileUtilProxy::GetFileInfoFromPlatformFile( | 268 if (!base::FileUtilProxy::GetFileInfoFromPlatformFile( |
267 delegate_->GetFileThreadMessageLoopProxy(), file_, | 269 delegate_->GetFileThreadMessageLoopProxy(), file_, |
268 callback_factory_.NewCallback(&FileIO::QueryInfoCallback))) | 270 callback_factory_.NewCallback(&PPB_FileIO_Impl::QueryInfoCallback))) |
269 return PP_ERROR_FAILED; | 271 return PP_ERROR_FAILED; |
270 | 272 |
271 return PP_ERROR_WOULDBLOCK; | 273 return PP_ERROR_WOULDBLOCK; |
272 } | 274 } |
273 | 275 |
274 int32_t FileIO::Touch(PP_Time last_access_time, | 276 int32_t PPB_FileIO_Impl::Touch(PP_Time last_access_time, |
275 PP_Time last_modified_time, | 277 PP_Time last_modified_time, |
276 PP_CompletionCallback callback) { | 278 PP_CompletionCallback callback) { |
277 if (file_ == base::kInvalidPlatformFileValue) | 279 if (file_ == base::kInvalidPlatformFileValue) |
278 return PP_ERROR_FAILED; | 280 return PP_ERROR_FAILED; |
279 | 281 |
280 DCHECK(!callback_.func); | 282 DCHECK(!callback_.func); |
281 callback_ = callback; | 283 callback_ = callback; |
282 | 284 |
283 if (!base::FileUtilProxy::Touch( | 285 if (!base::FileUtilProxy::Touch( |
284 delegate_->GetFileThreadMessageLoopProxy(), | 286 delegate_->GetFileThreadMessageLoopProxy(), |
285 file_, base::Time::FromDoubleT(last_access_time), | 287 file_, base::Time::FromDoubleT(last_access_time), |
286 base::Time::FromDoubleT(last_modified_time), | 288 base::Time::FromDoubleT(last_modified_time), |
287 callback_factory_.NewCallback(&FileIO::StatusCallback))) | 289 callback_factory_.NewCallback(&PPB_FileIO_Impl::StatusCallback))) |
288 return PP_ERROR_FAILED; | 290 return PP_ERROR_FAILED; |
289 | 291 |
290 return PP_ERROR_WOULDBLOCK; | 292 return PP_ERROR_WOULDBLOCK; |
291 } | 293 } |
292 | 294 |
293 int32_t FileIO::Read(int64_t offset, | 295 int32_t PPB_FileIO_Impl::Read(int64_t offset, |
294 char* buffer, | 296 char* buffer, |
295 int32_t bytes_to_read, | 297 int32_t bytes_to_read, |
296 PP_CompletionCallback callback) { | 298 PP_CompletionCallback callback) { |
297 if (file_ == base::kInvalidPlatformFileValue) | 299 if (file_ == base::kInvalidPlatformFileValue) |
298 return PP_ERROR_FAILED; | 300 return PP_ERROR_FAILED; |
299 | 301 |
300 DCHECK(!callback_.func); | 302 DCHECK(!callback_.func); |
301 callback_ = callback; | 303 callback_ = callback; |
302 | 304 |
303 if (!base::FileUtilProxy::Read( | 305 if (!base::FileUtilProxy::Read( |
304 delegate_->GetFileThreadMessageLoopProxy(), | 306 delegate_->GetFileThreadMessageLoopProxy(), |
305 file_, offset, buffer, bytes_to_read, | 307 file_, offset, buffer, bytes_to_read, |
306 callback_factory_.NewCallback(&FileIO::ReadWriteCallback))) | 308 callback_factory_.NewCallback(&PPB_FileIO_Impl::ReadWriteCallback))) |
307 return PP_ERROR_FAILED; | 309 return PP_ERROR_FAILED; |
308 | 310 |
309 return PP_ERROR_WOULDBLOCK; | 311 return PP_ERROR_WOULDBLOCK; |
310 } | 312 } |
311 | 313 |
312 int32_t FileIO::Write(int64_t offset, | 314 int32_t PPB_FileIO_Impl::Write(int64_t offset, |
313 const char* buffer, | 315 const char* buffer, |
314 int32_t bytes_to_write, | 316 int32_t bytes_to_write, |
315 PP_CompletionCallback callback) { | 317 PP_CompletionCallback callback) { |
316 if (file_ == base::kInvalidPlatformFileValue) | 318 if (file_ == base::kInvalidPlatformFileValue) |
317 return PP_ERROR_FAILED; | 319 return PP_ERROR_FAILED; |
318 | 320 |
319 DCHECK(!callback_.func); | 321 DCHECK(!callback_.func); |
320 callback_ = callback; | 322 callback_ = callback; |
321 | 323 |
322 if (!base::FileUtilProxy::Write( | 324 if (!base::FileUtilProxy::Write( |
323 delegate_->GetFileThreadMessageLoopProxy(), | 325 delegate_->GetFileThreadMessageLoopProxy(), |
324 file_, offset, buffer, bytes_to_write, | 326 file_, offset, buffer, bytes_to_write, |
325 callback_factory_.NewCallback(&FileIO::ReadWriteCallback))) | 327 callback_factory_.NewCallback(&PPB_FileIO_Impl::ReadWriteCallback))) |
326 return PP_ERROR_FAILED; | 328 return PP_ERROR_FAILED; |
327 | 329 |
328 return PP_ERROR_WOULDBLOCK; | 330 return PP_ERROR_WOULDBLOCK; |
329 } | 331 } |
330 | 332 |
331 int32_t FileIO::SetLength(int64_t length, | 333 int32_t PPB_FileIO_Impl::SetLength(int64_t length, |
332 PP_CompletionCallback callback) { | 334 PP_CompletionCallback callback) { |
333 if (file_ == base::kInvalidPlatformFileValue) | 335 if (file_ == base::kInvalidPlatformFileValue) |
334 return PP_ERROR_FAILED; | 336 return PP_ERROR_FAILED; |
335 | 337 |
336 DCHECK(!callback_.func); | 338 DCHECK(!callback_.func); |
337 callback_ = callback; | 339 callback_ = callback; |
338 | 340 |
339 if (!base::FileUtilProxy::Truncate( | 341 if (!base::FileUtilProxy::Truncate( |
340 delegate_->GetFileThreadMessageLoopProxy(), | 342 delegate_->GetFileThreadMessageLoopProxy(), |
341 file_, length, | 343 file_, length, |
342 callback_factory_.NewCallback(&FileIO::StatusCallback))) | 344 callback_factory_.NewCallback(&PPB_FileIO_Impl::StatusCallback))) |
343 return PP_ERROR_FAILED; | 345 return PP_ERROR_FAILED; |
344 | 346 |
345 return PP_ERROR_WOULDBLOCK; | 347 return PP_ERROR_WOULDBLOCK; |
346 } | 348 } |
347 | 349 |
348 int32_t FileIO::Flush(PP_CompletionCallback callback) { | 350 int32_t PPB_FileIO_Impl::Flush(PP_CompletionCallback callback) { |
349 if (file_ == base::kInvalidPlatformFileValue) | 351 if (file_ == base::kInvalidPlatformFileValue) |
350 return PP_ERROR_FAILED; | 352 return PP_ERROR_FAILED; |
351 | 353 |
352 DCHECK(!callback_.func); | 354 DCHECK(!callback_.func); |
353 callback_ = callback; | 355 callback_ = callback; |
354 | 356 |
355 if (!base::FileUtilProxy::Flush( | 357 if (!base::FileUtilProxy::Flush( |
356 delegate_->GetFileThreadMessageLoopProxy(), file_, | 358 delegate_->GetFileThreadMessageLoopProxy(), file_, |
357 callback_factory_.NewCallback(&FileIO::StatusCallback))) | 359 callback_factory_.NewCallback(&PPB_FileIO_Impl::StatusCallback))) |
358 return PP_ERROR_FAILED; | 360 return PP_ERROR_FAILED; |
359 | 361 |
360 return PP_ERROR_WOULDBLOCK; | 362 return PP_ERROR_WOULDBLOCK; |
361 } | 363 } |
362 | 364 |
363 void FileIO::Close() { | 365 void PPB_FileIO_Impl::Close() { |
364 if (file_ != base::kInvalidPlatformFileValue) | 366 if (file_ != base::kInvalidPlatformFileValue) |
365 base::FileUtilProxy::Close( | 367 base::FileUtilProxy::Close( |
366 delegate_->GetFileThreadMessageLoopProxy(), file_, NULL); | 368 delegate_->GetFileThreadMessageLoopProxy(), file_, NULL); |
367 } | 369 } |
368 | 370 |
369 int32_t FileIO::GetOSFileDescriptor() { | 371 int32_t PPB_FileIO_Impl::GetOSFileDescriptor() { |
370 #if defined(OS_POSIX) | 372 #if defined(OS_POSIX) |
371 return file_; | 373 return file_; |
372 #elif defined(OS_WIN) | 374 #elif defined(OS_WIN) |
373 return reinterpret_cast<uintptr_t>(file_); | 375 return reinterpret_cast<uintptr_t>(file_); |
374 #else | 376 #else |
375 #error "Platform not supported." | 377 #error "Platform not supported." |
376 #endif | 378 #endif |
377 } | 379 } |
378 | 380 |
379 int32_t FileIO::WillWrite(int64_t offset, | 381 int32_t PPB_FileIO_Impl::WillWrite(int64_t offset, |
380 int32_t bytes_to_write, | 382 int32_t bytes_to_write, |
381 PP_CompletionCallback callback) { | 383 PP_CompletionCallback callback) { |
382 // TODO(dumi): implement me | 384 // TODO(dumi): implement me |
383 return PP_OK; | 385 return PP_OK; |
384 } | 386 } |
385 | 387 |
386 int32_t FileIO::WillSetLength(int64_t length, | 388 int32_t PPB_FileIO_Impl::WillSetLength(int64_t length, |
387 PP_CompletionCallback callback) { | 389 PP_CompletionCallback callback) { |
388 // TODO(dumi): implement me | 390 // TODO(dumi): implement me |
389 return PP_OK; | 391 return PP_OK; |
390 } | 392 } |
391 | 393 |
392 void FileIO::RunPendingCallback(int result) { | 394 void PPB_FileIO_Impl::RunPendingCallback(int result) { |
393 if (!callback_.func) | 395 if (!callback_.func) |
394 return; | 396 return; |
395 | 397 |
396 PP_CompletionCallback callback = {0}; | 398 PP_CompletionCallback callback = {0}; |
397 std::swap(callback, callback_); | 399 std::swap(callback, callback_); |
398 PP_RunCompletionCallback(&callback, result); | 400 PP_RunCompletionCallback(&callback, result); |
399 } | 401 } |
400 | 402 |
401 void FileIO::StatusCallback(base::PlatformFileError error_code) { | 403 void PPB_FileIO_Impl::StatusCallback(base::PlatformFileError error_code) { |
402 RunPendingCallback(PlatformFileErrorToPepperError(error_code)); | 404 RunPendingCallback(PlatformFileErrorToPepperError(error_code)); |
403 } | 405 } |
404 | 406 |
405 void FileIO::AsyncOpenFileCallback(base::PlatformFileError error_code, | 407 void PPB_FileIO_Impl::AsyncOpenFileCallback( |
406 base::PlatformFile file) { | 408 base::PlatformFileError error_code, |
| 409 base::PlatformFile file) { |
407 DCHECK(file_ == base::kInvalidPlatformFileValue); | 410 DCHECK(file_ == base::kInvalidPlatformFileValue); |
408 file_ = file; | 411 file_ = file; |
409 RunPendingCallback(PlatformFileErrorToPepperError(error_code)); | 412 RunPendingCallback(PlatformFileErrorToPepperError(error_code)); |
410 } | 413 } |
411 | 414 |
412 void FileIO::QueryInfoCallback(base::PlatformFileError error_code, | 415 void PPB_FileIO_Impl::QueryInfoCallback( |
413 const base::PlatformFileInfo& file_info) { | 416 base::PlatformFileError error_code, |
| 417 const base::PlatformFileInfo& file_info) { |
414 DCHECK(info_); | 418 DCHECK(info_); |
415 if (error_code == base::PLATFORM_FILE_OK) { | 419 if (error_code == base::PLATFORM_FILE_OK) { |
416 info_->size = file_info.size; | 420 info_->size = file_info.size; |
417 info_->creation_time = file_info.creation_time.ToDoubleT(); | 421 info_->creation_time = file_info.creation_time.ToDoubleT(); |
418 info_->last_access_time = file_info.last_accessed.ToDoubleT(); | 422 info_->last_access_time = file_info.last_accessed.ToDoubleT(); |
419 info_->last_modified_time = file_info.last_modified.ToDoubleT(); | 423 info_->last_modified_time = file_info.last_modified.ToDoubleT(); |
420 info_->system_type = file_system_type_; | 424 info_->system_type = file_system_type_; |
421 if (file_info.is_directory) | 425 if (file_info.is_directory) |
422 info_->type = PP_FILETYPE_DIRECTORY; | 426 info_->type = PP_FILETYPE_DIRECTORY; |
423 else | 427 else |
424 info_->type = PP_FILETYPE_REGULAR; | 428 info_->type = PP_FILETYPE_REGULAR; |
425 } | 429 } |
426 RunPendingCallback(PlatformFileErrorToPepperError(error_code)); | 430 RunPendingCallback(PlatformFileErrorToPepperError(error_code)); |
427 } | 431 } |
428 | 432 |
429 void FileIO::ReadWriteCallback(base::PlatformFileError error_code, | 433 void PPB_FileIO_Impl::ReadWriteCallback(base::PlatformFileError error_code, |
430 int bytes_read_or_written) { | 434 int bytes_read_or_written) { |
431 if (error_code != base::PLATFORM_FILE_OK) | 435 if (error_code != base::PLATFORM_FILE_OK) |
432 RunPendingCallback(PlatformFileErrorToPepperError(error_code)); | 436 RunPendingCallback(PlatformFileErrorToPepperError(error_code)); |
433 else | 437 else |
434 RunPendingCallback(bytes_read_or_written); | 438 RunPendingCallback(bytes_read_or_written); |
435 } | 439 } |
436 | 440 |
437 } // namespace pepper | 441 } // namespace ppapi |
| 442 } // namespace webkit |
| 443 |
OLD | NEW |