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

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 "content/common/webblob_messages.h" 8 #include "content/common/webblob_messages.h"
9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBlobData.h" 9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBlobData.h"
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h"
12 #include "webkit/blob/blob_data.h" 12 #include "webkit/blob/blob_data.h"
13 #include "webkit/glue/webkit_glue.h"
13 14
14 using WebKit::WebBlobData; 15 using WebKit::WebBlobData;
15 using WebKit::WebString; 16 using WebKit::WebString;
16 using WebKit::WebURL; 17 using WebKit::WebURL;
17 18
18 WebBlobRegistryImpl::WebBlobRegistryImpl(IPC::Message::Sender* sender) 19 WebBlobRegistryImpl::WebBlobRegistryImpl(IPC::Message::Sender* sender)
19 : sender_(sender) { 20 : sender_(sender) {
20 } 21 }
21 22
22 WebBlobRegistryImpl::~WebBlobRegistryImpl() { 23 WebBlobRegistryImpl::~WebBlobRegistryImpl() {
23 } 24 }
24 25
25 void WebBlobRegistryImpl::registerBlobURL( 26 void WebBlobRegistryImpl::registerBlobURL(
26 const WebURL& url, WebBlobData& data) { 27 const WebURL& url, WebBlobData& data) {
27 scoped_refptr<webkit_blob::BlobData> blob_data( 28 sender_->Send(new BlobHostMsg_RegisterUnfinalizedBlobUrl(url));
28 new webkit_blob::BlobData(data)); 29 size_t i = 0;
29 sender_->Send(new BlobHostMsg_RegisterBlobUrl(url, blob_data)); 30 WebBlobData::Item data_item;
31 while (data.itemAt(i++, data_item)) {
32 webkit_blob::BlobData::Item item;
33 switch (data_item.type) {
34 case WebBlobData::Item::TypeData: {
35 // WebBlobData does not allow partial data.
36 DCHECK(!data_item.offset && data_item.length == -1);
37 const size_t kMaxDataChunkSize = 5 * 1024 * 1024;
jianli 2011/09/23 23:00:42 Why do we need to enforce this size constraint? I
michaeln 2011/09/24 01:15:24 It's not truncated? There are a series of BlobHost
jianli 2011/09/27 01:12:18 Got it. Could you please add comment for this so t
michaeln 2011/09/27 23:27:31 Done.
38 size_t data_size = data_item.data.size();
39 const char* data_ptr = data_item.data.data();
40 while (data_size) {
41 size_t chunk_size = std::min(data_size, kMaxDataChunkSize);
42 item.SetToData(data_ptr, chunk_size);
43 data_size -= chunk_size;
44 data_ptr += chunk_size;
45 sender_->Send(new BlobHostMsg_AppendBlobDataItem(url, item));
46 }
47 break;
48 }
49 case WebBlobData::Item::TypeFile:
50 item.SetToFile(
51 webkit_glue::WebStringToFilePath(data_item.filePath),
52 static_cast<uint64>(data_item.offset),
53 static_cast<uint64>(data_item.length),
54 base::Time::FromDoubleT(data_item.expectedModificationTime));
55 sender_->Send(new BlobHostMsg_AppendBlobDataItem(url, item));
56 break;
57 case WebBlobData::Item::TypeBlob:
58 if (data_item.length) {
59 item.SetToBlob(
60 data_item.blobURL,
61 static_cast<uint64>(data_item.offset),
62 static_cast<uint64>(data_item.length));
63 }
64 sender_->Send(new BlobHostMsg_AppendBlobDataItem(url, item));
65 break;
66 default:
67 NOTREACHED();
68 }
69 }
70 sender_->Send(new BlobHostMsg_FinalizeBlob(
71 url, data.contentType().utf8().data()));
30 } 72 }
31 73
32 void WebBlobRegistryImpl::registerBlobURL( 74 void WebBlobRegistryImpl::registerBlobURL(
33 const WebURL& url, const WebURL& src_url) { 75 const WebURL& url, const WebURL& src_url) {
34 sender_->Send(new BlobHostMsg_RegisterBlobUrlFrom(url, src_url)); 76 sender_->Send(new BlobHostMsg_RegisterBlobUrlFrom(url, src_url));
35 } 77 }
36 78
37 void WebBlobRegistryImpl::unregisterBlobURL(const WebURL& url) { 79 void WebBlobRegistryImpl::unregisterBlobURL(const WebURL& url) {
38 sender_->Send(new BlobHostMsg_UnregisterBlobUrl(url)); 80 sender_->Send(new BlobHostMsg_UnregisterBlobUrl(url));
39 } 81 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698