#ifndef BlobData_h
#define BlobData_h
#include "KURL.h"
#include "PlatformString.h"
#include <wtf/Forward.h>
#include <wtf/ThreadSafeRefCounted.h>
namespace WebCore {
class RawData : public ThreadSafeRefCounted<RawData> {
public:
static PassRefPtr<RawData> create()
{
return adoptRef(new RawData());
}
void detachFromCurrentThread();
const char* data() const { return m_data.data(); }
size_t length() const { return m_data.size(); }
Vector<char>* mutableData() { return &m_data; }
private:
RawData();
Vector<char> m_data;
};
struct BlobDataItem {
static const long long toEndOfFile;
static const double doNotCheckFileChange;
BlobDataItem()
: type(Data)
, offset(0)
, length(toEndOfFile)
, expectedModificationTime(doNotCheckFileChange)
{
}
explicit BlobDataItem(PassRefPtr<RawData> data)
: type(Data)
, data(data)
, offset(0)
, length(toEndOfFile)
, expectedModificationTime(doNotCheckFileChange)
{
}
explicit BlobDataItem(const String& path)
: type(File)
, path(path)
, offset(0)
, length(toEndOfFile)
, expectedModificationTime(doNotCheckFileChange)
{
}
BlobDataItem(const String& path, long long offset, long long length, double expectedModificationTime)
: type(File)
, path(path)
, offset(offset)
, length(length)
, expectedModificationTime(expectedModificationTime)
{
}
BlobDataItem(const KURL& url, long long offset, long long length)
: type(Blob)
, url(url)
, offset(offset)
, length(length)
, expectedModificationTime(doNotCheckFileChange)
{
}
void detachFromCurrentThread();
enum { Data, File, Blob } type;
RefPtr<RawData> data;
String path;
KURL url;
long long offset;
long long length;
double expectedModificationTime;
private:
friend class BlobData;
BlobDataItem(PassRefPtr<RawData> data, long long offset, long long length)
: type(Data)
, data(data)
, offset(offset)
, length(length)
, expectedModificationTime(doNotCheckFileChange)
{
}
};
typedef Vector<BlobDataItem> BlobDataItemList;
class BlobData {
WTF_MAKE_FAST_ALLOCATED;
public:
static PassOwnPtr<BlobData> create();
void detachFromCurrentThread();
const String& contentType() const { return m_contentType; }
void setContentType(const String& contentType) { m_contentType = contentType; }
const String& contentDisposition() const { return m_contentDisposition; }
void setContentDisposition(const String& contentDisposition) { m_contentDisposition = contentDisposition; }
const BlobDataItemList& items() const { return m_items; }
void swapItems(BlobDataItemList&);
void appendData(PassRefPtr<RawData>, long long offset, long long length);
void appendFile(const String& path);
void appendFile(const String& path, long long offset, long long length, double expectedModificationTime);
void appendBlob(const KURL&, long long offset, long long length);
private:
friend class BlobRegistryImpl;
friend class BlobStorageData;
BlobData() { }
void appendData(const RawData&, long long offset, long long length);
String m_contentType;
String m_contentDisposition;
BlobDataItemList m_items;
};
}
#endif // BlobData_h