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