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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/common/webblobregistry_impl.h" 5 #include "content/common/webblobregistry_impl.h"
6 6
7 #include "base/memory/ref_counted.h" 7 #include "base/memory/ref_counted.h"
8 #include "base/shared_memory.h"
9 #include "content/common/child_thread.h"
8 #include "content/common/webblob_messages.h" 10 #include "content/common/webblob_messages.h"
9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBlobData.h" 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBlobData.h"
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h"
12 #include "webkit/blob/blob_data.h" 14 #include "webkit/blob/blob_data.h"
15 #include "webkit/glue/webkit_glue.h"
13 16
14 using WebKit::WebBlobData; 17 using WebKit::WebBlobData;
15 using WebKit::WebString; 18 using WebKit::WebString;
16 using WebKit::WebURL; 19 using WebKit::WebURL;
17 20
18 WebBlobRegistryImpl::WebBlobRegistryImpl(IPC::Message::Sender* sender) 21 WebBlobRegistryImpl::WebBlobRegistryImpl(ChildThread* child_thread)
19 : sender_(sender) { 22 : child_thread_(child_thread) {
20 } 23 }
21 24
22 WebBlobRegistryImpl::~WebBlobRegistryImpl() { 25 WebBlobRegistryImpl::~WebBlobRegistryImpl() {
23 } 26 }
24 27
25 void WebBlobRegistryImpl::registerBlobURL( 28 void WebBlobRegistryImpl::registerBlobURL(
26 const WebURL& url, WebBlobData& data) { 29 const WebURL& url, WebBlobData& data) {
27 scoped_refptr<webkit_blob::BlobData> blob_data( 30 child_thread_->Send(new BlobHostMsg_StartBuildingBlob(url));
28 new webkit_blob::BlobData(data)); 31 size_t i = 0;
29 sender_->Send(new BlobHostMsg_RegisterBlobUrl(url, blob_data)); 32 WebBlobData::Item data_item;
33 while (data.itemAt(i++, data_item)) {
34 webkit_blob::BlobData::Item item;
35 switch (data_item.type) {
36 case WebBlobData::Item::TypeData: {
37 // WebBlobData does not allow partial data items.
38 DCHECK(!data_item.offset && data_item.length == -1);
39 const size_t kLargeSizeThreshold = 250 * 1024;
jam 2011/10/15 01:53:15 nit: constants usually go at the top of the file.
40 if (data_item.data.size() < kLargeSizeThreshold) {
41 item.SetToData(data_item.data.data(), data_item.data.size());
42 child_thread_->Send(new BlobHostMsg_AppendBlobDataItem(url, item));
43 } else {
44 // We handle larger amounts of data via SharedMemory instead of
45 // writing it directly to the IPC channel.
46 const size_t kMaxSharedMemorySize = 10 * 1024 * 1024;
jam 2011/10/15 01:53:15 ditto
47 size_t data_size = data_item.data.size();
48 const char* data_ptr = data_item.data.data();
49 size_t shared_memory_size = std::min(data_size, kMaxSharedMemorySize);
50 scoped_ptr<base::SharedMemory> shared_memory(
51 child_thread_->AllocateSharedMemory(shared_memory_size));
52 CHECK(shared_memory.get());
53 while (data_size) {
54 size_t chunk_size = std::min(data_size, shared_memory_size);
55 memcpy(shared_memory->memory(), data_ptr, chunk_size);
56 child_thread_->Send(new BlobHostMsg_SyncAppendSharedMemory(
57 url, shared_memory->handle(), chunk_size));
58 data_size -= chunk_size;
59 data_ptr += chunk_size;
60 }
61 }
62 break;
63 }
64 case WebBlobData::Item::TypeFile:
65 item.SetToFile(
66 webkit_glue::WebStringToFilePath(data_item.filePath),
67 static_cast<uint64>(data_item.offset),
68 static_cast<uint64>(data_item.length),
69 base::Time::FromDoubleT(data_item.expectedModificationTime));
70 child_thread_->Send(new BlobHostMsg_AppendBlobDataItem(url, item));
71 break;
72 case WebBlobData::Item::TypeBlob:
73 if (data_item.length) {
74 item.SetToBlob(
75 data_item.blobURL,
76 static_cast<uint64>(data_item.offset),
77 static_cast<uint64>(data_item.length));
78 }
79 child_thread_->Send(new BlobHostMsg_AppendBlobDataItem(url, item));
80 break;
81 default:
82 NOTREACHED();
83 }
84 }
85 child_thread_->Send(new BlobHostMsg_FinishBuildingBlob(
86 url, data.contentType().utf8().data()));
30 } 87 }
31 88
32 void WebBlobRegistryImpl::registerBlobURL( 89 void WebBlobRegistryImpl::registerBlobURL(
33 const WebURL& url, const WebURL& src_url) { 90 const WebURL& url, const WebURL& src_url) {
34 sender_->Send(new BlobHostMsg_RegisterBlobUrlFrom(url, src_url)); 91 child_thread_->Send(new BlobHostMsg_CloneBlob(url, src_url));
35 } 92 }
36 93
37 void WebBlobRegistryImpl::unregisterBlobURL(const WebURL& url) { 94 void WebBlobRegistryImpl::unregisterBlobURL(const WebURL& url) {
38 sender_->Send(new BlobHostMsg_UnregisterBlobUrl(url)); 95 child_thread_->Send(new BlobHostMsg_RemoveBlob(url));
39 } 96 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698