| 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/browser/fileapi/native_file_util.h" | 5 #include "webkit/browser/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/browser/fileapi/file_system_operation_context.h" | 10 #include "webkit/browser/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 17 matching lines...) Expand all Loading... |
| 35 | 36 |
| 36 using base::PlatformFile; | 37 using base::PlatformFile; |
| 37 using base::PlatformFileError; | 38 using base::PlatformFileError; |
| 38 | 39 |
| 39 class NativeFileEnumerator : public FileSystemFileUtil::AbstractFileEnumerator { | 40 class NativeFileEnumerator : public FileSystemFileUtil::AbstractFileEnumerator { |
| 40 public: | 41 public: |
| 41 NativeFileEnumerator(const base::FilePath& root_path, | 42 NativeFileEnumerator(const base::FilePath& root_path, |
| 42 bool recursive, | 43 bool recursive, |
| 43 int file_type) | 44 int file_type) |
| 44 : file_enum_(root_path, recursive, file_type) { | 45 : file_enum_(root_path, recursive, file_type) { |
| 45 #if defined(OS_WIN) | |
| 46 memset(&file_util_info_, 0, sizeof(file_util_info_)); | |
| 47 #endif // defined(OS_WIN) | |
| 48 } | 46 } |
| 49 | 47 |
| 50 virtual ~NativeFileEnumerator() {} | 48 virtual ~NativeFileEnumerator() {} |
| 51 | 49 |
| 52 virtual base::FilePath Next() OVERRIDE; | 50 virtual base::FilePath Next() OVERRIDE; |
| 53 virtual int64 Size() OVERRIDE; | 51 virtual int64 Size() OVERRIDE; |
| 54 virtual base::Time LastModifiedTime() OVERRIDE; | 52 virtual base::Time LastModifiedTime() OVERRIDE; |
| 55 virtual bool IsDirectory() OVERRIDE; | 53 virtual bool IsDirectory() OVERRIDE; |
| 56 | 54 |
| 57 private: | 55 private: |
| 58 file_util::FileEnumerator file_enum_; | 56 base::FileEnumerator file_enum_; |
| 59 file_util::FileEnumerator::FindInfo file_util_info_; | 57 base::FileEnumerator::FileInfo file_util_info_; |
| 60 }; | 58 }; |
| 61 | 59 |
| 62 base::FilePath NativeFileEnumerator::Next() { | 60 base::FilePath NativeFileEnumerator::Next() { |
| 63 base::FilePath rv = file_enum_.Next(); | 61 base::FilePath rv = file_enum_.Next(); |
| 64 if (!rv.empty()) | 62 if (!rv.empty()) |
| 65 file_enum_.GetFindInfo(&file_util_info_); | 63 file_util_info_ = file_enum_.GetInfo(); |
| 66 return rv; | 64 return rv; |
| 67 } | 65 } |
| 68 | 66 |
| 69 int64 NativeFileEnumerator::Size() { | 67 int64 NativeFileEnumerator::Size() { |
| 70 return file_util::FileEnumerator::GetFilesize(file_util_info_); | 68 return file_util_info_.GetSize(); |
| 71 } | 69 } |
| 72 | 70 |
| 73 base::Time NativeFileEnumerator::LastModifiedTime() { | 71 base::Time NativeFileEnumerator::LastModifiedTime() { |
| 74 return file_util::FileEnumerator::GetLastModifiedTime(file_util_info_); | 72 return file_util_info_.GetLastModifiedTime(); |
| 75 } | 73 } |
| 76 | 74 |
| 77 bool NativeFileEnumerator::IsDirectory() { | 75 bool NativeFileEnumerator::IsDirectory() { |
| 78 return file_util::FileEnumerator::IsDirectory(file_util_info_); | 76 return file_util_info_.IsDirectory(); |
| 79 } | 77 } |
| 80 | 78 |
| 81 PlatformFileError NativeFileUtil::CreateOrOpen( | 79 PlatformFileError NativeFileUtil::CreateOrOpen( |
| 82 const base::FilePath& path, int file_flags, | 80 const base::FilePath& path, int file_flags, |
| 83 PlatformFile* file_handle, bool* created) { | 81 PlatformFile* file_handle, bool* created) { |
| 84 if (!file_util::DirectoryExists(path.DirName())) { | 82 if (!file_util::DirectoryExists(path.DirName())) { |
| 85 // If its parent does not exist, should return NOT_FOUND error. | 83 // If its parent does not exist, should return NOT_FOUND error. |
| 86 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 84 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| 87 } | 85 } |
| 88 if (file_util::DirectoryExists(path)) | 86 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)) | 154 if (!file_util::GetFileInfo(path, file_info)) |
| 157 return base::PLATFORM_FILE_ERROR_FAILED; | 155 return base::PLATFORM_FILE_ERROR_FAILED; |
| 158 return base::PLATFORM_FILE_OK; | 156 return base::PLATFORM_FILE_OK; |
| 159 } | 157 } |
| 160 | 158 |
| 161 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> | 159 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> |
| 162 NativeFileUtil::CreateFileEnumerator(const base::FilePath& root_path, | 160 NativeFileUtil::CreateFileEnumerator(const base::FilePath& root_path, |
| 163 bool recursive) { | 161 bool recursive) { |
| 164 return make_scoped_ptr(new NativeFileEnumerator( | 162 return make_scoped_ptr(new NativeFileEnumerator( |
| 165 root_path, recursive, | 163 root_path, recursive, |
| 166 file_util::FileEnumerator::FILES | | 164 base::FileEnumerator::FILES | base::FileEnumerator::DIRECTORIES)) |
| 167 file_util::FileEnumerator::DIRECTORIES)) | |
| 168 .PassAs<FileSystemFileUtil::AbstractFileEnumerator>(); | 165 .PassAs<FileSystemFileUtil::AbstractFileEnumerator>(); |
| 169 } | 166 } |
| 170 | 167 |
| 171 PlatformFileError NativeFileUtil::Touch( | 168 PlatformFileError NativeFileUtil::Touch( |
| 172 const base::FilePath& path, | 169 const base::FilePath& path, |
| 173 const base::Time& last_access_time, | 170 const base::Time& last_access_time, |
| 174 const base::Time& last_modified_time) { | 171 const base::Time& last_modified_time) { |
| 175 if (!file_util::TouchFile( | 172 if (!file_util::TouchFile( |
| 176 path, last_access_time, last_modified_time)) | 173 path, last_access_time, last_modified_time)) |
| 177 return base::PLATFORM_FILE_ERROR_FAILED; | 174 return base::PLATFORM_FILE_ERROR_FAILED; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 if (!file_util::DirectoryExists(path)) | 253 if (!file_util::DirectoryExists(path)) |
| 257 return base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY; | 254 return base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY; |
| 258 if (!file_util::IsDirectoryEmpty(path)) | 255 if (!file_util::IsDirectoryEmpty(path)) |
| 259 return base::PLATFORM_FILE_ERROR_NOT_EMPTY; | 256 return base::PLATFORM_FILE_ERROR_NOT_EMPTY; |
| 260 if (!file_util::Delete(path, false)) | 257 if (!file_util::Delete(path, false)) |
| 261 return base::PLATFORM_FILE_ERROR_FAILED; | 258 return base::PLATFORM_FILE_ERROR_FAILED; |
| 262 return base::PLATFORM_FILE_OK; | 259 return base::PLATFORM_FILE_OK; |
| 263 } | 260 } |
| 264 | 261 |
| 265 } // namespace fileapi | 262 } // namespace fileapi |
| OLD | NEW |