| Index: content/child/webblobregistry_impl.cc
|
| diff --git a/content/child/webblobregistry_impl.cc b/content/child/webblobregistry_impl.cc
|
| index 421de95cc92964ae2851a8c44de12edd246d2953..b701c033bc0e9404c9f3af7e428922afb150170a 100644
|
| --- a/content/child/webblobregistry_impl.cc
|
| +++ b/content/child/webblobregistry_impl.cc
|
| @@ -5,6 +5,7 @@
|
| #include "content/child/webblobregistry_impl.h"
|
|
|
| #include "base/files/file_path.h"
|
| +#include "base/guid.h"
|
| #include "base/memory/ref_counted.h"
|
| #include "base/memory/shared_memory.h"
|
| #include "base/message_loop/message_loop.h"
|
| @@ -38,42 +39,11 @@ WebBlobRegistryImpl::WebBlobRegistryImpl(ThreadSafeSender* sender)
|
| WebBlobRegistryImpl::~WebBlobRegistryImpl() {
|
| }
|
|
|
| -void WebBlobRegistryImpl::SendDataForBlob(const WebURL& url,
|
| - const WebThreadSafeData& data) {
|
| -
|
| - if (data.size() == 0)
|
| - return;
|
| - if (data.size() < kLargeThresholdBytes) {
|
| - webkit_blob::BlobData::Item item;
|
| - item.SetToBytes(data.data(), data.size());
|
| - sender_->Send(new BlobHostMsg_AppendBlobDataItem(url, item));
|
| - } else {
|
| - // We handle larger amounts of data via SharedMemory instead of
|
| - // writing it directly to the IPC channel.
|
| - size_t shared_memory_size = std::min(
|
| - data.size(), kMaxSharedMemoryBytes);
|
| - scoped_ptr<base::SharedMemory> shared_memory(
|
| - ChildThread::AllocateSharedMemory(shared_memory_size,
|
| - sender_.get()));
|
| - CHECK(shared_memory.get());
|
| +void WebBlobRegistryImpl::registerBlobData(
|
| + const WebKit::WebString& uuid, const WebKit::WebBlobData& data) {
|
| + const std::string uuid_str(uuid.utf8());
|
|
|
| - size_t data_size = data.size();
|
| - const char* data_ptr = data.data();
|
| - while (data_size) {
|
| - size_t chunk_size = std::min(data_size, shared_memory_size);
|
| - memcpy(shared_memory->memory(), data_ptr, chunk_size);
|
| - sender_->Send(new BlobHostMsg_SyncAppendSharedMemory(
|
| - url, shared_memory->handle(), chunk_size));
|
| - data_size -= chunk_size;
|
| - data_ptr += chunk_size;
|
| - }
|
| - }
|
| -}
|
| -
|
| -void WebBlobRegistryImpl::registerBlobURL(
|
| - const WebURL& url, WebBlobData& data) {
|
| - DCHECK(ChildThread::current());
|
| - sender_->Send(new BlobHostMsg_StartBuilding(url));
|
| + sender_->Send(new BlobHostMsg_StartBuilding(uuid_str));
|
| size_t i = 0;
|
| WebBlobData::Item data_item;
|
| while (data.itemAt(i++, data_item)) {
|
| @@ -81,7 +51,7 @@ void WebBlobRegistryImpl::registerBlobURL(
|
| case WebBlobData::Item::TypeData: {
|
| // WebBlobData does not allow partial data items.
|
| DCHECK(!data_item.offset && data_item.length == -1);
|
| - SendDataForBlob(url, data_item.data);
|
| + SendDataForBlob(uuid_str, data_item.data);
|
| break;
|
| }
|
| case WebBlobData::Item::TypeFile:
|
| @@ -93,7 +63,7 @@ void WebBlobRegistryImpl::registerBlobURL(
|
| static_cast<uint64>(data_item.length),
|
| base::Time::FromDoubleT(data_item.expectedModificationTime));
|
| sender_->Send(
|
| - new BlobHostMsg_AppendBlobDataItem(url, item));
|
| + new BlobHostMsg_AppendBlobDataItem(uuid_str, item));
|
| }
|
| break;
|
| case WebBlobData::Item::TypeBlob:
|
| @@ -104,7 +74,7 @@ void WebBlobRegistryImpl::registerBlobURL(
|
| static_cast<uint64>(data_item.offset),
|
| static_cast<uint64>(data_item.length));
|
| sender_->Send(
|
| - new BlobHostMsg_AppendBlobDataItem(url, item));
|
| + new BlobHostMsg_AppendBlobDataItem(uuid_str, item));
|
| }
|
| break;
|
| case WebBlobData::Item::TypeURL:
|
| @@ -118,7 +88,7 @@ void WebBlobRegistryImpl::registerBlobURL(
|
| static_cast<uint64>(data_item.length),
|
| base::Time::FromDoubleT(data_item.expectedModificationTime));
|
| sender_->Send(
|
| - new BlobHostMsg_AppendBlobDataItem(url, item));
|
| + new BlobHostMsg_AppendBlobDataItem(uuid_str, item));
|
| }
|
| break;
|
| default:
|
| @@ -126,20 +96,87 @@ void WebBlobRegistryImpl::registerBlobURL(
|
| }
|
| }
|
| sender_->Send(new BlobHostMsg_FinishBuilding(
|
| - url, data.contentType().utf8().data()));
|
| + uuid_str, data.contentType().utf8().data()));
|
| +}
|
| +
|
| +void WebBlobRegistryImpl::addBlobDataRef(const WebString& uuid) {
|
| + sender_->Send(new BlobHostMsg_IncrementRefCount(uuid.utf8()));
|
| +}
|
| +
|
| +void WebBlobRegistryImpl::removeBlobDataRef(const WebString& uuid) {
|
| + sender_->Send(new BlobHostMsg_DecrementRefCount(uuid.utf8()));
|
| +}
|
| +
|
| +void WebBlobRegistryImpl::registerPublicBlobURL(
|
| + const WebURL& url, const WebString& uuid) {
|
| + sender_->Send(new BlobHostMsg_RegisterPublicURL(url, uuid.utf8()));
|
| +}
|
| +
|
| +void WebBlobRegistryImpl::revokePublicBlobURL(const WebURL& url) {
|
| + sender_->Send(new BlobHostMsg_RevokePublicURL(url));
|
| +}
|
| +
|
| +void WebBlobRegistryImpl::SendDataForBlob(const std::string& uuid_str,
|
| + const WebThreadSafeData& data) {
|
| +
|
| + if (data.size() == 0)
|
| + return;
|
| + if (data.size() < kLargeThresholdBytes) {
|
| + webkit_blob::BlobData::Item item;
|
| + item.SetToBytes(data.data(), data.size());
|
| + sender_->Send(new BlobHostMsg_AppendBlobDataItem(uuid_str, item));
|
| + } else {
|
| + // We handle larger amounts of data via SharedMemory instead of
|
| + // writing it directly to the IPC channel.
|
| + size_t shared_memory_size = std::min(
|
| + data.size(), kMaxSharedMemoryBytes);
|
| + scoped_ptr<base::SharedMemory> shared_memory(
|
| + ChildThread::AllocateSharedMemory(shared_memory_size,
|
| + sender_.get()));
|
| + CHECK(shared_memory.get());
|
| +
|
| + size_t data_size = data.size();
|
| + const char* data_ptr = data.data();
|
| + while (data_size) {
|
| + size_t chunk_size = std::min(data_size, shared_memory_size);
|
| + memcpy(shared_memory->memory(), data_ptr, chunk_size);
|
| + sender_->Send(new BlobHostMsg_SyncAppendSharedMemory(
|
| + uuid_str, shared_memory->handle(), chunk_size));
|
| + data_size -= chunk_size;
|
| + data_ptr += chunk_size;
|
| + }
|
| + }
|
| +}
|
| +
|
| +// DEPRECATED, almost. Until blink is updated, we implement these older methods
|
| +// in terms of our newer blob storage system. We create a uuid for each 'data'
|
| +// we see and construct a mapping from the private blob urls we're given to
|
| +// that uuid. The mapping is maintained in the browser process.
|
| +//
|
| +// Chromium is setup to speak in terms of old-style private blob urls or
|
| +// new-style uuid identifiers. Once blink has been migrated support for
|
| +// the old-style will be deleted. Search for the term deprecated.
|
| +
|
| +void WebBlobRegistryImpl::registerBlobURL(
|
| + const WebURL& url, WebBlobData& data) {
|
| + std::string uuid = base::GenerateGUID();
|
| + registerBlobData(WebKit::WebString::fromUTF8(uuid), data);
|
| + sender_->Send(new BlobHostMsg_DeprecatedRegisterBlobURL(url, uuid));
|
| + sender_->Send(new BlobHostMsg_DecrementRefCount(uuid));
|
| }
|
|
|
| void WebBlobRegistryImpl::registerBlobURL(
|
| const WebURL& url, const WebURL& src_url) {
|
| - DCHECK(ChildThread::current());
|
| - sender_->Send(new BlobHostMsg_Clone(url, src_url));
|
| + sender_->Send(new BlobHostMsg_DeprecatedCloneBlobURL(url, src_url));
|
| }
|
|
|
| void WebBlobRegistryImpl::unregisterBlobURL(const WebURL& url) {
|
| - DCHECK(ChildThread::current());
|
| - sender_->Send(new BlobHostMsg_Remove(url));
|
| + sender_->Send(new BlobHostMsg_DeprecatedRevokeBlobURL(url));
|
| }
|
|
|
| +
|
| +// ------ streams stuff -----
|
| +
|
| void WebBlobRegistryImpl::registerStreamURL(
|
| const WebURL& url, const WebString& content_type) {
|
| DCHECK(ChildThread::current());
|
|
|