OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 struct stat stat_; | 73 struct stat stat_; |
74 #endif | 74 #endif |
75 }; | 75 }; |
76 | 76 |
77 enum FileTimeType { FTT_CREATED, FTT_MODIFIED, FTT_ACCESSED }; | 77 enum FileTimeType { FTT_CREATED, FTT_MODIFIED, FTT_ACCESSED }; |
78 | 78 |
79 class FilesystemInterface { | 79 class FilesystemInterface { |
80 public: | 80 public: |
81 virtual ~FilesystemInterface() {} | 81 virtual ~FilesystemInterface() {} |
82 | 82 |
83 // Returns a DirectoryIterator for a given pathname. | |
84 // TODO: Do fancy abstracted stuff | |
85 virtual DirectoryIterator* IterateDirectory(); | |
86 | |
87 // Opens a file. Returns an open StreamInterface if function succeeds. | |
88 // Otherwise, returns null. | |
89 // TODO: Add an error param to indicate failure reason, similar to | |
90 // FileStream::Open | |
91 virtual FileStream *OpenFile(const Pathname &filename, | |
92 const std::string &mode) = 0; | |
93 | |
94 // This will attempt to delete the path located at filename. | 83 // This will attempt to delete the path located at filename. |
95 // It DCHECKs and returns false if the path points to a folder or a | 84 // It DCHECKs and returns false if the path points to a folder or a |
96 // non-existent file. | 85 // non-existent file. |
97 virtual bool DeleteFile(const Pathname &filename) = 0; | 86 virtual bool DeleteFile(const Pathname &filename) = 0; |
98 | 87 |
99 // This will attempt to delete the empty folder located at 'folder' | 88 // This will attempt to delete the empty folder located at 'folder' |
100 // It DCHECKs and returns false if the path points to a file or a non-existent | 89 // It DCHECKs and returns false if the path points to a file or a non-existent |
101 // folder. It fails normally if the folder is not empty or can otherwise | 90 // folder. It fails normally if the folder is not empty or can otherwise |
102 // not be deleted. | 91 // not be deleted. |
103 virtual bool DeleteEmptyFolder(const Pathname &folder) = 0; | 92 virtual bool DeleteEmptyFolder(const Pathname &folder) = 0; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 default_filesystem_ = filesystem; | 158 default_filesystem_ = filesystem; |
170 } | 159 } |
171 | 160 |
172 static FilesystemInterface *swap_default_filesystem( | 161 static FilesystemInterface *swap_default_filesystem( |
173 FilesystemInterface *filesystem) { | 162 FilesystemInterface *filesystem) { |
174 FilesystemInterface *cur = default_filesystem_; | 163 FilesystemInterface *cur = default_filesystem_; |
175 default_filesystem_ = filesystem; | 164 default_filesystem_ = filesystem; |
176 return cur; | 165 return cur; |
177 } | 166 } |
178 | 167 |
179 static DirectoryIterator *IterateDirectory() { | |
180 return EnsureDefaultFilesystem()->IterateDirectory(); | |
181 } | |
182 | |
183 static bool CreateFolder(const Pathname &pathname) { | 168 static bool CreateFolder(const Pathname &pathname) { |
184 return EnsureDefaultFilesystem()->CreateFolder(pathname); | 169 return EnsureDefaultFilesystem()->CreateFolder(pathname); |
185 } | 170 } |
186 | 171 |
187 static FileStream *OpenFile(const Pathname &filename, | |
188 const std::string &mode) { | |
189 return EnsureDefaultFilesystem()->OpenFile(filename, mode); | |
190 } | |
191 | |
192 static bool DeleteFile(const Pathname &filename) { | 172 static bool DeleteFile(const Pathname &filename) { |
193 return EnsureDefaultFilesystem()->DeleteFile(filename); | 173 return EnsureDefaultFilesystem()->DeleteFile(filename); |
194 } | 174 } |
195 | 175 |
196 static bool MoveFile(const Pathname &old_path, const Pathname &new_path) { | 176 static bool MoveFile(const Pathname &old_path, const Pathname &new_path) { |
197 return EnsureDefaultFilesystem()->MoveFile(old_path, new_path); | 177 return EnsureDefaultFilesystem()->MoveFile(old_path, new_path); |
198 } | 178 } |
199 | 179 |
200 static bool IsFolder(const Pathname& pathname) { | 180 static bool IsFolder(const Pathname& pathname) { |
201 return EnsureDefaultFilesystem()->IsFolder(pathname); | 181 return EnsureDefaultFilesystem()->IsFolder(pathname); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 private: | 227 private: |
248 static FilesystemInterface* default_filesystem_; | 228 static FilesystemInterface* default_filesystem_; |
249 | 229 |
250 static FilesystemInterface *EnsureDefaultFilesystem(); | 230 static FilesystemInterface *EnsureDefaultFilesystem(); |
251 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(Filesystem); | 231 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(Filesystem); |
252 }; | 232 }; |
253 | 233 |
254 } // namespace rtc | 234 } // namespace rtc |
255 | 235 |
256 #endif // WEBRTC_BASE_FILEUTILS_H_ | 236 #endif // WEBRTC_BASE_FILEUTILS_H_ |
OLD | NEW |