Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(287)

Side by Side Diff: webkit/chromeos/fileapi/memory_file_util.h

Issue 8907014: Implement async verision of FileSystemFileUtil and in-memory file system for testing purposes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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_FILEAPI_FILE_SYSTEM_FILE_UTIL_MEMORY_H_
6 #define WEBKIT_FILEAPI_FILE_SYSTEM_FILE_UTIL_MEMORY_H_
7
8 #include <map>
9 #include <vector>
10
11 #include "base/callback.h"
12 #include "base/time.h"
13 #include "webkit/chromeos/fileapi/file_util_async.h"
14
15 namespace fileapi {
16
17 // The in-memory file system. Primarily for the purpose of testing
18 // FileUtilAsync.
19 class MemoryFileUtil : public FileUtilAsync {
20 public:
21 MemoryFileUtil(const FilePath& root_path);
22
23 virtual void GetFileInfo(
24 const FilePath& file_path,
25 const GetFileInfoCallback& callback) OVERRIDE;
26 virtual void Create(
27 const FilePath& file_path,
28 const StatusCallback& callback) OVERRIDE;
29 virtual void Truncate(
30 const FilePath& file_path,
31 int64 length,
32 const StatusCallback& callback) OVERRIDE;
33 // This FS ignores last_access_time.
34 virtual void Touch(
35 const FilePath& file_path,
36 const base::Time& last_access_time,
37 const base::Time& last_modified_time,
38 const StatusCallback& callback) OVERRIDE;
39 virtual void Remove(
40 const FilePath& file_path,
41 bool recursive,
42 const StatusCallback& callback) OVERRIDE;
43 virtual void CreateDirectory(
44 const FilePath& dir_path,
45 const StatusCallback& callback) OVERRIDE;
46 virtual void ReadDirectory(
47 const FilePath& dir_path,
48 const ReadDirectoryCallback& callback) OVERRIDE;
49
50 protected:
51 virtual void Write(
52 const FilePath& file_path,
53 int64 offset,
54 const char* data,
55 int64 length,
56 const ReadWriteCallback& callback) OVERRIDE;
57 virtual void Read(
58 const FilePath& file_path,
59 int64 offset,
60 char* buffer,
61 int64 length,
62 const ReadWriteCallback& callback) OVERRIDE;
63
64 private:
65 friend class MemoryFileUtilTest;
66
67 struct FileEntry {
68 bool is_directory;
69 std::vector<char> contents;
70 base::Time last_modified;
71 };
72
73 typedef std::map<FilePath, FileEntry>::iterator FileIterator;
74 typedef std::map<FilePath, FileEntry>::const_iterator ConstFileIterator;
75
76 FileIterator GetFile(const FilePath& file_path) {
77 return files_.find(file_path);
78 }
79
80 bool FileExists(const FilePath& file_path) {
81 return files_.find(file_path) != files_.end();
82 }
83
84 bool IsDirectory(const FilePath& file_path);
85
86 void DoGetFileInfo(
87 const FilePath& file_path,
88 const GetFileInfoCallback& callback);
89
90 void DoCreate(
91 const FilePath& file_path,
92 bool is_directory,
93 const StatusCallback& callback);
94
95 void DoTruncate(
96 const FilePath& file_path,
97 int64 length,
98 const StatusCallback& callback);
99
100 void DoTouch(
101 const FilePath& file_path,
102 const base::Time& last_modified_time,
103 const StatusCallback& callback);
104
105 void DoRemoveSingleFile(
106 const FilePath& file_path,
107 const StatusCallback& callback);
108
109 void DoRemoveRecursive(
110 const FilePath& file_path,
111 const StatusCallback& callback);
112
113 // Will start enumerating with file from. If |from" path is empty, will start
114 // from the beginning.
kinuko 2011/12/14 03:39:22 Please surround the param names with | |. (from -
satorux1 2011/12/14 04:43:26 Done.
115 void DoReadDirectory(
116 const FilePath& dir_path,
117 FilePath from,
kinuko 2011/12/14 03:39:22 const FilePath&
satorux1 2011/12/14 04:43:26 Done.
118 const ReadDirectoryCallback& callback);
119
120 void DoRead(
121 const FilePath& file_path,
122 int64 offset,
123 char* buffer,
124 int64 length,
125 const ReadWriteCallback& callback);
126
127 void DoWrite(
128 const FilePath& file_path,
129 int64 offset,
130 const char* data,
131 int64 length,
132 const ReadWriteCallback& callback);
133
134 // Mainly for the purpose of testing.
135 void set_read_directory_buffer_size(int size) {
kinuko 2011/12/14 03:39:22 int -> size_t ?
satorux1 2011/12/14 04:43:26 Done.
136 read_directory_buffer_size_ = size;
137 }
138
139 std::map<FilePath, FileEntry> files_;
140
141 size_t read_directory_buffer_size_;
142 std::vector<DirectoryEntry> read_directory_buffer_;
143
144 DISALLOW_COPY_AND_ASSIGN(MemoryFileUtil);
145 };
146
147 }
148
149 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_FILE_UTIL_ASYNC_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698