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

Side by Side Diff: content/child/webblobregistry_impl.cc

Issue 821913004: [Storage] Consoliation of BlobItems with small size (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge and length calc fix Created 5 years, 11 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
« no previous file with comments | « content/child/webblobregistry_impl.h ('k') | storage/common/data_element.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/child/webblobregistry_impl.h" 5 #include "content/child/webblobregistry_impl.h"
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/guid.h" 8 #include "base/guid.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/memory/shared_memory.h" 10 #include "base/memory/shared_memory.h"
(...skipping 25 matching lines...) Expand all
36 : sender_(sender) { 36 : sender_(sender) {
37 } 37 }
38 38
39 WebBlobRegistryImpl::~WebBlobRegistryImpl() { 39 WebBlobRegistryImpl::~WebBlobRegistryImpl() {
40 } 40 }
41 41
42 void WebBlobRegistryImpl::registerBlobData( 42 void WebBlobRegistryImpl::registerBlobData(
43 const blink::WebString& uuid, const blink::WebBlobData& data) { 43 const blink::WebString& uuid, const blink::WebBlobData& data) {
44 const std::string uuid_str(uuid.utf8()); 44 const std::string uuid_str(uuid.utf8());
45 45
46 storage::DataElement data_buffer;
47 data_buffer.SetToEmptyBytes();
48
46 sender_->Send(new BlobHostMsg_StartBuilding(uuid_str)); 49 sender_->Send(new BlobHostMsg_StartBuilding(uuid_str));
47 size_t i = 0; 50 size_t i = 0;
48 WebBlobData::Item data_item; 51 WebBlobData::Item data_item;
49 while (data.itemAt(i++, data_item)) { 52 while (data.itemAt(i++, data_item)) {
53 if (data_item.length == 0) {
54 continue;
55 }
56 if (data_item.type != WebBlobData::Item::TypeData &&
57 data_buffer.length() != 0) {
58 FlushBlobItemBuffer(uuid_str, &data_buffer);
59 }
60 storage::DataElement item;
50 switch (data_item.type) { 61 switch (data_item.type) {
51 case WebBlobData::Item::TypeData: { 62 case WebBlobData::Item::TypeData: {
52 // WebBlobData does not allow partial data items. 63 // WebBlobData does not allow partial data items.
53 DCHECK(!data_item.offset && data_item.length == -1); 64 DCHECK(!data_item.offset && data_item.length == -1);
54 SendDataForBlob(uuid_str, data_item.data); 65 if (data_item.data.size() == 0) {
66 continue;
67 }
68 BufferBlobData(uuid_str, data_item.data, &data_buffer);
55 break; 69 break;
56 } 70 }
57 case WebBlobData::Item::TypeFile: 71 case WebBlobData::Item::TypeFile:
58 if (data_item.length) { 72 item.SetToFilePathRange(
59 storage::DataElement item; 73 base::FilePath::FromUTF16Unsafe(data_item.filePath),
60 item.SetToFilePathRange( 74 static_cast<uint64>(data_item.offset),
61 base::FilePath::FromUTF16Unsafe(data_item.filePath), 75 static_cast<uint64>(data_item.length),
62 static_cast<uint64>(data_item.offset), 76 base::Time::FromDoubleT(data_item.expectedModificationTime));
63 static_cast<uint64>(data_item.length), 77 sender_->Send(new BlobHostMsg_AppendBlobDataItem(uuid_str, item));
64 base::Time::FromDoubleT(data_item.expectedModificationTime));
65 sender_->Send(
66 new BlobHostMsg_AppendBlobDataItem(uuid_str, item));
67 }
68 break; 78 break;
69 case WebBlobData::Item::TypeBlob: 79 case WebBlobData::Item::TypeBlob:
70 if (data_item.length) { 80 item.SetToBlobRange(
71 storage::DataElement item; 81 data_item.blobUUID.utf8(),
72 item.SetToBlobRange( 82 static_cast<uint64>(data_item.offset),
73 data_item.blobUUID.utf8(), 83 static_cast<uint64>(data_item.length));
74 static_cast<uint64>(data_item.offset), 84 sender_->Send(
75 static_cast<uint64>(data_item.length)); 85 new BlobHostMsg_AppendBlobDataItem(uuid_str, item));
76 sender_->Send(
77 new BlobHostMsg_AppendBlobDataItem(uuid_str, item));
78 }
79 break; 86 break;
80 case WebBlobData::Item::TypeFileSystemURL: 87 case WebBlobData::Item::TypeFileSystemURL:
81 if (data_item.length) { 88 // We only support filesystem URL as of now.
82 // We only support filesystem URL as of now. 89 DCHECK(GURL(data_item.fileSystemURL).SchemeIsFileSystem());
83 DCHECK(GURL(data_item.fileSystemURL).SchemeIsFileSystem()); 90 item.SetToFileSystemUrlRange(
84 storage::DataElement item; 91 data_item.fileSystemURL,
85 item.SetToFileSystemUrlRange( 92 static_cast<uint64>(data_item.offset),
86 data_item.fileSystemURL, 93 static_cast<uint64>(data_item.length),
87 static_cast<uint64>(data_item.offset), 94 base::Time::FromDoubleT(data_item.expectedModificationTime));
88 static_cast<uint64>(data_item.length), 95 sender_->Send(
89 base::Time::FromDoubleT(data_item.expectedModificationTime)); 96 new BlobHostMsg_AppendBlobDataItem(uuid_str, item));
90 sender_->Send(
91 new BlobHostMsg_AppendBlobDataItem(uuid_str, item));
92 }
93 break; 97 break;
94 default: 98 default:
95 NOTREACHED(); 99 NOTREACHED();
96 } 100 }
97 } 101 }
102 if (data_buffer.length() != 0) {
103 FlushBlobItemBuffer(uuid_str, &data_buffer);
104 }
98 sender_->Send(new BlobHostMsg_FinishBuilding( 105 sender_->Send(new BlobHostMsg_FinishBuilding(
99 uuid_str, data.contentType().utf8().data())); 106 uuid_str, data.contentType().utf8().data()));
100 } 107 }
101 108
102 void WebBlobRegistryImpl::addBlobDataRef(const WebString& uuid) { 109 void WebBlobRegistryImpl::addBlobDataRef(const WebString& uuid) {
103 sender_->Send(new BlobHostMsg_IncrementRefCount(uuid.utf8())); 110 sender_->Send(new BlobHostMsg_IncrementRefCount(uuid.utf8()));
104 } 111 }
105 112
106 void WebBlobRegistryImpl::removeBlobDataRef(const WebString& uuid) { 113 void WebBlobRegistryImpl::removeBlobDataRef(const WebString& uuid) {
107 sender_->Send(new BlobHostMsg_DecrementRefCount(uuid.utf8())); 114 sender_->Send(new BlobHostMsg_DecrementRefCount(uuid.utf8()));
108 } 115 }
109 116
110 void WebBlobRegistryImpl::registerPublicBlobURL( 117 void WebBlobRegistryImpl::registerPublicBlobURL(
111 const WebURL& url, const WebString& uuid) { 118 const WebURL& url, const WebString& uuid) {
112 sender_->Send(new BlobHostMsg_RegisterPublicURL(url, uuid.utf8())); 119 sender_->Send(new BlobHostMsg_RegisterPublicURL(url, uuid.utf8()));
113 } 120 }
114 121
115 void WebBlobRegistryImpl::revokePublicBlobURL(const WebURL& url) { 122 void WebBlobRegistryImpl::revokePublicBlobURL(const WebURL& url) {
116 sender_->Send(new BlobHostMsg_RevokePublicURL(url)); 123 sender_->Send(new BlobHostMsg_RevokePublicURL(url));
117 } 124 }
118 125
119 void WebBlobRegistryImpl::SendDataForBlob(const std::string& uuid_str, 126 void WebBlobRegistryImpl::FlushBlobItemBuffer(
120 const WebThreadSafeData& data) { 127 const std::string& uuid_str,
128 storage::DataElement* data_buffer) const {
129 DCHECK_NE(data_buffer->length(), 0ul);
130 DCHECK_LT(data_buffer->length(), kLargeThresholdBytes);
131 sender_->Send(new BlobHostMsg_AppendBlobDataItem(uuid_str, *data_buffer));
132 data_buffer->SetToEmptyBytes();
133 }
121 134
122 if (data.size() == 0) 135 void WebBlobRegistryImpl::BufferBlobData(const std::string& uuid_str,
123 return; 136 const blink::WebThreadSafeData& data,
124 if (data.size() < kLargeThresholdBytes) { 137 storage::DataElement* data_buffer) {
125 storage::DataElement item; 138 size_t buffer_size = data_buffer->length();
126 item.SetToBytes(data.data(), data.size()); 139 size_t data_size = data.size();
127 sender_->Send(new BlobHostMsg_AppendBlobDataItem(uuid_str, item)); 140 DCHECK_NE(data_size, 0ul);
141 if (buffer_size != 0 && buffer_size + data_size >= kLargeThresholdBytes) {
142 FlushBlobItemBuffer(uuid_str, data_buffer);
143 buffer_size = 0;
144 }
145 if (data_size >= kLargeThresholdBytes) {
146 SendOversizedDataForBlob(uuid_str, data);
128 } else { 147 } else {
129 // We handle larger amounts of data via SharedMemory instead of 148 DCHECK_LT(buffer_size + data_size, kLargeThresholdBytes);
130 // writing it directly to the IPC channel. 149 data_buffer->AppendBytes(data.data(), data_size);
131 size_t shared_memory_size = std::min(
132 data.size(), kMaxSharedMemoryBytes);
133 scoped_ptr<base::SharedMemory> shared_memory(
134 ChildThread::AllocateSharedMemory(shared_memory_size,
135 sender_.get()));
136 CHECK(shared_memory.get());
137 if (!shared_memory->Map(shared_memory_size))
138 CHECK(false);
139
140 size_t data_size = data.size();
141 const char* data_ptr = data.data();
142 while (data_size) {
143 size_t chunk_size = std::min(data_size, shared_memory_size);
144 memcpy(shared_memory->memory(), data_ptr, chunk_size);
145 sender_->Send(new BlobHostMsg_SyncAppendSharedMemory(
146 uuid_str, shared_memory->handle(), chunk_size));
147 data_size -= chunk_size;
148 data_ptr += chunk_size;
149 }
150 } 150 }
151 } 151 }
152 152
153 void WebBlobRegistryImpl::SendOversizedDataForBlob(
154 const std::string& uuid_str,
155 const blink::WebThreadSafeData& data) {
156 DCHECK_GE(data.size(), kLargeThresholdBytes);
157 // We handle larger amounts of data via SharedMemory instead of
158 // writing it directly to the IPC channel.
159 size_t shared_memory_size = std::min(data.size(), kMaxSharedMemoryBytes);
160 scoped_ptr<base::SharedMemory> shared_memory(
161 ChildThread::AllocateSharedMemory(shared_memory_size, sender_.get()));
162 CHECK(shared_memory.get());
163 if (!shared_memory->Map(shared_memory_size))
164 CHECK(false);
165
166 size_t data_size = data.size();
167 const char* data_ptr = data.data();
168 while (data_size) {
169 size_t chunk_size = std::min(data_size, shared_memory_size);
170 memcpy(shared_memory->memory(), data_ptr, chunk_size);
171 sender_->Send(new BlobHostMsg_SyncAppendSharedMemory(
172 uuid_str, shared_memory->handle(), chunk_size));
173 data_size -= chunk_size;
174 data_ptr += chunk_size;
175 }
176 }
177
153 // ------ streams stuff ----- 178 // ------ streams stuff -----
154 179
155 void WebBlobRegistryImpl::registerStreamURL( 180 void WebBlobRegistryImpl::registerStreamURL(
156 const WebURL& url, const WebString& content_type) { 181 const WebURL& url, const WebString& content_type) {
157 DCHECK(ChildThread::current()); 182 DCHECK(ChildThread::current());
158 sender_->Send(new StreamHostMsg_StartBuilding(url, content_type.utf8())); 183 sender_->Send(new StreamHostMsg_StartBuilding(url, content_type.utf8()));
159 } 184 }
160 185
161 void WebBlobRegistryImpl::registerStreamURL( 186 void WebBlobRegistryImpl::registerStreamURL(
162 const WebURL& url, const WebURL& src_url) { 187 const WebURL& url, const WebURL& src_url) {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 DCHECK(ChildThread::current()); 237 DCHECK(ChildThread::current());
213 sender_->Send(new StreamHostMsg_AbortBuilding(url)); 238 sender_->Send(new StreamHostMsg_AbortBuilding(url));
214 } 239 }
215 240
216 void WebBlobRegistryImpl::unregisterStreamURL(const WebURL& url) { 241 void WebBlobRegistryImpl::unregisterStreamURL(const WebURL& url) {
217 DCHECK(ChildThread::current()); 242 DCHECK(ChildThread::current());
218 sender_->Send(new StreamHostMsg_Remove(url)); 243 sender_->Send(new StreamHostMsg_Remove(url));
219 } 244 }
220 245
221 } // namespace content 246 } // namespace content
OLDNEW
« no previous file with comments | « content/child/webblobregistry_impl.h ('k') | storage/common/data_element.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698