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 | |
| 36 | #include "PlatformString.h" |
kinuko@chromium.org | 709beb1 | 2010-08-30 20:50:19 +0000 | [diff] [blame] | 37 | #include "Timer.h" |
kinuko@chromium.org | df557d9 | 2010-08-27 21:15:35 +0000 | [diff] [blame] | 38 | #include <wtf/PassOwnPtr.h> |
| 39 | |
| 40 | namespace WebCore { |
| 41 | |
| 42 | class AsyncFileSystem; |
| 43 | class AsyncFileSystemCallbacks; |
commit-queue@webkit.org | e23242e | 2010-09-23 19:33:39 +0000 | [diff] [blame] | 44 | class AsyncFileWriterClient; |
kinuko@chromium.org | df557d9 | 2010-08-27 21:15:35 +0000 | [diff] [blame] | 45 | |
kinuko@chromium.org | 709beb1 | 2010-08-30 20:50:19 +0000 | [diff] [blame] | 46 | // This class provides async interface for platform-specific file system implementation. Note that all the methods take platform paths. |
kinuko@chromium.org | df557d9 | 2010-08-27 21:15:35 +0000 | [diff] [blame] | 47 | class AsyncFileSystem : public Noncopyable { |
| 48 | public: |
| 49 | virtual ~AsyncFileSystem() { } |
| 50 | |
| 51 | // FileSystem type |
| 52 | enum Type { |
| 53 | Temporary, |
| 54 | Persistent, |
| 55 | }; |
| 56 | |
| 57 | virtual void stop() { } |
| 58 | virtual bool hasPendingActivity() { return false; } |
| 59 | |
kinuko@chromium.org | 5434e1b | 2010-09-24 00:46:01 +0000 | [diff] [blame^] | 60 | static bool isAvailable(); |
| 61 | |
kinuko@chromium.org | df557d9 | 2010-08-27 21:15:35 +0000 | [diff] [blame] | 62 | // Creates and returns a new platform-specific AsyncFileSystem instance if the platform has its own implementation. |
| 63 | static PassOwnPtr<AsyncFileSystem> create(const String& rootPath); |
| 64 | |
| 65 | // Opens a new file system. |
| 66 | static void openFileSystem(const String& basePath, const String& storageIdentifier, Type, 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 String& srcPath, const String& 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 String& srcPath, const String& destPath, PassOwnPtr<AsyncFileSystemCallbacks>) = 0; |
| 77 | |
| 78 | // Deletes a file or directory at a given path. |
| 79 | // AsyncFileSystemCallbacks::didSucceed() is called when the operation is completed successfully. |
| 80 | // AsyncFileSystemCallbacks::didFail() is called otherwise. |
| 81 | virtual void remove(const String& path, PassOwnPtr<AsyncFileSystemCallbacks>) = 0; |
| 82 | |
| 83 | // Retrieves the metadata information of the file or directory at a given path. |
| 84 | // AsyncFileSystemCallbacks::didReadMetadata() is called when the operation is completed successfully. |
| 85 | // AsyncFileSystemCallbacks::didFail() is called otherwise. |
| 86 | virtual void readMetadata(const String& path, PassOwnPtr<AsyncFileSystemCallbacks>) = 0; |
| 87 | |
| 88 | // Creates a file at a given path. If exclusive flag is true, it fails if the path already exists. |
| 89 | // AsyncFileSystemCallbacks::didSucceed() is called when the operation is completed successfully. |
| 90 | // AsyncFileSystemCallbacks::didFail() is called otherwise. |
| 91 | virtual void createFile(const String& path, bool exclusive, PassOwnPtr<AsyncFileSystemCallbacks>) = 0; |
| 92 | |
| 93 | // Creates a directory at a given path. If exclusive flag is true, it fails if the path already exists. |
| 94 | // AsyncFileSystemCallbacks::didSucceed() is called when the operation is completed successfully. |
| 95 | // AsyncFileSystemCallbacks::didFail() is called otherwise. |
| 96 | virtual void createDirectory(const String& path, bool exclusive, PassOwnPtr<AsyncFileSystemCallbacks>) = 0; |
| 97 | |
| 98 | // Checks if a file exists at a given path. |
| 99 | // AsyncFileSystemCallbacks::didSucceed() is called if the file exists. |
| 100 | // AsyncFileSystemCallbacks::didFail() is called otherwise. |
| 101 | virtual void fileExists(const String& path, PassOwnPtr<AsyncFileSystemCallbacks>) = 0; |
| 102 | |
| 103 | // Checks if a directory exists at a given path. |
| 104 | // AsyncFileSystemCallbacks::didSucceed() is called if the directory exists. |
| 105 | // AsyncFileSystemCallbacks::didFail() is called otherwise. |
| 106 | virtual void directoryExists(const String& path, PassOwnPtr<AsyncFileSystemCallbacks>) = 0; |
| 107 | |
| 108 | // Reads directory entries of a given directory at path. |
| 109 | // AsyncFileSystemCallbacks::didReadDirectoryEntry() is called when each directory entry is called. AsyncFileSystemCallbacks::didReadDirectoryEntries() is called after a chunk of directory entries have been read. |
| 110 | // AsyncFileSystemCallbacks::didFail() is when there is an error. |
| 111 | virtual void readDirectory(const String& path, PassOwnPtr<AsyncFileSystemCallbacks>) = 0; |
| 112 | |
commit-queue@webkit.org | b12498d | 2010-09-23 00:07:46 +0000 | [diff] [blame] | 113 | // Creates an AsyncFileWriter for a given file path. |
| 114 | // AsyncFileSystemCallbacks::didCreateFileWriter() is called when an AsyncFileWriter is created successfully. |
| 115 | // AsyncFileSystemCallbacks::didFail() is called otherwise. |
commit-queue@webkit.org | e23242e | 2010-09-23 19:33:39 +0000 | [diff] [blame] | 116 | virtual void createWriter(AsyncFileWriterClient* client, const String& path, PassOwnPtr<AsyncFileSystemCallbacks>) = 0; |
commit-queue@webkit.org | b12498d | 2010-09-23 00:07:46 +0000 | [diff] [blame] | 117 | |
kinuko@chromium.org | df557d9 | 2010-08-27 21:15:35 +0000 | [diff] [blame] | 118 | // Converts a given absolute virtual path to a platform path that starts with the platform root path of this file system. |
| 119 | virtual String virtualToPlatformPath(const String& path) const; |
| 120 | |
| 121 | protected: |
| 122 | AsyncFileSystem(const String& platformRootPath) |
| 123 | : m_platformRootPath(platformRootPath) |
| 124 | { |
| 125 | } |
| 126 | |
| 127 | String m_platformRootPath; |
| 128 | }; |
| 129 | |
| 130 | } // namespace WebCore |
| 131 | |
| 132 | #endif // ENABLE(FILE_SYSTEM) |
| 133 | |
| 134 | #endif // AsyncFileSystem_h |