Home | History | Annotate | Download | only in platform
      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 AsyncFileSystem_h
     32 #define AsyncFileSystem_h
     33 
     34 #include "core/platform/Timer.h"
     35 #include "modules/filesystem/FileSystemType.h"
     36 #include "wtf/PassOwnPtr.h"
     37 #include "wtf/text/WTFString.h"
     38 
     39 namespace WebCore {
     40 
     41 class AsyncFileSystem;
     42 class AsyncFileSystemCallbacks;
     43 class AsyncFileWriterClient;
     44 class KURL;
     45 
     46 // This class provides async interface for platform-specific file system implementation.  Note that all the methods take platform paths.
     47 class AsyncFileSystem {
     48     WTF_MAKE_NONCOPYABLE(AsyncFileSystem);
     49 public:
     50     virtual ~AsyncFileSystem() { }
     51 
     52     virtual void stop() { }
     53     virtual bool hasPendingActivity() { return false; }
     54 
     55     // Subclass must implement this if it supports synchronous operations.
     56     // This should return false if there are no pending operations.
     57     virtual bool waitForOperationToComplete() { return false; }
     58 
     59     // Creates and returns a new platform-specific AsyncFileSystem instance if the platform has its own implementation.
     60     static PassOwnPtr<AsyncFileSystem> create();
     61 
     62     // Opens a new file system. The create parameter specifies whether or not to create the path if it does not already exists.
     63     static void openFileSystem(const String& basePath, const String& storageIdentifier, FileSystemType, bool create, PassOwnPtr<AsyncFileSystemCallbacks>);
     64 
     65     // Deletes the file system.
     66     static void deleteFileSystem(const String& basePath, const String& storageIdentifier, FileSystemType, PassOwnPtr<AsyncFileSystemCallbacks>);
     67 
     68     // Moves a file or directory from srcPath to destPath.
     69     // AsyncFileSystemCallbacks::didSucceed() is called when the operation is completed successfully.
     70     // AsyncFileSystemCallbacks::didFail() is called otherwise.
     71     virtual void move(const KURL& srcPath, const KURL& destPath, PassOwnPtr<AsyncFileSystemCallbacks>) = 0;
     72 
     73     // Copies a file or directory from srcPath to destPath.
     74     // AsyncFileSystemCallbacks::didSucceed() is called when the operation is completed successfully.
     75     // AsyncFileSystemCallbacks::didFail() is called otherwise.
     76     virtual void copy(const KURL& srcPath, const KURL& destPath, PassOwnPtr<AsyncFileSystemCallbacks>) = 0;
     77 
     78     // Deletes a file or directory at a given path.
     79     // It is an error to try to remove a directory that is not empty.
     80     // AsyncFileSystemCallbacks::didSucceed() is called when the operation is completed successfully.
     81     // AsyncFileSystemCallbacks::didFail() is called otherwise.
     82     virtual void remove(const KURL& path, PassOwnPtr<AsyncFileSystemCallbacks>) = 0;
     83 
     84     // Recursively deletes a directory at a given path.
     85     // AsyncFileSystemCallbacks::didSucceed() is called when the operation is completed successfully.
     86     // AsyncFileSystemCallbacks::didFail() is called otherwise.
     87     virtual void removeRecursively(const KURL& path, PassOwnPtr<AsyncFileSystemCallbacks>) = 0;
     88 
     89     // Retrieves the metadata information of the file or directory at a given path.
     90     // AsyncFileSystemCallbacks::didReadMetadata() is called when the operation is completed successfully.
     91     // AsyncFileSystemCallbacks::didFail() is called otherwise.
     92     virtual void readMetadata(const KURL& path, PassOwnPtr<AsyncFileSystemCallbacks>) = 0;
     93 
     94     // Creates a file at a given path.  If exclusive flag is true, it fails if the path already exists.
     95     // AsyncFileSystemCallbacks::didSucceed() is called when the operation is completed successfully.
     96     // AsyncFileSystemCallbacks::didFail() is called otherwise.
     97     virtual void createFile(const KURL& path, bool exclusive, PassOwnPtr<AsyncFileSystemCallbacks>) = 0;
     98 
     99     // Creates a directory at a given path.  If exclusive flag is true, it fails if the path already exists.
    100     // AsyncFileSystemCallbacks::didSucceed() is called when the operation is completed successfully.
    101     // AsyncFileSystemCallbacks::didFail() is called otherwise.
    102     virtual void createDirectory(const KURL& path, bool exclusive, PassOwnPtr<AsyncFileSystemCallbacks>) = 0;
    103 
    104     // Checks if a file exists at a given path.
    105     // AsyncFileSystemCallbacks::didSucceed() is called if the file exists.
    106     // AsyncFileSystemCallbacks::didFail() is called otherwise.
    107     virtual void fileExists(const KURL& path, PassOwnPtr<AsyncFileSystemCallbacks>) = 0;
    108 
    109     // Checks if a directory exists at a given path.
    110     // AsyncFileSystemCallbacks::didSucceed() is called if the directory exists.
    111     // AsyncFileSystemCallbacks::didFail() is called otherwise.
    112     virtual void directoryExists(const KURL& path, PassOwnPtr<AsyncFileSystemCallbacks>) = 0;
    113 
    114     // Reads directory entries of a given directory at path.
    115     // AsyncFileSystemCallbacks::didReadDirectoryEntry() is called when each directory entry is called. AsyncFileSystemCallbacks::didReadDirectoryEntries() is called after a chunk of directory entries have been read.
    116     // AsyncFileSystemCallbacks::didFail() is when there is an error.
    117     virtual void readDirectory(const KURL& path, PassOwnPtr<AsyncFileSystemCallbacks>) = 0;
    118 
    119     // Creates an AsyncFileWriter for a given file path.
    120     // AsyncFileSystemCallbacks::didCreateFileWriter() is called when an AsyncFileWriter is created successfully.
    121     // AsyncFileSystemCallbacks::didFail() is called otherwise.
    122     virtual void createWriter(AsyncFileWriterClient*, const KURL& path, PassOwnPtr<AsyncFileSystemCallbacks>) = 0;
    123 
    124     // Creates a snapshot file and read its metadata for a new File object.
    125     // In local filesystem cases the backend may simply return the metadata of the file itself (as well as readMetadata does),
    126     // while in remote filesystem case the backend may download the file into a temporary snapshot file and return the metadata of the temporary file.
    127     // AsyncFileSystemCallbacks::didReadMetadata() is called when the metadata for the snapshot file is successfully returned.
    128     // AsyncFileSystemCallbacks::didFail() is called otherwise.
    129     //
    130     // Note: the returned metadata info is cached in the File object for non-regular filesystem types (neither Temporary nor Persistent). The port could return valid metadata if it wants File object to cache metadata (e.g. if the file body is on a remote server), but otherwise should NOT return valid metadata.
    131     virtual void createSnapshotFileAndReadMetadata(const KURL& path, PassOwnPtr<AsyncFileSystemCallbacks>) = 0;
    132 
    133 protected:
    134     AsyncFileSystem() { }
    135 };
    136 
    137 } // namespace WebCore
    138 
    139 #endif // AsyncFileSystem_h
    140