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_CHROMEOS_FILEAPI_FILE_SYSTEM_FILE_UTIL_ASYNC_H_ | |
| 6 #define WEBKIT_CHROMEOS_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 interface class of asynchronous file utils. All functions are pure | |
| 18 // virtual. | |
| 19 class FileUtilAsync { | |
| 20 public: | |
| 21 virtual ~FileUtilAsync() {} | |
| 22 | |
| 23 typedef base::FileUtilProxy::Entry DirectoryEntry; | |
| 24 | |
| 25 // The mode used for Remove(). | |
| 26 enum RemoveMode { | |
| 27 SINGLE, | |
| 28 RECURSIVE, | |
| 29 }; | |
| 30 | |
| 31 // Used for GetFileInfo(). |result| is the return code of the operation, | |
| 32 // and |file_info| is the obtained file info. | |
| 33 typedef base::Callback<void( | |
| 34 PlatformFileError result, | |
| 35 const base::PlatformFileInfo& file_info)> GetFileInfoCallback; | |
| 36 | |
| 37 // Used for Create(), etc. |result| is the return code of the operation. | |
| 38 typedef base::Callback<void(PlatformFileError)> StatusCallback; | |
| 39 | |
| 40 // Used for Open(). |result| is the return code of the operation, and | |
| 41 // |stream| is the stream of the opened file. | |
| 42 typedef base::Callback<void( | |
| 43 PlatformFileError result, | |
| 44 AsyncFileStream* stream)> OpenCallback; | |
| 45 | |
| 46 typedef std::vector<DirectoryEntry> FileList; | |
| 47 | |
| 48 // Used for ReadDirectoryCallback(). |result| is the return code of the | |
| 49 // operation, |file_list| is the list of files read, and |completed| is | |
| 50 // true if all files are read. | |
| 51 typedef base::Callback<void( | |
| 52 PlatformFileError result, | |
| 53 const FileList& file_list, | |
| 54 bool completed)> ReadDirectoryCallback; | |
| 55 | |
| 56 // Opens a file of the given |file_path| with |flags|. On success, | |
| 57 // PLATFORM_FILE_OK is passed to |callback| with a pointer to newly | |
| 58 // created AsyncFileStream object. The caller should delete the | |
| 59 // stream. On failure, an error code is passed instead. | |
| 60 virtual void Open(const FilePath& file_path, | |
| 61 int file_flags, // PlatformFileFlags | |
| 62 const OpenCallback& callback) = 0; | |
| 63 | |
| 64 // Gets file info of the given |file_path|. On success, | |
| 65 // PLATFORM_FILE_OK is passed to |callback| with the the obtained file | |
| 66 // info. On failure, an error code is passed instead. | |
| 67 virtual void GetFileInfo(const FilePath& file_path, | |
| 68 const GetFileInfoCallback& callback) = 0; | |
| 69 | |
| 70 // Creates a file of the given |file_path|. On success, | |
| 71 // PLATFORM_FILE_OK is passed to |callback|. On failure, an error code | |
| 72 // is passed instead. | |
| 73 virtual void Create(const FilePath& file_path, | |
| 74 const StatusCallback& callback) = 0; | |
| 75 | |
| 76 // Truncates a file of the given |file_path| to |length|. On success, | |
| 77 // PLATFORM_FILE_OK is passed to |callback|. On failure, an error code | |
| 78 // is passed instead. | |
| 79 virtual void Truncate(const FilePath& file_path, | |
| 80 int64 length, | |
| 81 const StatusCallback& callback) = 0; | |
| 82 | |
| 83 // Modifies the timestamps of a file of the given |file_path|. On | |
| 84 // success, PLATFORM_FILE_OK is passed to |callback|. On failure, an | |
| 85 // error code is passed instead. | |
| 86 virtual void Touch(const FilePath& file_path, | |
| 87 const base::Time& last_access_time, | |
| 88 const base::Time& last_modified_time, | |
| 89 const StatusCallback& callback) = 0; | |
| 90 | |
| 91 // Removes a file or directory of the given |file_path|. If RECURSIVE | |
| 92 // 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.
| |
| 93 // recursively. On success, PLATFORM_FILE_OK is passed to |callback|. On | |
| 94 // failure, an error code is passed instead. | |
| 95 virtual void Remove(const FilePath& file_path, | |
| 96 RemoveMode mode, | |
| 97 const StatusCallback& callback) = 0; | |
| 98 | |
| 99 // Creates a directory of the given |dir_path|. On success, | |
| 100 // PLATFORM_FILE_OK is passed to |callback|. On failure, an error code | |
| 101 // is passed instead. | |
| 102 virtual void CreateDirectory(const FilePath& dir_path, | |
| 103 const StatusCallback& callback) = 0; | |
| 104 | |
| 105 // Reads a directory of the given |dir_path|. On success, | |
| 106 // PLATFORM_FILE_OK is passed to |callback| with the list of files, and | |
| 107 // a boolean value indicating if all files are read. On failure, an | |
| 108 // error code is passed instead. | |
| 109 // | |
| 110 // The ReadDirectoryCallback may be called several times, returning the | |
| 111 // portions of the whole directory listing. The reference to vector with | |
| 112 // DirectoryEntry objects, passed to callback is guaranteed to contain the | |
| 113 // results of the operation only while callback is running. | |
| 114 // | |
| 115 // The implementations of FileUtilAsync should be careful to populate the | |
| 116 // vector on the same thread, on which the callback is called. Otherwise, | |
| 117 // if callback is called through PostTask, the data might get overwritten | |
| 118 // before callback is actually called. | |
| 119 // | |
| 120 // TODO(olege): Maybe make it possible to read only a part of the directory. | |
| 121 virtual void ReadDirectory(const FilePath& dir_path, | |
| 122 const ReadDirectoryCallback& callback) = 0; | |
| 123 | |
| 124 // TODO(olege): Add LocalCopy and LocalMove. | |
| 125 }; | |
| 126 | |
| 127 } // fileapi | |
| 128 | |
| 129 #endif // WEBKIT_CHROMEOS_FILEAPI_FILE_SYSTEM_FILE_UTIL_ASYNC_H_ | |
| OLD | NEW |