Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / Source / modules / filesystem / FileSystemCallbacks.h
blobebb7dcb85e91a655ca8ee8d0ce5e6a716a14e564
1 /*
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
6 * met:
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
13 * distribution.
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"
40 namespace blink {
42 class DOMFileSystemBase;
43 class DirectoryReaderBase;
44 class EntriesCallback;
45 class EntryCallback;
46 class ErrorCallback;
47 class FileCallback;
48 class FileMetadata;
49 class FileSystemCallback;
50 class FileWriterBase;
51 class FileWriterBaseCallback;
52 class MetadataCallback;
53 class ExecutionContext;
54 class VoidCallback;
56 class FileSystemCallbacksBase : public AsyncFileSystemCallbacks {
57 public:
58 ~FileSystemCallbacksBase() override;
60 // For ErrorCallback.
61 void didFail(int code) final;
63 // Other callback methods are implemented by each subclass.
65 protected:
66 FileSystemCallbacksBase(ErrorCallback*, DOMFileSystemBase*, ExecutionContext*);
68 bool shouldScheduleCallback() const;
70 template <typename CB, typename CBArg>
71 void handleEventOrScheduleCallback(RawPtr<CB>, CBArg*);
73 template <typename CB>
74 void handleEventOrScheduleCallback(RawPtr<CB>);
76 Persistent<ErrorCallback> m_errorCallback;
77 Persistent<DOMFileSystemBase> m_fileSystem;
78 RefPtrWillBePersistent<ExecutionContext> m_executionContext;
79 int m_asyncOperationId;
82 // Subclasses ----------------------------------------------------------------
84 class EntryCallbacks final : public FileSystemCallbacksBase {
85 public:
86 static PassOwnPtr<AsyncFileSystemCallbacks> create(EntryCallback*, ErrorCallback*, ExecutionContext*, DOMFileSystemBase*, const String& expectedPath, bool isDirectory);
87 void didSucceed() override;
89 private:
90 EntryCallbacks(EntryCallback*, ErrorCallback*, ExecutionContext*, DOMFileSystemBase*, const String& expectedPath, bool isDirectory);
91 Persistent<EntryCallback> m_successCallback;
92 String m_expectedPath;
93 bool m_isDirectory;
96 class EntriesCallbacks final : public FileSystemCallbacksBase {
97 public:
98 static PassOwnPtr<AsyncFileSystemCallbacks> create(EntriesCallback*, ErrorCallback*, ExecutionContext*, DirectoryReaderBase*, const String& basePath);
99 void didReadDirectoryEntry(const String& name, bool isDirectory) override;
100 void didReadDirectoryEntries(bool hasMore) override;
102 private:
103 EntriesCallbacks(EntriesCallback*, ErrorCallback*, ExecutionContext*, DirectoryReaderBase*, const String& basePath);
104 Persistent<EntriesCallback> m_successCallback;
105 Persistent<DirectoryReaderBase> m_directoryReader;
106 String m_basePath;
107 PersistentHeapVector<Member<Entry>> m_entries;
110 class FileSystemCallbacks final : public FileSystemCallbacksBase {
111 public:
112 static PassOwnPtr<AsyncFileSystemCallbacks> create(FileSystemCallback*, ErrorCallback*, ExecutionContext*, FileSystemType);
113 void didOpenFileSystem(const String& name, const KURL& rootURL) override;
115 private:
116 FileSystemCallbacks(FileSystemCallback*, ErrorCallback*, ExecutionContext*, FileSystemType);
117 Persistent<FileSystemCallback> m_successCallback;
118 FileSystemType m_type;
121 class ResolveURICallbacks final : public FileSystemCallbacksBase {
122 public:
123 static PassOwnPtr<AsyncFileSystemCallbacks> create(EntryCallback*, ErrorCallback*, ExecutionContext*);
124 void didResolveURL(const String& name, const KURL& rootURL, FileSystemType, const String& filePath, bool isDirectry) override;
126 private:
127 ResolveURICallbacks(EntryCallback*, ErrorCallback*, ExecutionContext*);
128 Persistent<EntryCallback> m_successCallback;
131 class MetadataCallbacks final : public FileSystemCallbacksBase {
132 public:
133 static PassOwnPtr<AsyncFileSystemCallbacks> create(MetadataCallback*, ErrorCallback*, ExecutionContext*, DOMFileSystemBase*);
134 void didReadMetadata(const FileMetadata&) override;
136 private:
137 MetadataCallbacks(MetadataCallback*, ErrorCallback*, ExecutionContext*, DOMFileSystemBase*);
138 Persistent<MetadataCallback> m_successCallback;
141 class FileWriterBaseCallbacks final : public FileSystemCallbacksBase {
142 public:
143 static PassOwnPtr<AsyncFileSystemCallbacks> create(FileWriterBase*, FileWriterBaseCallback*, ErrorCallback*, ExecutionContext*);
144 void didCreateFileWriter(PassOwnPtr<WebFileWriter>, long long length) override;
146 private:
147 FileWriterBaseCallbacks(FileWriterBase*, FileWriterBaseCallback*, ErrorCallback*, ExecutionContext*);
148 Persistent<FileWriterBase> m_fileWriter;
149 Persistent<FileWriterBaseCallback> m_successCallback;
152 class SnapshotFileCallback final : public FileSystemCallbacksBase {
153 public:
154 static PassOwnPtr<AsyncFileSystemCallbacks> create(DOMFileSystemBase*, const String& name, const KURL&, FileCallback*, ErrorCallback*, ExecutionContext*);
155 virtual void didCreateSnapshotFile(const FileMetadata&, PassRefPtr<BlobDataHandle> snapshot);
157 private:
158 SnapshotFileCallback(DOMFileSystemBase*, const String& name, const KURL&, FileCallback*, ErrorCallback*, ExecutionContext*);
159 String m_name;
160 KURL m_url;
161 Persistent<FileCallback> m_successCallback;
164 class VoidCallbacks final : public FileSystemCallbacksBase {
165 public:
166 static PassOwnPtr<AsyncFileSystemCallbacks> create(VoidCallback*, ErrorCallback*, ExecutionContext*, DOMFileSystemBase*);
167 void didSucceed() override;
169 private:
170 VoidCallbacks(VoidCallback*, ErrorCallback*, ExecutionContext*, DOMFileSystemBase*);
171 Persistent<VoidCallback> m_successCallback;
174 } // namespace blink
176 #endif // FileSystemCallbacks_h