OLD | NEW |
---|---|
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/scoped_ptr.h" | |
10 #include "base/memory/shared_memory.h" | 11 #include "base/memory/shared_memory.h" |
11 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
12 #include "base/trace_event/trace_event.h" | 13 #include "base/trace_event/trace_event.h" |
13 #include "content/child/child_thread_impl.h" | 14 #include "content/child/child_thread_impl.h" |
14 #include "content/child/thread_safe_sender.h" | 15 #include "content/child/thread_safe_sender.h" |
15 #include "content/common/fileapi/webblob_messages.h" | 16 #include "content/common/fileapi/webblob_messages.h" |
16 #include "third_party/WebKit/public/platform/WebBlobData.h" | 17 #include "third_party/WebKit/public/platform/WebBlobData.h" |
17 #include "third_party/WebKit/public/platform/WebString.h" | 18 #include "third_party/WebKit/public/platform/WebString.h" |
18 #include "third_party/WebKit/public/platform/WebThreadSafeData.h" | 19 #include "third_party/WebKit/public/platform/WebThreadSafeData.h" |
19 #include "third_party/WebKit/public/platform/WebURL.h" | 20 #include "third_party/WebKit/public/platform/WebURL.h" |
20 | 21 |
21 using blink::WebBlobData; | 22 using blink::WebBlobData; |
22 using blink::WebString; | 23 using blink::WebString; |
23 using blink::WebThreadSafeData; | 24 using blink::WebThreadSafeData; |
24 using blink::WebURL; | 25 using blink::WebURL; |
26 using blink::WebBlobRegistry; | |
27 using storage::DataElement; | |
25 | 28 |
26 namespace content { | 29 namespace content { |
27 | 30 |
28 namespace { | 31 namespace { |
29 | 32 |
30 const size_t kLargeThresholdBytes = 250 * 1024; | 33 const size_t kLargeThresholdBytes = 250 * 1024; |
31 const size_t kMaxSharedMemoryBytes = 10 * 1024 * 1024; | 34 const size_t kMaxSharedMemoryBytes = 10 * 1024 * 1024; |
32 | 35 |
33 } // namespace | 36 } // namespace |
34 | 37 |
35 WebBlobRegistryImpl::WebBlobRegistryImpl(ThreadSafeSender* sender) | 38 WebBlobRegistryImpl::WebBlobRegistryImpl(ThreadSafeSender* sender) |
36 : sender_(sender) { | 39 : sender_(sender) { |
37 // Record a dummy trace event on startup so the 'Storage' category shows up | 40 // Record a dummy trace event on startup so the 'Storage' category shows up |
38 // in the chrome://tracing viewer. | 41 // in the chrome://tracing viewer. |
39 TRACE_EVENT0("Blob", "Init"); | 42 TRACE_EVENT0("Blob", "Init"); |
40 } | 43 } |
41 | 44 |
42 WebBlobRegistryImpl::~WebBlobRegistryImpl() { | 45 WebBlobRegistryImpl::~WebBlobRegistryImpl() {} |
46 | |
47 blink::WebBlobRegistry::Builder* WebBlobRegistryImpl::createBuilder( | |
48 const blink::WebString& uuid, const blink::WebString& contentType) { | |
49 return new BuilderImpl(uuid, contentType, sender_.get()); | |
43 } | 50 } |
44 | 51 |
45 void WebBlobRegistryImpl::registerBlobData( | 52 void WebBlobRegistryImpl::registerBlobData(const blink::WebString& uuid, |
46 const blink::WebString& uuid, const blink::WebBlobData& data) { | 53 const blink::WebBlobData& data) { |
47 TRACE_EVENT0("Blob", "Registry::RegisterBlob"); | 54 TRACE_EVENT0("Blob", "Registry::RegisterBlob"); |
48 const std::string uuid_str(uuid.utf8()); | 55 scoped_ptr<Builder> builder(createBuilder(uuid, data.contentType())); |
49 | 56 |
50 storage::DataElement data_buffer; | 57 // This is temporary until we move to createBuilder() as our blob creation |
51 data_buffer.SetToEmptyBytes(); | 58 // method. |
52 | |
53 sender_->Send(new BlobHostMsg_StartBuilding(uuid_str)); | |
54 size_t i = 0; | 59 size_t i = 0; |
55 WebBlobData::Item data_item; | 60 WebBlobData::Item data_item; |
56 while (data.itemAt(i++, data_item)) { | 61 while (data.itemAt(i++, data_item)) { |
57 // NOTE: data_item.length == -1 when we want to use the whole file. This | |
58 // only happens when we are creating a file object in Blink, and the file | |
59 // object is the only item in the 'blob'. If we use that file blob to | |
60 // create another blob, it is sent here as a 'file' item and not a blob, | |
61 // and the correct size is populated. | |
62 // static_cast<uint64>(-1) == kuint64max, which is what DataElement uses | |
63 // to specificy "use the whole file". | |
64 if (data_item.length == 0) { | |
michaeln
2015/06/17 03:17:55
This filter for blink giving us empty items got lo
dmurph
2015/06/17 18:29:51
Done. I added this check in the append methods in
| |
65 continue; | |
66 } | |
67 if (data_item.type != WebBlobData::Item::TypeData && | |
68 data_buffer.length() != 0) { | |
69 FlushBlobItemBuffer(uuid_str, &data_buffer); | |
70 } | |
71 storage::DataElement item; | |
72 switch (data_item.type) { | 62 switch (data_item.type) { |
73 case WebBlobData::Item::TypeData: { | 63 case WebBlobData::Item::TypeData: { |
74 // WebBlobData does not allow partial data items. | 64 // WebBlobData does not allow partial data items. |
75 DCHECK(!data_item.offset && data_item.length == -1); | 65 DCHECK(!data_item.offset && data_item.length == -1); |
76 if (data_item.data.size() == 0) { | 66 builder->appendData(data_item.data); |
77 continue; | |
78 } | |
79 BufferBlobData(uuid_str, data_item.data, &data_buffer); | |
80 break; | 67 break; |
81 } | 68 } |
82 case WebBlobData::Item::TypeFile: | 69 case WebBlobData::Item::TypeFile: |
83 item.SetToFilePathRange( | 70 builder->appendFile(data_item.filePath, |
84 base::FilePath::FromUTF16Unsafe(data_item.filePath), | 71 static_cast<uint64_t>(data_item.offset), |
85 static_cast<uint64>(data_item.offset), | 72 static_cast<uint64_t>(data_item.length), |
86 static_cast<uint64>(data_item.length), | 73 data_item.expectedModificationTime); |
87 base::Time::FromDoubleT(data_item.expectedModificationTime)); | |
88 sender_->Send(new BlobHostMsg_AppendBlobDataItem(uuid_str, item)); | |
89 break; | 74 break; |
90 case WebBlobData::Item::TypeBlob: | 75 case WebBlobData::Item::TypeBlob: |
91 item.SetToBlobRange( | 76 builder->appendBlob(data_item.blobUUID, data_item.offset, |
92 data_item.blobUUID.utf8(), | 77 data_item.length); |
93 static_cast<uint64>(data_item.offset), | |
94 static_cast<uint64>(data_item.length)); | |
95 sender_->Send( | |
96 new BlobHostMsg_AppendBlobDataItem(uuid_str, item)); | |
97 break; | 78 break; |
98 case WebBlobData::Item::TypeFileSystemURL: | 79 case WebBlobData::Item::TypeFileSystemURL: |
99 // We only support filesystem URL as of now. | 80 // We only support filesystem URL as of now. |
100 DCHECK(GURL(data_item.fileSystemURL).SchemeIsFileSystem()); | 81 DCHECK(GURL(data_item.fileSystemURL).SchemeIsFileSystem()); |
101 item.SetToFileSystemUrlRange( | 82 builder->appendFileSystemURL(data_item.fileSystemURL, |
102 data_item.fileSystemURL, | 83 static_cast<uint64>(data_item.offset), |
103 static_cast<uint64>(data_item.offset), | 84 static_cast<uint64>(data_item.length), |
104 static_cast<uint64>(data_item.length), | 85 data_item.expectedModificationTime); |
105 base::Time::FromDoubleT(data_item.expectedModificationTime)); | |
106 sender_->Send( | |
107 new BlobHostMsg_AppendBlobDataItem(uuid_str, item)); | |
108 break; | 86 break; |
109 default: | 87 default: |
110 NOTREACHED(); | 88 NOTREACHED(); |
111 } | 89 } |
112 } | 90 } |
113 if (data_buffer.length() != 0) { | 91 builder->build(); |
114 FlushBlobItemBuffer(uuid_str, &data_buffer); | |
115 } | |
116 sender_->Send(new BlobHostMsg_FinishBuilding( | |
117 uuid_str, data.contentType().utf8().data())); | |
118 } | 92 } |
119 | 93 |
120 void WebBlobRegistryImpl::addBlobDataRef(const WebString& uuid) { | 94 void WebBlobRegistryImpl::addBlobDataRef(const WebString& uuid) { |
121 sender_->Send(new BlobHostMsg_IncrementRefCount(uuid.utf8())); | 95 sender_->Send(new BlobHostMsg_IncrementRefCount(uuid.utf8())); |
122 } | 96 } |
123 | 97 |
124 void WebBlobRegistryImpl::removeBlobDataRef(const WebString& uuid) { | 98 void WebBlobRegistryImpl::removeBlobDataRef(const WebString& uuid) { |
125 sender_->Send(new BlobHostMsg_DecrementRefCount(uuid.utf8())); | 99 sender_->Send(new BlobHostMsg_DecrementRefCount(uuid.utf8())); |
126 } | 100 } |
127 | 101 |
128 void WebBlobRegistryImpl::registerPublicBlobURL( | 102 void WebBlobRegistryImpl::registerPublicBlobURL(const WebURL& url, |
129 const WebURL& url, const WebString& uuid) { | 103 const WebString& uuid) { |
130 sender_->Send(new BlobHostMsg_RegisterPublicURL(url, uuid.utf8())); | 104 sender_->Send(new BlobHostMsg_RegisterPublicURL(url, uuid.utf8())); |
131 } | 105 } |
132 | 106 |
133 void WebBlobRegistryImpl::revokePublicBlobURL(const WebURL& url) { | 107 void WebBlobRegistryImpl::revokePublicBlobURL(const WebURL& url) { |
134 sender_->Send(new BlobHostMsg_RevokePublicURL(url)); | 108 sender_->Send(new BlobHostMsg_RevokePublicURL(url)); |
135 } | 109 } |
136 | 110 |
137 void WebBlobRegistryImpl::FlushBlobItemBuffer( | |
138 const std::string& uuid_str, | |
139 storage::DataElement* data_buffer) const { | |
140 DCHECK_NE(data_buffer->length(), 0ul); | |
141 DCHECK_LT(data_buffer->length(), kLargeThresholdBytes); | |
142 sender_->Send(new BlobHostMsg_AppendBlobDataItem(uuid_str, *data_buffer)); | |
143 data_buffer->SetToEmptyBytes(); | |
144 } | |
145 | |
146 void WebBlobRegistryImpl::BufferBlobData(const std::string& uuid_str, | |
147 const blink::WebThreadSafeData& data, | |
148 storage::DataElement* data_buffer) { | |
149 size_t buffer_size = data_buffer->length(); | |
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, data_buffer); | |
154 buffer_size = 0; | |
155 } | |
156 if (data_size >= kLargeThresholdBytes) { | |
157 TRACE_EVENT0("Blob", "Registry::SendOversizedBlobData"); | |
158 SendOversizedDataForBlob(uuid_str, data); | |
159 } else { | |
160 DCHECK_LT(buffer_size + data_size, kLargeThresholdBytes); | |
161 data_buffer->AppendBytes(data.data(), data_size); | |
162 } | |
163 } | |
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 ChildThreadImpl::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 TRACE_EVENT0("Blob", "Registry::SendOversizedBlobItem"); | |
182 size_t chunk_size = std::min(data_size, shared_memory_size); | |
183 memcpy(shared_memory->memory(), data_ptr, chunk_size); | |
184 sender_->Send(new BlobHostMsg_SyncAppendSharedMemory( | |
185 uuid_str, shared_memory->handle(), chunk_size)); | |
186 data_size -= chunk_size; | |
187 data_ptr += chunk_size; | |
188 } | |
189 } | |
190 | |
191 // ------ streams stuff ----- | 111 // ------ streams stuff ----- |
192 | 112 |
193 void WebBlobRegistryImpl::registerStreamURL( | 113 void WebBlobRegistryImpl::registerStreamURL(const WebURL& url, |
194 const WebURL& url, const WebString& content_type) { | 114 const WebString& content_type) { |
195 DCHECK(ChildThreadImpl::current()); | 115 DCHECK(ChildThreadImpl::current()); |
196 sender_->Send(new StreamHostMsg_StartBuilding(url, content_type.utf8())); | 116 sender_->Send(new StreamHostMsg_StartBuilding(url, content_type.utf8())); |
197 } | 117 } |
198 | 118 |
199 void WebBlobRegistryImpl::registerStreamURL( | 119 void WebBlobRegistryImpl::registerStreamURL(const WebURL& url, |
200 const WebURL& url, const WebURL& src_url) { | 120 const WebURL& src_url) { |
201 DCHECK(ChildThreadImpl::current()); | 121 DCHECK(ChildThreadImpl::current()); |
202 sender_->Send(new StreamHostMsg_Clone(url, src_url)); | 122 sender_->Send(new StreamHostMsg_Clone(url, src_url)); |
203 } | 123 } |
204 | 124 |
205 void WebBlobRegistryImpl::addDataToStream(const WebURL& url, | 125 void WebBlobRegistryImpl::addDataToStream(const WebURL& url, const char* data, |
206 const char* data, size_t length) { | 126 size_t length) { |
207 DCHECK(ChildThreadImpl::current()); | 127 DCHECK(ChildThreadImpl::current()); |
208 if (length == 0) | 128 if (length == 0) return; |
209 return; | |
210 if (length < kLargeThresholdBytes) { | 129 if (length < kLargeThresholdBytes) { |
211 storage::DataElement item; | 130 DataElement item; |
212 item.SetToBytes(data, length); | 131 item.SetToBytes(data, length); |
213 sender_->Send(new StreamHostMsg_AppendBlobDataItem(url, item)); | 132 sender_->Send(new StreamHostMsg_AppendBlobDataItem(url, item)); |
214 } else { | 133 } else { |
215 // We handle larger amounts of data via SharedMemory instead of | 134 // We handle larger amounts of data via SharedMemory instead of |
216 // writing it directly to the IPC channel. | 135 // writing it directly to the IPC channel. |
217 size_t shared_memory_size = std::min( | 136 size_t shared_memory_size = std::min(length, kMaxSharedMemoryBytes); |
218 length, kMaxSharedMemoryBytes); | |
219 scoped_ptr<base::SharedMemory> shared_memory( | 137 scoped_ptr<base::SharedMemory> shared_memory( |
220 ChildThreadImpl::AllocateSharedMemory(shared_memory_size, | 138 ChildThreadImpl::AllocateSharedMemory(shared_memory_size, |
221 sender_.get())); | 139 sender_.get())); |
222 CHECK(shared_memory.get()); | 140 CHECK(shared_memory.get()); |
223 if (!shared_memory->Map(shared_memory_size)) | 141 if (!shared_memory->Map(shared_memory_size)) CHECK(false); |
224 CHECK(false); | |
225 | 142 |
226 size_t remaining_bytes = length; | 143 size_t remaining_bytes = length; |
227 const char* current_ptr = data; | 144 const char* current_ptr = data; |
228 while (remaining_bytes) { | 145 while (remaining_bytes) { |
229 size_t chunk_size = std::min(remaining_bytes, shared_memory_size); | 146 size_t chunk_size = std::min(remaining_bytes, shared_memory_size); |
230 memcpy(shared_memory->memory(), current_ptr, chunk_size); | 147 memcpy(shared_memory->memory(), current_ptr, chunk_size); |
231 sender_->Send(new StreamHostMsg_SyncAppendSharedMemory( | 148 sender_->Send(new StreamHostMsg_SyncAppendSharedMemory( |
232 url, shared_memory->handle(), chunk_size)); | 149 url, shared_memory->handle(), chunk_size)); |
233 remaining_bytes -= chunk_size; | 150 remaining_bytes -= chunk_size; |
234 current_ptr += chunk_size; | 151 current_ptr += chunk_size; |
(...skipping 14 matching lines...) Expand all Loading... | |
249 void WebBlobRegistryImpl::abortStream(const WebURL& url) { | 166 void WebBlobRegistryImpl::abortStream(const WebURL& url) { |
250 DCHECK(ChildThreadImpl::current()); | 167 DCHECK(ChildThreadImpl::current()); |
251 sender_->Send(new StreamHostMsg_AbortBuilding(url)); | 168 sender_->Send(new StreamHostMsg_AbortBuilding(url)); |
252 } | 169 } |
253 | 170 |
254 void WebBlobRegistryImpl::unregisterStreamURL(const WebURL& url) { | 171 void WebBlobRegistryImpl::unregisterStreamURL(const WebURL& url) { |
255 DCHECK(ChildThreadImpl::current()); | 172 DCHECK(ChildThreadImpl::current()); |
256 sender_->Send(new StreamHostMsg_Remove(url)); | 173 sender_->Send(new StreamHostMsg_Remove(url)); |
257 } | 174 } |
258 | 175 |
176 WebBlobRegistryImpl::BuilderImpl::BuilderImpl( | |
177 const blink::WebString& uuid, const blink::WebString& contentType, | |
178 ThreadSafeSender* sender) | |
179 : uuid_(uuid.utf8()), content_type_(contentType.utf8()), sender_(sender) { | |
180 } | |
181 | |
182 WebBlobRegistryImpl::BuilderImpl::~BuilderImpl() {} | |
183 | |
184 void WebBlobRegistryImpl::BuilderImpl::appendData( | |
185 const WebThreadSafeData& data) { | |
186 consolidation_.AddDataItem(data); | |
187 } | |
188 | |
189 void WebBlobRegistryImpl::BuilderImpl::appendBlob(const WebString& uuid, | |
190 uint64_t offset, | |
191 uint64_t length) { | |
192 consolidation_.AddBlobItem(uuid, offset, length); | |
193 } | |
194 | |
195 void WebBlobRegistryImpl::BuilderImpl::appendFile( | |
196 const WebString& path, uint64_t offset, uint64_t length, | |
197 double expectedModificationTime) { | |
198 consolidation_.AddFileItem(path, offset, length, expectedModificationTime); | |
199 } | |
200 | |
201 void WebBlobRegistryImpl::BuilderImpl::appendFileSystemURL( | |
202 const WebURL& fileSystemURL, uint64_t offset, uint64_t length, | |
203 double expectedModificationTime) { | |
204 consolidation_.AddFileSystemItem(fileSystemURL, offset, length, | |
205 expectedModificationTime); | |
206 // NOTE: length == -1 when we want to use the whole file. This | |
207 // only happens when we are creating a file object in Blink, and the file | |
208 // object is the only item in the 'blob'. If we use that file blob to | |
209 // create another blob, it is sent here as a 'file' item and not a blob, | |
210 // and the correct size is populated. | |
211 // static_cast<uint64>(-1) == kuint64max, which is what DataElement uses | |
212 // to specificy "use the whole file". | |
213 storage::DataElement item; | |
214 DCHECK(GURL(fileSystemURL).SchemeIsFileSystem()); | |
215 item.SetToFileSystemUrlRange( | |
216 GURL(fileSystemURL), static_cast<uint64>(offset), | |
217 static_cast<uint64>(length), | |
218 base::Time::FromDoubleT(expectedModificationTime)); | |
219 sender_->Send(new BlobHostMsg_AppendBlobDataItem(uuid_, item)); | |
michaeln
2015/06/17 03:17:55
This message being sent looks out of place as does
dmurph
2015/06/17 18:29:51
Whoops, you're right, thanks.
| |
220 } | |
221 | |
222 void WebBlobRegistryImpl::BuilderImpl::build() { | |
223 sender_->Send(new BlobHostMsg_StartBuilding(uuid_)); | |
224 const auto& items = consolidation_.consolidated_items(); | |
225 | |
226 // We still need a buffer to hold the continuous block of data so the | |
227 // DataElement can hold it. | |
228 size_t buffer_size = 0; | |
229 scoped_ptr<char> buffer; | |
230 for (size_t i = 0; i < items.size(); i++) { | |
231 const BlobConsolidation::ConsolidatedItem& item = items[i]; | |
232 DataElement element; | |
233 // NOTE: length == -1 when we want to use the whole file. This | |
234 // only happens when we are creating a file object in Blink, and the file | |
235 // object is the only item in the 'blob'. If we use that file blob to | |
236 // create another blob, it is sent here as a 'file' item and not a blob, | |
237 // and the correct size is populated. | |
238 // static_cast<uint64>(-1) == kuint64max, which is what DataElement uses | |
239 // to specificy "use the whole file". | |
240 switch (item.type) { | |
241 case DataElement::TYPE_BYTES: | |
242 if (item.length > kLargeThresholdBytes) { | |
243 SendOversizedDataForBlob(i); | |
244 break; | |
245 } | |
246 if (buffer_size < item.length) { | |
247 buffer.reset(new char[item.length]); | |
248 buffer_size = item.length; | |
249 } | |
250 consolidation_.ReadMemory(i, 0, item.length, buffer.get()); | |
251 element.SetToSharedBytes(buffer.get(), item.length); | |
252 sender_->Send(new BlobHostMsg_AppendBlobDataItem(uuid_, element)); | |
253 break; | |
254 case DataElement::TYPE_FILE: | |
255 element.SetToFilePathRange( | |
256 base::FilePath::FromUTF16Unsafe(base::string16(item.path)), | |
257 static_cast<uint64>(item.offset), static_cast<uint64>(item.length), | |
258 base::Time::FromDoubleT(item.expected_modification_time)); | |
259 sender_->Send(new BlobHostMsg_AppendBlobDataItem(uuid_, element)); | |
260 break; | |
261 case DataElement::TYPE_BLOB: | |
262 element.SetToBlobRange(item.blob_uuid.utf8(), | |
263 static_cast<uint64>(item.offset), | |
264 static_cast<uint64>(item.length)); | |
265 sender_->Send(new BlobHostMsg_AppendBlobDataItem(uuid_, element)); | |
266 break; | |
267 case DataElement::TYPE_FILE_FILESYSTEM: | |
268 DCHECK(GURL(item.filesystem_url).SchemeIsFileSystem()); | |
269 element.SetToFileSystemUrlRange( | |
270 GURL(item.filesystem_url), static_cast<uint64>(item.offset), | |
271 static_cast<uint64>(item.length), | |
272 base::Time::FromDoubleT(item.expected_modification_time)); | |
273 sender_->Send(new BlobHostMsg_AppendBlobDataItem(uuid_, element)); | |
274 break; | |
275 default: | |
276 NOTREACHED(); | |
277 } | |
278 } | |
279 sender_->Send(new BlobHostMsg_FinishBuilding(uuid_, content_type_)); | |
280 } | |
281 | |
282 void WebBlobRegistryImpl::BuilderImpl::SendOversizedDataForBlob( | |
283 size_t consolidated_item_index) { | |
284 TRACE_EVENT0("Blob", "Registry::SendOversizedBlobData"); | |
285 const BlobConsolidation::ConsolidatedItem& item = | |
286 consolidation_.consolidated_items()[consolidated_item_index]; | |
287 // We handle larger amounts of data via SharedMemory instead of | |
288 // writing it directly to the IPC channel. | |
289 | |
290 size_t data_size = item.length; | |
291 size_t shared_memory_size = std::min(item.length, kMaxSharedMemoryBytes); | |
292 scoped_ptr<base::SharedMemory> shared_memory( | |
293 ChildThreadImpl::AllocateSharedMemory(shared_memory_size, sender_.get())); | |
294 CHECK(shared_memory.get()); | |
295 if (!shared_memory->Map(shared_memory_size)) CHECK(false); | |
296 | |
297 size_t offset = 0; | |
298 while (data_size) { | |
299 TRACE_EVENT0("Blob", "Registry::SendOversizedBlobItem"); | |
300 size_t chunk_size = std::min(data_size, shared_memory_size); | |
301 consolidation_.ReadMemory(consolidated_item_index, offset, chunk_size, | |
302 static_cast<char*>(shared_memory->memory())); | |
303 sender_->Send(new BlobHostMsg_SyncAppendSharedMemory( | |
304 uuid_, shared_memory->handle(), chunk_size)); | |
305 data_size -= chunk_size; | |
306 offset += chunk_size; | |
307 } | |
308 } | |
309 | |
259 } // namespace content | 310 } // namespace content |
OLD | NEW |