summaryrefslogtreecommitdiffstats
path: root/WebCore/fileapi
diff options
context:
space:
mode:
authorKristian Monsen <kristianm@google.com>2010-09-30 15:42:16 +0100
committerSteve Block <steveblock@google.com>2010-10-07 10:59:29 +0100
commitbec39347bb3bb5bf1187ccaf471d26247f28b585 (patch)
tree56bdc4c2978fbfd3d79d0d36d5d6c640ecc09cc8 /WebCore/fileapi
parent90b7966e7815b262cd19ac25f03aaad9b21fdc06 (diff)
downloadexternal_webkit-bec39347bb3bb5bf1187ccaf471d26247f28b585.zip
external_webkit-bec39347bb3bb5bf1187ccaf471d26247f28b585.tar.gz
external_webkit-bec39347bb3bb5bf1187ccaf471d26247f28b585.tar.bz2
Merge WebKit at r68651 : Initial merge by git.
Change-Id: I3d6bff59f17eedd6722723354f386fec9be8ad12
Diffstat (limited to 'WebCore/fileapi')
-rw-r--r--WebCore/fileapi/AsyncFileWriter.h3
-rw-r--r--WebCore/fileapi/AsyncFileWriterClient.h (renamed from WebCore/fileapi/FileWriterClient.h)12
-rw-r--r--WebCore/fileapi/DOMFileSystem.cpp31
-rw-r--r--WebCore/fileapi/DOMFileSystem.h3
-rw-r--r--WebCore/fileapi/DOMFileSystem.idl3
-rw-r--r--WebCore/fileapi/DirectoryEntry.idl3
-rw-r--r--WebCore/fileapi/DirectoryReader.idl3
-rw-r--r--WebCore/fileapi/Entry.idl3
-rw-r--r--WebCore/fileapi/EntryArray.idl1
-rw-r--r--WebCore/fileapi/FileEntry.idl3
-rw-r--r--WebCore/fileapi/FileSystemCallbacks.cpp56
-rw-r--r--WebCore/fileapi/FileSystemCallbacks.h32
-rw-r--r--WebCore/fileapi/FileWriter.cpp36
-rw-r--r--WebCore/fileapi/FileWriter.h9
-rw-r--r--WebCore/fileapi/Flags.idl3
-rw-r--r--WebCore/fileapi/LocalFileSystem.cpp36
-rw-r--r--WebCore/fileapi/LocalFileSystem.h36
-rw-r--r--WebCore/fileapi/Metadata.idl3
18 files changed, 210 insertions, 66 deletions
diff --git a/WebCore/fileapi/AsyncFileWriter.h b/WebCore/fileapi/AsyncFileWriter.h
index ff6c1fa..fef1643 100644
--- a/WebCore/fileapi/AsyncFileWriter.h
+++ b/WebCore/fileapi/AsyncFileWriter.h
@@ -39,14 +39,11 @@
namespace WebCore {
class Blob;
-class FileWriterClient;
class AsyncFileWriter {
public:
virtual ~AsyncFileWriter() {}
- virtual void setFileWriterClient(FileWriterClient* client) = 0;
-
virtual void write(long long position, Blob* data) = 0;
virtual void truncate(long long length) = 0;
virtual void abort() = 0;
diff --git a/WebCore/fileapi/FileWriterClient.h b/WebCore/fileapi/AsyncFileWriterClient.h
index 1bebbd6..327b19c 100644
--- a/WebCore/fileapi/FileWriterClient.h
+++ b/WebCore/fileapi/AsyncFileWriterClient.h
@@ -28,8 +28,8 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef FileWriterClient_h
-#define FileWriterClient_h
+#ifndef AsyncFileWriterClient_h
+#define AsyncFileWriterClient_h
#if ENABLE(FILE_SYSTEM)
@@ -37,12 +37,12 @@
namespace WebCore {
-class FileWriterClient {
+class AsyncFileWriterClient {
public:
- virtual ~FileWriterClient() {}
+ virtual ~AsyncFileWriterClient() {}
virtual void didWrite(long long bytes, bool complete) = 0;
- virtual void didTruncate(long long position) = 0;
+ virtual void didTruncate() = 0;
virtual void didFail(ExceptionCode) = 0;
};
@@ -50,4 +50,4 @@ public:
#endif // ENABLE(FILE_SYSTEM)
-#endif // FileWriterClient_h
+#endif // AsyncFileWriterClient_h
diff --git a/WebCore/fileapi/DOMFileSystem.cpp b/WebCore/fileapi/DOMFileSystem.cpp
index a8a7e6b..2bd09c2 100644
--- a/WebCore/fileapi/DOMFileSystem.cpp
+++ b/WebCore/fileapi/DOMFileSystem.cpp
@@ -38,10 +38,14 @@
#include "DirectoryEntry.h"
#include "EntriesCallback.h"
#include "Entry.h"
+#include "EntryArray.h"
#include "EntryCallback.h"
#include "ErrorCallback.h"
+#include "FileEntry.h"
#include "FileError.h"
#include "FileSystemCallbacks.h"
+#include "FileWriter.h"
+#include "FileWriterCallback.h"
#include "MetadataCallback.h"
#include "ScriptExecutionContext.h"
#include "VoidCallback.h"
@@ -84,7 +88,7 @@ void DOMFileSystem::contextDestroyed()
void DOMFileSystem::getMetadata(const Entry* entry, PassRefPtr<MetadataCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback)
{
String platformPath = m_asyncFileSystem->virtualToPlatformPath(entry->fullPath());
- m_asyncFileSystem->readMetadata(platformPath, new MetadataCallbacks(successCallback, errorCallback));
+ m_asyncFileSystem->readMetadata(platformPath, MetadataCallbacks::create(successCallback, errorCallback));
}
static bool checkValidityForForCopyOrMove(const Entry* src, Entry* parent, const String& newName)
@@ -123,7 +127,7 @@ void DOMFileSystem::move(const Entry* src, PassRefPtr<Entry> parent, const Strin
String srcPlatformPath = m_asyncFileSystem->virtualToPlatformPath(src->fullPath());
String destPlatformPath = parent->filesystem()->asyncFileSystem()->virtualToPlatformPath(destPath);
- m_asyncFileSystem->move(srcPlatformPath, destPlatformPath, new EntryCallbacks(successCallback, errorCallback, this, destPath, src->isDirectory()));
+ m_asyncFileSystem->move(srcPlatformPath, destPlatformPath, EntryCallbacks::create(successCallback, errorCallback, this, destPath, src->isDirectory()));
}
void DOMFileSystem::copy(const Entry* src, PassRefPtr<Entry> parent, const String& newName, PassRefPtr<EntryCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback)
@@ -141,14 +145,14 @@ void DOMFileSystem::copy(const Entry* src, PassRefPtr<Entry> parent, const Strin
String srcPlatformPath = m_asyncFileSystem->virtualToPlatformPath(src->fullPath());
String destPlatformPath = parent->filesystem()->asyncFileSystem()->virtualToPlatformPath(destPath);
- m_asyncFileSystem->copy(srcPlatformPath, destPlatformPath, new EntryCallbacks(successCallback, errorCallback, this, destPath, src->isDirectory()));
+ m_asyncFileSystem->copy(srcPlatformPath, destPlatformPath, EntryCallbacks::create(successCallback, errorCallback, this, destPath, src->isDirectory()));
}
void DOMFileSystem::remove(const Entry* entry, PassRefPtr<VoidCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback)
{
ASSERT(entry);
String platformPath = m_asyncFileSystem->virtualToPlatformPath(entry->fullPath());
- m_asyncFileSystem->remove(platformPath, new VoidCallbacks(successCallback, errorCallback));
+ m_asyncFileSystem->remove(platformPath, VoidCallbacks::create(successCallback, errorCallback));
}
void DOMFileSystem::getParent(const Entry* entry, PassRefPtr<EntryCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback)
@@ -156,7 +160,7 @@ void DOMFileSystem::getParent(const Entry* entry, PassRefPtr<EntryCallback> succ
ASSERT(entry);
String path = DOMFilePath::getDirectory(entry->fullPath());
String platformPath = m_asyncFileSystem->virtualToPlatformPath(path);
- m_asyncFileSystem->directoryExists(platformPath, new EntryCallbacks(successCallback, errorCallback, this, path, true));
+ m_asyncFileSystem->directoryExists(platformPath, EntryCallbacks::create(successCallback, errorCallback, this, path, true));
}
void DOMFileSystem::getFile(const Entry* base, const String& path, PassRefPtr<Flags> flags, PassRefPtr<EntryCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback)
@@ -172,7 +176,7 @@ void DOMFileSystem::getFile(const Entry* base, const String& path, PassRefPtr<Fl
absolutePath = DOMFilePath::removeExtraParentReferences(DOMFilePath::append(base->fullPath(), path));
String platformPath = m_asyncFileSystem->virtualToPlatformPath(absolutePath);
- OwnPtr<EntryCallbacks> callbacks = adoptPtr(new EntryCallbacks(successCallback, errorCallback, this, absolutePath, false));
+ OwnPtr<EntryCallbacks> callbacks = EntryCallbacks::create(successCallback, errorCallback, this, absolutePath, false);
if (flags && flags->isCreate())
m_asyncFileSystem->createFile(platformPath, flags->isExclusive(), callbacks.release());
else
@@ -192,18 +196,29 @@ void DOMFileSystem::getDirectory(const Entry* base, const String& path, PassRefP
absolutePath = DOMFilePath::removeExtraParentReferences(DOMFilePath::append(base->fullPath(), path));
String platformPath = m_asyncFileSystem->virtualToPlatformPath(absolutePath);
- OwnPtr<EntryCallbacks> callbacks = adoptPtr(new EntryCallbacks(successCallback, errorCallback, this, absolutePath, true));
+ OwnPtr<EntryCallbacks> callbacks = EntryCallbacks::create(successCallback, errorCallback, this, absolutePath, true);
if (flags && flags->isCreate())
m_asyncFileSystem->createDirectory(platformPath, flags->isExclusive(), callbacks.release());
else
m_asyncFileSystem->directoryExists(platformPath, callbacks.release());
}
+void DOMFileSystem::createWriter(const FileEntry* file, PassRefPtr<FileWriterCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback)
+{
+ ASSERT(file);
+
+ String platformPath = m_asyncFileSystem->virtualToPlatformPath(file->fullPath());
+
+ RefPtr<FileWriter> fileWriter = FileWriter::create(scriptExecutionContext());
+ OwnPtr<FileWriterCallbacks> callbacks = FileWriterCallbacks::create(fileWriter, successCallback, errorCallback);
+ m_asyncFileSystem->createWriter(fileWriter.get(), platformPath, callbacks.release());
+}
+
void DOMFileSystem::readDirectory(const String& path, PassRefPtr<EntriesCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback)
{
ASSERT(DOMFilePath::isAbsolute(path));
String platformPath = m_asyncFileSystem->virtualToPlatformPath(path);
- m_asyncFileSystem->readDirectory(platformPath, new EntriesCallbacks(successCallback, errorCallback, this, path));
+ m_asyncFileSystem->readDirectory(platformPath, EntriesCallbacks::create(successCallback, errorCallback, this, path));
}
} // namespace
diff --git a/WebCore/fileapi/DOMFileSystem.h b/WebCore/fileapi/DOMFileSystem.h
index f779aba..881ffc5 100644
--- a/WebCore/fileapi/DOMFileSystem.h
+++ b/WebCore/fileapi/DOMFileSystem.h
@@ -48,6 +48,8 @@ class Entry;
class EntryCallback;
class EntriesCallback;
class ErrorCallback;
+class FileEntry;
+class FileWriterCallback;
class MetadataCallback;
class VoidCallback;
@@ -77,6 +79,7 @@ public:
void getFile(const Entry* base, const String& path, PassRefPtr<Flags>, PassRefPtr<EntryCallback>, PassRefPtr<ErrorCallback>);
void getDirectory(const Entry* base, const String& path, PassRefPtr<Flags>, PassRefPtr<EntryCallback>, PassRefPtr<ErrorCallback>);
void readDirectory(const String& path, PassRefPtr<EntriesCallback>, PassRefPtr<ErrorCallback>);
+ void createWriter(const FileEntry* file, PassRefPtr<FileWriterCallback>, PassRefPtr<ErrorCallback>);
// Schedule a callback. This should not cross threads (should be called on the same context thread).
template <typename CB, typename CBArg>
diff --git a/WebCore/fileapi/DOMFileSystem.idl b/WebCore/fileapi/DOMFileSystem.idl
index b7307e2..037770b 100644
--- a/WebCore/fileapi/DOMFileSystem.idl
+++ b/WebCore/fileapi/DOMFileSystem.idl
@@ -30,7 +30,8 @@
module storage {
interface [
- Conditional=FILE_SYSTEM
+ Conditional=FILE_SYSTEM,
+ NoStaticTables
] DOMFileSystem {
readonly attribute DOMString name;
readonly attribute DirectoryEntry root;
diff --git a/WebCore/fileapi/DirectoryEntry.idl b/WebCore/fileapi/DirectoryEntry.idl
index 7a0efdd..2880ed0 100644
--- a/WebCore/fileapi/DirectoryEntry.idl
+++ b/WebCore/fileapi/DirectoryEntry.idl
@@ -32,7 +32,8 @@ module storage {
interface [
Conditional=FILE_SYSTEM,
GenerateNativeConverter,
- GenerateToJS
+ GenerateToJS,
+ NoStaticTables
] DirectoryEntry : Entry {
DirectoryReader createReader();
[Custom] void getFile(in [ConvertUndefinedOrNullToNullString] DOMString path, in [Optional] Flags flags, in [Optional, Callback] EntryCallback successCallback, in [Optional, Callback] ErrorCallback errorCallback);
diff --git a/WebCore/fileapi/DirectoryReader.idl b/WebCore/fileapi/DirectoryReader.idl
index c3c7012..831fb05 100644
--- a/WebCore/fileapi/DirectoryReader.idl
+++ b/WebCore/fileapi/DirectoryReader.idl
@@ -30,7 +30,8 @@
module storage {
interface [
- Conditional=FILE_SYSTEM
+ Conditional=FILE_SYSTEM,
+ NoStaticTables
] DirectoryReader {
void readEntries(in [Callback] EntriesCallback successCallback, in [Optional, Callback] ErrorCallback errorCallback);
};
diff --git a/WebCore/fileapi/Entry.idl b/WebCore/fileapi/Entry.idl
index b674455..d363bcd 100644
--- a/WebCore/fileapi/Entry.idl
+++ b/WebCore/fileapi/Entry.idl
@@ -31,7 +31,8 @@
module storage {
interface [
Conditional=FILE_SYSTEM,
- CustomToJS
+ CustomToJS,
+ NoStaticTables
] Entry {
readonly attribute boolean isFile;
readonly attribute boolean isDirectory;
diff --git a/WebCore/fileapi/EntryArray.idl b/WebCore/fileapi/EntryArray.idl
index e987ece..dca7827 100644
--- a/WebCore/fileapi/EntryArray.idl
+++ b/WebCore/fileapi/EntryArray.idl
@@ -32,6 +32,7 @@ module storage {
interface [
Conditional=FILE_SYSTEM,
HasIndexGetter,
+ NoStaticTables
] EntryArray {
readonly attribute unsigned long length;
Entry item(in [IsIndex] unsigned long index);
diff --git a/WebCore/fileapi/FileEntry.idl b/WebCore/fileapi/FileEntry.idl
index eb913b8..73ef895 100644
--- a/WebCore/fileapi/FileEntry.idl
+++ b/WebCore/fileapi/FileEntry.idl
@@ -32,7 +32,8 @@ module storage {
interface [
Conditional=FILE_SYSTEM,
GenerateNativeConverter,
- GenerateToJS
+ GenerateToJS,
+ NoStaticTables
] FileEntry : Entry {
void createWriter(in [Callback] FileWriterCallback successCallback, in [Optional, Callback] ErrorCallback errorCallback);
void file(in [Callback] FileCallback successCallback, in [Optional, Callback] ErrorCallback errorCallback);
diff --git a/WebCore/fileapi/FileSystemCallbacks.cpp b/WebCore/fileapi/FileSystemCallbacks.cpp
index d59e47a..550b509 100644
--- a/WebCore/fileapi/FileSystemCallbacks.cpp
+++ b/WebCore/fileapi/FileSystemCallbacks.cpp
@@ -34,6 +34,7 @@
#if ENABLE(FILE_SYSTEM)
#include "AsyncFileSystem.h"
+#include "AsyncFileWriter.h"
#include "DOMFilePath.h"
#include "DOMFileSystem.h"
#include "DirectoryEntry.h"
@@ -45,6 +46,8 @@
#include "FileEntry.h"
#include "FileError.h"
#include "FileSystemCallback.h"
+#include "FileWriter.h"
+#include "FileWriterCallback.h"
#include "Metadata.h"
#include "MetadataCallback.h"
#include "ScriptExecutionContext.h"
@@ -91,6 +94,12 @@ void FileSystemCallbacksBase::didReadDirectoryEntry(const String&, bool)
ASSERT_NOT_REACHED();
}
+void FileSystemCallbacksBase::didCreateFileWriter(PassOwnPtr<AsyncFileWriter>, long long)
+{
+ // Each subclass must implement an appropriate one.
+ ASSERT_NOT_REACHED();
+}
+
void FileSystemCallbacksBase::didFail(int code)
{
if (m_errorCallback) {
@@ -101,6 +110,11 @@ void FileSystemCallbacksBase::didFail(int code)
// EntryCallbacks -------------------------------------------------------------
+PassOwnPtr<EntryCallbacks> EntryCallbacks::create(PassRefPtr<EntryCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback, DOMFileSystem* fileSystem, const String& expectedPath, bool isDirectory)
+{
+ return adoptPtr(new EntryCallbacks(successCallback, errorCallback, fileSystem, expectedPath, isDirectory));
+}
+
EntryCallbacks::EntryCallbacks(PassRefPtr<EntryCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback, DOMFileSystem* fileSystem, const String& expectedPath, bool isDirectory)
: FileSystemCallbacksBase(errorCallback)
, m_successCallback(successCallback)
@@ -123,6 +137,11 @@ void EntryCallbacks::didSucceed()
// EntriesCallbacks -----------------------------------------------------------
+PassOwnPtr<EntriesCallbacks> EntriesCallbacks::create(PassRefPtr<EntriesCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback, DOMFileSystem* fileSystem, const String& basePath)
+{
+ return adoptPtr(new EntriesCallbacks(successCallback, errorCallback, fileSystem, basePath));
+}
+
EntriesCallbacks::EntriesCallbacks(PassRefPtr<EntriesCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback, DOMFileSystem* fileSystem, const String& basePath)
: FileSystemCallbacksBase(errorCallback)
, m_successCallback(successCallback)
@@ -155,6 +174,11 @@ void EntriesCallbacks::didReadDirectoryEntries(bool hasMore)
// FileSystemCallbacks --------------------------------------------------------
+PassOwnPtr<FileSystemCallbacks> FileSystemCallbacks::create(PassRefPtr<FileSystemCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback, ScriptExecutionContext* scriptExecutionContext)
+{
+ return adoptPtr(new FileSystemCallbacks(successCallback, errorCallback, scriptExecutionContext));
+}
+
FileSystemCallbacks::FileSystemCallbacks(PassRefPtr<FileSystemCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback, ScriptExecutionContext* context)
: FileSystemCallbacksBase(errorCallback)
, m_successCallback(successCallback)
@@ -174,6 +198,11 @@ void FileSystemCallbacks::didOpenFileSystem(const String& name, PassOwnPtr<Async
// MetadataCallbacks ----------------------------------------------------------
+PassOwnPtr<MetadataCallbacks> MetadataCallbacks::create(PassRefPtr<MetadataCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback)
+{
+ return adoptPtr(new MetadataCallbacks(successCallback, errorCallback));
+}
+
MetadataCallbacks::MetadataCallbacks(PassRefPtr<MetadataCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback)
: FileSystemCallbacksBase(errorCallback)
, m_successCallback(successCallback)
@@ -187,8 +216,35 @@ void MetadataCallbacks::didReadMetadata(double modificationTime)
m_successCallback.clear();
}
+// FileWriterCallbacks ----------------------------------------------------------
+
+PassOwnPtr<FileWriterCallbacks> FileWriterCallbacks::create(PassRefPtr<FileWriter> fileWriter, PassRefPtr<FileWriterCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback)
+{
+ return adoptPtr(new FileWriterCallbacks(fileWriter, successCallback, errorCallback));
+}
+
+FileWriterCallbacks::FileWriterCallbacks(PassRefPtr<FileWriter> fileWriter, PassRefPtr<FileWriterCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback)
+ : FileSystemCallbacksBase(errorCallback)
+ , m_fileWriter(fileWriter)
+ , m_successCallback(successCallback)
+{
+}
+
+void FileWriterCallbacks::didCreateFileWriter(PassOwnPtr<AsyncFileWriter> asyncFileWriter, long long length)
+{
+ m_fileWriter->initialize(asyncFileWriter, length);
+ if (m_successCallback)
+ m_successCallback->handleEvent(m_fileWriter.release().get());
+ m_successCallback.clear();
+}
+
// VoidCallbacks --------------------------------------------------------------
+PassOwnPtr<VoidCallbacks> VoidCallbacks::create(PassRefPtr<VoidCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback)
+{
+ return adoptPtr(new VoidCallbacks(successCallback, errorCallback));
+}
+
VoidCallbacks::VoidCallbacks(PassRefPtr<VoidCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback)
: FileSystemCallbacksBase(errorCallback)
, m_successCallback(successCallback)
diff --git a/WebCore/fileapi/FileSystemCallbacks.h b/WebCore/fileapi/FileSystemCallbacks.h
index 31a2a0c..3647ad3 100644
--- a/WebCore/fileapi/FileSystemCallbacks.h
+++ b/WebCore/fileapi/FileSystemCallbacks.h
@@ -40,12 +40,15 @@
namespace WebCore {
+class AsyncFileWriter;
class DOMFileSystem;
class ErrorCallback;
class EntriesCallback;
class EntryArray;
class EntryCallback;
class FileSystemCallback;
+class FileWriter;
+class FileWriterCallback;
class MetadataCallback;
class ScriptExecutionContext;
class VoidCallback;
@@ -67,6 +70,9 @@ public:
virtual void didReadDirectoryEntry(const String& name, bool isDirectory);
virtual void didReadDirectoryEntries(bool hasMore);
+ // For createFileWriter.
+ virtual void didCreateFileWriter(PassOwnPtr<AsyncFileWriter>, long long length);
+
// For ErrorCallback.
virtual void didFail(int code);
@@ -79,10 +85,11 @@ protected:
class EntryCallbacks : public FileSystemCallbacksBase {
public:
- EntryCallbacks(PassRefPtr<EntryCallback>, PassRefPtr<ErrorCallback>, DOMFileSystem*, const String& expectedPath, bool isDirectory);
+ static PassOwnPtr<EntryCallbacks> create(PassRefPtr<EntryCallback>, PassRefPtr<ErrorCallback>, DOMFileSystem*, const String& expectedPath, bool isDirectory);
virtual void didSucceed();
private:
+ EntryCallbacks(PassRefPtr<EntryCallback>, PassRefPtr<ErrorCallback>, DOMFileSystem*, const String& expectedPath, bool isDirectory);
RefPtr<EntryCallback> m_successCallback;
DOMFileSystem* m_fileSystem;
String m_expectedPath;
@@ -91,11 +98,12 @@ private:
class EntriesCallbacks : public FileSystemCallbacksBase {
public:
- EntriesCallbacks(PassRefPtr<EntriesCallback>, PassRefPtr<ErrorCallback>, DOMFileSystem*, const String& basePath);
+ static PassOwnPtr<EntriesCallbacks> create(PassRefPtr<EntriesCallback>, PassRefPtr<ErrorCallback>, DOMFileSystem*, const String& basePath);
virtual void didReadDirectoryEntry(const String& name, bool isDirectory);
virtual void didReadDirectoryEntries(bool hasMore);
private:
+ EntriesCallbacks(PassRefPtr<EntriesCallback>, PassRefPtr<ErrorCallback>, DOMFileSystem*, const String& basePath);
RefPtr<EntriesCallback> m_successCallback;
DOMFileSystem* m_fileSystem;
String m_basePath;
@@ -104,29 +112,43 @@ private:
class FileSystemCallbacks : public FileSystemCallbacksBase {
public:
- FileSystemCallbacks(PassRefPtr<FileSystemCallback>, PassRefPtr<ErrorCallback>, ScriptExecutionContext*);
+ static PassOwnPtr<FileSystemCallbacks> create(PassRefPtr<FileSystemCallback>, PassRefPtr<ErrorCallback>, ScriptExecutionContext*);
virtual void didOpenFileSystem(const String& name, PassOwnPtr<AsyncFileSystem>);
private:
+ FileSystemCallbacks(PassRefPtr<FileSystemCallback>, PassRefPtr<ErrorCallback>, ScriptExecutionContext*);
RefPtr<FileSystemCallback> m_successCallback;
RefPtr<ScriptExecutionContext> m_scriptExecutionContext;
};
class MetadataCallbacks : public FileSystemCallbacksBase {
public:
- MetadataCallbacks(PassRefPtr<MetadataCallback>, PassRefPtr<ErrorCallback>);
+ static PassOwnPtr<MetadataCallbacks> create(PassRefPtr<MetadataCallback>, PassRefPtr<ErrorCallback>);
virtual void didReadMetadata(double modificationTime);
private:
+ MetadataCallbacks(PassRefPtr<MetadataCallback>, PassRefPtr<ErrorCallback>);
RefPtr<MetadataCallback> m_successCallback;
};
+class FileWriterCallbacks : public FileSystemCallbacksBase {
+public:
+ static PassOwnPtr<FileWriterCallbacks> create(PassRefPtr<FileWriter>, PassRefPtr<FileWriterCallback>, PassRefPtr<ErrorCallback>);
+ virtual void didCreateFileWriter(PassOwnPtr<AsyncFileWriter>, long long length);
+
+private:
+ FileWriterCallbacks(PassRefPtr<FileWriter>, PassRefPtr<FileWriterCallback>, PassRefPtr<ErrorCallback>);
+ RefPtr<FileWriter> m_fileWriter;
+ RefPtr<FileWriterCallback> m_successCallback;
+};
+
class VoidCallbacks : public FileSystemCallbacksBase {
public:
- VoidCallbacks(PassRefPtr<VoidCallback>, PassRefPtr<ErrorCallback>);
+ static PassOwnPtr<VoidCallbacks> create(PassRefPtr<VoidCallback>, PassRefPtr<ErrorCallback>);
virtual void didSucceed();
private:
+ VoidCallbacks(PassRefPtr<VoidCallback>, PassRefPtr<ErrorCallback>);
RefPtr<VoidCallback> m_successCallback;
};
diff --git a/WebCore/fileapi/FileWriter.cpp b/WebCore/fileapi/FileWriter.cpp
index a9f9afd..8367bf9 100644
--- a/WebCore/fileapi/FileWriter.cpp
+++ b/WebCore/fileapi/FileWriter.cpp
@@ -48,6 +48,7 @@ FileWriter::FileWriter(ScriptExecutionContext* context)
, m_position(0)
, m_bytesWritten(0)
, m_bytesToWrite(0)
+ , m_truncateLength(-1)
{
}
@@ -95,7 +96,6 @@ void FileWriter::write(Blob* data, ExceptionCode& ec)
m_readyState = WRITING;
m_bytesWritten = 0;
m_bytesToWrite = data->size();
- fireEvent(eventNames().writestartEvent);
m_writer->write(m_position, data);
}
@@ -122,7 +122,7 @@ void FileWriter::seek(long long position, ExceptionCode& ec)
void FileWriter::truncate(long long position, ExceptionCode& ec)
{
ASSERT(m_writer);
- if (m_readyState == WRITING || position >= m_length) {
+ if (m_readyState == WRITING || position < 0) {
ec = INVALID_STATE_ERR;
m_error = FileError::create(ec);
return;
@@ -130,7 +130,7 @@ void FileWriter::truncate(long long position, ExceptionCode& ec)
m_readyState = WRITING;
m_bytesWritten = 0;
m_bytesToWrite = 0;
- fireEvent(eventNames().writestartEvent);
+ m_truncateLength = position;
m_writer->truncate(position);
}
@@ -142,11 +142,8 @@ void FileWriter::abort(ExceptionCode& ec)
m_error = FileError::create(ec);
return;
}
+
m_error = FileError::create(ABORT_ERR);
- m_readyState = DONE;
- fireEvent(eventNames().errorEvent);
- fireEvent(eventNames().abortEvent);
- fireEvent(eventNames().writeendEvent);
m_writer->abort();
}
@@ -155,36 +152,41 @@ void FileWriter::didWrite(long long bytes, bool complete)
ASSERT(bytes > 0);
ASSERT(bytes + m_bytesWritten > 0);
ASSERT(bytes + m_bytesWritten <= m_bytesToWrite);
+ if (!m_bytesWritten)
+ fireEvent(eventNames().writestartEvent);
m_bytesWritten += bytes;
ASSERT((m_bytesWritten == m_bytesToWrite) == complete);
m_position += bytes;
if (m_position > m_length)
m_length = m_position;
- if (complete)
- m_readyState = DONE;
fireEvent(eventNames().writeEvent);
- if (complete)
+ if (complete) {
+ m_readyState = DONE;
fireEvent(eventNames().writeendEvent);
+ }
}
-void FileWriter::didTruncate(long long length)
+void FileWriter::didTruncate()
{
- ASSERT(length > 0);
- ASSERT(length >= 0);
- ASSERT(length < m_length);
- m_length = length;
+ ASSERT(m_truncateLength >= 0);
+ fireEvent(eventNames().writestartEvent);
+ m_length = m_truncateLength;
if (m_position > m_length)
m_position = m_length;
- m_readyState = DONE;
+ m_truncateLength = -1;
fireEvent(eventNames().writeEvent);
+ m_readyState = DONE;
fireEvent(eventNames().writeendEvent);
}
void FileWriter::didFail(ExceptionCode ec)
{
m_error = FileError::create(ec);
- m_readyState = DONE;
fireEvent(eventNames().errorEvent);
+ if (ABORT_ERR == ec)
+ fireEvent(eventNames().abortEvent);
+ fireEvent(eventNames().errorEvent);
+ m_readyState = DONE;
fireEvent(eventNames().writeendEvent);
}
diff --git a/WebCore/fileapi/FileWriter.h b/WebCore/fileapi/FileWriter.h
index 0737085..4bb91ef 100644
--- a/WebCore/fileapi/FileWriter.h
+++ b/WebCore/fileapi/FileWriter.h
@@ -34,8 +34,8 @@
#if ENABLE(FILE_SYSTEM)
#include "ActiveDOMObject.h"
+#include "AsyncFileWriterClient.h"
#include "EventTarget.h"
-#include "FileWriterClient.h"
#include <wtf/OwnPtr.h>
#include <wtf/PassOwnPtr.h>
#include <wtf/PassRefPtr.h>
@@ -49,7 +49,7 @@ class Blob;
class FileError;
class ScriptExecutionContext;
-class FileWriter : public RefCounted<FileWriter>, public ActiveDOMObject, public EventTarget, public FileWriterClient {
+class FileWriter : public RefCounted<FileWriter>, public ActiveDOMObject, public EventTarget, public AsyncFileWriterClient {
public:
static PassRefPtr<FileWriter> create(ScriptExecutionContext* context)
{
@@ -74,9 +74,9 @@ public:
long long position() const { return m_position; }
long long length() const { return m_length; }
- // FileWriterClient
+ // AsyncFileWriterClient
void didWrite(long long bytes, bool complete);
- void didTruncate(long long length);
+ void didTruncate();
void didFail(ExceptionCode ec);
// ActiveDOMObject
@@ -121,6 +121,7 @@ private:
long long m_length;
long long m_bytesWritten;
long long m_bytesToWrite;
+ long long m_truncateLength;
};
} // namespace WebCore
diff --git a/WebCore/fileapi/Flags.idl b/WebCore/fileapi/Flags.idl
index 29658a1..88cede3 100644
--- a/WebCore/fileapi/Flags.idl
+++ b/WebCore/fileapi/Flags.idl
@@ -31,7 +31,8 @@
module storage {
interface [
Conditional=FILE_SYSTEM,
- CanBeConstructed
+ CanBeConstructed,
+ NoStaticTables
] Flags {
attribute boolean create;
attribute boolean exclusive;
diff --git a/WebCore/fileapi/LocalFileSystem.cpp b/WebCore/fileapi/LocalFileSystem.cpp
index 59ec2a1..567aafe 100644
--- a/WebCore/fileapi/LocalFileSystem.cpp
+++ b/WebCore/fileapi/LocalFileSystem.cpp
@@ -50,25 +50,41 @@
namespace WebCore {
-PassRefPtr<LocalFileSystem> LocalFileSystem::create(const String& basePath)
+LocalFileSystem* LocalFileSystem::s_instance = 0;
+
+void LocalFileSystem::initializeLocalFileSystem(const String& basePath)
{
- return adoptRef(new LocalFileSystem(basePath));
+ // FIXME: Should initialize the quota settings as well.
+ ASSERT(isMainThread());
+ ASSERT(!s_instance);
+ if (s_instance)
+ return;
+
+ OwnPtr<LocalFileSystem> localFileSystem = adoptPtr(new LocalFileSystem(basePath));
+ s_instance = localFileSystem.leakPtr();
}
-static void openFileSystem(ScriptExecutionContext*, const String& basePath, const String& identifier, AsyncFileSystem::Type type, PassOwnPtr<FileSystemCallbacks> callbacks)
+LocalFileSystem& LocalFileSystem::localFileSystem()
{
- AsyncFileSystem::openFileSystem(basePath, identifier, type, callbacks);
+ // initializeLocalFileSystem must be called prior calling this.
+ ASSERT(s_instance);
+ return *s_instance;
}
-void LocalFileSystem::requestFileSystem(ScriptExecutionContext* context, AsyncFileSystem::Type type, long long, PassRefPtr<FileSystemCallback> successCallback, PassRefPtr<ErrorCallback> errorCallback)
+String LocalFileSystem::fileSystemBasePath() const
{
- if (type != AsyncFileSystem::Temporary && type != AsyncFileSystem::Persistent) {
- DOMFileSystem::scheduleCallback(context, errorCallback, FileError::create(INVALID_MODIFICATION_ERR));
- return;
- }
+ return m_basePath;
+}
+static void openFileSystem(ScriptExecutionContext*, const String& basePath, const String& identifier, AsyncFileSystem::Type type, PassOwnPtr<AsyncFileSystemCallbacks> callbacks)
+{
+ AsyncFileSystem::openFileSystem(basePath, identifier, type, callbacks);
+}
+
+void LocalFileSystem::requestFileSystem(ScriptExecutionContext* context, AsyncFileSystem::Type type, long long, PassOwnPtr<AsyncFileSystemCallbacks> callbacks)
+{
// AsyncFileSystem::openFileSystem calls callbacks synchronously, so the method needs to be called asynchronously.
- context->postTask(createCallbackTask(&openFileSystem, m_basePath, context->securityOrigin()->databaseIdentifier(), type, new FileSystemCallbacks(successCallback, errorCallback, context)));
+ context->postTask(createCallbackTask(&openFileSystem, fileSystemBasePath(), context->securityOrigin()->databaseIdentifier(), type, callbacks));
}
} // namespace
diff --git a/WebCore/fileapi/LocalFileSystem.h b/WebCore/fileapi/LocalFileSystem.h
index 48cfa8f..bb1d045 100644
--- a/WebCore/fileapi/LocalFileSystem.h
+++ b/WebCore/fileapi/LocalFileSystem.h
@@ -44,20 +44,44 @@ class ErrorCallback;
class FileSystemCallback;
class ScriptExecutionContext;
-class LocalFileSystem : public RefCounted<LocalFileSystem> {
+// Keeps per-process information and provides an entry point to open a file system.
+class LocalFileSystem : public Noncopyable {
public:
- static PassRefPtr<LocalFileSystem> create(const String& basePath);
- virtual ~LocalFileSystem() { }
+ // Returns a per-process instance of LocalFileSystem.
+ // Note that LocalFileSystem::initializeLocalFileSystem must be called before
+ // calling this one.
+ static LocalFileSystem& localFileSystem();
- void requestFileSystem(ScriptExecutionContext*, AsyncFileSystem::Type, long long size, PassRefPtr<FileSystemCallback>, PassRefPtr<ErrorCallback>);
+ void requestFileSystem(ScriptExecutionContext*, AsyncFileSystem::Type, long long size, PassOwnPtr<AsyncFileSystemCallbacks>);
-protected:
+#if !PLATFORM(CHROMIUM)
+ // This call is not thread-safe; must be called before any worker threads are created.
+ void initializeLocalFileSystem(const String&);
+
+ String fileSystemBasePath() const;
+#endif
+
+private:
LocalFileSystem(const String& basePath)
: m_basePath(basePath)
{
}
- String m_basePath;
+ static LocalFileSystem* s_instance;
+
+ // An inner class that enforces thread-safe string access.
+ class SystemBasePath {
+ public:
+ explicit SystemBasePath(const String& path) : m_value(path) { }
+ operator String() const
+ {
+ return m_value.threadsafeCopy();
+ }
+ private:
+ String m_value;
+ };
+
+ SystemBasePath m_basePath;
};
} // namespace
diff --git a/WebCore/fileapi/Metadata.idl b/WebCore/fileapi/Metadata.idl
index a5a90bc..df50b66 100644
--- a/WebCore/fileapi/Metadata.idl
+++ b/WebCore/fileapi/Metadata.idl
@@ -30,7 +30,8 @@
module storage {
interface [
- Conditional=FILE_SYSTEM
+ Conditional=FILE_SYSTEM,
+ NoStaticTables
] Metadata {
readonly attribute Date modificationTime;
};