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

Side by Side Diff: third_party/WebKit/Source/modules/filesystem/FileSystemCallbacks.h

Issue 2297043002: Web expose FileSystemFileEntry, FileSystemDirectoryEntry and friends (Closed)
Patch Set: Rebased Created 4 years, 1 month 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 14 matching lines...) Expand all
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #ifndef FileSystemCallbacks_h 31 #ifndef FileSystemCallbacks_h
32 #define FileSystemCallbacks_h 32 #define FileSystemCallbacks_h
33 33
34 #include "core/fileapi/FileError.h" 34 #include "core/fileapi/FileError.h"
35 #include "modules/filesystem/EntriesCallback.h" 35 #include "modules/filesystem/FileSystemEntriesCallback.h"
36 #include "platform/AsyncFileSystemCallbacks.h" 36 #include "platform/AsyncFileSystemCallbacks.h"
37 #include "platform/FileSystemType.h" 37 #include "platform/FileSystemType.h"
38 #include "wtf/Vector.h" 38 #include "wtf/Vector.h"
39 #include "wtf/text/WTFString.h" 39 #include "wtf/text/WTFString.h"
40 #include <memory> 40 #include <memory>
41 41
42 namespace blink { 42 namespace blink {
43 43
44 class DOMFileSystemBase;
45 class DirectoryReaderBase;
46 class BlobCallback; 44 class BlobCallback;
47 class EntriesCallback;
48 class EntryCallback;
49 class ErrorCallback; 45 class ErrorCallback;
46 class ExecutionContext;
50 class FileMetadata; 47 class FileMetadata;
48 class FileSystemBase;
51 class FileSystemCallback; 49 class FileSystemCallback;
50 class FileSystemDirectoryReaderBase;
51 class FileSystemEntriesCallback;
52 class FileSystemEntryCallback;
53 class FileSystemMetadataCallback;
52 class FileWriterBase; 54 class FileWriterBase;
53 class FileWriterBaseCallback; 55 class FileWriterBaseCallback;
54 class MetadataCallback;
55 class ExecutionContext;
56 class VoidCallback; 56 class VoidCallback;
57 57
58 // Passed to DOMFileSystem implementations that may report errors. Subclasses 58 // Passed to FileSystem implementations that may report errors. Subclasses
59 // may capture the error for throwing on return to script (for synchronous APIs) 59 // may capture the error for throwing on return to script (for synchronous APIs)
60 // or call an actual script callback (for asynchronous APIs). 60 // or call an actual script callback (for asynchronous APIs).
61 class ErrorCallbackBase : public GarbageCollectedFinalized<ErrorCallbackBase> { 61 class ErrorCallbackBase : public GarbageCollectedFinalized<ErrorCallbackBase> {
62 public: 62 public:
63 virtual ~ErrorCallbackBase() {} 63 virtual ~ErrorCallbackBase() {}
64 DEFINE_INLINE_VIRTUAL_TRACE() {} 64 DEFINE_INLINE_VIRTUAL_TRACE() {}
65 virtual void invoke(FileError::ErrorCode) = 0; 65 virtual void invoke(FileError::ErrorCode) = 0;
66 }; 66 };
67 67
68 class FileSystemCallbacksBase : public AsyncFileSystemCallbacks { 68 class FileSystemCallbacksBase : public AsyncFileSystemCallbacks {
69 public: 69 public:
70 ~FileSystemCallbacksBase() override; 70 ~FileSystemCallbacksBase() override;
71 71
72 // For ErrorCallback. 72 // For ErrorCallback.
73 void didFail(int code) final; 73 void didFail(int code) final;
74 74
75 // Other callback methods are implemented by each subclass. 75 // Other callback methods are implemented by each subclass.
76 76
77 protected: 77 protected:
78 FileSystemCallbacksBase(ErrorCallbackBase*, 78 FileSystemCallbacksBase(ErrorCallbackBase*,
79 DOMFileSystemBase*, 79 FileSystemBase*,
80 ExecutionContext*); 80 ExecutionContext*);
81 81
82 bool shouldScheduleCallback() const; 82 bool shouldScheduleCallback() const;
83 83
84 template <typename CB, typename CBArg> 84 template <typename CB, typename CBArg>
85 void invokeOrScheduleCallback(CB*, CBArg); 85 void invokeOrScheduleCallback(CB*, CBArg);
86 86
87 template <typename CB, typename CBArg> 87 template <typename CB, typename CBArg>
88 void handleEventOrScheduleCallback(CB*, CBArg*); 88 void handleEventOrScheduleCallback(CB*, CBArg*);
89 89
90 template <typename CB> 90 template <typename CB>
91 void handleEventOrScheduleCallback(CB*); 91 void handleEventOrScheduleCallback(CB*);
92 92
93 Persistent<ErrorCallbackBase> m_errorCallback; 93 Persistent<ErrorCallbackBase> m_errorCallback;
94 Persistent<DOMFileSystemBase> m_fileSystem; 94 Persistent<FileSystemBase> m_fileSystem;
95 Persistent<ExecutionContext> m_executionContext; 95 Persistent<ExecutionContext> m_executionContext;
96 int m_asyncOperationId; 96 int m_asyncOperationId;
97 }; 97 };
98 98
99 // Subclasses ---------------------------------------------------------------- 99 // Subclasses ----------------------------------------------------------------
100 100
101 // Wraps a script-provided callback for use in DOMFileSystem operations. 101 // Wraps a script-provided callback for use in FileSystem operations.
102 class ScriptErrorCallback final : public ErrorCallbackBase { 102 class ScriptErrorCallback final : public ErrorCallbackBase {
103 public: 103 public:
104 static ScriptErrorCallback* wrap(ErrorCallback*); 104 static ScriptErrorCallback* wrap(ErrorCallback*);
105 virtual ~ScriptErrorCallback() {} 105 virtual ~ScriptErrorCallback() {}
106 DECLARE_VIRTUAL_TRACE(); 106 DECLARE_VIRTUAL_TRACE();
107 107
108 void invoke(FileError::ErrorCode) override; 108 void invoke(FileError::ErrorCode) override;
109 109
110 private: 110 private:
111 explicit ScriptErrorCallback(ErrorCallback*); 111 explicit ScriptErrorCallback(ErrorCallback*);
112 Member<ErrorCallback> m_callback; 112 Member<ErrorCallback> m_callback;
113 }; 113 };
114 114
115 class EntryCallbacks final : public FileSystemCallbacksBase { 115 class EntryCallbacks final : public FileSystemCallbacksBase {
116 public: 116 public:
117 static std::unique_ptr<AsyncFileSystemCallbacks> create( 117 static std::unique_ptr<AsyncFileSystemCallbacks> create(
118 EntryCallback*, 118 FileSystemEntryCallback*,
119 ErrorCallbackBase*, 119 ErrorCallbackBase*,
120 ExecutionContext*, 120 ExecutionContext*,
121 DOMFileSystemBase*, 121 FileSystemBase*,
122 const String& expectedPath, 122 const String& expectedPath,
123 bool isDirectory); 123 bool isDirectory);
124 void didSucceed() override; 124 void didSucceed() override;
125 125
126 private: 126 private:
127 EntryCallbacks(EntryCallback*, 127 EntryCallbacks(FileSystemEntryCallback*,
128 ErrorCallbackBase*, 128 ErrorCallbackBase*,
129 ExecutionContext*, 129 ExecutionContext*,
130 DOMFileSystemBase*, 130 FileSystemBase*,
131 const String& expectedPath, 131 const String& expectedPath,
132 bool isDirectory); 132 bool isDirectory);
133 Persistent<EntryCallback> m_successCallback; 133 Persistent<FileSystemEntryCallback> m_successCallback;
134 String m_expectedPath; 134 String m_expectedPath;
135 bool m_isDirectory; 135 bool m_isDirectory;
136 }; 136 };
137 137
138 class EntriesCallbacks final : public FileSystemCallbacksBase { 138 class EntriesCallbacks final : public FileSystemCallbacksBase {
139 public: 139 public:
140 static std::unique_ptr<AsyncFileSystemCallbacks> create( 140 static std::unique_ptr<AsyncFileSystemCallbacks> create(
141 EntriesCallback*, 141 FileSystemEntriesCallback*,
142 ErrorCallbackBase*, 142 ErrorCallbackBase*,
143 ExecutionContext*, 143 ExecutionContext*,
144 DirectoryReaderBase*, 144 FileSystemDirectoryReaderBase*,
145 const String& basePath); 145 const String& basePath);
146 void didReadDirectoryEntry(const String& name, bool isDirectory) override; 146 void didReadDirectoryEntry(const String& name, bool isDirectory) override;
147 void didReadDirectoryEntries(bool hasMore) override; 147 void didReadDirectoryEntries(bool hasMore) override;
148 148
149 private: 149 private:
150 EntriesCallbacks(EntriesCallback*, 150 EntriesCallbacks(FileSystemEntriesCallback*,
151 ErrorCallbackBase*, 151 ErrorCallbackBase*,
152 ExecutionContext*, 152 ExecutionContext*,
153 DirectoryReaderBase*, 153 FileSystemDirectoryReaderBase*,
154 const String& basePath); 154 const String& basePath);
155 Persistent<EntriesCallback> m_successCallback; 155 Persistent<FileSystemEntriesCallback> m_successCallback;
156 Persistent<DirectoryReaderBase> m_directoryReader; 156 Persistent<FileSystemDirectoryReaderBase> m_directoryReader;
157 String m_basePath; 157 String m_basePath;
158 PersistentHeapVector<Member<Entry>> m_entries; 158 PersistentHeapVector<Member<FileSystemEntry>> m_entries;
159 }; 159 };
160 160
161 class FileSystemCallbacks final : public FileSystemCallbacksBase { 161 class FileSystemCallbacks final : public FileSystemCallbacksBase {
162 public: 162 public:
163 static std::unique_ptr<AsyncFileSystemCallbacks> create(FileSystemCallback*, 163 static std::unique_ptr<AsyncFileSystemCallbacks> create(FileSystemCallback*,
164 ErrorCallbackBase*, 164 ErrorCallbackBase*,
165 ExecutionContext*, 165 ExecutionContext*,
166 FileSystemType); 166 FileSystemType);
167 void didOpenFileSystem(const String& name, const KURL& rootURL) override; 167 void didOpenFileSystem(const String& name, const KURL& rootURL) override;
168 168
169 private: 169 private:
170 FileSystemCallbacks(FileSystemCallback*, 170 FileSystemCallbacks(FileSystemCallback*,
171 ErrorCallbackBase*, 171 ErrorCallbackBase*,
172 ExecutionContext*, 172 ExecutionContext*,
173 FileSystemType); 173 FileSystemType);
174 Persistent<FileSystemCallback> m_successCallback; 174 Persistent<FileSystemCallback> m_successCallback;
175 FileSystemType m_type; 175 FileSystemType m_type;
176 }; 176 };
177 177
178 class ResolveURICallbacks final : public FileSystemCallbacksBase { 178 class ResolveURICallbacks final : public FileSystemCallbacksBase {
179 public: 179 public:
180 static std::unique_ptr<AsyncFileSystemCallbacks> create(EntryCallback*, 180 static std::unique_ptr<AsyncFileSystemCallbacks>
181 ErrorCallbackBase*, 181 create(FileSystemEntryCallback*, ErrorCallbackBase*, ExecutionContext*);
182 ExecutionContext*);
183 void didResolveURL(const String& name, 182 void didResolveURL(const String& name,
184 const KURL& rootURL, 183 const KURL& rootURL,
185 FileSystemType, 184 FileSystemType,
186 const String& filePath, 185 const String& filePath,
187 bool isDirectry) override; 186 bool isDirectry) override;
188 187
189 private: 188 private:
190 ResolveURICallbacks(EntryCallback*, ErrorCallbackBase*, ExecutionContext*); 189 ResolveURICallbacks(FileSystemEntryCallback*,
191 Persistent<EntryCallback> m_successCallback; 190 ErrorCallbackBase*,
191 ExecutionContext*);
192 Persistent<FileSystemEntryCallback> m_successCallback;
192 }; 193 };
193 194
194 class MetadataCallbacks final : public FileSystemCallbacksBase { 195 class MetadataCallbacks final : public FileSystemCallbacksBase {
195 public: 196 public:
196 static std::unique_ptr<AsyncFileSystemCallbacks> create(MetadataCallback*, 197 static std::unique_ptr<AsyncFileSystemCallbacks> create(
197 ErrorCallbackBase*, 198 FileSystemMetadataCallback*,
198 ExecutionContext*, 199 ErrorCallbackBase*,
199 DOMFileSystemBase*); 200 ExecutionContext*,
201 FileSystemBase*);
200 void didReadMetadata(const FileMetadata&) override; 202 void didReadMetadata(const FileMetadata&) override;
201 203
202 private: 204 private:
203 MetadataCallbacks(MetadataCallback*, 205 MetadataCallbacks(FileSystemMetadataCallback*,
204 ErrorCallbackBase*, 206 ErrorCallbackBase*,
205 ExecutionContext*, 207 ExecutionContext*,
206 DOMFileSystemBase*); 208 FileSystemBase*);
207 Persistent<MetadataCallback> m_successCallback; 209 Persistent<FileSystemMetadataCallback> m_successCallback;
208 }; 210 };
209 211
210 class FileWriterBaseCallbacks final : public FileSystemCallbacksBase { 212 class FileWriterBaseCallbacks final : public FileSystemCallbacksBase {
211 public: 213 public:
212 static std::unique_ptr<AsyncFileSystemCallbacks> create( 214 static std::unique_ptr<AsyncFileSystemCallbacks> create(
213 FileWriterBase*, 215 FileWriterBase*,
214 FileWriterBaseCallback*, 216 FileWriterBaseCallback*,
215 ErrorCallbackBase*, 217 ErrorCallbackBase*,
216 ExecutionContext*); 218 ExecutionContext*);
217 void didCreateFileWriter(std::unique_ptr<WebFileWriter>, 219 void didCreateFileWriter(std::unique_ptr<WebFileWriter>,
218 long long length) override; 220 long long length) override;
219 221
220 private: 222 private:
221 FileWriterBaseCallbacks(FileWriterBase*, 223 FileWriterBaseCallbacks(FileWriterBase*,
222 FileWriterBaseCallback*, 224 FileWriterBaseCallback*,
223 ErrorCallbackBase*, 225 ErrorCallbackBase*,
224 ExecutionContext*); 226 ExecutionContext*);
225 Persistent<FileWriterBase> m_fileWriter; 227 Persistent<FileWriterBase> m_fileWriter;
226 Persistent<FileWriterBaseCallback> m_successCallback; 228 Persistent<FileWriterBaseCallback> m_successCallback;
227 }; 229 };
228 230
229 class SnapshotFileCallback final : public FileSystemCallbacksBase { 231 class SnapshotFileCallback final : public FileSystemCallbacksBase {
230 public: 232 public:
231 static std::unique_ptr<AsyncFileSystemCallbacks> create(DOMFileSystemBase*, 233 static std::unique_ptr<AsyncFileSystemCallbacks> create(FileSystemBase*,
232 const String& name, 234 const String& name,
233 const KURL&, 235 const KURL&,
234 BlobCallback*, 236 BlobCallback*,
235 ErrorCallbackBase*, 237 ErrorCallbackBase*,
236 ExecutionContext*); 238 ExecutionContext*);
237 virtual void didCreateSnapshotFile(const FileMetadata&, 239 virtual void didCreateSnapshotFile(const FileMetadata&,
238 PassRefPtr<BlobDataHandle> snapshot); 240 PassRefPtr<BlobDataHandle> snapshot);
239 241
240 private: 242 private:
241 SnapshotFileCallback(DOMFileSystemBase*, 243 SnapshotFileCallback(FileSystemBase*,
242 const String& name, 244 const String& name,
243 const KURL&, 245 const KURL&,
244 BlobCallback*, 246 BlobCallback*,
245 ErrorCallbackBase*, 247 ErrorCallbackBase*,
246 ExecutionContext*); 248 ExecutionContext*);
247 String m_name; 249 String m_name;
248 KURL m_url; 250 KURL m_url;
249 Persistent<BlobCallback> m_successCallback; 251 Persistent<BlobCallback> m_successCallback;
250 }; 252 };
251 253
252 class VoidCallbacks final : public FileSystemCallbacksBase { 254 class VoidCallbacks final : public FileSystemCallbacksBase {
253 public: 255 public:
254 static std::unique_ptr<AsyncFileSystemCallbacks> create(VoidCallback*, 256 static std::unique_ptr<AsyncFileSystemCallbacks> create(VoidCallback*,
255 ErrorCallbackBase*, 257 ErrorCallbackBase*,
256 ExecutionContext*, 258 ExecutionContext*,
257 DOMFileSystemBase*); 259 FileSystemBase*);
258 void didSucceed() override; 260 void didSucceed() override;
259 261
260 private: 262 private:
261 VoidCallbacks(VoidCallback*, 263 VoidCallbacks(VoidCallback*,
262 ErrorCallbackBase*, 264 ErrorCallbackBase*,
263 ExecutionContext*, 265 ExecutionContext*,
264 DOMFileSystemBase*); 266 FileSystemBase*);
265 Persistent<VoidCallback> m_successCallback; 267 Persistent<VoidCallback> m_successCallback;
266 }; 268 };
267 269
268 } // namespace blink 270 } // namespace blink
269 271
270 #endif // FileSystemCallbacks_h 272 #endif // FileSystemCallbacks_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698