| 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 #ifndef WEBKIT_CHROMEOS_FILEAPI_FILE_SYSTEM_FILE_UTIL_MEMORY_H_ | 5 #ifndef WEBKIT_CHROMEOS_FILEAPI_FILE_SYSTEM_FILE_UTIL_MEMORY_H_ |
| 6 #define WEBKIT_CHROMEOS_FILEAPI_FILE_SYSTEM_FILE_UTIL_MEMORY_H_ | 6 #define WEBKIT_CHROMEOS_FILEAPI_FILE_SYSTEM_FILE_UTIL_MEMORY_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 public: | 21 public: |
| 22 struct FileEntry { | 22 struct FileEntry { |
| 23 FileEntry(); | 23 FileEntry(); |
| 24 ~FileEntry(); | 24 ~FileEntry(); |
| 25 | 25 |
| 26 bool is_directory; | 26 bool is_directory; |
| 27 std::string contents; | 27 std::string contents; |
| 28 base::Time last_modified; | 28 base::Time last_modified; |
| 29 }; | 29 }; |
| 30 | 30 |
| 31 MemoryFileUtil(const FilePath& root_path); | 31 MemoryFileUtil(const base::FilePath& root_path); |
| 32 virtual ~MemoryFileUtil(); | 32 virtual ~MemoryFileUtil(); |
| 33 | 33 |
| 34 // FileUtilAsync overrides. | 34 // FileUtilAsync overrides. |
| 35 virtual void Open(const FilePath& file_path, | 35 virtual void Open(const base::FilePath& file_path, |
| 36 int file_flags, // PlatformFileFlags | 36 int file_flags, // PlatformFileFlags |
| 37 const OpenCallback& callback) OVERRIDE; | 37 const OpenCallback& callback) OVERRIDE; |
| 38 virtual void GetFileInfo(const FilePath& file_path, | 38 virtual void GetFileInfo(const base::FilePath& file_path, |
| 39 const GetFileInfoCallback& callback) OVERRIDE; | 39 const GetFileInfoCallback& callback) OVERRIDE; |
| 40 virtual void Create(const FilePath& file_path, | 40 virtual void Create(const base::FilePath& file_path, |
| 41 const StatusCallback& callback) OVERRIDE; | 41 const StatusCallback& callback) OVERRIDE; |
| 42 virtual void Truncate(const FilePath& file_path, | 42 virtual void Truncate(const base::FilePath& file_path, |
| 43 int64 length, | 43 int64 length, |
| 44 const StatusCallback& callback) OVERRIDE; | 44 const StatusCallback& callback) OVERRIDE; |
| 45 // This FS ignores last_access_time. | 45 // This FS ignores last_access_time. |
| 46 virtual void Touch(const FilePath& file_path, | 46 virtual void Touch(const base::FilePath& file_path, |
| 47 const base::Time& last_access_time, | 47 const base::Time& last_access_time, |
| 48 const base::Time& last_modified_time, | 48 const base::Time& last_modified_time, |
| 49 const StatusCallback& callback) OVERRIDE; | 49 const StatusCallback& callback) OVERRIDE; |
| 50 virtual void Remove(const FilePath& file_path, | 50 virtual void Remove(const base::FilePath& file_path, |
| 51 bool recursive, | 51 bool recursive, |
| 52 const StatusCallback& callback) OVERRIDE; | 52 const StatusCallback& callback) OVERRIDE; |
| 53 virtual void CreateDirectory(const FilePath& dir_path, | 53 virtual void CreateDirectory(const base::FilePath& dir_path, |
| 54 const StatusCallback& callback) OVERRIDE; | 54 const StatusCallback& callback) OVERRIDE; |
| 55 virtual void ReadDirectory(const FilePath& dir_path, | 55 virtual void ReadDirectory(const base::FilePath& dir_path, |
| 56 const ReadDirectoryCallback& callback) OVERRIDE; | 56 const ReadDirectoryCallback& callback) OVERRIDE; |
| 57 | 57 |
| 58 private: | 58 private: |
| 59 friend class MemoryFileUtilTest; | 59 friend class MemoryFileUtilTest; |
| 60 | 60 |
| 61 typedef std::map<FilePath, FileEntry>::iterator FileIterator; | 61 typedef std::map<base::FilePath, FileEntry>::iterator FileIterator; |
| 62 typedef std::map<FilePath, FileEntry>::const_iterator ConstFileIterator; | 62 typedef std::map<base::FilePath, FileEntry>::const_iterator ConstFileIterator; |
| 63 | 63 |
| 64 // Returns true if the given |file_path| is present in the file system. | 64 // Returns true if the given |file_path| is present in the file system. |
| 65 bool FileExists(const FilePath& file_path) const { | 65 bool FileExists(const base::FilePath& file_path) const { |
| 66 return files_.find(file_path) != files_.end(); | 66 return files_.find(file_path) != files_.end(); |
| 67 } | 67 } |
| 68 | 68 |
| 69 // Returns true if the given |file_path| is present and a directory. | 69 // Returns true if the given |file_path| is present and a directory. |
| 70 bool IsDirectory(const FilePath& file_path) const { | 70 bool IsDirectory(const base::FilePath& file_path) const { |
| 71 ConstFileIterator it = files_.find(file_path); | 71 ConstFileIterator it = files_.find(file_path); |
| 72 return it != files_.end() && it->second.is_directory; | 72 return it != files_.end() && it->second.is_directory; |
| 73 } | 73 } |
| 74 | 74 |
| 75 // Callback function used to implement GetFileInfo(). | 75 // Callback function used to implement GetFileInfo(). |
| 76 void DoGetFileInfo(const FilePath& file_path, | 76 void DoGetFileInfo(const base::FilePath& file_path, |
| 77 const GetFileInfoCallback& callback); | 77 const GetFileInfoCallback& callback); |
| 78 | 78 |
| 79 // Callback function used to implement Create(). | 79 // Callback function used to implement Create(). |
| 80 void DoCreate(const FilePath& file_path, | 80 void DoCreate(const base::FilePath& file_path, |
| 81 bool is_directory, | 81 bool is_directory, |
| 82 const StatusCallback& callback); | 82 const StatusCallback& callback); |
| 83 | 83 |
| 84 // Callback function used to implement Truncate(). | 84 // Callback function used to implement Truncate(). |
| 85 void DoTruncate(const FilePath& file_path, | 85 void DoTruncate(const base::FilePath& file_path, |
| 86 int64 length, | 86 int64 length, |
| 87 const StatusCallback& callback); | 87 const StatusCallback& callback); |
| 88 | 88 |
| 89 // Callback function used to implement Touch(). | 89 // Callback function used to implement Touch(). |
| 90 void DoTouch(const FilePath& file_path, | 90 void DoTouch(const base::FilePath& file_path, |
| 91 const base::Time& last_modified_time, | 91 const base::Time& last_modified_time, |
| 92 const StatusCallback& callback); | 92 const StatusCallback& callback); |
| 93 | 93 |
| 94 // Callback function used to implement Remove(). | 94 // Callback function used to implement Remove(). |
| 95 void DoRemoveSingleFile(const FilePath& file_path, | 95 void DoRemoveSingleFile(const base::FilePath& file_path, |
| 96 const StatusCallback& callback); | 96 const StatusCallback& callback); |
| 97 | 97 |
| 98 // Callback function used to implement Remove(). | 98 // Callback function used to implement Remove(). |
| 99 void DoRemoveRecursive(const FilePath& file_path, | 99 void DoRemoveRecursive(const base::FilePath& file_path, |
| 100 const StatusCallback& callback); | 100 const StatusCallback& callback); |
| 101 | 101 |
| 102 // Will start enumerating with file path |from|. If |from| path is | 102 // Will start enumerating with file path |from|. If |from| path is |
| 103 // empty, will start from the beginning. | 103 // empty, will start from the beginning. |
| 104 void DoReadDirectory(const FilePath& dir_path, | 104 void DoReadDirectory(const base::FilePath& dir_path, |
| 105 const FilePath& from, | 105 const base::FilePath& from, |
| 106 const ReadDirectoryCallback& callback); | 106 const ReadDirectoryCallback& callback); |
| 107 | 107 |
| 108 // Opens a file of the given |file_path| with |flags|. A file is | 108 // Opens a file of the given |file_path| with |flags|. A file is |
| 109 // guaranteed to be present at |file_path|. | 109 // guaranteed to be present at |file_path|. |
| 110 void OpenVerifiedFile(const FilePath& file_path, | 110 void OpenVerifiedFile(const base::FilePath& file_path, |
| 111 int flags, | 111 int flags, |
| 112 const OpenCallback& callback); | 112 const OpenCallback& callback); |
| 113 | 113 |
| 114 // Callback function used to implement Open(). | 114 // Callback function used to implement Open(). |
| 115 void DidGetFileInfoForOpen(const FilePath& file_path, | 115 void DidGetFileInfoForOpen(const base::FilePath& file_path, |
| 116 int flags, | 116 int flags, |
| 117 const OpenCallback& callback, | 117 const OpenCallback& callback, |
| 118 PlatformFileError get_info_result, | 118 PlatformFileError get_info_result, |
| 119 const base::PlatformFileInfo& file_info); | 119 const base::PlatformFileInfo& file_info); |
| 120 | 120 |
| 121 // Callback function used to implement Open(). | 121 // Callback function used to implement Open(). |
| 122 void OpenTruncatedFileOrCreate(const FilePath& file_path, | 122 void OpenTruncatedFileOrCreate(const base::FilePath& file_path, |
| 123 int flags, | 123 int flags, |
| 124 const OpenCallback& callback, | 124 const OpenCallback& callback, |
| 125 PlatformFileError result); | 125 PlatformFileError result); |
| 126 | 126 |
| 127 // Callback function used to implement Open(). | 127 // Callback function used to implement Open(). |
| 128 void DidCreateOrTruncateForOpen(const FilePath& file_path, | 128 void DidCreateOrTruncateForOpen(const base::FilePath& file_path, |
| 129 int flags, | 129 int flags, |
| 130 int64 size, | 130 int64 size, |
| 131 const OpenCallback& callback, | 131 const OpenCallback& callback, |
| 132 PlatformFileError result); | 132 PlatformFileError result); |
| 133 | 133 |
| 134 // Sets the read directory size buffer. | 134 // Sets the read directory size buffer. |
| 135 // Mainly for the purpose of testing. | 135 // Mainly for the purpose of testing. |
| 136 void set_read_directory_buffer_size(size_t size) { | 136 void set_read_directory_buffer_size(size_t size) { |
| 137 read_directory_buffer_size_ = size; | 137 read_directory_buffer_size_ = size; |
| 138 } | 138 } |
| 139 | 139 |
| 140 // The files in the file system. | 140 // The files in the file system. |
| 141 std::map<FilePath, FileEntry> files_; | 141 std::map<base::FilePath, FileEntry> files_; |
| 142 size_t read_directory_buffer_size_; | 142 size_t read_directory_buffer_size_; |
| 143 std::vector<DirectoryEntry> read_directory_buffer_; | 143 std::vector<DirectoryEntry> read_directory_buffer_; |
| 144 | 144 |
| 145 DISALLOW_COPY_AND_ASSIGN(MemoryFileUtil); | 145 DISALLOW_COPY_AND_ASSIGN(MemoryFileUtil); |
| 146 }; | 146 }; |
| 147 | 147 |
| 148 } // namespace fileapi | 148 } // namespace fileapi |
| 149 | 149 |
| 150 #endif // WEBKIT_CHROMEOS_FILEAPI_FILE_SYSTEM_FILE_UTIL_ASYNC_H_ | 150 #endif // WEBKIT_CHROMEOS_FILEAPI_FILE_SYSTEM_FILE_UTIL_ASYNC_H_ |
| OLD | NEW |