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..eaf12d128499b8e115c001358fef67e4e52abfaa |
| --- /dev/null |
| +++ b/webkit/chromeos/fileapi/file_util_async.h |
| @@ -0,0 +1,120 @@ |
| +// 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 implementation of this base class should override all the pure virtual |
| +// methods and OpenVerifiedFile(). |
| +class FileUtilAsync { |
| + public: |
| + typedef base::FileUtilProxy::Entry DirectoryEntry; |
| + |
| + // 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; |
| + |
| + typedef base::Callback<void( |
| + PlatformFileError error, |
| + const FileList& file_list, |
| + // True if completed. |
| + bool success)> ReadDirectoryCallback; |
| + |
| + virtual void GetFileInfo(const FilePath& file_path, |
| + const GetFileInfoCallback& callback) = 0; |
| + |
| + virtual void Create(const FilePath& file_path, |
| + const StatusCallback& callback) = 0; |
| + |
| + virtual void Truncate(const FilePath& file_path, |
| + int64 length, |
| + const StatusCallback& callback) = 0; |
| + |
| + virtual void Touch(const FilePath& file_path, |
| + const base::Time& last_access_time, |
| + const base::Time& last_modified_time, |
| + const StatusCallback& callback) = 0; |
| + |
| + virtual void Remove(const FilePath& file_path, |
| + bool recursive, |
|
satorux1
2011/12/14 08:27:03
Use of boolean parameter like this is discouraged
satorux1
2011/12/14 08:55:32
Introduced RemoveMode.
Oleg Eterevsky
2011/12/14 15:20:59
Just want to note that boolean here is consistent
|
| + const StatusCallback& callback) = 0; |
| + |
| + void Open(const FilePath& file_path, |
| + int file_flags, // PlatformFileFlags |
| + const OpenCallback& callback); |
| + |
| + virtual void CreateDirectory(const FilePath& dir_path, |
| + const StatusCallback& callback) = 0; |
| + |
| + // 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 |
| + // reults 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. |
| + |
| + protected: |
| + FileUtilAsync(); |
| + |
| + virtual void OpenVerifiedFile(const FilePath& file_path, |
| + int flags, |
| + const OpenCallback& callback) = 0; |
| + |
| + private: |
| + friend class FileUtilAsyncFileStream; |
| + |
| + void DidGetFileInfoForOpen(const FilePath& file_path, |
| + int flags, |
| + const OpenCallback& callback, |
| + PlatformFileError get_info_result, |
| + const base::PlatformFileInfo& file_info); |
| + |
| + void OpenTruncatedFileOrCreate(const FilePath& file_path, |
| + int flags, |
| + const OpenCallback& callback, |
| + PlatformFileError result); |
| + |
| + void DidCreateOrTruncateForOpen(const FilePath& file_path, |
| + int flags, |
| + int64 size, |
| + const OpenCallback& callback, |
| + PlatformFileError result); |
| + |
| + DISALLOW_COPY_AND_ASSIGN(FileUtilAsync); |
| +}; |
| + |
| +} |
| + |
| +#endif // WEBKIT_CHROMEOS_FILEAPI_FILE_SYSTEM_FILE_UTIL_ASYNC_H_ |