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 ~FileSystemCallbacksBase() override
;
61 void didFail(int code
) final
;
63 // Other callback methods are implemented by each subclass.
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
{
86 static PassOwnPtr
<AsyncFileSystemCallbacks
> create(EntryCallback
*, ErrorCallback
*, ExecutionContext
*, DOMFileSystemBase
*, const String
& expectedPath
, bool isDirectory
);
87 void didSucceed() override
;
90 EntryCallbacks(EntryCallback
*, ErrorCallback
*, ExecutionContext
*, DOMFileSystemBase
*, const String
& expectedPath
, bool isDirectory
);
91 Persistent
<EntryCallback
> m_successCallback
;
92 String m_expectedPath
;
96 class EntriesCallbacks final
: public FileSystemCallbacksBase
{
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
;
103 EntriesCallbacks(EntriesCallback
*, ErrorCallback
*, ExecutionContext
*, DirectoryReaderBase
*, const String
& basePath
);
104 Persistent
<EntriesCallback
> m_successCallback
;
105 Persistent
<DirectoryReaderBase
> m_directoryReader
;
107 PersistentHeapVector
<Member
<Entry
>> m_entries
;
110 class FileSystemCallbacks final
: public FileSystemCallbacksBase
{
112 static PassOwnPtr
<AsyncFileSystemCallbacks
> create(FileSystemCallback
*, ErrorCallback
*, ExecutionContext
*, FileSystemType
);
113 void didOpenFileSystem(const String
& name
, const KURL
& rootURL
) override
;
116 FileSystemCallbacks(FileSystemCallback
*, ErrorCallback
*, ExecutionContext
*, FileSystemType
);
117 Persistent
<FileSystemCallback
> m_successCallback
;
118 FileSystemType m_type
;
121 class ResolveURICallbacks final
: public FileSystemCallbacksBase
{
123 static PassOwnPtr
<AsyncFileSystemCallbacks
> create(EntryCallback
*, ErrorCallback
*, ExecutionContext
*);
124 void didResolveURL(const String
& name
, const KURL
& rootURL
, FileSystemType
, const String
& filePath
, bool isDirectry
) override
;
127 ResolveURICallbacks(EntryCallback
*, ErrorCallback
*, ExecutionContext
*);
128 Persistent
<EntryCallback
> m_successCallback
;
131 class MetadataCallbacks final
: public FileSystemCallbacksBase
{
133 static PassOwnPtr
<AsyncFileSystemCallbacks
> create(MetadataCallback
*, ErrorCallback
*, ExecutionContext
*, DOMFileSystemBase
*);
134 void didReadMetadata(const FileMetadata
&) override
;
137 MetadataCallbacks(MetadataCallback
*, ErrorCallback
*, ExecutionContext
*, DOMFileSystemBase
*);
138 Persistent
<MetadataCallback
> m_successCallback
;
141 class FileWriterBaseCallbacks final
: public FileSystemCallbacksBase
{
143 static PassOwnPtr
<AsyncFileSystemCallbacks
> create(FileWriterBase
*, FileWriterBaseCallback
*, ErrorCallback
*, ExecutionContext
*);
144 void didCreateFileWriter(PassOwnPtr
<WebFileWriter
>, long long length
) override
;
147 FileWriterBaseCallbacks(FileWriterBase
*, FileWriterBaseCallback
*, ErrorCallback
*, ExecutionContext
*);
148 Persistent
<FileWriterBase
> m_fileWriter
;
149 Persistent
<FileWriterBaseCallback
> m_successCallback
;
152 class SnapshotFileCallback final
: public FileSystemCallbacksBase
{
154 static PassOwnPtr
<AsyncFileSystemCallbacks
> create(DOMFileSystemBase
*, const String
& name
, const KURL
&, FileCallback
*, ErrorCallback
*, ExecutionContext
*);
155 virtual void didCreateSnapshotFile(const FileMetadata
&, PassRefPtr
<BlobDataHandle
> snapshot
);
158 SnapshotFileCallback(DOMFileSystemBase
*, const String
& name
, const KURL
&, FileCallback
*, ErrorCallback
*, ExecutionContext
*);
161 Persistent
<FileCallback
> m_successCallback
;
164 class VoidCallbacks final
: public FileSystemCallbacksBase
{
166 static PassOwnPtr
<AsyncFileSystemCallbacks
> create(VoidCallback
*, ErrorCallback
*, ExecutionContext
*, DOMFileSystemBase
*);
167 void didSucceed() override
;
170 VoidCallbacks(VoidCallback
*, ErrorCallback
*, ExecutionContext
*, DOMFileSystemBase
*);
171 Persistent
<VoidCallback
> m_successCallback
;
176 #endif // FileSystemCallbacks_h