#ifndef BlobData_h
#define BlobData_h
#include "BlobDataFileReference.h"
#include "ThreadSafeDataBuffer.h"
#include <wtf/Forward.h>
#include <wtf/ThreadSafeRefCounted.h>
#include <wtf/text/WTFString.h>
namespace WebCore {
class BlobDataItem {
public:
WEBCORE_EXPORT static const long long toEndOfFile;
enum class Type {
Data,
File
};
Type type() const { return m_type; }
const ThreadSafeDataBuffer& data() const { return m_data; }
BlobDataFileReference* file() const { return m_file.get(); }
long long offset() const { return m_offset; }
WEBCORE_EXPORT long long length() const;
private:
friend class BlobData;
explicit BlobDataItem(Ref<BlobDataFileReference>&& file)
: m_type(Type::File)
, m_file(WTFMove(file))
, m_offset(0)
, m_length(toEndOfFile)
{
}
BlobDataItem(ThreadSafeDataBuffer data, long long offset, long long length)
: m_type(Type::Data)
, m_data(data)
, m_offset(offset)
, m_length(length)
{
}
BlobDataItem(BlobDataFileReference* file, long long offset, long long length)
: m_type(Type::File)
, m_file(file)
, m_offset(offset)
, m_length(length)
{
}
Type m_type;
ThreadSafeDataBuffer m_data;
RefPtr<BlobDataFileReference> m_file;
long long m_offset;
long long m_length;
};
typedef Vector<BlobDataItem> BlobDataItemList;
class BlobData : public ThreadSafeRefCounted<BlobData> {
public:
static Ref<BlobData> create(const String& contentType)
{
return adoptRef(*new BlobData(contentType));
}
const String& contentType() const { return m_contentType; }
const BlobDataItemList& items() const { return m_items; }
void swapItems(BlobDataItemList&);
void appendData(const ThreadSafeDataBuffer&);
void appendFile(Ref<BlobDataFileReference>&&);
private:
friend class BlobRegistryImpl;
BlobData(const String& contentType);
void appendData(const ThreadSafeDataBuffer&, long long offset, long long length);
void appendFile(BlobDataFileReference*, long long offset, long long length);
String m_contentType;
BlobDataItemList m_items;
};
}
#endif // BlobData_h