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 40namespace blink { 41 42class DOMFileSystemBase; 43class DirectoryReaderBase; 44class EntriesCallback; 45class EntryCallback; 46class ErrorCallback; 47class FileCallback; 48struct FileMetadata; 49class FileSystemCallback; 50class FileWriterBase; 51class FileWriterBaseCallback; 52class MetadataCallback; 53class ExecutionContext; 54class VoidCallback; 55 56class FileSystemCallbacksBase : public AsyncFileSystemCallbacks { 57public: 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 65protected: 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 92class EntryCallbacks FINAL : public FileSystemCallbacksBase { 93public: 94 static PassOwnPtr<AsyncFileSystemCallbacks> create(EntryCallback*, ErrorCallback*, ExecutionContext*, DOMFileSystemBase*, const String& expectedPath, bool isDirectory); 95 virtual void didSucceed() OVERRIDE; 96 97private: 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 104class EntriesCallbacks FINAL : public FileSystemCallbacksBase { 105public: 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 110private: 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 118class FileSystemCallbacks FINAL : public FileSystemCallbacksBase { 119public: 120 static PassOwnPtr<AsyncFileSystemCallbacks> create(FileSystemCallback*, ErrorCallback*, ExecutionContext*, FileSystemType); 121 virtual void didOpenFileSystem(const String& name, const KURL& rootURL) OVERRIDE; 122 123private: 124 FileSystemCallbacks(FileSystemCallback*, ErrorCallback*, ExecutionContext*, FileSystemType); 125 Persistent<FileSystemCallback> m_successCallback; 126 FileSystemType m_type; 127}; 128 129class ResolveURICallbacks FINAL : public FileSystemCallbacksBase { 130public: 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 134private: 135 ResolveURICallbacks(EntryCallback*, ErrorCallback*, ExecutionContext*); 136 Persistent<EntryCallback> m_successCallback; 137}; 138 139class MetadataCallbacks FINAL : public FileSystemCallbacksBase { 140public: 141 static PassOwnPtr<AsyncFileSystemCallbacks> create(MetadataCallback*, ErrorCallback*, ExecutionContext*, DOMFileSystemBase*); 142 virtual void didReadMetadata(const FileMetadata&) OVERRIDE; 143 144private: 145 MetadataCallbacks(MetadataCallback*, ErrorCallback*, ExecutionContext*, DOMFileSystemBase*); 146 Persistent<MetadataCallback> m_successCallback; 147}; 148 149class FileWriterBaseCallbacks FINAL : public FileSystemCallbacksBase { 150public: 151 static PassOwnPtr<AsyncFileSystemCallbacks> create(PassRefPtrWillBeRawPtr<FileWriterBase>, FileWriterBaseCallback*, ErrorCallback*, ExecutionContext*); 152 virtual void didCreateFileWriter(PassOwnPtr<WebFileWriter>, long long length) OVERRIDE; 153 154private: 155 FileWriterBaseCallbacks(PassRefPtrWillBeRawPtr<FileWriterBase>, FileWriterBaseCallback*, ErrorCallback*, ExecutionContext*); 156 Persistent<FileWriterBase> m_fileWriter; 157 Persistent<FileWriterBaseCallback> m_successCallback; 158}; 159 160class SnapshotFileCallback FINAL : public FileSystemCallbacksBase { 161public: 162 static PassOwnPtr<AsyncFileSystemCallbacks> create(DOMFileSystemBase*, const String& name, const KURL&, FileCallback*, ErrorCallback*, ExecutionContext*); 163 virtual void didCreateSnapshotFile(const FileMetadata&, PassRefPtr<BlobDataHandle> snapshot); 164 165private: 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 172class VoidCallbacks FINAL : public FileSystemCallbacksBase { 173public: 174 static PassOwnPtr<AsyncFileSystemCallbacks> create(VoidCallback*, ErrorCallback*, ExecutionContext*, DOMFileSystemBase*); 175 virtual void didSucceed() OVERRIDE; 176 177private: 178 VoidCallbacks(VoidCallback*, ErrorCallback*, ExecutionContext*, DOMFileSystemBase*); 179 Persistent<VoidCallback> m_successCallback; 180}; 181 182} // namespace blink 183 184#endif // FileSystemCallbacks_h 185