Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 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_FILEAPI_FILE_SYSTEM_FILE_UTIL_ASYNC_H_ | |
| 6 #define WEBKIT_FILEAPI_FILE_SYSTEM_FILE_UTIL_ASYNC_H_ | |
| 7 | |
| 8 #include "base/callback.h" | |
| 9 #include "base/file_util_proxy.h" | |
| 10 #include "base/platform_file.h" | |
| 11 #include "webkit/chromeos/fileapi/async_file_stream.h" | |
| 12 | |
| 13 namespace fileapi { | |
| 14 | |
| 15 using base::PlatformFileError; | |
| 16 | |
| 17 // The implementation of this base class should override all the pure virtual | |
| 18 // methods and one of the following 3 choices: | |
| 19 // - Read() & Write() | |
| 20 // - OpenVerifiedFile() | |
| 21 // - Open() | |
| 22 // Read() & Write() are the easiest to implement, but in that case | |
| 23 // the FileUtilAsync implementation does not have any "opened file" entity. | |
| 24 // OpenVerifiedFile() will allow to overload FileSystemAsyncFileStream, making | |
| 25 // it possible to hold some handle for an open file, like PlatformFile*. | |
| 26 // Open() is the same as OpenVerifiedFile(), but in its case the implementation | |
| 27 // is responsible for all the checks. It is preferrable in the case of remote | |
| 28 // operation when it is possible to batch several checks into one query. | |
| 29 class FileUtilAsync { | |
| 30 public: | |
| 31 typedef base::FileUtilProxy::Entry DirectoryEntry; | |
| 32 | |
| 33 typedef base::Callback<void( | |
| 34 PlatformFileError, | |
| 35 const base::PlatformFileInfo&)> GetFileInfoCallback; | |
| 36 | |
| 37 // AsyncFileStream is reference-counted. | |
| 38 typedef base::Callback<void( | |
| 39 PlatformFileError, | |
| 40 AsyncFileStream*)> OpenCallback; | |
| 41 | |
| 42 typedef std::vector<DirectoryEntry> FileList; | |
| 43 | |
| 44 typedef base::Callback<void( | |
| 45 PlatformFileError, | |
| 46 const FileList&, | |
| 47 bool // true if completed | |
| 48 )> ReadDirectoryCallback; | |
|
kinuko
2011/12/14 03:39:22
nit: weird indentation
satorux1
2011/12/14 04:43:26
Done.
| |
| 49 | |
| 50 virtual void GetFileInfo( | |
| 51 const FilePath& file_path, | |
| 52 const GetFileInfoCallback& callback) = 0; | |
| 53 | |
| 54 virtual void Create( | |
| 55 const FilePath& file_path, | |
| 56 const StatusCallback& callback) = 0; | |
| 57 | |
| 58 virtual void Truncate( | |
| 59 const FilePath& file_path, | |
| 60 int64 length, | |
| 61 const StatusCallback& callback) = 0; | |
| 62 | |
| 63 virtual void Touch( | |
| 64 const FilePath& file_path, | |
| 65 const base::Time& last_access_time, | |
| 66 const base::Time& last_modified_time, | |
| 67 const StatusCallback& callback) = 0; | |
| 68 | |
| 69 virtual void Remove( | |
| 70 const FilePath& file_path, | |
| 71 bool recursive, | |
| 72 const StatusCallback& callback) = 0; | |
| 73 | |
| 74 virtual void Open( | |
| 75 const FilePath& file_path, | |
| 76 int file_flags, // PlatformFileFlags | |
| 77 const OpenCallback& callback); | |
| 78 | |
| 79 virtual void CreateDirectory( | |
| 80 const FilePath& dir_path, | |
| 81 const StatusCallback& callback) = 0; | |
| 82 | |
| 83 // The ReadDirectoryCallback may be called several times, returning the | |
| 84 // portions of the whole directory listing. The reference to vector with | |
| 85 // DirectoryEntry objects, passed to callback is guaranteed to contain the | |
| 86 // reults of the operation only while callback is running. | |
| 87 // | |
| 88 // The implementations of FileUtilAsync should be careful to populate the | |
| 89 // vector on the same thread, on which the callback is called. Otherwise, | |
| 90 // if callback is called through PostTask, the data might get overwritten | |
| 91 // before callback is actually called. | |
| 92 // | |
| 93 // TODO(olege): Maybe make it possible to read only a part of the directory. | |
| 94 virtual void ReadDirectory( | |
| 95 const FilePath& dir_path, | |
| 96 const ReadDirectoryCallback& callback) = 0; | |
| 97 | |
| 98 // TODO(olege): Add LocalCopy and LocalMove. | |
| 99 | |
| 100 protected: | |
| 101 FileUtilAsync(); | |
| 102 | |
| 103 virtual void Write( | |
| 104 const FilePath& file_path, | |
| 105 int64 offset, | |
| 106 const char* data, | |
| 107 int64 length, | |
| 108 const ReadWriteCallback& callback) { | |
| 109 NOTREACHED(); | |
| 110 } | |
| 111 | |
| 112 virtual void Read( | |
| 113 const FilePath& file_path, | |
| 114 int64 offset, | |
| 115 char* buffer, | |
| 116 int64 length, | |
| 117 const ReadWriteCallback& callback) { | |
| 118 NOTREACHED(); | |
| 119 } | |
| 120 | |
| 121 virtual void OpenVerifiedFile( | |
| 122 const FilePath& file_path, | |
| 123 int flags, | |
| 124 const OpenCallback& callback); | |
| 125 | |
| 126 private: | |
| 127 friend class FileUtilAsyncFileStream; | |
| 128 | |
| 129 void DidGetFileInfoForOpen( | |
| 130 const FilePath& file_path, | |
| 131 int flags, | |
| 132 const OpenCallback& callback, | |
| 133 PlatformFileError get_info_res, | |
| 134 const base::PlatformFileInfo& file_info); | |
| 135 | |
| 136 void OpenTruncatedFileOrCreate( | |
| 137 const FilePath& file_path, | |
| 138 int flags, | |
| 139 const OpenCallback& callback, | |
| 140 PlatformFileError res); | |
| 141 | |
| 142 void DidCreateOrTruncateForOpen( | |
| 143 const FilePath& file_path, | |
| 144 int flags, | |
| 145 int64 size, | |
| 146 const OpenCallback& callback, | |
| 147 PlatformFileError res); | |
| 148 | |
| 149 void ReturnOpenError(PlatformFileError error, | |
| 150 const OpenCallback& callback); | |
| 151 | |
| 152 DISALLOW_COPY_AND_ASSIGN(FileUtilAsync); | |
| 153 }; | |
| 154 | |
| 155 } | |
| 156 | |
| 157 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_FILE_UTIL_ASYNC_H_ | |
| OLD | NEW |