This source file includes following definitions.
- create
- callbacks
- reset
- assign
- didSucceed
- didReadMetadata
- didCreateSnapshotFile
- didReadDirectory
- didOpenFileSystem
- didResolveURL
- didCreateFileWriter
- didFail
- shouldBlockUntilCompletion
#include "config.h"
#include "public/platform/WebFileSystemCallbacks.h"
#include "platform/AsyncFileSystemCallbacks.h"
#include "platform/FileMetadata.h"
#include "public/platform/WebFileInfo.h"
#include "public/platform/WebFileSystem.h"
#include "public/platform/WebFileSystemEntry.h"
#include "public/platform/WebFileWriter.h"
#include "public/platform/WebString.h"
#include "wtf/PassOwnPtr.h"
#include "wtf/PassRefPtr.h"
#include "wtf/RefCounted.h"
using namespace WebCore;
namespace blink {
class WebFileSystemCallbacksPrivate : public RefCounted<WebFileSystemCallbacksPrivate> {
public:
static PassRefPtr<WebFileSystemCallbacksPrivate> create(const PassOwnPtr<AsyncFileSystemCallbacks>& callbacks)
{
return adoptRef(new WebFileSystemCallbacksPrivate(callbacks));
}
AsyncFileSystemCallbacks* callbacks() { return m_callbacks.get(); }
private:
WebFileSystemCallbacksPrivate(const PassOwnPtr<AsyncFileSystemCallbacks>& callbacks) : m_callbacks(callbacks) { }
OwnPtr<AsyncFileSystemCallbacks> m_callbacks;
};
WebFileSystemCallbacks::WebFileSystemCallbacks(const PassOwnPtr<AsyncFileSystemCallbacks>& callbacks)
{
m_private = WebFileSystemCallbacksPrivate::create(callbacks);
}
void WebFileSystemCallbacks::reset()
{
m_private.reset();
}
void WebFileSystemCallbacks::assign(const WebFileSystemCallbacks& other)
{
m_private = other.m_private;
}
void WebFileSystemCallbacks::didSucceed()
{
ASSERT(!m_private.isNull());
m_private->callbacks()->didSucceed();
m_private.reset();
}
void WebFileSystemCallbacks::didReadMetadata(const WebFileInfo& webFileInfo)
{
ASSERT(!m_private.isNull());
FileMetadata fileMetadata;
fileMetadata.modificationTime = webFileInfo.modificationTime;
fileMetadata.length = webFileInfo.length;
fileMetadata.type = static_cast<FileMetadata::Type>(webFileInfo.type);
fileMetadata.platformPath = webFileInfo.platformPath;
m_private->callbacks()->didReadMetadata(fileMetadata);
m_private.reset();
}
void WebFileSystemCallbacks::didCreateSnapshotFile(const WebFileInfo& webFileInfo)
{
ASSERT(!m_private.isNull());
OwnPtr<BlobData> blobData = BlobData::create();
blobData->appendFile(webFileInfo.platformPath);
RefPtr<BlobDataHandle> snapshotBlob = BlobDataHandle::create(blobData.release(), webFileInfo.length);
FileMetadata fileMetadata;
fileMetadata.modificationTime = webFileInfo.modificationTime;
fileMetadata.length = webFileInfo.length;
fileMetadata.type = static_cast<FileMetadata::Type>(webFileInfo.type);
fileMetadata.platformPath = webFileInfo.platformPath;
m_private->callbacks()->didCreateSnapshotFile(fileMetadata, snapshotBlob);
m_private.reset();
}
void WebFileSystemCallbacks::didReadDirectory(const WebVector<WebFileSystemEntry>& entries, bool hasMore)
{
ASSERT(!m_private.isNull());
for (size_t i = 0; i < entries.size(); ++i)
m_private->callbacks()->didReadDirectoryEntry(entries[i].name, entries[i].isDirectory);
m_private->callbacks()->didReadDirectoryEntries(hasMore);
m_private.reset();
}
void WebFileSystemCallbacks::didOpenFileSystem(const WebString& name, const WebURL& rootURL)
{
ASSERT(!m_private.isNull());
m_private->callbacks()->didOpenFileSystem(name, rootURL);
m_private.reset();
}
void WebFileSystemCallbacks::didResolveURL(const WebString& name, const WebURL& rootURL, WebFileSystemType type, const WebString& filePath, bool isDirectory)
{
ASSERT(!m_private.isNull());
m_private->callbacks()->didResolveURL(name, rootURL, static_cast<WebCore::FileSystemType>(type), filePath, isDirectory);
m_private.reset();
}
void WebFileSystemCallbacks::didCreateFileWriter(WebFileWriter* webFileWriter, long long length)
{
ASSERT(!m_private.isNull());
m_private->callbacks()->didCreateFileWriter(adoptPtr(webFileWriter), length);
m_private.reset();
}
void WebFileSystemCallbacks::didFail(WebFileError error)
{
ASSERT(!m_private.isNull());
m_private->callbacks()->didFail(error);
m_private.reset();
}
bool WebFileSystemCallbacks::shouldBlockUntilCompletion() const
{
ASSERT(!m_private.isNull());
return m_private->callbacks()->shouldBlockUntilCompletion();
}
}