AsyncFileSystem.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. #ifndef AsyncFileSystem_h
  31. #define AsyncFileSystem_h
  32. #if ENABLE(FILE_SYSTEM)
  33. #include "FileSystemType.h"
  34. #include "KURL.h"
  35. #include "Timer.h"
  36. #include <wtf/PassOwnPtr.h>
  37. #include <wtf/text/WTFString.h>
  38. namespace WebCore {
  39. class AsyncFileSystem;
  40. class AsyncFileSystemCallbacks;
  41. class AsyncFileWriterClient;
  42. // This class provides async interface for platform-specific file system implementation. Note that all the methods take platform paths.
  43. class AsyncFileSystem {
  44. WTF_MAKE_NONCOPYABLE(AsyncFileSystem);
  45. public:
  46. virtual ~AsyncFileSystem() { }
  47. virtual void stop() { }
  48. virtual bool hasPendingActivity() { return false; }
  49. static bool isAvailable();
  50. // Subclass must implement this if it supports synchronous operations.
  51. // This should return false if there are no pending operations.
  52. virtual bool waitForOperationToComplete() { return false; }
  53. // Creates and returns a new platform-specific AsyncFileSystem instance if the platform has its own implementation.
  54. static PassOwnPtr<AsyncFileSystem> create();
  55. // Opens a new file system. The create parameter specifies whether or not to create the path if it does not already exists.
  56. static void openFileSystem(const String& basePath, const String& storageIdentifier, FileSystemType, bool create, PassOwnPtr<AsyncFileSystemCallbacks>);
  57. // Deletes the file system.
  58. static void deleteFileSystem(const String& basePath, const String& storageIdentifier, FileSystemType, PassOwnPtr<AsyncFileSystemCallbacks>);
  59. // Moves a file or directory from srcPath to destPath.
  60. // AsyncFileSystemCallbacks::didSucceed() is called when the operation is completed successfully.
  61. // AsyncFileSystemCallbacks::didFail() is called otherwise.
  62. virtual void move(const KURL& srcPath, const KURL& destPath, PassOwnPtr<AsyncFileSystemCallbacks>) = 0;
  63. // Copies a file or directory from srcPath to destPath.
  64. // AsyncFileSystemCallbacks::didSucceed() is called when the operation is completed successfully.
  65. // AsyncFileSystemCallbacks::didFail() is called otherwise.
  66. virtual void copy(const KURL& srcPath, const KURL& destPath, PassOwnPtr<AsyncFileSystemCallbacks>) = 0;
  67. // Deletes a file or directory at a given path.
  68. // It is an error to try to remove a directory that is not empty.
  69. // AsyncFileSystemCallbacks::didSucceed() is called when the operation is completed successfully.
  70. // AsyncFileSystemCallbacks::didFail() is called otherwise.
  71. virtual void remove(const KURL& path, PassOwnPtr<AsyncFileSystemCallbacks>) = 0;
  72. // Recursively deletes a directory at a given path.
  73. // AsyncFileSystemCallbacks::didSucceed() is called when the operation is completed successfully.
  74. // AsyncFileSystemCallbacks::didFail() is called otherwise.
  75. virtual void removeRecursively(const KURL& path, PassOwnPtr<AsyncFileSystemCallbacks>) = 0;
  76. // Retrieves the metadata information of the file or directory at a given path.
  77. // AsyncFileSystemCallbacks::didReadMetadata() is called when the operation is completed successfully.
  78. // AsyncFileSystemCallbacks::didFail() is called otherwise.
  79. virtual void readMetadata(const KURL& path, PassOwnPtr<AsyncFileSystemCallbacks>) = 0;
  80. // Creates a file at a given path. If exclusive flag is true, it fails if the path already exists.
  81. // AsyncFileSystemCallbacks::didSucceed() is called when the operation is completed successfully.
  82. // AsyncFileSystemCallbacks::didFail() is called otherwise.
  83. virtual void createFile(const KURL& path, bool exclusive, PassOwnPtr<AsyncFileSystemCallbacks>) = 0;
  84. // Creates a directory at a given path. If exclusive flag is true, it fails if the path already exists.
  85. // AsyncFileSystemCallbacks::didSucceed() is called when the operation is completed successfully.
  86. // AsyncFileSystemCallbacks::didFail() is called otherwise.
  87. virtual void createDirectory(const KURL& path, bool exclusive, PassOwnPtr<AsyncFileSystemCallbacks>) = 0;
  88. // Checks if a file exists at a given path.
  89. // AsyncFileSystemCallbacks::didSucceed() is called if the file exists.
  90. // AsyncFileSystemCallbacks::didFail() is called otherwise.
  91. virtual void fileExists(const KURL& path, PassOwnPtr<AsyncFileSystemCallbacks>) = 0;
  92. // Checks if a directory exists at a given path.
  93. // AsyncFileSystemCallbacks::didSucceed() is called if the directory exists.
  94. // AsyncFileSystemCallbacks::didFail() is called otherwise.
  95. virtual void directoryExists(const KURL& path, PassOwnPtr<AsyncFileSystemCallbacks>) = 0;
  96. // Reads directory entries of a given directory at path.
  97. // AsyncFileSystemCallbacks::didReadDirectoryEntry() is called when each directory entry is called. AsyncFileSystemCallbacks::didReadDirectoryEntries() is called after a chunk of directory entries have been read.
  98. // AsyncFileSystemCallbacks::didFail() is when there is an error.
  99. virtual void readDirectory(const KURL& path, PassOwnPtr<AsyncFileSystemCallbacks>) = 0;
  100. // Creates an AsyncFileWriter for a given file path.
  101. // AsyncFileSystemCallbacks::didCreateFileWriter() is called when an AsyncFileWriter is created successfully.
  102. // AsyncFileSystemCallbacks::didFail() is called otherwise.
  103. virtual void createWriter(AsyncFileWriterClient*, const KURL& path, PassOwnPtr<AsyncFileSystemCallbacks>) = 0;
  104. // Creates a snapshot file and read its metadata for a new File object.
  105. // In local filesystem cases the backend may simply return the metadata of the file itself (as well as readMetadata does),
  106. // while in remote filesystem case the backend may download the file into a temporary snapshot file and return the metadata of the temporary file.
  107. // AsyncFileSystemCallbacks::didReadMetadata() is called when the metadata for the snapshot file is successfully returned.
  108. // AsyncFileSystemCallbacks::didFail() is called otherwise.
  109. //
  110. // 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.
  111. virtual void createSnapshotFileAndReadMetadata(const KURL& path, PassOwnPtr<AsyncFileSystemCallbacks>) = 0;
  112. protected:
  113. AsyncFileSystem() { }
  114. };
  115. } // namespace WebCore
  116. #endif // ENABLE(FILE_SYSTEM)
  117. #endif // AsyncFileSystem_h