Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / modules / filesystem / FileSystemCallbacks.h
1 /*
2  * Copyright (C) 2010 Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
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.
17  *
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.
29  */
30
31 #ifndef FileSystemCallbacks_h
32 #define FileSystemCallbacks_h
33
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"
39
40 namespace blink {
41
42 class DOMFileSystemBase;
43 class DirectoryReaderBase;
44 class EntriesCallback;
45 class EntryCallback;
46 class ErrorCallback;
47 class FileCallback;
48 struct FileMetadata;
49 class FileSystemCallback;
50 class FileWriterBase;
51 class FileWriterBaseCallback;
52 class MetadataCallback;
53 class ExecutionContext;
54 class VoidCallback;
55
56 class FileSystemCallbacksBase : public AsyncFileSystemCallbacks {
57 public:
58     virtual ~FileSystemCallbacksBase();
59
60     // For ErrorCallback.
61     virtual void didFail(int code) override final;
62
63     // Other callback methods are implemented by each subclass.
64
65 protected:
66     FileSystemCallbacksBase(ErrorCallback*, DOMFileSystemBase*, ExecutionContext*);
67
68     bool shouldScheduleCallback() const;
69
70 #if !ENABLE(OILPAN)
71     template <typename CB, typename CBArg>
72     void handleEventOrScheduleCallback(RawPtr<CB>, RawPtr<CBArg>);
73 #endif
74
75     template <typename CB, typename CBArg>
76     void handleEventOrScheduleCallback(RawPtr<CB>, CBArg*);
77
78     template <typename CB, typename CBArg>
79     void handleEventOrScheduleCallback(RawPtr<CB>, PassRefPtrWillBeRawPtr<CBArg>);
80
81     template <typename CB>
82     void handleEventOrScheduleCallback(RawPtr<CB>);
83
84     Persistent<ErrorCallback> m_errorCallback;
85     Persistent<DOMFileSystemBase> m_fileSystem;
86     RefPtrWillBePersistent<ExecutionContext> m_executionContext;
87     int m_asyncOperationId;
88 };
89
90 // Subclasses ----------------------------------------------------------------
91
92 class EntryCallbacks final : public FileSystemCallbacksBase {
93 public:
94     static PassOwnPtr<AsyncFileSystemCallbacks> create(EntryCallback*, ErrorCallback*, ExecutionContext*, DOMFileSystemBase*, const String& expectedPath, bool isDirectory);
95     virtual void didSucceed() override;
96
97 private:
98     EntryCallbacks(EntryCallback*, ErrorCallback*, ExecutionContext*, DOMFileSystemBase*, const String& expectedPath, bool isDirectory);
99     Persistent<EntryCallback> m_successCallback;
100     String m_expectedPath;
101     bool m_isDirectory;
102 };
103
104 class EntriesCallbacks final : public FileSystemCallbacksBase {
105 public:
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;
109
110 private:
111     EntriesCallbacks(EntriesCallback*, ErrorCallback*, ExecutionContext*, DirectoryReaderBase*, const String& basePath);
112     Persistent<EntriesCallback> m_successCallback;
113     Persistent<DirectoryReaderBase> m_directoryReader;
114     String m_basePath;
115     PersistentHeapVector<Member<Entry> > m_entries;
116 };
117
118 class FileSystemCallbacks final : public FileSystemCallbacksBase {
119 public:
120     static PassOwnPtr<AsyncFileSystemCallbacks> create(FileSystemCallback*, ErrorCallback*, ExecutionContext*, FileSystemType);
121     virtual void didOpenFileSystem(const String& name, const KURL& rootURL) override;
122
123 private:
124     FileSystemCallbacks(FileSystemCallback*, ErrorCallback*, ExecutionContext*, FileSystemType);
125     Persistent<FileSystemCallback> m_successCallback;
126     FileSystemType m_type;
127 };
128
129 class ResolveURICallbacks final : public FileSystemCallbacksBase {
130 public:
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;
133
134 private:
135     ResolveURICallbacks(EntryCallback*, ErrorCallback*, ExecutionContext*);
136     Persistent<EntryCallback> m_successCallback;
137 };
138
139 class MetadataCallbacks final : public FileSystemCallbacksBase {
140 public:
141     static PassOwnPtr<AsyncFileSystemCallbacks> create(MetadataCallback*, ErrorCallback*, ExecutionContext*, DOMFileSystemBase*);
142     virtual void didReadMetadata(const FileMetadata&) override;
143
144 private:
145     MetadataCallbacks(MetadataCallback*, ErrorCallback*, ExecutionContext*, DOMFileSystemBase*);
146     Persistent<MetadataCallback> m_successCallback;
147 };
148
149 class FileWriterBaseCallbacks final : public FileSystemCallbacksBase {
150 public:
151     static PassOwnPtr<AsyncFileSystemCallbacks> create(PassRefPtrWillBeRawPtr<FileWriterBase>, FileWriterBaseCallback*, ErrorCallback*, ExecutionContext*);
152     virtual void didCreateFileWriter(PassOwnPtr<WebFileWriter>, long long length) override;
153
154 private:
155     FileWriterBaseCallbacks(PassRefPtrWillBeRawPtr<FileWriterBase>, FileWriterBaseCallback*, ErrorCallback*, ExecutionContext*);
156     Persistent<FileWriterBase> m_fileWriter;
157     Persistent<FileWriterBaseCallback> m_successCallback;
158 };
159
160 class SnapshotFileCallback final : public FileSystemCallbacksBase {
161 public:
162     static PassOwnPtr<AsyncFileSystemCallbacks> create(DOMFileSystemBase*, const String& name, const KURL&, FileCallback*, ErrorCallback*, ExecutionContext*);
163     virtual void didCreateSnapshotFile(const FileMetadata&, PassRefPtr<BlobDataHandle> snapshot);
164
165 private:
166     SnapshotFileCallback(DOMFileSystemBase*, const String& name, const KURL&, FileCallback*, ErrorCallback*, ExecutionContext*);
167     String m_name;
168     KURL m_url;
169     Persistent<FileCallback> m_successCallback;
170 };
171
172 class VoidCallbacks final : public FileSystemCallbacksBase {
173 public:
174     static PassOwnPtr<AsyncFileSystemCallbacks> create(VoidCallback*, ErrorCallback*, ExecutionContext*, DOMFileSystemBase*);
175     virtual void didSucceed() override;
176
177 private:
178     VoidCallbacks(VoidCallback*, ErrorCallback*, ExecutionContext*, DOMFileSystemBase*);
179     Persistent<VoidCallback> m_successCallback;
180 };
181
182 } // namespace blink
183
184 #endif // FileSystemCallbacks_h