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 "core/platform/AsyncFileSystemCallbacks.h"
     35 #include "modules/filesystem/EntriesCallback.h"
     36 #include "modules/filesystem/FileSystemType.h"
     37 #include "wtf/PassRefPtr.h"
     38 #include "wtf/Vector.h"
     39 #include "wtf/text/WTFString.h"
     40 
     41 namespace WebCore {
     42 
     43 class AsyncFileWriter;
     44 class DOMFileSystemBase;
     45 class DirectoryReaderBase;
     46 class EntriesCallback;
     47 class EntryCallback;
     48 class ErrorCallback;
     49 struct FileMetadata;
     50 class FileSystemCallback;
     51 class FileWriterBase;
     52 class FileWriterBaseCallback;
     53 class MetadataCallback;
     54 class ScriptExecutionContext;
     55 class VoidCallback;
     56 
     57 class FileSystemCallbacksBase : public AsyncFileSystemCallbacks {
     58 public:
     59     virtual ~FileSystemCallbacksBase();
     60 
     61     // For ErrorCallback.
     62     virtual void didFail(int code) OVERRIDE;
     63 
     64     // Other callback methods are implemented by each subclass.
     65 
     66     virtual bool shouldBlockUntilCompletion() const OVERRIDE
     67     {
     68         return m_blockUntilCompletion;
     69     }
     70 
     71     void setShouldBlockUntilCompletion(bool flag)
     72     {
     73         m_blockUntilCompletion = flag;
     74     }
     75 
     76 protected:
     77     FileSystemCallbacksBase(PassRefPtr<ErrorCallback>);
     78     RefPtr<ErrorCallback> m_errorCallback;
     79     bool m_blockUntilCompletion;
     80 };
     81 
     82 // Subclasses ----------------------------------------------------------------
     83 
     84 class EntryCallbacks : public FileSystemCallbacksBase {
     85 public:
     86     static PassOwnPtr<EntryCallbacks> create(PassRefPtr<EntryCallback>, PassRefPtr<ErrorCallback>, PassRefPtr<DOMFileSystemBase>, const String& expectedPath, bool isDirectory);
     87     virtual void didSucceed();
     88 
     89 private:
     90     EntryCallbacks(PassRefPtr<EntryCallback>, PassRefPtr<ErrorCallback>, PassRefPtr<DOMFileSystemBase>, const String& expectedPath, bool isDirectory);
     91     RefPtr<EntryCallback> m_successCallback;
     92     RefPtr<DOMFileSystemBase> m_fileSystem;
     93     String m_expectedPath;
     94     bool m_isDirectory;
     95 };
     96 
     97 class EntriesCallbacks : public FileSystemCallbacksBase {
     98 public:
     99     static PassOwnPtr<EntriesCallbacks> create(PassRefPtr<EntriesCallback>, PassRefPtr<ErrorCallback>, PassRefPtr<DirectoryReaderBase>, const String& basePath);
    100     virtual void didReadDirectoryEntry(const String& name, bool isDirectory);
    101     virtual void didReadDirectoryEntries(bool hasMore);
    102 
    103 private:
    104     EntriesCallbacks(PassRefPtr<EntriesCallback>, PassRefPtr<ErrorCallback>, PassRefPtr<DirectoryReaderBase>, const String& basePath);
    105     RefPtr<EntriesCallback> m_successCallback;
    106     RefPtr<DirectoryReaderBase> m_directoryReader;
    107     String m_basePath;
    108     EntryVector m_entries;
    109 };
    110 
    111 class FileSystemCallbacks : public FileSystemCallbacksBase {
    112 public:
    113     static PassOwnPtr<FileSystemCallbacks> create(PassRefPtr<FileSystemCallback>, PassRefPtr<ErrorCallback>, ScriptExecutionContext*, FileSystemType);
    114     virtual void didOpenFileSystem(const String& name, const KURL& rootURL, PassOwnPtr<AsyncFileSystem>);
    115 
    116 private:
    117     FileSystemCallbacks(PassRefPtr<FileSystemCallback>, PassRefPtr<ErrorCallback>, ScriptExecutionContext*, FileSystemType);
    118     RefPtr<FileSystemCallback> m_successCallback;
    119     RefPtr<ScriptExecutionContext> m_scriptExecutionContext;
    120     FileSystemType m_type;
    121 };
    122 
    123 class ResolveURICallbacks : public FileSystemCallbacksBase {
    124 public:
    125     static PassOwnPtr<ResolveURICallbacks> create(PassRefPtr<EntryCallback>, PassRefPtr<ErrorCallback>, ScriptExecutionContext*, FileSystemType, const String& filePath);
    126     virtual void didOpenFileSystem(const String& name, const KURL& rootURL, PassOwnPtr<AsyncFileSystem>);
    127 
    128 private:
    129     ResolveURICallbacks(PassRefPtr<EntryCallback>, PassRefPtr<ErrorCallback>, ScriptExecutionContext*, FileSystemType, const String& filePath);
    130     RefPtr<EntryCallback> m_successCallback;
    131     RefPtr<ScriptExecutionContext> m_scriptExecutionContext;
    132     FileSystemType m_type;
    133     String m_filePath;
    134 };
    135 
    136 class MetadataCallbacks : public FileSystemCallbacksBase {
    137 public:
    138     static PassOwnPtr<MetadataCallbacks> create(PassRefPtr<MetadataCallback>, PassRefPtr<ErrorCallback>);
    139     virtual void didReadMetadata(const FileMetadata&);
    140 
    141 private:
    142     MetadataCallbacks(PassRefPtr<MetadataCallback>, PassRefPtr<ErrorCallback>);
    143     RefPtr<MetadataCallback> m_successCallback;
    144 };
    145 
    146 class FileWriterBaseCallbacks : public FileSystemCallbacksBase {
    147 public:
    148     static PassOwnPtr<FileWriterBaseCallbacks> create(PassRefPtr<FileWriterBase>, PassRefPtr<FileWriterBaseCallback>, PassRefPtr<ErrorCallback>);
    149     virtual void didCreateFileWriter(PassOwnPtr<AsyncFileWriter>, long long length);
    150 
    151 private:
    152     FileWriterBaseCallbacks(PassRefPtr<FileWriterBase>, PassRefPtr<FileWriterBaseCallback>, PassRefPtr<ErrorCallback>);
    153     RefPtr<FileWriterBase> m_fileWriter;
    154     RefPtr<FileWriterBaseCallback> m_successCallback;
    155 };
    156 
    157 class VoidCallbacks : public FileSystemCallbacksBase {
    158 public:
    159     static PassOwnPtr<VoidCallbacks> create(PassRefPtr<VoidCallback>, PassRefPtr<ErrorCallback>);
    160     virtual void didSucceed();
    161 
    162 private:
    163     VoidCallbacks(PassRefPtr<VoidCallback>, PassRefPtr<ErrorCallback>);
    164     RefPtr<VoidCallback> m_successCallback;
    165 };
    166 
    167 } // namespace
    168 
    169 #endif // FileSystemCallbacks_h
    170