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