2 * Copyright (C) 2010 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
31 #ifndef FileSystemCallbacks_h
32 #define FileSystemCallbacks_h
34 #include "modules/filesystem/EntriesCallback.h"
35 #include "platform/AsyncFileSystemCallbacks.h"
36 #include "platform/FileSystemType.h"
37 #include "wtf/Vector.h"
38 #include "wtf/text/WTFString.h"
42 class DOMFileSystemBase;
43 class DirectoryReaderBase;
44 class EntriesCallback;
49 class FileSystemCallback;
51 class FileWriterBaseCallback;
52 class MetadataCallback;
53 class ExecutionContext;
56 class FileSystemCallbacksBase : public AsyncFileSystemCallbacks {
58 virtual ~FileSystemCallbacksBase();
61 virtual void didFail(int code) override final;
63 // Other callback methods are implemented by each subclass.
66 FileSystemCallbacksBase(ErrorCallback*, DOMFileSystemBase*, ExecutionContext*);
68 bool shouldScheduleCallback() const;
71 template <typename CB, typename CBArg>
72 void handleEventOrScheduleCallback(RawPtr<CB>, RawPtr<CBArg>);
75 template <typename CB, typename CBArg>
76 void handleEventOrScheduleCallback(RawPtr<CB>, CBArg*);
78 template <typename CB, typename CBArg>
79 void handleEventOrScheduleCallback(RawPtr<CB>, PassRefPtrWillBeRawPtr<CBArg>);
81 template <typename CB>
82 void handleEventOrScheduleCallback(RawPtr<CB>);
84 Persistent<ErrorCallback> m_errorCallback;
85 Persistent<DOMFileSystemBase> m_fileSystem;
86 RefPtrWillBePersistent<ExecutionContext> m_executionContext;
87 int m_asyncOperationId;
90 // Subclasses ----------------------------------------------------------------
92 class EntryCallbacks final : public FileSystemCallbacksBase {
94 static PassOwnPtr<AsyncFileSystemCallbacks> create(EntryCallback*, ErrorCallback*, ExecutionContext*, DOMFileSystemBase*, const String& expectedPath, bool isDirectory);
95 virtual void didSucceed() override;
98 EntryCallbacks(EntryCallback*, ErrorCallback*, ExecutionContext*, DOMFileSystemBase*, const String& expectedPath, bool isDirectory);
99 Persistent<EntryCallback> m_successCallback;
100 String m_expectedPath;
104 class EntriesCallbacks final : public FileSystemCallbacksBase {
106 static PassOwnPtr<AsyncFileSystemCallbacks> create(EntriesCallback*, ErrorCallback*, ExecutionContext*, DirectoryReaderBase*, const String& basePath);
107 virtual void didReadDirectoryEntry(const String& name, bool isDirectory) override;
108 virtual void didReadDirectoryEntries(bool hasMore) override;
111 EntriesCallbacks(EntriesCallback*, ErrorCallback*, ExecutionContext*, DirectoryReaderBase*, const String& basePath);
112 Persistent<EntriesCallback> m_successCallback;
113 Persistent<DirectoryReaderBase> m_directoryReader;
115 PersistentHeapVector<Member<Entry> > m_entries;
118 class FileSystemCallbacks final : public FileSystemCallbacksBase {
120 static PassOwnPtr<AsyncFileSystemCallbacks> create(FileSystemCallback*, ErrorCallback*, ExecutionContext*, FileSystemType);
121 virtual void didOpenFileSystem(const String& name, const KURL& rootURL) override;
124 FileSystemCallbacks(FileSystemCallback*, ErrorCallback*, ExecutionContext*, FileSystemType);
125 Persistent<FileSystemCallback> m_successCallback;
126 FileSystemType m_type;
129 class ResolveURICallbacks final : public FileSystemCallbacksBase {
131 static PassOwnPtr<AsyncFileSystemCallbacks> create(EntryCallback*, ErrorCallback*, ExecutionContext*);
132 virtual void didResolveURL(const String& name, const KURL& rootURL, FileSystemType, const String& filePath, bool isDirectry) override;
135 ResolveURICallbacks(EntryCallback*, ErrorCallback*, ExecutionContext*);
136 Persistent<EntryCallback> m_successCallback;
139 class MetadataCallbacks final : public FileSystemCallbacksBase {
141 static PassOwnPtr<AsyncFileSystemCallbacks> create(MetadataCallback*, ErrorCallback*, ExecutionContext*, DOMFileSystemBase*);
142 virtual void didReadMetadata(const FileMetadata&) override;
145 MetadataCallbacks(MetadataCallback*, ErrorCallback*, ExecutionContext*, DOMFileSystemBase*);
146 Persistent<MetadataCallback> m_successCallback;
149 class FileWriterBaseCallbacks final : public FileSystemCallbacksBase {
151 static PassOwnPtr<AsyncFileSystemCallbacks> create(PassRefPtrWillBeRawPtr<FileWriterBase>, FileWriterBaseCallback*, ErrorCallback*, ExecutionContext*);
152 virtual void didCreateFileWriter(PassOwnPtr<WebFileWriter>, long long length) override;
155 FileWriterBaseCallbacks(PassRefPtrWillBeRawPtr<FileWriterBase>, FileWriterBaseCallback*, ErrorCallback*, ExecutionContext*);
156 Persistent<FileWriterBase> m_fileWriter;
157 Persistent<FileWriterBaseCallback> m_successCallback;
160 class SnapshotFileCallback final : public FileSystemCallbacksBase {
162 static PassOwnPtr<AsyncFileSystemCallbacks> create(DOMFileSystemBase*, const String& name, const KURL&, FileCallback*, ErrorCallback*, ExecutionContext*);
163 virtual void didCreateSnapshotFile(const FileMetadata&, PassRefPtr<BlobDataHandle> snapshot);
166 SnapshotFileCallback(DOMFileSystemBase*, const String& name, const KURL&, FileCallback*, ErrorCallback*, ExecutionContext*);
169 Persistent<FileCallback> m_successCallback;
172 class VoidCallbacks final : public FileSystemCallbacksBase {
174 static PassOwnPtr<AsyncFileSystemCallbacks> create(VoidCallback*, ErrorCallback*, ExecutionContext*, DOMFileSystemBase*);
175 virtual void didSucceed() override;
178 VoidCallbacks(VoidCallback*, ErrorCallback*, ExecutionContext*, DOMFileSystemBase*);
179 Persistent<VoidCallback> m_successCallback;
184 #endif // FileSystemCallbacks_h