OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "nacl_io/html5fs/html5_fs_node.h" | 5 #include "nacl_io/html5fs/html5_fs_node.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <ppapi/c/pp_completion_callback.h> | 9 #include <ppapi/c/pp_completion_callback.h> |
10 #include <ppapi/c/pp_directory_entry.h> | 10 #include <ppapi/c/pp_directory_entry.h> |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 static_cast<const char*>(buf), | 220 static_cast<const char*>(buf), |
221 static_cast<int32_t>(count), | 221 static_cast<int32_t>(count), |
222 PP_BlockUntilComplete()); | 222 PP_BlockUntilComplete()); |
223 if (result < 0) | 223 if (result < 0) |
224 return PPErrorToErrno(result); | 224 return PPErrorToErrno(result); |
225 | 225 |
226 *out_bytes = result; | 226 *out_bytes = result; |
227 return 0; | 227 return 0; |
228 } | 228 } |
229 | 229 |
230 int Html5FsNode::GetType() { return fileio_resource_ ? S_IFREG : S_IFDIR; } | 230 int Html5FsNode::GetType() { |
| 231 return fileio_resource_ ? S_IFREG : S_IFDIR; |
| 232 } |
231 | 233 |
232 Error Html5FsNode::GetSize(off_t* out_size) { | 234 Error Html5FsNode::GetSize(off_t* out_size) { |
233 *out_size = 0; | 235 *out_size = 0; |
234 | 236 |
235 if (IsaDir()) | 237 if (IsaDir()) |
236 return 0; | 238 return 0; |
237 | 239 |
238 AUTO_LOCK(node_lock_); | 240 AUTO_LOCK(node_lock_); |
239 | 241 |
240 PP_FileInfo info; | 242 PP_FileInfo info; |
241 int32_t result = filesystem_->ppapi()->GetFileIoInterface()->Query( | 243 int32_t result = filesystem_->ppapi()->GetFileIoInterface()->Query( |
242 fileio_resource_, &info, PP_BlockUntilComplete()); | 244 fileio_resource_, &info, PP_BlockUntilComplete()); |
243 if (result != PP_OK) | 245 if (result != PP_OK) |
244 return PPErrorToErrno(result); | 246 return PPErrorToErrno(result); |
245 | 247 |
246 *out_size = info.size; | 248 *out_size = info.size; |
247 return 0; | 249 return 0; |
248 } | 250 } |
249 | 251 |
250 bool Html5FsNode::IsaDir() { return !fileio_resource_; } | 252 bool Html5FsNode::IsaDir() { |
| 253 return !fileio_resource_; |
| 254 } |
251 | 255 |
252 bool Html5FsNode::IsaFile() { return fileio_resource_; } | 256 bool Html5FsNode::IsaFile() { |
| 257 return fileio_resource_; |
| 258 } |
253 | 259 |
254 Html5FsNode::Html5FsNode(Filesystem* filesystem, PP_Resource fileref_resource) | 260 Html5FsNode::Html5FsNode(Filesystem* filesystem, PP_Resource fileref_resource) |
255 : Node(filesystem), | 261 : Node(filesystem), |
256 fileref_resource_(fileref_resource), | 262 fileref_resource_(fileref_resource), |
257 fileio_resource_(0) {} | 263 fileio_resource_(0) { |
| 264 } |
258 | 265 |
259 Error Html5FsNode::Init(int open_flags) { | 266 Error Html5FsNode::Init(int open_flags) { |
260 Error error = Node::Init(open_flags); | 267 Error error = Node::Init(open_flags); |
261 if (error) | 268 if (error) |
262 return error; | 269 return error; |
263 | 270 |
264 // First query the FileRef to see if it is a file or directory. | 271 // First query the FileRef to see if it is a file or directory. |
265 PP_FileInfo file_info; | 272 PP_FileInfo file_info; |
266 int32_t query_result = filesystem_->ppapi()->GetFileRefInterface()->Query( | 273 int32_t query_result = filesystem_->ppapi()->GetFileRefInterface()->Query( |
267 fileref_resource_, &file_info, PP_BlockUntilComplete()); | 274 fileref_resource_, &file_info, PP_BlockUntilComplete()); |
(...skipping 23 matching lines...) Expand all Loading... |
291 filesystem_->ppapi()->ReleaseResource(fileio_resource_); | 298 filesystem_->ppapi()->ReleaseResource(fileio_resource_); |
292 } | 299 } |
293 | 300 |
294 filesystem_->ppapi()->ReleaseResource(fileref_resource_); | 301 filesystem_->ppapi()->ReleaseResource(fileref_resource_); |
295 fileio_resource_ = 0; | 302 fileio_resource_ = 0; |
296 fileref_resource_ = 0; | 303 fileref_resource_ = 0; |
297 Node::Destroy(); | 304 Node::Destroy(); |
298 } | 305 } |
299 | 306 |
300 } // namespace nacl_io | 307 } // namespace nacl_io |
OLD | NEW |