blob: af5c51232a94d5c9d3a82d0245892a2fc568f169 [file] [log] [blame]
kinuko@chromium.orgdf557d92010-08-27 21:15:35 +00001/*
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.org88ad0f02012-05-07 07:39:20 +000036#include "FileSystemType.h"
ericu@chromium.org5a589cc2011-06-14 20:01:19 +000037#include "KURL.h"
kinuko@chromium.org709beb12010-08-30 20:50:19 +000038#include "Timer.h"
kinuko@chromium.orgdf557d92010-08-27 21:15:35 +000039#include <wtf/PassOwnPtr.h>
weinig@apple.com3f5ab022012-09-06 17:36:48 +000040#include <wtf/text/WTFString.h>
kinuko@chromium.orgdf557d92010-08-27 21:15:35 +000041
42namespace WebCore {
43
44class AsyncFileSystem;
45class AsyncFileSystemCallbacks;
commit-queue@webkit.orge23242e2010-09-23 19:33:39 +000046class AsyncFileWriterClient;
kinuko@chromium.orgdf557d92010-08-27 21:15:35 +000047
kinuko@chromium.org709beb12010-08-30 20:50:19 +000048// This class provides async interface for platform-specific file system implementation. Note that all the methods take platform paths.
ossy@webkit.org95c1bc42011-01-20 16:30:54 +000049class AsyncFileSystem {
50 WTF_MAKE_NONCOPYABLE(AsyncFileSystem);
kinuko@chromium.orgdf557d92010-08-27 21:15:35 +000051public:
52 virtual ~AsyncFileSystem() { }
53
kinuko@chromium.orgdf557d92010-08-27 21:15:35 +000054 virtual void stop() { }
55 virtual bool hasPendingActivity() { return false; }
56
kinuko@chromium.org5434e1b2010-09-24 00:46:01 +000057 static bool isAvailable();
58
kinuko@chromium.org3256c0f2010-10-06 23:08:50 +000059 // 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.orgdf557d92010-08-27 21:15:35 +000063 // Creates and returns a new platform-specific AsyncFileSystem instance if the platform has its own implementation.
kinuko@chromium.org7918db32012-05-08 03:34:47 +000064 static PassOwnPtr<AsyncFileSystem> create();
kinuko@chromium.orgdf557d92010-08-27 21:15:35 +000065
commit-queue@webkit.org175640d2010-11-03 02:59:03 +000066 // 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.orga664e112012-09-30 02:29:57 +000067 static void openFileSystem(const String& basePath, const String& storageIdentifier, FileSystemType, bool create, PassOwnPtr<AsyncFileSystemCallbacks>);
kinuko@chromium.orgdf557d92010-08-27 21:15:35 +000068
commit-queue@webkit.orgd7d8bc72012-07-25 20:44:27 +000069 // Deletes the file system.
70 static void deleteFileSystem(const String& basePath, const String& storageIdentifier, FileSystemType, PassOwnPtr<AsyncFileSystemCallbacks>);
71
kinuko@chromium.orgdf557d92010-08-27 21:15:35 +000072 // 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.org7918db32012-05-08 03:34:47 +000075 virtual void move(const KURL& srcPath, const KURL& destPath, PassOwnPtr<AsyncFileSystemCallbacks>) = 0;
kinuko@chromium.orgdf557d92010-08-27 21:15:35 +000076
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.org7918db32012-05-08 03:34:47 +000080 virtual void copy(const KURL& srcPath, const KURL& destPath, PassOwnPtr<AsyncFileSystemCallbacks>) = 0;
kinuko@chromium.orgdf557d92010-08-27 21:15:35 +000081
82 // Deletes a file or directory at a given path.
kinuko@chromium.orgb107ea22010-10-11 11:21:28 +000083 // It is an error to try to remove a directory that is not empty.
kinuko@chromium.orgdf557d92010-08-27 21:15:35 +000084 // AsyncFileSystemCallbacks::didSucceed() is called when the operation is completed successfully.
85 // AsyncFileSystemCallbacks::didFail() is called otherwise.
kinuko@chromium.org7918db32012-05-08 03:34:47 +000086 virtual void remove(const KURL& path, PassOwnPtr<AsyncFileSystemCallbacks>) = 0;
kinuko@chromium.orgdf557d92010-08-27 21:15:35 +000087
kinuko@chromium.orgb107ea22010-10-11 11:21:28 +000088 // 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.org7918db32012-05-08 03:34:47 +000091 virtual void removeRecursively(const KURL& path, PassOwnPtr<AsyncFileSystemCallbacks>) = 0;
kinuko@chromium.orgb107ea22010-10-11 11:21:28 +000092
kinuko@chromium.orgdf557d92010-08-27 21:15:35 +000093 // 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.org7918db32012-05-08 03:34:47 +000096 virtual void readMetadata(const KURL& path, PassOwnPtr<AsyncFileSystemCallbacks>) = 0;
kinuko@chromium.orgdf557d92010-08-27 21:15:35 +000097
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.org7918db32012-05-08 03:34:47 +0000101 virtual void createFile(const KURL& path, bool exclusive, PassOwnPtr<AsyncFileSystemCallbacks>) = 0;
kinuko@chromium.orgdf557d92010-08-27 21:15:35 +0000102
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.org7918db32012-05-08 03:34:47 +0000106 virtual void createDirectory(const KURL& path, bool exclusive, PassOwnPtr<AsyncFileSystemCallbacks>) = 0;
kinuko@chromium.orgdf557d92010-08-27 21:15:35 +0000107
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.org7918db32012-05-08 03:34:47 +0000111 virtual void fileExists(const KURL& path, PassOwnPtr<AsyncFileSystemCallbacks>) = 0;
kinuko@chromium.orgdf557d92010-08-27 21:15:35 +0000112
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.org7918db32012-05-08 03:34:47 +0000116 virtual void directoryExists(const KURL& path, PassOwnPtr<AsyncFileSystemCallbacks>) = 0;
kinuko@chromium.orgdf557d92010-08-27 21:15:35 +0000117
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.org7918db32012-05-08 03:34:47 +0000121 virtual void readDirectory(const KURL& path, PassOwnPtr<AsyncFileSystemCallbacks>) = 0;
kinuko@chromium.orgdf557d92010-08-27 21:15:35 +0000122
commit-queue@webkit.orgb12498d2010-09-23 00:07:46 +0000123 // 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.org7918db32012-05-08 03:34:47 +0000126 virtual void createWriter(AsyncFileWriterClient*, const KURL& path, PassOwnPtr<AsyncFileSystemCallbacks>) = 0;
commit-queue@webkit.orgb12498d2010-09-23 00:07:46 +0000127
kinuko@chromium.orge2f14c42012-03-01 09:18:28 +0000128 // 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.org5d696952012-05-17 12:07:55 +0000133 //
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.org7918db32012-05-08 03:34:47 +0000135 virtual void createSnapshotFileAndReadMetadata(const KURL& path, PassOwnPtr<AsyncFileSystemCallbacks>) = 0;
commit-queue@webkit.org3b8fac52011-02-11 21:39:04 +0000136
kinuko@chromium.orgdf557d92010-08-27 21:15:35 +0000137protected:
kinuko@chromium.org7918db32012-05-08 03:34:47 +0000138 AsyncFileSystem() { }
kinuko@chromium.orgdf557d92010-08-27 21:15:35 +0000139};
140
141} // namespace WebCore
142
143#endif // ENABLE(FILE_SYSTEM)
144
145#endif // AsyncFileSystem_h