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

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: fix for clearing buffer 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> buf_;
michaeln 2015/01/21 02:16:48 nit: nix trailing underbar
dmurph 2015/01/21 23:57:42 Done.
47 buf_.reserve(kLargeThresholdBytes);
48 size_t consolidating_items_size_bytes;
michaeln 2015/01/21 02:16:48 do we need this local? what about buf.size()?
dmurph 2015/01/21 23:57:42 Ah, I was getting confused with arrays and vectors
49
46 sender_->Send(new BlobHostMsg_StartBuilding(uuid_str)); 50 sender_->Send(new BlobHostMsg_StartBuilding(uuid_str));
47 size_t i = 0; 51 size_t i = 0;
48 WebBlobData::Item data_item; 52 WebBlobData::Item data_item;
49 while (data.itemAt(i++, data_item)) { 53 while (data.itemAt(i++, data_item)) {
michaeln 2015/01/21 02:16:48 in each case below, you could avoid flushing the b
dmurph 2015/01/21 23:57:42 Done.
54 if (data_item.type != WebBlobData::Item::TypeData &&
55 consolidating_items_size_bytes != 0) {
56 SendAndClearConsolidatingBuffer(uuid_str, &buf_,
57 &consolidating_items_size_bytes);
58 }
50 switch (data_item.type) { 59 switch (data_item.type) {
51 case WebBlobData::Item::TypeData: { 60 case WebBlobData::Item::TypeData: {
52 // WebBlobData does not allow partial data items. 61 // WebBlobData does not allow partial data items.
53 DCHECK(!data_item.offset && data_item.length == -1); 62 DCHECK(!data_item.offset && data_item.length == -1);
54 SendDataForBlob(uuid_str, data_item.data); 63 if (consolidating_items_size_bytes + data_item.length >=
michaeln 2015/01/21 02:16:47 might be nice to bury the new buffering logic insi
64 kLargeThresholdBytes) {
65 SendAndClearConsolidatingBuffer(uuid_str, &buf_,
michaeln 2015/01/21 02:16:48 i think this can get called even if consolidating_
dmurph 2015/01/21 23:57:42 Done.
66 &consolidating_items_size_bytes);
67 }
68 if (data_item.length >= static_cast<long long>(kLargeThresholdBytes)) {
69 SendOversizedDataForBlob(uuid_str, data_item.data);
70 } else {
71 AddItemToBuffer(data_item.data, &buf_,
72 &consolidating_items_size_bytes);
73 }
55 break; 74 break;
56 } 75 }
57 case WebBlobData::Item::TypeFile: 76 case WebBlobData::Item::TypeFile:
58 if (data_item.length) { 77 if (data_item.length) {
59 storage::BlobData::Item item; 78 storage::BlobData::Item item;
60 item.SetToFilePathRange( 79 item.SetToFilePathRange(
61 base::FilePath::FromUTF16Unsafe(data_item.filePath), 80 base::FilePath::FromUTF16Unsafe(data_item.filePath),
62 static_cast<uint64>(data_item.offset), 81 static_cast<uint64>(data_item.offset),
63 static_cast<uint64>(data_item.length), 82 static_cast<uint64>(data_item.length),
64 base::Time::FromDoubleT(data_item.expectedModificationTime)); 83 base::Time::FromDoubleT(data_item.expectedModificationTime));
(...skipping 23 matching lines...) Expand all
88 static_cast<uint64>(data_item.length), 107 static_cast<uint64>(data_item.length),
89 base::Time::FromDoubleT(data_item.expectedModificationTime)); 108 base::Time::FromDoubleT(data_item.expectedModificationTime));
90 sender_->Send( 109 sender_->Send(
91 new BlobHostMsg_AppendBlobDataItem(uuid_str, item)); 110 new BlobHostMsg_AppendBlobDataItem(uuid_str, item));
92 } 111 }
93 break; 112 break;
94 default: 113 default:
95 NOTREACHED(); 114 NOTREACHED();
96 } 115 }
97 } 116 }
117 if (consolidating_items_size_bytes != 0) {
118 SendAndClearConsolidatingBuffer(uuid_str, &buf_,
119 &consolidating_items_size_bytes);
120 }
98 sender_->Send(new BlobHostMsg_FinishBuilding( 121 sender_->Send(new BlobHostMsg_FinishBuilding(
99 uuid_str, data.contentType().utf8().data())); 122 uuid_str, data.contentType().utf8().data()));
100 } 123 }
101 124
102 void WebBlobRegistryImpl::addBlobDataRef(const WebString& uuid) { 125 void WebBlobRegistryImpl::addBlobDataRef(const WebString& uuid) {
103 sender_->Send(new BlobHostMsg_IncrementRefCount(uuid.utf8())); 126 sender_->Send(new BlobHostMsg_IncrementRefCount(uuid.utf8()));
104 } 127 }
105 128
106 void WebBlobRegistryImpl::removeBlobDataRef(const WebString& uuid) { 129 void WebBlobRegistryImpl::removeBlobDataRef(const WebString& uuid) {
107 sender_->Send(new BlobHostMsg_DecrementRefCount(uuid.utf8())); 130 sender_->Send(new BlobHostMsg_DecrementRefCount(uuid.utf8()));
108 } 131 }
109 132
110 void WebBlobRegistryImpl::registerPublicBlobURL( 133 void WebBlobRegistryImpl::registerPublicBlobURL(
111 const WebURL& url, const WebString& uuid) { 134 const WebURL& url, const WebString& uuid) {
112 sender_->Send(new BlobHostMsg_RegisterPublicURL(url, uuid.utf8())); 135 sender_->Send(new BlobHostMsg_RegisterPublicURL(url, uuid.utf8()));
113 } 136 }
114 137
115 void WebBlobRegistryImpl::revokePublicBlobURL(const WebURL& url) { 138 void WebBlobRegistryImpl::revokePublicBlobURL(const WebURL& url) {
116 sender_->Send(new BlobHostMsg_RevokePublicURL(url)); 139 sender_->Send(new BlobHostMsg_RevokePublicURL(url));
117 } 140 }
118 141
119 void WebBlobRegistryImpl::SendDataForBlob(const std::string& uuid_str, 142 void WebBlobRegistryImpl::SendAndClearConsolidatingBuffer(
michaeln 2015/01/21 02:16:47 having a test for if (buffer->size()) return in he
dmurph 2015/01/21 23:57:42 Done.
120 const WebThreadSafeData& data) { 143 const std::string& uuid_str,
144 std::vector<char>* consolidating_buffer,
145 size_t* consolidating_items_size_bytes) const {
146 DCHECK_NE(*consolidating_items_size_bytes, 0ul);
147 DCHECK_LT(*consolidating_items_size_bytes, kLargeThresholdBytes);
148 storage::BlobData::Item item;
149 item.SetToBytes(consolidating_buffer->data(),
150 *consolidating_items_size_bytes);
151 sender_->Send(new BlobHostMsg_AppendBlobDataItem(uuid_str, item));
152 *consolidating_items_size_bytes = 0;
153 consolidating_buffer->clear();
154 }
121 155
122 if (data.size() == 0) 156 void WebBlobRegistryImpl::AddItemToBuffer(
157 const blink::WebThreadSafeData& data,
158 std::vector<char>* consolidating_buffer,
159 size_t* consolidating_items_size_bytes) const {
160 if (data.size() == 0) {
123 return; 161 return;
124 if (data.size() < kLargeThresholdBytes) { 162 }
125 storage::BlobData::Item item; 163 DCHECK_LT(*consolidating_items_size_bytes + data.size(),
126 item.SetToBytes(data.data(), data.size()); 164 kLargeThresholdBytes);
127 sender_->Send(new BlobHostMsg_AppendBlobDataItem(uuid_str, item)); 165 consolidating_buffer->insert(consolidating_buffer->end(), data.data(),
128 } else { 166 data.data() + data.size());
129 // We handle larger amounts of data via SharedMemory instead of 167 *consolidating_items_size_bytes += data.size();
130 // writing it directly to the IPC channel. 168 }
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 169
140 size_t data_size = data.size(); 170 void WebBlobRegistryImpl::SendOversizedDataForBlob(
141 const char* data_ptr = data.data(); 171 const std::string& uuid_str,
142 while (data_size) { 172 const WebThreadSafeData& data) {
143 size_t chunk_size = std::min(data_size, shared_memory_size); 173 DCHECK_GE(data.size(), kLargeThresholdBytes);
144 memcpy(shared_memory->memory(), data_ptr, chunk_size); 174 // We handle larger amounts of data via SharedMemory instead of
145 sender_->Send(new BlobHostMsg_SyncAppendSharedMemory( 175 // writing it directly to the IPC channel.
146 uuid_str, shared_memory->handle(), chunk_size)); 176 size_t shared_memory_size = std::min(data.size(), kMaxSharedMemoryBytes);
147 data_size -= chunk_size; 177 scoped_ptr<base::SharedMemory> shared_memory(
148 data_ptr += chunk_size; 178 ChildThread::AllocateSharedMemory(shared_memory_size, sender_.get()));
149 } 179 CHECK(shared_memory.get());
180 if (!shared_memory->Map(shared_memory_size))
181 CHECK(false);
182
183 size_t data_size = data.size();
184 const char* data_ptr = data.data();
185 while (data_size) {
186 size_t chunk_size = std::min(data_size, shared_memory_size);
187 memcpy(shared_memory->memory(), data_ptr, chunk_size);
188 sender_->Send(new BlobHostMsg_SyncAppendSharedMemory(
189 uuid_str, shared_memory->handle(), chunk_size));
190 data_size -= chunk_size;
191 data_ptr += chunk_size;
150 } 192 }
151 } 193 }
152 194
153 // ------ streams stuff ----- 195 // ------ streams stuff -----
154 196
155 void WebBlobRegistryImpl::registerStreamURL( 197 void WebBlobRegistryImpl::registerStreamURL(
156 const WebURL& url, const WebString& content_type) { 198 const WebURL& url, const WebString& content_type) {
157 DCHECK(ChildThread::current()); 199 DCHECK(ChildThread::current());
158 sender_->Send(new StreamHostMsg_StartBuilding(url, content_type.utf8())); 200 sender_->Send(new StreamHostMsg_StartBuilding(url, content_type.utf8()));
159 } 201 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 DCHECK(ChildThread::current()); 254 DCHECK(ChildThread::current());
213 sender_->Send(new StreamHostMsg_AbortBuilding(url)); 255 sender_->Send(new StreamHostMsg_AbortBuilding(url));
214 } 256 }
215 257
216 void WebBlobRegistryImpl::unregisterStreamURL(const WebURL& url) { 258 void WebBlobRegistryImpl::unregisterStreamURL(const WebURL& url) {
217 DCHECK(ChildThread::current()); 259 DCHECK(ChildThread::current());
218 sender_->Send(new StreamHostMsg_Remove(url)); 260 sender_->Send(new StreamHostMsg_Remove(url));
219 } 261 }
220 262
221 } // namespace content 263 } // 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