Chromium Code Reviews| Index: webkit/chromeos/fileapi/memory_file_util.h |
| diff --git a/webkit/chromeos/fileapi/memory_file_util.h b/webkit/chromeos/fileapi/memory_file_util.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..02b889bb805df421d8af849f709aad3090f0b315 |
| --- /dev/null |
| +++ b/webkit/chromeos/fileapi/memory_file_util.h |
| @@ -0,0 +1,149 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef WEBKIT_FILEAPI_FILE_SYSTEM_FILE_UTIL_MEMORY_H_ |
| +#define WEBKIT_FILEAPI_FILE_SYSTEM_FILE_UTIL_MEMORY_H_ |
| + |
| +#include <map> |
| +#include <vector> |
| + |
| +#include "base/callback.h" |
| +#include "base/time.h" |
| +#include "webkit/chromeos/fileapi/file_util_async.h" |
| + |
| +namespace fileapi { |
| + |
| +// The in-memory file system. Primarily for the purpose of testing |
| +// FileUtilAsync. |
| +class MemoryFileUtil : public FileUtilAsync { |
| + public: |
| + MemoryFileUtil(const FilePath& root_path); |
| + |
| + virtual void GetFileInfo( |
| + const FilePath& file_path, |
| + const GetFileInfoCallback& callback) OVERRIDE; |
| + virtual void Create( |
| + const FilePath& file_path, |
| + const StatusCallback& callback) OVERRIDE; |
| + virtual void Truncate( |
| + const FilePath& file_path, |
| + int64 length, |
| + const StatusCallback& callback) OVERRIDE; |
| + // This FS ignores last_access_time. |
| + virtual void Touch( |
| + const FilePath& file_path, |
| + const base::Time& last_access_time, |
| + const base::Time& last_modified_time, |
| + const StatusCallback& callback) OVERRIDE; |
| + virtual void Remove( |
| + const FilePath& file_path, |
| + bool recursive, |
| + const StatusCallback& callback) OVERRIDE; |
| + virtual void CreateDirectory( |
| + const FilePath& dir_path, |
| + const StatusCallback& callback) OVERRIDE; |
| + virtual void ReadDirectory( |
| + const FilePath& dir_path, |
| + const ReadDirectoryCallback& callback) OVERRIDE; |
| + |
| + protected: |
| + virtual void Write( |
| + const FilePath& file_path, |
| + int64 offset, |
| + const char* data, |
| + int64 length, |
| + const ReadWriteCallback& callback) OVERRIDE; |
| + virtual void Read( |
| + const FilePath& file_path, |
| + int64 offset, |
| + char* buffer, |
| + int64 length, |
| + const ReadWriteCallback& callback) OVERRIDE; |
| + |
| + private: |
| + friend class MemoryFileUtilTest; |
| + |
| + struct FileEntry { |
| + bool is_directory; |
| + std::vector<char> contents; |
| + base::Time last_modified; |
| + }; |
| + |
| + typedef std::map<FilePath, FileEntry>::iterator FileIterator; |
| + typedef std::map<FilePath, FileEntry>::const_iterator ConstFileIterator; |
| + |
| + FileIterator GetFile(const FilePath& file_path) { |
| + return files_.find(file_path); |
| + } |
| + |
| + bool FileExists(const FilePath& file_path) { |
| + return files_.find(file_path) != files_.end(); |
| + } |
| + |
| + bool IsDirectory(const FilePath& file_path); |
| + |
| + void DoGetFileInfo( |
| + const FilePath& file_path, |
| + const GetFileInfoCallback& callback); |
| + |
| + void DoCreate( |
| + const FilePath& file_path, |
| + bool is_directory, |
| + const StatusCallback& callback); |
| + |
| + void DoTruncate( |
| + const FilePath& file_path, |
| + int64 length, |
| + const StatusCallback& callback); |
| + |
| + void DoTouch( |
| + const FilePath& file_path, |
| + const base::Time& last_modified_time, |
| + const StatusCallback& callback); |
| + |
| + void DoRemoveSingleFile( |
| + const FilePath& file_path, |
| + const StatusCallback& callback); |
| + |
| + void DoRemoveRecursive( |
| + const FilePath& file_path, |
| + const StatusCallback& callback); |
| + |
| + // Will start enumerating with file from. If |from" path is empty, will start |
| + // 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.
|
| + void DoReadDirectory( |
| + const FilePath& dir_path, |
| + FilePath from, |
|
kinuko
2011/12/14 03:39:22
const FilePath&
satorux1
2011/12/14 04:43:26
Done.
|
| + const ReadDirectoryCallback& callback); |
| + |
| + void DoRead( |
| + const FilePath& file_path, |
| + int64 offset, |
| + char* buffer, |
| + int64 length, |
| + const ReadWriteCallback& callback); |
| + |
| + void DoWrite( |
| + const FilePath& file_path, |
| + int64 offset, |
| + const char* data, |
| + int64 length, |
| + const ReadWriteCallback& callback); |
| + |
| + // Mainly for the purpose of testing. |
| + 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.
|
| + read_directory_buffer_size_ = size; |
| + } |
| + |
| + std::map<FilePath, FileEntry> files_; |
| + |
| + size_t read_directory_buffer_size_; |
| + std::vector<DirectoryEntry> read_directory_buffer_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(MemoryFileUtil); |
| +}; |
| + |
| +} |
| + |
| +#endif // WEBKIT_FILEAPI_FILE_SYSTEM_FILE_UTIL_ASYNC_H_ |