kinuko@chromium.org | df557d9 | 2010-08-27 21:15:35 +0000 | [diff] [blame] | 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 | #if ENABLE(FILE_SYSTEM) |
| 35 | |
kinuko@chromium.org | 88ad0f0 | 2012-05-07 07:39:20 +0000 | [diff] [blame] | 36 | #include "FileSystemType.h" |
ericu@chromium.org | 5a589cc | 2011-06-14 20:01:19 +0000 | [diff] [blame] | 37 | #include "KURL.h" |
kinuko@chromium.org | 709beb1 | 2010-08-30 20:50:19 +0000 | [diff] [blame] | 38 | #include "Timer.h" |
kinuko@chromium.org | df557d9 | 2010-08-27 21:15:35 +0000 | [diff] [blame] | 39 | #include <wtf/PassOwnPtr.h> |
weinig@apple.com | 3f5ab02 | 2012-09-06 17:36:48 +0000 | [diff] [blame] | 40 | #include <wtf/text/WTFString.h> |
kinuko@chromium.org | df557d9 | 2010-08-27 21:15:35 +0000 | [diff] [blame] | 41 | |
| 42 | namespace WebCore { |
| 43 | |
| 44 | class AsyncFileSystem; |
| 45 | class AsyncFileSystemCallbacks; |
commit-queue@webkit.org | e23242e | 2010-09-23 19:33:39 +0000 | [diff] [blame] | 46 | class AsyncFileWriterClient; |
kinuko@chromium.org | df557d9 | 2010-08-27 21:15:35 +0000 | [diff] [blame] | 47 | |
kinuko@chromium.org | 709beb1 | 2010-08-30 20:50:19 +0000 | [diff] [blame] | 48 | // This class provides async interface for platform-specific file system implementation. Note that all the methods take platform paths. |
ossy@webkit.org | 95c1bc4 | 2011-01-20 16:30:54 +0000 | [diff] [blame] | 49 | class AsyncFileSystem { |
| 50 | WTF_MAKE_NONCOPYABLE(AsyncFileSystem); |
kinuko@chromium.org | df557d9 | 2010-08-27 21:15:35 +0000 | [diff] [blame] | 51 | public: |
| 52 | virtual ~AsyncFileSystem() { } |
| 53 | |
kinuko@chromium.org | df557d9 | 2010-08-27 21:15:35 +0000 | [diff] [blame] | 54 | virtual void stop() { } |
| 55 | virtual bool hasPendingActivity() { return false; } |
| 56 | |
kinuko@chromium.org | 5434e1b | 2010-09-24 00:46:01 +0000 | [diff] [blame] | 57 | static bool isAvailable(); |
| 58 | |
kinuko@chromium.org | 3256c0f | 2010-10-06 23:08:50 +0000 | [diff] [blame] | 59 | // Subclass must implement this if it supports synchronous operations. |
| 60 | // This should return false if there are no pending operations. |
| 61 | virtual bool waitForOperationToComplete() { return false; } |
| 62 | |
kinuko@chromium.org | df557d9 | 2010-08-27 21:15:35 +0000 | [diff] [blame] | 63 | // Creates and returns a new platform-specific AsyncFileSystem instance if the platform has its own implementation. |
kinuko@chromium.org | 7918db3 | 2012-05-08 03:34:47 +0000 | [diff] [blame] | 64 | static PassOwnPtr<AsyncFileSystem> create(); |
kinuko@chromium.org | df557d9 | 2010-08-27 21:15:35 +0000 | [diff] [blame] | 65 | |
commit-queue@webkit.org | 175640d | 2010-11-03 02:59:03 +0000 | [diff] [blame] | 66 | // Opens a new file system. The create parameter specifies whether or not to create the path if it does not already exists. |
commit-queue@webkit.org | a664e11 | 2012-09-30 02:29:57 +0000 | [diff] [blame] | 67 | static void openFileSystem(const String& basePath, const String& storageIdentifier, FileSystemType, bool create, PassOwnPtr<AsyncFileSystemCallbacks>); |
kinuko@chromium.org | df557d9 | 2010-08-27 21:15:35 +0000 | [diff] [blame] | 68 | |
commit-queue@webkit.org | d7d8bc7 | 2012-07-25 20:44:27 +0000 | [diff] [blame] | 69 | // Deletes the file system. |
| 70 | static void deleteFileSystem(const String& basePath, const String& storageIdentifier, FileSystemType, PassOwnPtr<AsyncFileSystemCallbacks>); |
| 71 | |
kinuko@chromium.org | df557d9 | 2010-08-27 21:15:35 +0000 | [diff] [blame] | 72 | // Moves a file or directory from srcPath to destPath. |
| 73 | // AsyncFileSystemCallbacks::didSucceed() is called when the operation is completed successfully. |
| 74 | // AsyncFileSystemCallbacks::didFail() is called otherwise. |
kinuko@chromium.org | 7918db3 | 2012-05-08 03:34:47 +0000 | [diff] [blame] | 75 | virtual void move(const KURL& srcPath, const KURL& destPath, PassOwnPtr<AsyncFileSystemCallbacks>) = 0; |
kinuko@chromium.org | df557d9 | 2010-08-27 21:15:35 +0000 | [diff] [blame] | 76 | |
| 77 | // Copies a file or directory from srcPath to destPath. |
| 78 | // AsyncFileSystemCallbacks::didSucceed() is called when the operation is completed successfully. |
| 79 | // AsyncFileSystemCallbacks::didFail() is called otherwise. |
kinuko@chromium.org | 7918db3 | 2012-05-08 03:34:47 +0000 | [diff] [blame] | 80 | virtual void copy(const KURL& srcPath, const KURL& destPath, PassOwnPtr<AsyncFileSystemCallbacks>) = 0; |
kinuko@chromium.org | df557d9 | 2010-08-27 21:15:35 +0000 | [diff] [blame] | 81 | |
| 82 | // Deletes a file or directory at a given path. |
kinuko@chromium.org | b107ea2 | 2010-10-11 11:21:28 +0000 | [diff] [blame] | 83 | // It is an error to try to remove a directory that is not empty. |
kinuko@chromium.org | df557d9 | 2010-08-27 21:15:35 +0000 | [diff] [blame] | 84 | // AsyncFileSystemCallbacks::didSucceed() is called when the operation is completed successfully. |
| 85 | // AsyncFileSystemCallbacks::didFail() is called otherwise. |
kinuko@chromium.org | 7918db3 | 2012-05-08 03:34:47 +0000 | [diff] [blame] | 86 | virtual void remove(const KURL& path, PassOwnPtr<AsyncFileSystemCallbacks>) = 0; |
kinuko@chromium.org | df557d9 | 2010-08-27 21:15:35 +0000 | [diff] [blame] | 87 | |
kinuko@chromium.org | b107ea2 | 2010-10-11 11:21:28 +0000 | [diff] [blame] | 88 | // Recursively deletes a directory at a given path. |
| 89 | // AsyncFileSystemCallbacks::didSucceed() is called when the operation is completed successfully. |
| 90 | // AsyncFileSystemCallbacks::didFail() is called otherwise. |
kinuko@chromium.org | 7918db3 | 2012-05-08 03:34:47 +0000 | [diff] [blame] | 91 | virtual void removeRecursively(const KURL& path, PassOwnPtr<AsyncFileSystemCallbacks>) = 0; |
kinuko@chromium.org | b107ea2 | 2010-10-11 11:21:28 +0000 | [diff] [blame] | 92 | |
kinuko@chromium.org | df557d9 | 2010-08-27 21:15:35 +0000 | [diff] [blame] | 93 | // Retrieves the metadata information of the file or directory at a given path. |
| 94 | // AsyncFileSystemCallbacks::didReadMetadata() is called when the operation is completed successfully. |
| 95 | // AsyncFileSystemCallbacks::didFail() is called otherwise. |
kinuko@chromium.org | 7918db3 | 2012-05-08 03:34:47 +0000 | [diff] [blame] | 96 | virtual void readMetadata(const KURL& path, PassOwnPtr<AsyncFileSystemCallbacks>) = 0; |
kinuko@chromium.org | df557d9 | 2010-08-27 21:15:35 +0000 | [diff] [blame] | 97 | |
| 98 | // Creates a file at a given path. If exclusive flag is true, it fails if the path already exists. |
| 99 | // AsyncFileSystemCallbacks::didSucceed() is called when the operation is completed successfully. |
| 100 | // AsyncFileSystemCallbacks::didFail() is called otherwise. |
kinuko@chromium.org | 7918db3 | 2012-05-08 03:34:47 +0000 | [diff] [blame] | 101 | virtual void createFile(const KURL& path, bool exclusive, PassOwnPtr<AsyncFileSystemCallbacks>) = 0; |
kinuko@chromium.org | df557d9 | 2010-08-27 21:15:35 +0000 | [diff] [blame] | 102 | |
| 103 | // Creates a directory at a given path. If exclusive flag is true, it fails if the path already exists. |
| 104 | // AsyncFileSystemCallbacks::didSucceed() is called when the operation is completed successfully. |
| 105 | // AsyncFileSystemCallbacks::didFail() is called otherwise. |
kinuko@chromium.org | 7918db3 | 2012-05-08 03:34:47 +0000 | [diff] [blame] | 106 | virtual void createDirectory(const KURL& path, bool exclusive, PassOwnPtr<AsyncFileSystemCallbacks>) = 0; |
kinuko@chromium.org | df557d9 | 2010-08-27 21:15:35 +0000 | [diff] [blame] | 107 | |
| 108 | // Checks if a file exists at a given path. |
| 109 | // AsyncFileSystemCallbacks::didSucceed() is called if the file exists. |
| 110 | // AsyncFileSystemCallbacks::didFail() is called otherwise. |
kinuko@chromium.org | 7918db3 | 2012-05-08 03:34:47 +0000 | [diff] [blame] | 111 | virtual void fileExists(const KURL& path, PassOwnPtr<AsyncFileSystemCallbacks>) = 0; |
kinuko@chromium.org | df557d9 | 2010-08-27 21:15:35 +0000 | [diff] [blame] | 112 | |
| 113 | // Checks if a directory exists at a given path. |
| 114 | // AsyncFileSystemCallbacks::didSucceed() is called if the directory exists. |
| 115 | // AsyncFileSystemCallbacks::didFail() is called otherwise. |
kinuko@chromium.org | 7918db3 | 2012-05-08 03:34:47 +0000 | [diff] [blame] | 116 | virtual void directoryExists(const KURL& path, PassOwnPtr<AsyncFileSystemCallbacks>) = 0; |
kinuko@chromium.org | df557d9 | 2010-08-27 21:15:35 +0000 | [diff] [blame] | 117 | |
| 118 | // Reads directory entries of a given directory at path. |
| 119 | // AsyncFileSystemCallbacks::didReadDirectoryEntry() is called when each directory entry is called. AsyncFileSystemCallbacks::didReadDirectoryEntries() is called after a chunk of directory entries have been read. |
| 120 | // AsyncFileSystemCallbacks::didFail() is when there is an error. |
kinuko@chromium.org | 7918db3 | 2012-05-08 03:34:47 +0000 | [diff] [blame] | 121 | virtual void readDirectory(const KURL& path, PassOwnPtr<AsyncFileSystemCallbacks>) = 0; |
kinuko@chromium.org | df557d9 | 2010-08-27 21:15:35 +0000 | [diff] [blame] | 122 | |
commit-queue@webkit.org | b12498d | 2010-09-23 00:07:46 +0000 | [diff] [blame] | 123 | // Creates an AsyncFileWriter for a given file path. |
| 124 | // AsyncFileSystemCallbacks::didCreateFileWriter() is called when an AsyncFileWriter is created successfully. |
| 125 | // AsyncFileSystemCallbacks::didFail() is called otherwise. |
kinuko@chromium.org | 7918db3 | 2012-05-08 03:34:47 +0000 | [diff] [blame] | 126 | virtual void createWriter(AsyncFileWriterClient*, const KURL& path, PassOwnPtr<AsyncFileSystemCallbacks>) = 0; |
commit-queue@webkit.org | b12498d | 2010-09-23 00:07:46 +0000 | [diff] [blame] | 127 | |
kinuko@chromium.org | e2f14c4 | 2012-03-01 09:18:28 +0000 | [diff] [blame] | 128 | // Creates a snapshot file and read its metadata for a new File object. |
| 129 | // In local filesystem cases the backend may simply return the metadata of the file itself (as well as readMetadata does), |
| 130 | // while in remote filesystem case the backend may download the file into a temporary snapshot file and return the metadata of the temporary file. |
| 131 | // AsyncFileSystemCallbacks::didReadMetadata() is called when the metadata for the snapshot file is successfully returned. |
| 132 | // AsyncFileSystemCallbacks::didFail() is called otherwise. |
kinuko@chromium.org | 5d69695 | 2012-05-17 12:07:55 +0000 | [diff] [blame] | 133 | // |
| 134 | // 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. |
kinuko@chromium.org | 7918db3 | 2012-05-08 03:34:47 +0000 | [diff] [blame] | 135 | virtual void createSnapshotFileAndReadMetadata(const KURL& path, PassOwnPtr<AsyncFileSystemCallbacks>) = 0; |
commit-queue@webkit.org | 3b8fac5 | 2011-02-11 21:39:04 +0000 | [diff] [blame] | 136 | |
kinuko@chromium.org | df557d9 | 2010-08-27 21:15:35 +0000 | [diff] [blame] | 137 | protected: |
kinuko@chromium.org | 7918db3 | 2012-05-08 03:34:47 +0000 | [diff] [blame] | 138 | AsyncFileSystem() { } |
kinuko@chromium.org | df557d9 | 2010-08-27 21:15:35 +0000 | [diff] [blame] | 139 | }; |
| 140 | |
| 141 | } // namespace WebCore |
| 142 | |
| 143 | #endif // ENABLE(FILE_SYSTEM) |
| 144 | |
| 145 | #endif // AsyncFileSystem_h |