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 implementation of this base class should override all the pure virtual | |
| 18 // methods and OpenVerifiedFile(). | |
| 19 class FileUtilAsync { | |
| 20 public: | |
| 21 typedef base::FileUtilProxy::Entry DirectoryEntry; | |
| 22 | |
| 23 // Used for GetFileInfo(). |result| is the return code of the operation, | |
| 24 // and |file_info| is the obtained file info. | |
| 25 typedef base::Callback<void( | |
| 26 PlatformFileError result, | |
| 27 const base::PlatformFileInfo& file_info)> GetFileInfoCallback; | |
| 28 | |
| 29 // Used for Create(), etc. |result| is the return code of the operation. | |
| 30 typedef base::Callback<void(PlatformFileError)> StatusCallback; | |
| 31 | |
| 32 // Used for Open(). |result| is the return code of the operation, and | |
| 33 // |stream| is the stream of the opened file. | |
| 34 typedef base::Callback<void( | |
| 35 PlatformFileError result, | |
| 36 AsyncFileStream* stream)> OpenCallback; | |
| 37 | |
| 38 typedef std::vector<DirectoryEntry> FileList; | |
| 39 | |
| 40 typedef base::Callback<void( | |
| 41 PlatformFileError error, | |
| 42 const FileList& file_list, | |
| 43 // True if completed. | |
| 44 bool success)> ReadDirectoryCallback; | |
| 45 | |
| 46 virtual void GetFileInfo(const FilePath& file_path, | |
| 47 const GetFileInfoCallback& callback) = 0; | |
| 48 | |
| 49 virtual void Create(const FilePath& file_path, | |
| 50 const StatusCallback& callback) = 0; | |
| 51 | |
| 52 virtual void Truncate(const FilePath& file_path, | |
| 53 int64 length, | |
| 54 const StatusCallback& callback) = 0; | |
| 55 | |
| 56 virtual void Touch(const FilePath& file_path, | |
| 57 const base::Time& last_access_time, | |
| 58 const base::Time& last_modified_time, | |
| 59 const StatusCallback& callback) = 0; | |
| 60 | |
| 61 virtual void Remove(const FilePath& file_path, | |
| 62 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
| |
| 63 const StatusCallback& callback) = 0; | |
| 64 | |
| 65 void Open(const FilePath& file_path, | |
| 66 int file_flags, // PlatformFileFlags | |
| 67 const OpenCallback& callback); | |
| 68 | |
| 69 virtual void CreateDirectory(const FilePath& dir_path, | |
| 70 const StatusCallback& callback) = 0; | |
| 71 | |
| 72 // The ReadDirectoryCallback may be called several times, returning the | |
| 73 // portions of the whole directory listing. The reference to vector with | |
| 74 // DirectoryEntry objects, passed to callback is guaranteed to contain the | |
| 75 // reults of the operation only while callback is running. | |
| 76 // | |
| 77 // The implementations of FileUtilAsync should be careful to populate the | |
| 78 // vector on the same thread, on which the callback is called. Otherwise, | |
| 79 // if callback is called through PostTask, the data might get overwritten | |
| 80 // before callback is actually called. | |
| 81 // | |
| 82 // TODO(olege): Maybe make it possible to read only a part of the directory. | |
| 83 virtual void ReadDirectory(const FilePath& dir_path, | |
| 84 const ReadDirectoryCallback& callback) = 0; | |
| 85 | |
| 86 // TODO(olege): Add LocalCopy and LocalMove. | |
| 87 | |
| 88 protected: | |
| 89 FileUtilAsync(); | |
| 90 | |
| 91 virtual void OpenVerifiedFile(const FilePath& file_path, | |
| 92 int flags, | |
| 93 const OpenCallback& callback) = 0; | |
| 94 | |
| 95 private: | |
| 96 friend class FileUtilAsyncFileStream; | |
| 97 | |
| 98 void DidGetFileInfoForOpen(const FilePath& file_path, | |
| 99 int flags, | |
| 100 const OpenCallback& callback, | |
| 101 PlatformFileError get_info_result, | |
| 102 const base::PlatformFileInfo& file_info); | |
| 103 | |
| 104 void OpenTruncatedFileOrCreate(const FilePath& file_path, | |
| 105 int flags, | |
| 106 const OpenCallback& callback, | |
| 107 PlatformFileError result); | |
| 108 | |
| 109 void DidCreateOrTruncateForOpen(const FilePath& file_path, | |
| 110 int flags, | |
| 111 int64 size, | |
| 112 const OpenCallback& callback, | |
| 113 PlatformFileError result); | |
| 114 | |
| 115 DISALLOW_COPY_AND_ASSIGN(FileUtilAsync); | |
| 116 }; | |
| 117 | |
| 118 } | |
| 119 | |
| 120 #endif // WEBKIT_CHROMEOS_FILEAPI_FILE_SYSTEM_FILE_UTIL_ASYNC_H_ | |
| OLD | NEW |