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