Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(232)

Side by Side Diff: webkit/chromeos/fileapi/file_util_async.h

Issue 8907014: Implement async verision of FileSystemFileUtil and in-memory file system for testing purposes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « webkit/chromeos/fileapi/async_file_stream.h ('k') | webkit/chromeos/fileapi/file_util_async.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 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.
satorux1 2011/12/14 05:19:55 Discussed this with Kinuko. She suggested providin
Oleg Eterevsky 2011/12/14 15:20:59 In that case I suggest to move OpenVerifiedFile fr
satorux1 2011/12/15 00:32:00 Kinuko and I found it awkward to implement Read()
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 error,
46 const FileList& file_list,
47 // True if completed.
48 bool success)> ReadDirectoryCallback;
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 }
satorux1 2011/12/14 05:19:55 Discussed this with kinuko. Providing Read() and W
Oleg Eterevsky 2011/12/14 15:20:59 These Read() and Write() allow the implementation
satorux1 2011/12/15 00:32:00 Read and write operations are inherently associate
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 DISALLOW_COPY_AND_ASSIGN(FileUtilAsync);
150 };
151
152 }
153
154 #endif // WEBKIT_CHROMEOS_FILEAPI_FILE_SYSTEM_FILE_UTIL_ASYNC_H_
OLDNEW
« no previous file with comments | « webkit/chromeos/fileapi/async_file_stream.h ('k') | webkit/chromeos/fileapi/file_util_async.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698