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