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 WebFileSystem_h
     32 #define WebFileSystem_h
     33 
     34 #include "WebCommon.h"
     35 #include "WebFileSystemType.h"
     36 #include "WebURL.h"
     37 
     38 namespace WebKit {
     39 
     40 // FIXME: Move these classes into platform.
     41 class WebFileSystemCallbacks;
     42 class WebFileWriter;
     43 class WebFileWriterClient;
     44 
     45 class WebFileSystem {
     46 public:
     47     enum Type {
     48         TypeTemporary,
     49         TypePersistent,
     50 
     51         // Indicates an isolated filesystem which only exposes a set of files.
     52         TypeIsolated,
     53 
     54         // Indicates a non-sandboxed filesystem.
     55         TypeExternal,
     56     };
     57 
     58     // Moves a file or directory at |srcPath| to |destPath|.
     59     // WebFileSystemCallbacks::didSucceed() must be called when the operation is completed successfully.
     60     // WebFileSystemCallbacks::didFail() must be called otherwise.
     61     virtual void move(const WebURL& srcPath, const WebURL& destPath, WebFileSystemCallbacks*) { WEBKIT_ASSERT_NOT_REACHED(); }
     62 
     63     // Copies a file or directory at |srcPath| to |destPath|.
     64     // WebFileSystemCallbacks::didSucceed() must be called when the operation is completed successfully.
     65     // WebFileSystemCallbacks::didFail() must be called otherwise.
     66     virtual void copy(const WebURL& srcPath, const WebURL& destPath, WebFileSystemCallbacks*) { WEBKIT_ASSERT_NOT_REACHED(); }
     67 
     68     // Deletes a file or directory at a given |path|.
     69     // It is an error to try to remove a directory that is not empty.
     70     // WebFileSystemCallbacks::didSucceed() must be called when the operation is completed successfully.
     71     // WebFileSystemCallbacks::didFail() must be called otherwise.
     72     virtual void remove(const WebURL& path, WebFileSystemCallbacks*) { WEBKIT_ASSERT_NOT_REACHED(); }
     73 
     74     // Deletes a file or directory recursively at a given |path|.
     75     // WebFileSystemCallbacks::didSucceed() must be called when the operation is completed successfully.
     76     // WebFileSystemCallbacks::didFail() must be called otherwise.
     77     virtual void removeRecursively(const WebURL& path, WebFileSystemCallbacks*) { WEBKIT_ASSERT_NOT_REACHED(); }
     78 
     79     // Retrieves the metadata information of the file or directory at the given |path|.
     80     // This may not always return the local platform path in remote filesystem cases.
     81     // WebFileSystemCallbacks::didReadMetadata() must be called with a valid metadata when the retrieval is completed successfully.
     82     // WebFileSystemCallbacks::didFail() must be called otherwise.
     83     virtual void readMetadata(const WebURL& path, WebFileSystemCallbacks*) { WEBKIT_ASSERT_NOT_REACHED(); }
     84 
     85     // Creates a file at given |path|.
     86     // If the |path| doesn't exist, it creates a new file at |path|.
     87     // If |exclusive| is true, it fails if the |path| already exists.
     88     // If |exclusive| is false, it succeeds if the |path| already exists or
     89     // it has successfully created a new file at |path|.
     90     //
     91     // WebFileSystemCallbacks::didSucceed() must be called when the operation is completed successfully.
     92     // WebFileSystemCallbacks::didFail() must be called otherwise.
     93     virtual void createFile(const WebURL& path, bool exclusive, WebFileSystemCallbacks*) { WEBKIT_ASSERT_NOT_REACHED(); }
     94 
     95     // Creates a directory at a given |path|.
     96     // If the |path| doesn't exist, it creates a new directory at |path|.
     97     // If |exclusive| is true, it fails if the |path| already exists.
     98     // If |exclusive| is false, it succeeds if the |path| already exists or it has successfully created a new directory at |path|.
     99     //
    100     // WebFileSystemCallbacks::didSucceed() must be called when
    101     // the operation is completed successfully.
    102     // WebFileSystemCallbacks::didFail() must be called otherwise.
    103     virtual void createDirectory(const WebURL& path, bool exclusive, WebFileSystemCallbacks*) { WEBKIT_ASSERT_NOT_REACHED(); }
    104 
    105     // Checks if a file exists at a given |path|.
    106     // WebFileSystemCallbacks::didSucceed() must be called when the operation is completed successfully.
    107     // WebFileSystemCallbacks::didFail() must be called otherwise.
    108     virtual void fileExists(const WebURL& path, WebFileSystemCallbacks*) { WEBKIT_ASSERT_NOT_REACHED(); }
    109 
    110     // Checks if a directory exists at a given |path|.
    111     // WebFileSystemCallbacks::didSucceed() must be called when the operation is completed successfully.
    112     // WebFileSystemCallbacks::didFail() must be called otherwise.
    113     virtual void directoryExists(const WebURL& path, WebFileSystemCallbacks*) { WEBKIT_ASSERT_NOT_REACHED(); }
    114 
    115     // Reads directory entries of a given directory at |path|.
    116     // WebFileSystemCallbacks::didReadDirectory() must be called when the operation is completed successfully.
    117     // WebFileSystemCallbacks::didFail() must be called otherwise.
    118     virtual void readDirectory(const WebURL& path, WebFileSystemCallbacks*) { WEBKIT_ASSERT_NOT_REACHED(); }
    119 
    120     // Creates a WebFileWriter that can be used to write to the given file.
    121     // This is a fast, synchronous call, and should not stat the filesystem.
    122     // FIXME: deprecate this after async version of createFileWriter is
    123     // implemented.
    124     virtual WebFileWriter* createFileWriter(const WebURL& path, WebFileWriterClient*) { WEBKIT_ASSERT_NOT_REACHED(); return 0; }
    125 
    126     // Creates a WebFileWriter that can be used to write to the given file.
    127     // WebFileSystemCallbacks::didCreateFileWriter() must be called with the created WebFileWriter when the operation is completed successfully.
    128     // WebFileSystemCallbacks::didFail() must be called otherwise.
    129     virtual void createFileWriter(const WebURL& path, WebFileWriterClient*, WebFileSystemCallbacks*) { WEBKIT_ASSERT_NOT_REACHED(); }
    130 
    131     // Creates a snapshot file for a given file specified by |path|. It returns the metadata of the created snapshot file.
    132     // The returned metadata should include a local platform path to the snapshot image.
    133     // In local filesystem cases the backend may simply return the metadata of the file itself (as well as readMetadata does), while in
    134     // remote filesystem case the backend may download the file into a temporary snapshot file and return the metadata of the temporary file.
    135     // The returned metadata is used to create a File object for the |path|.
    136     // The snapshot file is supposed to be deleted when the last reference to a WebCore::File referring to it's path is dropped.
    137     // WebFileSystemCallbacks::didCreateSnapshotFile() with the metadata of the snapshot file must be called when the operation is completed successfully.
    138     // WebFileSystemCallbacks::didFail() must be called otherwise.
    139     virtual void createSnapshotFileAndReadMetadata(const WebURL& path, WebFileSystemCallbacks*) { WEBKIT_ASSERT_NOT_REACHED(); }
    140 
    141 protected:
    142     virtual ~WebFileSystem() { }
    143 };
    144 
    145 } // namespace WebKit
    146 
    147 #endif
    148