Chromium Code Reviews| Index: webkit/chromeos/fileapi/file_util_async.h |
| diff --git a/webkit/chromeos/fileapi/file_util_async.h b/webkit/chromeos/fileapi/file_util_async.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..4e4dce41db2bf96432e30613b882d33e0058d6b8 |
| --- /dev/null |
| +++ b/webkit/chromeos/fileapi/file_util_async.h |
| @@ -0,0 +1,129 @@ |
| +// 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_CHROMEOS_FILEAPI_FILE_SYSTEM_FILE_UTIL_ASYNC_H_ |
| +#define WEBKIT_CHROMEOS_FILEAPI_FILE_SYSTEM_FILE_UTIL_ASYNC_H_ |
| + |
| +#include "base/callback.h" |
| +#include "base/file_util_proxy.h" |
| +#include "base/platform_file.h" |
| +#include "webkit/chromeos/fileapi/async_file_stream.h" |
| + |
| +namespace fileapi { |
| + |
| +using base::PlatformFileError; |
| + |
| +// The interface class of asynchronous file utils. All functions are pure |
| +// virtual. |
| +class FileUtilAsync { |
| + public: |
| + virtual ~FileUtilAsync() {} |
| + |
| + typedef base::FileUtilProxy::Entry DirectoryEntry; |
| + |
| + // The mode used for Remove(). |
| + enum RemoveMode { |
| + SINGLE, |
| + RECURSIVE, |
| + }; |
| + |
| + // Used for GetFileInfo(). |result| is the return code of the operation, |
| + // and |file_info| is the obtained file info. |
| + typedef base::Callback<void( |
| + PlatformFileError result, |
| + const base::PlatformFileInfo& file_info)> GetFileInfoCallback; |
| + |
| + // Used for Create(), etc. |result| is the return code of the operation. |
| + typedef base::Callback<void(PlatformFileError)> StatusCallback; |
| + |
| + // Used for Open(). |result| is the return code of the operation, and |
| + // |stream| is the stream of the opened file. |
| + typedef base::Callback<void( |
| + PlatformFileError result, |
| + AsyncFileStream* stream)> OpenCallback; |
| + |
| + typedef std::vector<DirectoryEntry> FileList; |
| + |
| + // Used for ReadDirectoryCallback(). |result| is the return code of the |
| + // operation, |file_list| is the list of files read, and |completed| is |
| + // true if all files are read. |
| + typedef base::Callback<void( |
| + PlatformFileError result, |
| + const FileList& file_list, |
| + bool completed)> ReadDirectoryCallback; |
| + |
| + // Opens a file of the given |file_path| with |flags|. On success, |
| + // PLATFORM_FILE_OK is passed to |callback| with a pointer to newly |
| + // created AsyncFileStream object. The caller should delete the |
| + // stream. On failure, an error code is passed instead. |
| + virtual void Open(const FilePath& file_path, |
| + int file_flags, // PlatformFileFlags |
| + const OpenCallback& callback) = 0; |
| + |
| + // Gets file info of the given |file_path|. On success, |
| + // PLATFORM_FILE_OK is passed to |callback| with the the obtained file |
| + // info. On failure, an error code is passed instead. |
| + virtual void GetFileInfo(const FilePath& file_path, |
| + const GetFileInfoCallback& callback) = 0; |
| + |
| + // Creates a file of the given |file_path|. On success, |
| + // PLATFORM_FILE_OK is passed to |callback|. On failure, an error code |
| + // is passed instead. |
| + virtual void Create(const FilePath& file_path, |
| + const StatusCallback& callback) = 0; |
| + |
| + // Truncates a file of the given |file_path| to |length|. On success, |
| + // PLATFORM_FILE_OK is passed to |callback|. On failure, an error code |
| + // is passed instead. |
| + virtual void Truncate(const FilePath& file_path, |
| + int64 length, |
| + const StatusCallback& callback) = 0; |
| + |
| + // Modifies the timestamps of a file of the given |file_path|. On |
| + // success, PLATFORM_FILE_OK is passed to |callback|. On failure, an |
| + // error code is passed instead. |
| + virtual void Touch(const FilePath& file_path, |
| + const base::Time& last_access_time, |
| + const base::Time& last_modified_time, |
| + const StatusCallback& callback) = 0; |
| + |
| + // Removes a file or directory of the given |file_path|. If RECURSIVE |
| + // option is set, remove the contents of the given directory |
|
kinuko
2011/12/14 11:19:13
nit: remove -> removes
satorux1
2011/12/15 04:38:05
Done.
|
| + // recursively. On success, PLATFORM_FILE_OK is passed to |callback|. On |
| + // failure, an error code is passed instead. |
| + virtual void Remove(const FilePath& file_path, |
| + RemoveMode mode, |
| + const StatusCallback& callback) = 0; |
| + |
| + // Creates a directory of the given |dir_path|. On success, |
| + // PLATFORM_FILE_OK is passed to |callback|. On failure, an error code |
| + // is passed instead. |
| + virtual void CreateDirectory(const FilePath& dir_path, |
| + const StatusCallback& callback) = 0; |
| + |
| + // Reads a directory of the given |dir_path|. On success, |
| + // PLATFORM_FILE_OK is passed to |callback| with the list of files, and |
| + // a boolean value indicating if all files are read. On failure, an |
| + // error code is passed instead. |
| + // |
| + // The ReadDirectoryCallback may be called several times, returning the |
| + // portions of the whole directory listing. The reference to vector with |
| + // DirectoryEntry objects, passed to callback is guaranteed to contain the |
| + // results of the operation only while callback is running. |
| + // |
| + // The implementations of FileUtilAsync should be careful to populate the |
| + // vector on the same thread, on which the callback is called. Otherwise, |
| + // if callback is called through PostTask, the data might get overwritten |
| + // before callback is actually called. |
| + // |
| + // TODO(olege): Maybe make it possible to read only a part of the directory. |
| + virtual void ReadDirectory(const FilePath& dir_path, |
| + const ReadDirectoryCallback& callback) = 0; |
| + |
| + // TODO(olege): Add LocalCopy and LocalMove. |
| +}; |
| + |
| +} // fileapi |
| + |
| +#endif // WEBKIT_CHROMEOS_FILEAPI_FILE_SYSTEM_FILE_UTIL_ASYNC_H_ |