| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "ppapi/shared_impl/file_type_conversion.h" | 5 #include "ppapi/shared_impl/file_type_conversion.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/platform_file.h" |
| 8 #include "ppapi/c/pp_errors.h" | 9 #include "ppapi/c/pp_errors.h" |
| 9 #include "ppapi/c/ppb_file_io.h" | 10 #include "ppapi/c/ppb_file_io.h" |
| 10 #include "ppapi/shared_impl/time_conversion.h" | 11 #include "ppapi/shared_impl/time_conversion.h" |
| 11 | 12 |
| 12 namespace ppapi { | 13 namespace ppapi { |
| 13 | 14 |
| 14 int PlatformFileErrorToPepperError(base::PlatformFileError error_code) { | 15 int FileErrorToPepperError(base::File::Error error_code) { |
| 15 switch (error_code) { | 16 switch (error_code) { |
| 16 case base::PLATFORM_FILE_OK: | 17 case base::File::FILE_OK: |
| 17 return PP_OK; | 18 return PP_OK; |
| 18 case base::PLATFORM_FILE_ERROR_EXISTS: | 19 case base::File::FILE_ERROR_EXISTS: |
| 19 return PP_ERROR_FILEEXISTS; | 20 return PP_ERROR_FILEEXISTS; |
| 20 case base::PLATFORM_FILE_ERROR_NOT_FOUND: | 21 case base::File::FILE_ERROR_NOT_FOUND: |
| 21 return PP_ERROR_FILENOTFOUND; | 22 return PP_ERROR_FILENOTFOUND; |
| 22 case base::PLATFORM_FILE_ERROR_ACCESS_DENIED: | 23 case base::File::FILE_ERROR_ACCESS_DENIED: |
| 23 case base::PLATFORM_FILE_ERROR_SECURITY: | 24 case base::File::FILE_ERROR_SECURITY: |
| 24 return PP_ERROR_NOACCESS; | 25 return PP_ERROR_NOACCESS; |
| 25 case base::PLATFORM_FILE_ERROR_NO_MEMORY: | 26 case base::File::FILE_ERROR_NO_MEMORY: |
| 26 return PP_ERROR_NOMEMORY; | 27 return PP_ERROR_NOMEMORY; |
| 27 case base::PLATFORM_FILE_ERROR_NO_SPACE: | 28 case base::File::FILE_ERROR_NO_SPACE: |
| 28 return PP_ERROR_NOSPACE; | 29 return PP_ERROR_NOSPACE; |
| 29 case base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY: | 30 case base::File::FILE_ERROR_NOT_A_DIRECTORY: |
| 30 return PP_ERROR_FAILED; | 31 return PP_ERROR_FAILED; |
| 31 case base::PLATFORM_FILE_ERROR_NOT_A_FILE: | 32 case base::File::FILE_ERROR_NOT_A_FILE: |
| 32 return PP_ERROR_NOTAFILE; | 33 return PP_ERROR_NOTAFILE; |
| 33 default: | 34 default: |
| 34 return PP_ERROR_FAILED; | 35 return PP_ERROR_FAILED; |
| 35 } | 36 } |
| 36 } | 37 } |
| 37 | 38 |
| 38 bool PepperFileOpenFlagsToPlatformFileFlags(int32_t pp_open_flags, | 39 bool PepperFileOpenFlagsToPlatformFileFlags(int32_t pp_open_flags, |
| 39 int* flags_out) { | 40 int* flags_out) { |
| 40 bool pp_read = !!(pp_open_flags & PP_FILEOPENFLAG_READ); | 41 bool pp_read = !!(pp_open_flags & PP_FILEOPENFLAG_READ); |
| 41 bool pp_write = !!(pp_open_flags & PP_FILEOPENFLAG_WRITE); | 42 bool pp_write = !!(pp_open_flags & PP_FILEOPENFLAG_WRITE); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 flags |= base::PLATFORM_FILE_OPEN_TRUNCATED; | 74 flags |= base::PLATFORM_FILE_OPEN_TRUNCATED; |
| 74 } else { | 75 } else { |
| 75 flags |= base::PLATFORM_FILE_OPEN; | 76 flags |= base::PLATFORM_FILE_OPEN; |
| 76 } | 77 } |
| 77 | 78 |
| 78 if (flags_out) | 79 if (flags_out) |
| 79 *flags_out = flags; | 80 *flags_out = flags; |
| 80 return true; | 81 return true; |
| 81 } | 82 } |
| 82 | 83 |
| 83 void PlatformFileInfoToPepperFileInfo(const base::PlatformFileInfo& info, | 84 void FileInfoToPepperFileInfo(const base::File::Info& info, |
| 84 PP_FileSystemType fs_type, | 85 PP_FileSystemType fs_type, |
| 85 PP_FileInfo* info_out) { | 86 PP_FileInfo* info_out) { |
| 86 DCHECK(info_out); | 87 DCHECK(info_out); |
| 87 info_out->size = info.size; | 88 info_out->size = info.size; |
| 88 info_out->creation_time = TimeToPPTime(info.creation_time); | 89 info_out->creation_time = TimeToPPTime(info.creation_time); |
| 89 info_out->last_access_time = TimeToPPTime(info.last_accessed); | 90 info_out->last_access_time = TimeToPPTime(info.last_accessed); |
| 90 info_out->last_modified_time = TimeToPPTime(info.last_modified); | 91 info_out->last_modified_time = TimeToPPTime(info.last_modified); |
| 91 info_out->system_type = fs_type; | 92 info_out->system_type = fs_type; |
| 92 if (info.is_directory) { | 93 if (info.is_directory) { |
| 93 info_out->type = PP_FILETYPE_DIRECTORY; | 94 info_out->type = PP_FILETYPE_DIRECTORY; |
| 94 } else if (info.is_symbolic_link) { | 95 } else if (info.is_symbolic_link) { |
| 95 DCHECK_EQ(PP_FILESYSTEMTYPE_EXTERNAL, fs_type); | 96 DCHECK_EQ(PP_FILESYSTEMTYPE_EXTERNAL, fs_type); |
| 96 info_out->type = PP_FILETYPE_OTHER; | 97 info_out->type = PP_FILETYPE_OTHER; |
| 97 } else { | 98 } else { |
| 98 info_out->type = PP_FILETYPE_REGULAR; | 99 info_out->type = PP_FILETYPE_REGULAR; |
| 99 } | 100 } |
| 100 } | 101 } |
| 101 | 102 |
| 102 } // namespace ppapi | 103 } // namespace ppapi |
| OLD | NEW |