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

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

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

Powered by Google App Engine
This is Rietveld 408576698