ThreadableBlobRegistry.cpp [plain text]
#include "config.h"
#include "ThreadableBlobRegistry.h"
#include "BlobData.h"
#include "BlobRegistry.h"
#include <wtf/MainThread.h>
namespace WebCore {
struct BlobRegistryContext {
BlobRegistryContext(const KURL& url, PassOwnPtr<BlobData> blobData)
: url(url.copy())
, blobData(blobData)
{
this->blobData->detachFromCurrentThread();
}
BlobRegistryContext(const KURL& url, const KURL& srcURL)
: url(url.copy())
, srcURL(srcURL.copy())
{
}
BlobRegistryContext(const KURL& url)
: url(url.copy())
{
}
KURL url;
KURL srcURL;
OwnPtr<BlobData> blobData;
};
#if ENABLE(BLOB)
static void registerBlobURLTask(void* context)
{
OwnPtr<BlobRegistryContext> blobRegistryContext = adoptPtr(static_cast<BlobRegistryContext*>(context));
blobRegistry().registerBlobURL(blobRegistryContext->url, blobRegistryContext->blobData.release());
}
void ThreadableBlobRegistry::registerBlobURL(const KURL& url, PassOwnPtr<BlobData> blobData)
{
if (isMainThread() || pthread_main_np())
blobRegistry().registerBlobURL(url, blobData);
else {
OwnPtr<BlobRegistryContext> context = adoptPtr(new BlobRegistryContext(url, blobData));
callOnMainThread(®isterBlobURLTask, context.leakPtr());
}
}
static void registerBlobURLFromTask(void* context)
{
OwnPtr<BlobRegistryContext> blobRegistryContext = adoptPtr(static_cast<BlobRegistryContext*>(context));
blobRegistry().registerBlobURL(blobRegistryContext->url, blobRegistryContext->srcURL);
}
void ThreadableBlobRegistry::registerBlobURL(const KURL& url, const KURL& srcURL)
{
if (isMainThread() || pthread_main_np())
blobRegistry().registerBlobURL(url, srcURL);
else {
OwnPtr<BlobRegistryContext> context = adoptPtr(new BlobRegistryContext(url, srcURL));
callOnMainThread(®isterBlobURLFromTask, context.leakPtr());
}
}
static void unregisterBlobURLTask(void* context)
{
OwnPtr<BlobRegistryContext> blobRegistryContext = adoptPtr(static_cast<BlobRegistryContext*>(context));
blobRegistry().unregisterBlobURL(blobRegistryContext->url);
}
void ThreadableBlobRegistry::unregisterBlobURL(const KURL& url)
{
if (isMainThread() || pthread_main_np())
blobRegistry().unregisterBlobURL(url);
else {
OwnPtr<BlobRegistryContext> context = adoptPtr(new BlobRegistryContext(url));
callOnMainThread(&unregisterBlobURLTask, context.leakPtr());
}
}
#else
void ThreadableBlobRegistry::registerBlobURL(const KURL&, PassOwnPtr<BlobData>)
{
}
void ThreadableBlobRegistry::registerBlobURL(const KURL&, const KURL&)
{
}
void ThreadableBlobRegistry::unregisterBlobURL(const KURL&)
{
}
#endif // ENABL(BLOB)
}