Home | History | Annotate | Download | only in filesystem
      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 WebCore {
     41 
     42 class DOMFileSystemBase;
     43 class DirectoryReaderBase;
     44 class EntriesCallback;
     45 class EntryCallback;
     46 class ErrorCallback;
     47 struct FileMetadata;
     48 class FileSystemCallback;
     49 class FileWriterBase;
     50 class FileWriterBaseCallback;
     51 class MetadataCallback;
     52 class ExecutionContext;
     53 class VoidCallback;
     54 
     55 class FileSystemCallbacksBase : public AsyncFileSystemCallbacks {
     56 public:
     57     virtual ~FileSystemCallbacksBase();
     58 
     59     // For ErrorCallback.
     60     virtual void didFail(int code) OVERRIDE FINAL;
     61 
     62     // Other callback methods are implemented by each subclass.
     63 
     64 protected:
     65     FileSystemCallbacksBase(PassOwnPtr<ErrorCallback>, DOMFileSystemBase*, ExecutionContext*);
     66 
     67     bool shouldScheduleCallback() const;
     68 
     69     template <typename CB, typename CBArg>
     70     void handleEventOrScheduleCallback(PassOwnPtr<CB>, CBArg*);
     71 
     72     template <typename CB, typename CBArg>
     73     void handleEventOrScheduleCallback(PassOwnPtr<CB>, PassRefPtrWillBeRawPtr<CBArg>);
     74 
     75     template <typename CB>
     76     void handleEventOrScheduleCallback(PassOwnPtr<CB>);
     77 
     78     OwnPtr<ErrorCallback> m_errorCallback;
     79     Persistent<DOMFileSystemBase> m_fileSystem;
     80     RefPtrWillBePersistent<ExecutionContext> m_executionContext;
     81 };
     82 
     83 // Subclasses ----------------------------------------------------------------
     84 
     85 class EntryCallbacks FINAL : public FileSystemCallbacksBase {
     86 public:
     87     static PassOwnPtr<AsyncFileSystemCallbacks> create(PassOwnPtr<EntryCallback>, PassOwnPtr<ErrorCallback>, ExecutionContext*, DOMFileSystemBase*, const String& expectedPath, bool isDirectory);
     88     virtual void didSucceed() OVERRIDE;
     89 
     90 private:
     91     EntryCallbacks(PassOwnPtr<EntryCallback>, PassOwnPtr<ErrorCallback>, ExecutionContext*, DOMFileSystemBase*, const String& expectedPath, bool isDirectory);
     92     OwnPtr<EntryCallback> m_successCallback;
     93     String m_expectedPath;
     94     bool m_isDirectory;
     95 };
     96 
     97 class EntriesCallbacks FINAL : public FileSystemCallbacksBase {
     98 public:
     99     static PassOwnPtr<AsyncFileSystemCallbacks> create(PassOwnPtr<EntriesCallback>, PassOwnPtr<ErrorCallback>, ExecutionContext*, DirectoryReaderBase*, const String& basePath);
    100     virtual void didReadDirectoryEntry(const String& name, bool isDirectory) OVERRIDE;
    101     virtual void didReadDirectoryEntries(bool hasMore) OVERRIDE;
    102 
    103 private:
    104     EntriesCallbacks(PassOwnPtr<EntriesCallback>, PassOwnPtr<ErrorCallback>, ExecutionContext*, DirectoryReaderBase*, const String& basePath);
    105     OwnPtr<EntriesCallback> m_successCallback;
    106     Persistent<DirectoryReaderBase> m_directoryReader;
    107     String m_basePath;
    108     PersistentHeapVector<Member<Entry> > m_entries;
    109 };
    110 
    111 class FileSystemCallbacks FINAL : public FileSystemCallbacksBase {
    112 public:
    113     static PassOwnPtr<AsyncFileSystemCallbacks> create(PassOwnPtr<FileSystemCallback>, PassOwnPtr<ErrorCallback>, ExecutionContext*, FileSystemType);
    114     virtual void didOpenFileSystem(const String& name, const KURL& rootURL) OVERRIDE;
    115 
    116 private:
    117     FileSystemCallbacks(PassOwnPtr<FileSystemCallback>, PassOwnPtr<ErrorCallback>, ExecutionContext*, FileSystemType);
    118     OwnPtr<FileSystemCallback> m_successCallback;
    119     FileSystemType m_type;
    120 };
    121 
    122 class ResolveURICallbacks FINAL : public FileSystemCallbacksBase {
    123 public:
    124     static PassOwnPtr<AsyncFileSystemCallbacks> create(PassOwnPtr<EntryCallback>, PassOwnPtr<ErrorCallback>, ExecutionContext*);
    125     virtual void didResolveURL(const String& name, const KURL& rootURL, FileSystemType, const String& filePath, bool isDirectry) OVERRIDE;
    126 
    127 private:
    128     ResolveURICallbacks(PassOwnPtr<EntryCallback>, PassOwnPtr<ErrorCallback>, ExecutionContext*);
    129     OwnPtr<EntryCallback> m_successCallback;
    130 };
    131 
    132 class MetadataCallbacks FINAL : public FileSystemCallbacksBase {
    133 public:
    134     static PassOwnPtr<AsyncFileSystemCallbacks> create(PassOwnPtr<MetadataCallback>, PassOwnPtr<ErrorCallback>, ExecutionContext*, DOMFileSystemBase*);
    135     virtual void didReadMetadata(const FileMetadata&) OVERRIDE;
    136 
    137 private:
    138     MetadataCallbacks(PassOwnPtr<MetadataCallback>, PassOwnPtr<ErrorCallback>, ExecutionContext*, DOMFileSystemBase*);
    139     OwnPtr<MetadataCallback> m_successCallback;
    140 };
    141 
    142 class FileWriterBaseCallbacks FINAL : public FileSystemCallbacksBase {
    143 public:
    144     static PassOwnPtr<AsyncFileSystemCallbacks> create(PassRefPtrWillBeRawPtr<FileWriterBase>, PassOwnPtr<FileWriterBaseCallback>, PassOwnPtr<ErrorCallback>, ExecutionContext*);
    145     virtual void didCreateFileWriter(PassOwnPtr<blink::WebFileWriter>, long long length) OVERRIDE;
    146 
    147 private:
    148     FileWriterBaseCallbacks(PassRefPtrWillBeRawPtr<FileWriterBase>, PassOwnPtr<FileWriterBaseCallback>, PassOwnPtr<ErrorCallback>, ExecutionContext*);
    149     Persistent<FileWriterBase> m_fileWriter;
    150     OwnPtr<FileWriterBaseCallback> m_successCallback;
    151 };
    152 
    153 class VoidCallbacks FINAL : public FileSystemCallbacksBase {
    154 public:
    155     static PassOwnPtr<AsyncFileSystemCallbacks> create(PassOwnPtr<VoidCallback>, PassOwnPtr<ErrorCallback>, ExecutionContext*, DOMFileSystemBase*);
    156     virtual void didSucceed() OVERRIDE;
    157 
    158 private:
    159     VoidCallbacks(PassOwnPtr<VoidCallback>, PassOwnPtr<ErrorCallback>, ExecutionContext*, DOMFileSystemBase*);
    160     OwnPtr<VoidCallback> m_successCallback;
    161 };
    162 
    163 } // namespace
    164 
    165 #endif // FileSystemCallbacks_h
    166