blob: 1bf7580821bb307bdef01b6bf004c9b3498b75ff [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
36#include "PlatformString.h"
kinuko@chromium.org709beb12010-08-30 20:50:19 +000037#include "Timer.h"
kinuko@chromium.orgdf557d92010-08-27 21:15:35 +000038#include <wtf/PassOwnPtr.h>
39
40namespace WebCore {
41
42class AsyncFileSystem;
43class AsyncFileSystemCallbacks;
commit-queue@webkit.orge23242e2010-09-23 19:33:39 +000044class AsyncFileWriterClient;
kinuko@chromium.orgdf557d92010-08-27 21:15:35 +000045
kinuko@chromium.org709beb12010-08-30 20:50:19 +000046// This class provides async interface for platform-specific file system implementation. Note that all the methods take platform paths.
kinuko@chromium.orgdf557d92010-08-27 21:15:35 +000047class AsyncFileSystem : public Noncopyable {
48public:
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.org5434e1b2010-09-24 00:46:01 +000060 static bool isAvailable();
61
kinuko@chromium.orgdf557d92010-08-27 21:15:35 +000062 // 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.orgb12498d2010-09-23 00:07:46 +0000113 // 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.orge23242e2010-09-23 19:33:39 +0000116 virtual void createWriter(AsyncFileWriterClient* client, const String& path, PassOwnPtr<AsyncFileSystemCallbacks>) = 0;
commit-queue@webkit.orgb12498d2010-09-23 00:07:46 +0000117
kinuko@chromium.orgdf557d92010-08-27 21:15:35 +0000118 // 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
121protected:
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