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/PassRefPtr.h"
     38 #include "wtf/Vector.h"
     39 #include "wtf/text/WTFString.h"
     40 
     41 namespace WebCore {
     42 
     43 class DOMFileSystemBase;
     44 class DirectoryReaderBase;
     45 class EntriesCallback;
     46 class EntryCallback;
     47 class ErrorCallback;
     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;
     62 
     63     // Other callback methods are implemented by each subclass.
     64 
     65 protected:
     66     FileSystemCallbacksBase(PassOwnPtr<ErrorCallback>, DOMFileSystemBase*);
     67     OwnPtr<ErrorCallback> m_errorCallback;
     68     DOMFileSystemBase* m_fileSystem;
     69 };
     70 
     71 // Subclasses ----------------------------------------------------------------
     72 
     73 class EntryCallbacks : public FileSystemCallbacksBase {
     74 public:
     75     static PassOwnPtr<AsyncFileSystemCallbacks> create(PassOwnPtr<EntryCallback>, PassOwnPtr<ErrorCallback>, PassRefPtr<DOMFileSystemBase>, const String& expectedPath, bool isDirectory);
     76     virtual void didSucceed();
     77 
     78 private:
     79     EntryCallbacks(PassOwnPtr<EntryCallback>, PassOwnPtr<ErrorCallback>, PassRefPtr<DOMFileSystemBase>, const String& expectedPath, bool isDirectory);
     80     OwnPtr<EntryCallback> m_successCallback;
     81     String m_expectedPath;
     82     bool m_isDirectory;
     83 };
     84 
     85 class EntriesCallbacks : public FileSystemCallbacksBase {
     86 public:
     87     static PassOwnPtr<AsyncFileSystemCallbacks> create(PassOwnPtr<EntriesCallback>, PassOwnPtr<ErrorCallback>, PassRefPtr<DirectoryReaderBase>, const String& basePath);
     88     virtual void didReadDirectoryEntry(const String& name, bool isDirectory);
     89     virtual void didReadDirectoryEntries(bool hasMore);
     90 
     91 private:
     92     EntriesCallbacks(PassOwnPtr<EntriesCallback>, PassOwnPtr<ErrorCallback>, PassRefPtr<DirectoryReaderBase>, const String& basePath);
     93     OwnPtr<EntriesCallback> m_successCallback;
     94     RefPtr<DirectoryReaderBase> m_directoryReader;
     95     String m_basePath;
     96     EntryVector m_entries;
     97 };
     98 
     99 class FileSystemCallbacks : public FileSystemCallbacksBase {
    100 public:
    101     static PassOwnPtr<AsyncFileSystemCallbacks> create(PassOwnPtr<FileSystemCallback>, PassOwnPtr<ErrorCallback>, ExecutionContext*, FileSystemType);
    102     virtual void didOpenFileSystem(const String& name, const KURL& rootURL);
    103 
    104 private:
    105     FileSystemCallbacks(PassOwnPtr<FileSystemCallback>, PassOwnPtr<ErrorCallback>, ExecutionContext*, FileSystemType);
    106     OwnPtr<FileSystemCallback> m_successCallback;
    107     RefPtr<ExecutionContext> m_executionContext;
    108     FileSystemType m_type;
    109 };
    110 
    111 class ResolveURICallbacks : public FileSystemCallbacksBase {
    112 public:
    113     static PassOwnPtr<AsyncFileSystemCallbacks> create(PassOwnPtr<EntryCallback>, PassOwnPtr<ErrorCallback>, ExecutionContext*);
    114     virtual void didResolveURL(const String& name, const KURL& rootURL, FileSystemType, const String& filePath, bool isDirectry);
    115 
    116 private:
    117     ResolveURICallbacks(PassOwnPtr<EntryCallback>, PassOwnPtr<ErrorCallback>, ExecutionContext*);
    118     OwnPtr<EntryCallback> m_successCallback;
    119     RefPtr<ExecutionContext> m_executionContext;
    120 };
    121 
    122 class MetadataCallbacks : public FileSystemCallbacksBase {
    123 public:
    124     static PassOwnPtr<AsyncFileSystemCallbacks> create(PassOwnPtr<MetadataCallback>, PassOwnPtr<ErrorCallback>, DOMFileSystemBase*);
    125     virtual void didReadMetadata(const FileMetadata&);
    126 
    127 private:
    128     MetadataCallbacks(PassOwnPtr<MetadataCallback>, PassOwnPtr<ErrorCallback>, DOMFileSystemBase*);
    129     OwnPtr<MetadataCallback> m_successCallback;
    130 };
    131 
    132 class FileWriterBaseCallbacks : public FileSystemCallbacksBase {
    133 public:
    134     static PassOwnPtr<AsyncFileSystemCallbacks> create(PassRefPtr<FileWriterBase>, PassOwnPtr<FileWriterBaseCallback>, PassOwnPtr<ErrorCallback>);
    135     virtual void didCreateFileWriter(PassOwnPtr<blink::WebFileWriter>, long long length);
    136 
    137 private:
    138     FileWriterBaseCallbacks(PassRefPtr<FileWriterBase>, PassOwnPtr<FileWriterBaseCallback>, PassOwnPtr<ErrorCallback>);
    139     RefPtr<FileWriterBase> m_fileWriter;
    140     OwnPtr<FileWriterBaseCallback> m_successCallback;
    141 };
    142 
    143 class VoidCallbacks : public FileSystemCallbacksBase {
    144 public:
    145     static PassOwnPtr<AsyncFileSystemCallbacks> create(PassOwnPtr<VoidCallback>, PassOwnPtr<ErrorCallback>, DOMFileSystemBase*);
    146     virtual void didSucceed();
    147 
    148 private:
    149     VoidCallbacks(PassOwnPtr<VoidCallback>, PassOwnPtr<ErrorCallback>, DOMFileSystemBase*);
    150     OwnPtr<VoidCallback> m_successCallback;
    151 };
    152 
    153 } // namespace
    154 
    155 #endif // FileSystemCallbacks_h
    156