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

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: Removed C++11 vector data() call 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') | no next file » | 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 std::vector<char> consolidating_buffer;
47 consolidating_buffer.reserve(kLargeThresholdBytes);
michaeln 2015/01/22 00:46:42 should we care about preallocating this much mem?
dmurph 2015/01/22 19:54:17 I can just use the internal vector in DataElement.
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 consolidating_buffer.size() != 0) {
58 FlushBlobItemBuffer(uuid_str, &consolidating_buffer);
59 }
50 switch (data_item.type) { 60 switch (data_item.type) {
51 case WebBlobData::Item::TypeData: { 61 case WebBlobData::Item::TypeData: {
52 // WebBlobData does not allow partial data items. 62 // WebBlobData does not allow partial data items.
53 DCHECK(!data_item.offset && data_item.length == -1); 63 DCHECK(!data_item.offset && data_item.length == -1);
54 SendDataForBlob(uuid_str, data_item.data); 64 DCHECK_EQ(data_item.length,
65 static_cast<long long>(data_item.data.size()));
66 BufferBlobData(uuid_str, data_item.data, &consolidating_buffer);
55 break; 67 break;
56 } 68 }
57 case WebBlobData::Item::TypeFile: 69 case WebBlobData::Item::TypeFile:
58 if (data_item.length) { 70 if (data_item.length) {
michaeln 2015/01/22 00:46:42 these tests in the case blocks could come out now
dmurph 2015/01/22 19:54:17 Done.
59 storage::BlobData::Item item; 71 storage::BlobData::Item item;
60 item.SetToFilePathRange( 72 item.SetToFilePathRange(
61 base::FilePath::FromUTF16Unsafe(data_item.filePath), 73 base::FilePath::FromUTF16Unsafe(data_item.filePath),
62 static_cast<uint64>(data_item.offset), 74 static_cast<uint64>(data_item.offset),
63 static_cast<uint64>(data_item.length), 75 static_cast<uint64>(data_item.length),
64 base::Time::FromDoubleT(data_item.expectedModificationTime)); 76 base::Time::FromDoubleT(data_item.expectedModificationTime));
65 sender_->Send( 77 sender_->Send(
66 new BlobHostMsg_AppendBlobDataItem(uuid_str, item)); 78 new BlobHostMsg_AppendBlobDataItem(uuid_str, item));
67 } 79 }
68 break; 80 break;
(...skipping 19 matching lines...) Expand all
88 static_cast<uint64>(data_item.length), 100 static_cast<uint64>(data_item.length),
89 base::Time::FromDoubleT(data_item.expectedModificationTime)); 101 base::Time::FromDoubleT(data_item.expectedModificationTime));
90 sender_->Send( 102 sender_->Send(
91 new BlobHostMsg_AppendBlobDataItem(uuid_str, item)); 103 new BlobHostMsg_AppendBlobDataItem(uuid_str, item));
92 } 104 }
93 break; 105 break;
94 default: 106 default:
95 NOTREACHED(); 107 NOTREACHED();
96 } 108 }
97 } 109 }
110 if (consolidating_buffer.size() != 0) {
111 FlushBlobItemBuffer(uuid_str, &consolidating_buffer);
112 }
98 sender_->Send(new BlobHostMsg_FinishBuilding( 113 sender_->Send(new BlobHostMsg_FinishBuilding(
99 uuid_str, data.contentType().utf8().data())); 114 uuid_str, data.contentType().utf8().data()));
100 } 115 }
101 116
102 void WebBlobRegistryImpl::addBlobDataRef(const WebString& uuid) { 117 void WebBlobRegistryImpl::addBlobDataRef(const WebString& uuid) {
103 sender_->Send(new BlobHostMsg_IncrementRefCount(uuid.utf8())); 118 sender_->Send(new BlobHostMsg_IncrementRefCount(uuid.utf8()));
104 } 119 }
105 120
106 void WebBlobRegistryImpl::removeBlobDataRef(const WebString& uuid) { 121 void WebBlobRegistryImpl::removeBlobDataRef(const WebString& uuid) {
107 sender_->Send(new BlobHostMsg_DecrementRefCount(uuid.utf8())); 122 sender_->Send(new BlobHostMsg_DecrementRefCount(uuid.utf8()));
108 } 123 }
109 124
110 void WebBlobRegistryImpl::registerPublicBlobURL( 125 void WebBlobRegistryImpl::registerPublicBlobURL(
111 const WebURL& url, const WebString& uuid) { 126 const WebURL& url, const WebString& uuid) {
112 sender_->Send(new BlobHostMsg_RegisterPublicURL(url, uuid.utf8())); 127 sender_->Send(new BlobHostMsg_RegisterPublicURL(url, uuid.utf8()));
113 } 128 }
114 129
115 void WebBlobRegistryImpl::revokePublicBlobURL(const WebURL& url) { 130 void WebBlobRegistryImpl::revokePublicBlobURL(const WebURL& url) {
116 sender_->Send(new BlobHostMsg_RevokePublicURL(url)); 131 sender_->Send(new BlobHostMsg_RevokePublicURL(url));
117 } 132 }
118 133
119 void WebBlobRegistryImpl::SendDataForBlob(const std::string& uuid_str, 134 void WebBlobRegistryImpl::FlushBlobItemBuffer(
120 const WebThreadSafeData& data) { 135 const std::string& uuid_str,
136 std::vector<char>* consolidating_buffer) const {
137 DCHECK_NE(consolidating_buffer->size(), 0ul);
138 DCHECK_LT(consolidating_buffer->size(), kLargeThresholdBytes);
139 storage::BlobData::Item item;
140 item.SetToBytes(&(*consolidating_buffer)[0], consolidating_buffer->size());
141 sender_->Send(new BlobHostMsg_AppendBlobDataItem(uuid_str, item));
142 consolidating_buffer->clear();
143 }
121 144
122 if (data.size() == 0) 145 void WebBlobRegistryImpl::BufferBlobData(
123 return; 146 const std::string& uuid_str,
124 if (data.size() < kLargeThresholdBytes) { 147 const blink::WebThreadSafeData& data,
125 storage::BlobData::Item item; 148 std::vector<char>* consolidating_buffer) {
126 item.SetToBytes(data.data(), data.size()); 149 size_t buffer_size = consolidating_buffer->size();
127 sender_->Send(new BlobHostMsg_AppendBlobDataItem(uuid_str, item)); 150 size_t data_size = data.size();
151 DCHECK_NE(data_size, 0ul);
152 if (buffer_size != 0 && buffer_size + data_size >= kLargeThresholdBytes) {
153 FlushBlobItemBuffer(uuid_str, consolidating_buffer);
154 buffer_size = 0;
155 }
156 if (data_size >= kLargeThresholdBytes) {
157 SendOversizedDataForBlob(uuid_str, data);
128 } else { 158 } else {
129 // We handle larger amounts of data via SharedMemory instead of 159 DCHECK_LT(buffer_size + data_size, kLargeThresholdBytes);
130 // writing it directly to the IPC channel. 160 consolidating_buffer->insert(consolidating_buffer->end(), data.data(),
131 size_t shared_memory_size = std::min( 161 data.data() + data_size);
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 } 162 }
151 } 163 }
152 164
165 void WebBlobRegistryImpl::SendOversizedDataForBlob(
166 const std::string& uuid_str,
167 const blink::WebThreadSafeData& data) {
168 DCHECK_GE(data.size(), kLargeThresholdBytes);
169 // We handle larger amounts of data via SharedMemory instead of
170 // writing it directly to the IPC channel.
171 size_t shared_memory_size = std::min(data.size(), kMaxSharedMemoryBytes);
172 scoped_ptr<base::SharedMemory> shared_memory(
173 ChildThread::AllocateSharedMemory(shared_memory_size, sender_.get()));
174 CHECK(shared_memory.get());
175 if (!shared_memory->Map(shared_memory_size))
176 CHECK(false);
177
178 size_t data_size = data.size();
179 const char* data_ptr = data.data();
180 while (data_size) {
181 size_t chunk_size = std::min(data_size, shared_memory_size);
182 memcpy(shared_memory->memory(), data_ptr, chunk_size);
183 sender_->Send(new BlobHostMsg_SyncAppendSharedMemory(
184 uuid_str, shared_memory->handle(), chunk_size));
185 data_size -= chunk_size;
186 data_ptr += chunk_size;
187 }
188 }
189
153 // ------ streams stuff ----- 190 // ------ streams stuff -----
154 191
155 void WebBlobRegistryImpl::registerStreamURL( 192 void WebBlobRegistryImpl::registerStreamURL(
156 const WebURL& url, const WebString& content_type) { 193 const WebURL& url, const WebString& content_type) {
157 DCHECK(ChildThread::current()); 194 DCHECK(ChildThread::current());
158 sender_->Send(new StreamHostMsg_StartBuilding(url, content_type.utf8())); 195 sender_->Send(new StreamHostMsg_StartBuilding(url, content_type.utf8()));
159 } 196 }
160 197
161 void WebBlobRegistryImpl::registerStreamURL( 198 void WebBlobRegistryImpl::registerStreamURL(
162 const WebURL& url, const WebURL& src_url) { 199 const WebURL& url, const WebURL& src_url) {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 DCHECK(ChildThread::current()); 249 DCHECK(ChildThread::current());
213 sender_->Send(new StreamHostMsg_AbortBuilding(url)); 250 sender_->Send(new StreamHostMsg_AbortBuilding(url));
214 } 251 }
215 252
216 void WebBlobRegistryImpl::unregisterStreamURL(const WebURL& url) { 253 void WebBlobRegistryImpl::unregisterStreamURL(const WebURL& url) {
217 DCHECK(ChildThread::current()); 254 DCHECK(ChildThread::current());
218 sender_->Send(new StreamHostMsg_Remove(url)); 255 sender_->Send(new StreamHostMsg_Remove(url));
219 } 256 }
220 257
221 } // namespace content 258 } // namespace content
OLDNEW
« no previous file with comments | « content/child/webblobregistry_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698