| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef WEBKIT_CHROMEOS_FILEAPI_FILE_SYSTEM_FILE_UTIL_MEMORY_H_ |
| 6 #define WEBKIT_CHROMEOS_FILEAPI_FILE_SYSTEM_FILE_UTIL_MEMORY_H_ |
| 7 |
| 8 #include <map> |
| 9 #include <string> |
| 10 #include <vector> |
| 11 |
| 12 #include "base/callback.h" |
| 13 #include "base/time.h" |
| 14 #include "webkit/chromeos/fileapi/file_util_async.h" |
| 15 |
| 16 namespace fileapi { |
| 17 |
| 18 // The in-memory file system. Primarily for the purpose of testing |
| 19 // FileUtilAsync. |
| 20 class MemoryFileUtil : public FileUtilAsync { |
| 21 public: |
| 22 struct FileEntry { |
| 23 bool is_directory; |
| 24 std::string contents; |
| 25 base::Time last_modified; |
| 26 }; |
| 27 |
| 28 MemoryFileUtil(const FilePath& root_path); |
| 29 |
| 30 virtual void OpenVerifiedFile( |
| 31 const FilePath& file_path, |
| 32 int flags, |
| 33 const OpenCallback& callback) OVERRIDE; |
| 34 virtual void GetFileInfo( |
| 35 const FilePath& file_path, |
| 36 const GetFileInfoCallback& callback) OVERRIDE; |
| 37 virtual void Create( |
| 38 const FilePath& file_path, |
| 39 const StatusCallback& callback) OVERRIDE; |
| 40 virtual void Truncate( |
| 41 const FilePath& file_path, |
| 42 int64 length, |
| 43 const StatusCallback& callback) OVERRIDE; |
| 44 // This FS ignores last_access_time. |
| 45 virtual void Touch( |
| 46 const FilePath& file_path, |
| 47 const base::Time& last_access_time, |
| 48 const base::Time& last_modified_time, |
| 49 const StatusCallback& callback) OVERRIDE; |
| 50 virtual void Remove( |
| 51 const FilePath& file_path, |
| 52 bool recursive, |
| 53 const StatusCallback& callback) OVERRIDE; |
| 54 virtual void CreateDirectory( |
| 55 const FilePath& dir_path, |
| 56 const StatusCallback& callback) OVERRIDE; |
| 57 virtual void ReadDirectory( |
| 58 const FilePath& dir_path, |
| 59 const ReadDirectoryCallback& callback) OVERRIDE; |
| 60 |
| 61 private: |
| 62 friend class MemoryFileUtilTest; |
| 63 |
| 64 typedef std::map<FilePath, FileEntry>::iterator FileIterator; |
| 65 typedef std::map<FilePath, FileEntry>::const_iterator ConstFileIterator; |
| 66 |
| 67 bool FileExists(const FilePath& file_path) { |
| 68 return files_.find(file_path) != files_.end(); |
| 69 } |
| 70 |
| 71 bool IsDirectory(const FilePath& file_path); |
| 72 |
| 73 void DoGetFileInfo( |
| 74 const FilePath& file_path, |
| 75 const GetFileInfoCallback& callback); |
| 76 |
| 77 void DoCreate( |
| 78 const FilePath& file_path, |
| 79 bool is_directory, |
| 80 const StatusCallback& callback); |
| 81 |
| 82 void DoTruncate( |
| 83 const FilePath& file_path, |
| 84 int64 length, |
| 85 const StatusCallback& callback); |
| 86 |
| 87 void DoTouch( |
| 88 const FilePath& file_path, |
| 89 const base::Time& last_modified_time, |
| 90 const StatusCallback& callback); |
| 91 |
| 92 void DoRemoveSingleFile( |
| 93 const FilePath& file_path, |
| 94 const StatusCallback& callback); |
| 95 |
| 96 void DoRemoveRecursive( |
| 97 const FilePath& file_path, |
| 98 const StatusCallback& callback); |
| 99 |
| 100 // Will start enumerating with file path |from|. If |from| path is |
| 101 // empty, will start from the beginning. |
| 102 void DoReadDirectory( |
| 103 const FilePath& dir_path, |
| 104 const FilePath& from, |
| 105 const ReadDirectoryCallback& callback); |
| 106 |
| 107 // Mainly for the purpose of testing. |
| 108 void set_read_directory_buffer_size(size_t size) { |
| 109 read_directory_buffer_size_ = size; |
| 110 } |
| 111 |
| 112 std::map<FilePath, FileEntry> files_; |
| 113 |
| 114 size_t read_directory_buffer_size_; |
| 115 std::vector<DirectoryEntry> read_directory_buffer_; |
| 116 |
| 117 DISALLOW_COPY_AND_ASSIGN(MemoryFileUtil); |
| 118 }; |
| 119 |
| 120 } |
| 121 |
| 122 #endif // WEBKIT_CHROMEOS_FILEAPI_FILE_SYSTEM_FILE_UTIL_ASYNC_H_ |
| OLD | NEW |