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..c1950e7d6fe9879049a8bd16ae8ea81b36b68619 |
| --- /dev/null |
| +++ b/webkit/chromeos/fileapi/file_util_async.h |
| @@ -0,0 +1,157 @@ |
| +// 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_ASYNC_H_ |
| +#define WEBKIT_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 one of the following 3 choices: |
| +// - Read() & Write() |
| +// - OpenVerifiedFile() |
| +// - Open() |
| +// Read() & Write() are the easiest to implement, but in that case |
| +// the FileUtilAsync implementation does not have any "opened file" entity. |
| +// OpenVerifiedFile() will allow to overload FileSystemAsyncFileStream, making |
| +// it possible to hold some handle for an open file, like PlatformFile*. |
| +// Open() is the same as OpenVerifiedFile(), but in its case the implementation |
| +// is responsible for all the checks. It is preferrable in the case of remote |
| +// operation when it is possible to batch several checks into one query. |
| +class FileUtilAsync { |
| + public: |
| + typedef base::FileUtilProxy::Entry DirectoryEntry; |
| + |
| + typedef base::Callback<void( |
| + PlatformFileError, |
| + const base::PlatformFileInfo&)> GetFileInfoCallback; |
| + |
| + // AsyncFileStream is reference-counted. |
| + typedef base::Callback<void( |
| + PlatformFileError, |
| + AsyncFileStream*)> OpenCallback; |
| + |
| + typedef std::vector<DirectoryEntry> FileList; |
| + |
| + typedef base::Callback<void( |
| + PlatformFileError, |
| + const FileList&, |
| + bool // true if completed |
| + )> ReadDirectoryCallback; |
|
kinuko
2011/12/14 03:39:22
nit: weird indentation
satorux1
2011/12/14 04:43:26
Done.
|
| + |
| + 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, |
| + const StatusCallback& callback) = 0; |
| + |
| + virtual 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 Write( |
| + const FilePath& file_path, |
| + int64 offset, |
| + const char* data, |
| + int64 length, |
| + const ReadWriteCallback& callback) { |
| + NOTREACHED(); |
| + } |
| + |
| + virtual void Read( |
| + const FilePath& file_path, |
| + int64 offset, |
| + char* buffer, |
| + int64 length, |
| + const ReadWriteCallback& callback) { |
| + NOTREACHED(); |
| + } |
| + |
| + virtual void OpenVerifiedFile( |
| + const FilePath& file_path, |
| + int flags, |
| + const OpenCallback& callback); |
| + |
| + private: |
| + friend class FileUtilAsyncFileStream; |
| + |
| + void DidGetFileInfoForOpen( |
| + const FilePath& file_path, |
| + int flags, |
| + const OpenCallback& callback, |
| + PlatformFileError get_info_res, |
| + const base::PlatformFileInfo& file_info); |
| + |
| + void OpenTruncatedFileOrCreate( |
| + const FilePath& file_path, |
| + int flags, |
| + const OpenCallback& callback, |
| + PlatformFileError res); |
| + |
| + void DidCreateOrTruncateForOpen( |
| + const FilePath& file_path, |
| + int flags, |
| + int64 size, |
| + const OpenCallback& callback, |
| + PlatformFileError res); |
| + |
| + void ReturnOpenError(PlatformFileError error, |
| + const OpenCallback& callback); |
| + |
| + DISALLOW_COPY_AND_ASSIGN(FileUtilAsync); |
| +}; |
| + |
| +} |
| + |
| +#endif // WEBKIT_FILEAPI_FILE_SYSTEM_FILE_UTIL_ASYNC_H_ |