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 DOMFileSystem_h
32 #define DOMFileSystem_h
34 #include "bindings/core/v8/ScriptWrappable.h"
35 #include "core/dom/ActiveDOMObject.h"
36 #include "core/dom/ExecutionContext.h"
37 #include "core/dom/ExecutionContextTask.h"
38 #include "modules/filesystem/DOMFileSystemBase.h"
39 #include "modules/filesystem/EntriesCallback.h"
40 #include "platform/heap/Handle.h"
48 class FileWriterCallback;
50 class DOMFileSystem FINAL : public DOMFileSystemBase, public ScriptWrappable, public ActiveDOMObject {
51 DEFINE_WRAPPERTYPEINFO();
53 static DOMFileSystem* create(ExecutionContext*, const String& name, FileSystemType, const KURL& rootURL);
55 // Creates a new isolated file system for the given filesystemId.
56 static DOMFileSystem* createIsolatedFileSystem(ExecutionContext*, const String& filesystemId);
58 DirectoryEntry* root();
60 // DOMFileSystemBase overrides.
61 virtual void addPendingCallbacks() OVERRIDE;
62 virtual void removePendingCallbacks() OVERRIDE;
63 virtual void reportError(ErrorCallback*, PassRefPtrWillBeRawPtr<FileError>) OVERRIDE;
65 // ActiveDOMObject overrides.
66 virtual bool hasPendingActivity() const OVERRIDE;
68 void createWriter(const FileEntry*, FileWriterCallback*, ErrorCallback*);
69 void createFile(const FileEntry*, FileCallback*, ErrorCallback*);
71 // Schedule a callback. This should not cross threads (should be called on the same context thread).
72 // FIXME: move this to a more generic place.
73 template <typename CB, typename CBArg>
74 static void scheduleCallback(ExecutionContext*, CB*, PassRefPtrWillBeRawPtr<CBArg>);
76 template <typename CB, typename CBArg>
77 static void scheduleCallback(ExecutionContext*, CB*, CBArg*);
79 template <typename CB, typename CBArg>
80 static void scheduleCallback(ExecutionContext*, CB*, const HeapVector<CBArg>&);
82 template <typename CB, typename CBArg>
83 static void scheduleCallback(ExecutionContext*, CB*, const CBArg&);
85 template <typename CB>
86 static void scheduleCallback(ExecutionContext*, CB*);
88 template <typename CB, typename CBArg>
89 void scheduleCallback(CB* callback, PassRefPtrWillBeRawPtr<CBArg> callbackArg)
91 scheduleCallback(executionContext(), callback, callbackArg);
94 template <typename CB, typename CBArg>
95 void scheduleCallback(CB* callback, CBArg* callbackArg)
97 scheduleCallback(executionContext(), callback, callbackArg);
100 template <typename CB, typename CBArg>
101 void scheduleCallback(CB* callback, const CBArg& callbackArg)
103 scheduleCallback(executionContext(), callback, callbackArg);
107 DOMFileSystem(ExecutionContext*, const String& name, FileSystemType, const KURL& rootURL);
109 class DispatchCallbackTaskBase : public ExecutionContextTask {
111 DispatchCallbackTaskBase()
112 : m_taskName("FileSystem")
116 virtual const String& taskNameForInstrumentation() const OVERRIDE
122 const String m_taskName;
125 // A helper template to schedule a callback task.
126 template <typename CB, typename CBArg>
127 class DispatchCallbackRefPtrArgTask FINAL : public DispatchCallbackTaskBase {
129 DispatchCallbackRefPtrArgTask(CB* callback, PassRefPtrWillBeRawPtr<CBArg> arg)
130 : m_callback(callback)
135 virtual void performTask(ExecutionContext*) OVERRIDE
137 m_callback->handleEvent(m_callbackArg.get());
141 Persistent<CB> m_callback;
142 RefPtrWillBePersistent<CBArg> m_callbackArg;
145 template <typename CB, typename CBArg>
146 class DispatchCallbackPtrArgTask FINAL : public DispatchCallbackTaskBase {
148 DispatchCallbackPtrArgTask(CB* callback, CBArg* arg)
149 : m_callback(callback)
154 virtual void performTask(ExecutionContext*) OVERRIDE
156 m_callback->handleEvent(m_callbackArg.get());
160 Persistent<CB> m_callback;
161 Persistent<CBArg> m_callbackArg;
164 template <typename CB, typename CBArg>
165 class DispatchCallbackNonPtrArgTask FINAL : public DispatchCallbackTaskBase {
167 DispatchCallbackNonPtrArgTask(CB* callback, const CBArg& arg)
168 : m_callback(callback)
173 virtual void performTask(ExecutionContext*) OVERRIDE
175 m_callback->handleEvent(m_callbackArg);
179 Persistent<CB> m_callback;
183 template <typename CB>
184 class DispatchCallbackNoArgTask FINAL : public DispatchCallbackTaskBase {
186 DispatchCallbackNoArgTask(CB* callback)
187 : m_callback(callback)
191 virtual void performTask(ExecutionContext*) OVERRIDE
193 m_callback->handleEvent();
197 Persistent<CB> m_callback;
200 int m_numberOfPendingCallbacks;
203 template <typename CB, typename CBArg>
204 void DOMFileSystem::scheduleCallback(ExecutionContext* executionContext, CB* callback, PassRefPtrWillBeRawPtr<CBArg> arg)
206 ASSERT(executionContext->isContextThread());
208 executionContext->postTask(adoptPtr(new DispatchCallbackRefPtrArgTask<CB, CBArg>(callback, arg)));
211 template <typename CB, typename CBArg>
212 void DOMFileSystem::scheduleCallback(ExecutionContext* executionContext, CB* callback, CBArg* arg)
214 ASSERT(executionContext->isContextThread());
216 executionContext->postTask(adoptPtr(new DispatchCallbackPtrArgTask<CB, CBArg>(callback, arg)));
219 template <typename CB, typename CBArg>
220 void DOMFileSystem::scheduleCallback(ExecutionContext* executionContext, CB* callback, const HeapVector<CBArg>& arg)
222 ASSERT(executionContext->isContextThread());
224 executionContext->postTask(adoptPtr(new DispatchCallbackNonPtrArgTask<CB, PersistentHeapVector<CBArg> >(callback, arg)));
227 template <typename CB, typename CBArg>
228 void DOMFileSystem::scheduleCallback(ExecutionContext* executionContext, CB* callback, const CBArg& arg)
230 ASSERT(executionContext->isContextThread());
232 executionContext->postTask(adoptPtr(new DispatchCallbackNonPtrArgTask<CB, CBArg>(callback, arg)));
235 template <typename CB>
236 void DOMFileSystem::scheduleCallback(ExecutionContext* executionContext, CB* callback)
238 ASSERT(executionContext->isContextThread());
240 executionContext->postTask(adoptPtr(new DispatchCallbackNoArgTask<CB>(callback)));
245 #endif // DOMFileSystem_h