From 2bde8e466a4451c7319e3a072d118917957d6554 Mon Sep 17 00:00:00 2001 From: Steve Block Date: Wed, 25 May 2011 19:08:45 +0100 Subject: Merge WebKit at r82507: Initial merge by git Change-Id: I60ce9d780725b58b45e54165733a8ffee23b683e --- Source/WebCore/fileapi/DOMFileSystemSync.cpp | 98 ++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) (limited to 'Source/WebCore/fileapi/DOMFileSystemSync.cpp') diff --git a/Source/WebCore/fileapi/DOMFileSystemSync.cpp b/Source/WebCore/fileapi/DOMFileSystemSync.cpp index 5ae7545..0d26bb6 100644 --- a/Source/WebCore/fileapi/DOMFileSystemSync.cpp +++ b/Source/WebCore/fileapi/DOMFileSystemSync.cpp @@ -33,6 +33,8 @@ #if ENABLE(FILE_SYSTEM) +#include "AsyncFileSystem.h" +#include "AsyncFileWriter.h" #include "DOMFilePath.h" #include "DirectoryEntrySync.h" #include "ErrorCallback.h" @@ -40,6 +42,7 @@ #include "FileEntrySync.h" #include "FileError.h" #include "FileException.h" +#include "FileMetadata.h" #include "FileSystemCallbacks.h" #include "FileWriterBaseCallback.h" #include "FileWriterSync.h" @@ -67,10 +70,105 @@ PassRefPtr DOMFileSystemSync::root() return DirectoryEntrySync::create(this, DOMFilePath::root); } +namespace { + +class GetPathHelper : public AsyncFileSystemCallbacks { +public: + class GetPathResult : public RefCounted { + public: + static PassRefPtr create() + { + return adoptRef(new GetPathResult()); + } + + bool m_failed; + int m_code; + String m_path; + + private: + GetPathResult() + : m_failed(false) + , m_code(0) + { + } + + ~GetPathResult() + { + } + friend class WTF::RefCounted; + }; + + static PassOwnPtr create(PassRefPtr result) + { + return adoptPtr(new GetPathHelper(result)); + } + + virtual void didSucceed() + { + ASSERT_NOT_REACHED(); + } + + virtual void didOpenFileSystem(const String&, PassOwnPtr) + { + ASSERT_NOT_REACHED(); + } + + virtual void didReadDirectoryEntry(const String&, bool) + { + ASSERT_NOT_REACHED(); + } + + virtual void didReadDirectoryEntries(bool) + { + ASSERT_NOT_REACHED(); + } + + virtual void didCreateFileWriter(PassOwnPtr, long long) + { + ASSERT_NOT_REACHED(); + } + + virtual void didFail(int code) + { + m_result->m_failed = true; + m_result->m_code = code; + } + + virtual ~GetPathHelper() + { + } + + void didReadMetadata(const FileMetadata& metadata) + { + m_result->m_path = metadata.platformPath; + } +private: + GetPathHelper(PassRefPtr result) + : m_result(result) + { + } + + RefPtr m_result; +}; + +} // namespace + PassRefPtr DOMFileSystemSync::createFile(const FileEntrySync* fileEntry, ExceptionCode& ec) { ec = 0; String platformPath = m_asyncFileSystem->virtualToPlatformPath(fileEntry->fullPath()); + RefPtr result(GetPathHelper::GetPathResult::create()); + m_asyncFileSystem->readMetadata(platformPath, GetPathHelper::create(result)); + if (!m_asyncFileSystem->waitForOperationToComplete()) { + ec = FileException::ABORT_ERR; + return 0; + } + if (result->m_failed) { + ec = result->m_code; + return 0; + } + if (!result->m_path.isEmpty()) + platformPath = result->m_path; return File::create(platformPath); } -- cgit v1.1