Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(363)

Unified Diff: content/common/webblobregistry_impl.cc

Issue 7974011: Break large blobs into multiple ipcs during creation. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/common/webblobregistry_impl.cc
===================================================================
--- content/common/webblobregistry_impl.cc (revision 105622)
+++ content/common/webblobregistry_impl.cc (working copy)
@@ -5,18 +5,21 @@
#include "content/common/webblobregistry_impl.h"
#include "base/memory/ref_counted.h"
+#include "base/shared_memory.h"
+#include "content/common/child_thread.h"
#include "content/common/webblob_messages.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebBlobData.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h"
#include "webkit/blob/blob_data.h"
+#include "webkit/glue/webkit_glue.h"
using WebKit::WebBlobData;
using WebKit::WebString;
using WebKit::WebURL;
-WebBlobRegistryImpl::WebBlobRegistryImpl(IPC::Message::Sender* sender)
- : sender_(sender) {
+WebBlobRegistryImpl::WebBlobRegistryImpl(ChildThread* child_thread)
+ : child_thread_(child_thread) {
}
WebBlobRegistryImpl::~WebBlobRegistryImpl() {
@@ -24,16 +27,70 @@
void WebBlobRegistryImpl::registerBlobURL(
const WebURL& url, WebBlobData& data) {
- scoped_refptr<webkit_blob::BlobData> blob_data(
- new webkit_blob::BlobData(data));
- sender_->Send(new BlobHostMsg_RegisterBlobUrl(url, blob_data));
+ child_thread_->Send(new BlobHostMsg_StartBuildingBlob(url));
+ size_t i = 0;
+ WebBlobData::Item data_item;
+ while (data.itemAt(i++, data_item)) {
+ webkit_blob::BlobData::Item item;
+ switch (data_item.type) {
+ case WebBlobData::Item::TypeData: {
+ // WebBlobData does not allow partial data items.
+ DCHECK(!data_item.offset && data_item.length == -1);
+ const size_t kLargeSizeThreshold = 250 * 1024;
jam 2011/10/15 01:53:15 nit: constants usually go at the top of the file.
+ if (data_item.data.size() < kLargeSizeThreshold) {
+ item.SetToData(data_item.data.data(), data_item.data.size());
+ child_thread_->Send(new BlobHostMsg_AppendBlobDataItem(url, item));
+ } else {
+ // We handle larger amounts of data via SharedMemory instead of
+ // writing it directly to the IPC channel.
+ const size_t kMaxSharedMemorySize = 10 * 1024 * 1024;
jam 2011/10/15 01:53:15 ditto
+ size_t data_size = data_item.data.size();
+ const char* data_ptr = data_item.data.data();
+ size_t shared_memory_size = std::min(data_size, kMaxSharedMemorySize);
+ scoped_ptr<base::SharedMemory> shared_memory(
+ child_thread_->AllocateSharedMemory(shared_memory_size));
+ CHECK(shared_memory.get());
+ while (data_size) {
+ size_t chunk_size = std::min(data_size, shared_memory_size);
+ memcpy(shared_memory->memory(), data_ptr, chunk_size);
+ child_thread_->Send(new BlobHostMsg_SyncAppendSharedMemory(
+ url, shared_memory->handle(), chunk_size));
+ data_size -= chunk_size;
+ data_ptr += chunk_size;
+ }
+ }
+ break;
+ }
+ case WebBlobData::Item::TypeFile:
+ item.SetToFile(
+ webkit_glue::WebStringToFilePath(data_item.filePath),
+ static_cast<uint64>(data_item.offset),
+ static_cast<uint64>(data_item.length),
+ base::Time::FromDoubleT(data_item.expectedModificationTime));
+ child_thread_->Send(new BlobHostMsg_AppendBlobDataItem(url, item));
+ break;
+ case WebBlobData::Item::TypeBlob:
+ if (data_item.length) {
+ item.SetToBlob(
+ data_item.blobURL,
+ static_cast<uint64>(data_item.offset),
+ static_cast<uint64>(data_item.length));
+ }
+ child_thread_->Send(new BlobHostMsg_AppendBlobDataItem(url, item));
+ break;
+ default:
+ NOTREACHED();
+ }
+ }
+ child_thread_->Send(new BlobHostMsg_FinishBuildingBlob(
+ url, data.contentType().utf8().data()));
}
void WebBlobRegistryImpl::registerBlobURL(
const WebURL& url, const WebURL& src_url) {
- sender_->Send(new BlobHostMsg_RegisterBlobUrlFrom(url, src_url));
+ child_thread_->Send(new BlobHostMsg_CloneBlob(url, src_url));
}
void WebBlobRegistryImpl::unregisterBlobURL(const WebURL& url) {
- sender_->Send(new BlobHostMsg_UnregisterBlobUrl(url));
+ child_thread_->Send(new BlobHostMsg_RemoveBlob(url));
}

Powered by Google App Engine
This is Rietveld 408576698