| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/fileapi/native_file_util.h" | 5 #include "webkit/fileapi/native_file_util.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/files/file_enumerator.h" |
| 8 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 9 #include "webkit/fileapi/file_system_operation_context.h" | 10 #include "webkit/fileapi/file_system_operation_context.h" |
| 10 | 11 |
| 11 namespace fileapi { | 12 namespace fileapi { |
| 12 | 13 |
| 13 namespace { | 14 namespace { |
| 14 | 15 |
| 15 // Sets permissions on directory at |dir_path| based on the target platform. | 16 // Sets permissions on directory at |dir_path| based on the target platform. |
| 16 // Returns true on success, or false otherwise. | 17 // Returns true on success, or false otherwise. |
| 17 // | 18 // |
| (...skipping 30 matching lines...) Expand all Loading... |
| 48 } | 49 } |
| 49 | 50 |
| 50 virtual ~NativeFileEnumerator() {} | 51 virtual ~NativeFileEnumerator() {} |
| 51 | 52 |
| 52 virtual base::FilePath Next() OVERRIDE; | 53 virtual base::FilePath Next() OVERRIDE; |
| 53 virtual int64 Size() OVERRIDE; | 54 virtual int64 Size() OVERRIDE; |
| 54 virtual base::Time LastModifiedTime() OVERRIDE; | 55 virtual base::Time LastModifiedTime() OVERRIDE; |
| 55 virtual bool IsDirectory() OVERRIDE; | 56 virtual bool IsDirectory() OVERRIDE; |
| 56 | 57 |
| 57 private: | 58 private: |
| 58 file_util::FileEnumerator file_enum_; | 59 base::FileEnumerator file_enum_; |
| 59 file_util::FileEnumerator::FindInfo file_util_info_; | 60 base::FileEnumerator::FileInfo file_util_info_; |
| 60 }; | 61 }; |
| 61 | 62 |
| 62 base::FilePath NativeFileEnumerator::Next() { | 63 base::FilePath NativeFileEnumerator::Next() { |
| 63 base::FilePath rv = file_enum_.Next(); | 64 base::FilePath rv = file_enum_.Next(); |
| 64 if (!rv.empty()) | 65 if (!rv.empty()) |
| 65 file_enum_.GetFindInfo(&file_util_info_); | 66 file_util_info_ = file_enum_.GetInfo(); |
| 66 return rv; | 67 return rv; |
| 67 } | 68 } |
| 68 | 69 |
| 69 int64 NativeFileEnumerator::Size() { | 70 int64 NativeFileEnumerator::Size() { |
| 70 return file_util::FileEnumerator::GetFilesize(file_util_info_); | 71 return file_util_info_.GetSize(); |
| 71 } | 72 } |
| 72 | 73 |
| 73 base::Time NativeFileEnumerator::LastModifiedTime() { | 74 base::Time NativeFileEnumerator::LastModifiedTime() { |
| 74 return file_util::FileEnumerator::GetLastModifiedTime(file_util_info_); | 75 return file_util_info_.GetLastModifiedTime(); |
| 75 } | 76 } |
| 76 | 77 |
| 77 bool NativeFileEnumerator::IsDirectory() { | 78 bool NativeFileEnumerator::IsDirectory() { |
| 78 return file_util::FileEnumerator::IsDirectory(file_util_info_); | 79 return file_util_info_.IsDirectory(); |
| 79 } | 80 } |
| 80 | 81 |
| 81 PlatformFileError NativeFileUtil::CreateOrOpen( | 82 PlatformFileError NativeFileUtil::CreateOrOpen( |
| 82 const base::FilePath& path, int file_flags, | 83 const base::FilePath& path, int file_flags, |
| 83 PlatformFile* file_handle, bool* created) { | 84 PlatformFile* file_handle, bool* created) { |
| 84 if (!file_util::DirectoryExists(path.DirName())) { | 85 if (!file_util::DirectoryExists(path.DirName())) { |
| 85 // If its parent does not exist, should return NOT_FOUND error. | 86 // If its parent does not exist, should return NOT_FOUND error. |
| 86 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 87 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| 87 } | 88 } |
| 88 if (file_util::DirectoryExists(path)) | 89 if (file_util::DirectoryExists(path)) |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 if (!file_util::GetFileInfo(path, file_info)) | 157 if (!file_util::GetFileInfo(path, file_info)) |
| 157 return base::PLATFORM_FILE_ERROR_FAILED; | 158 return base::PLATFORM_FILE_ERROR_FAILED; |
| 158 return base::PLATFORM_FILE_OK; | 159 return base::PLATFORM_FILE_OK; |
| 159 } | 160 } |
| 160 | 161 |
| 161 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> | 162 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> |
| 162 NativeFileUtil::CreateFileEnumerator(const base::FilePath& root_path, | 163 NativeFileUtil::CreateFileEnumerator(const base::FilePath& root_path, |
| 163 bool recursive) { | 164 bool recursive) { |
| 164 return make_scoped_ptr(new NativeFileEnumerator( | 165 return make_scoped_ptr(new NativeFileEnumerator( |
| 165 root_path, recursive, | 166 root_path, recursive, |
| 166 file_util::FileEnumerator::FILES | | 167 base::FileEnumerator::FILES | base::FileEnumerator::DIRECTORIES)) |
| 167 file_util::FileEnumerator::DIRECTORIES)) | |
| 168 .PassAs<FileSystemFileUtil::AbstractFileEnumerator>(); | 168 .PassAs<FileSystemFileUtil::AbstractFileEnumerator>(); |
| 169 } | 169 } |
| 170 | 170 |
| 171 PlatformFileError NativeFileUtil::Touch( | 171 PlatformFileError NativeFileUtil::Touch( |
| 172 const base::FilePath& path, | 172 const base::FilePath& path, |
| 173 const base::Time& last_access_time, | 173 const base::Time& last_access_time, |
| 174 const base::Time& last_modified_time) { | 174 const base::Time& last_modified_time) { |
| 175 if (!file_util::TouchFile( | 175 if (!file_util::TouchFile( |
| 176 path, last_access_time, last_modified_time)) | 176 path, last_access_time, last_modified_time)) |
| 177 return base::PLATFORM_FILE_ERROR_FAILED; | 177 return base::PLATFORM_FILE_ERROR_FAILED; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 if (!file_util::DirectoryExists(path)) | 255 if (!file_util::DirectoryExists(path)) |
| 256 return base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY; | 256 return base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY; |
| 257 if (!file_util::IsDirectoryEmpty(path)) | 257 if (!file_util::IsDirectoryEmpty(path)) |
| 258 return base::PLATFORM_FILE_ERROR_NOT_EMPTY; | 258 return base::PLATFORM_FILE_ERROR_NOT_EMPTY; |
| 259 if (!file_util::Delete(path, false)) | 259 if (!file_util::Delete(path, false)) |
| 260 return base::PLATFORM_FILE_ERROR_FAILED; | 260 return base::PLATFORM_FILE_ERROR_FAILED; |
| 261 return base::PLATFORM_FILE_OK; | 261 return base::PLATFORM_FILE_OK; |
| 262 } | 262 } |
| 263 | 263 |
| 264 } // namespace fileapi | 264 } // namespace fileapi |
| OLD | NEW |