Chromium Code Reviews| 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/shared_memory.h" | 10 #include "base/memory/shared_memory.h" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/trace_event/trace_event.h" | |
| 12 #include "content/child/child_thread_impl.h" | 13 #include "content/child/child_thread_impl.h" |
| 13 #include "content/child/thread_safe_sender.h" | 14 #include "content/child/thread_safe_sender.h" |
| 14 #include "content/common/fileapi/webblob_messages.h" | 15 #include "content/common/fileapi/webblob_messages.h" |
| 15 #include "storage/common/data_element.h" | |
| 16 #include "third_party/WebKit/public/platform/WebBlobData.h" | 16 #include "third_party/WebKit/public/platform/WebBlobData.h" |
| 17 #include "third_party/WebKit/public/platform/WebString.h" | 17 #include "third_party/WebKit/public/platform/WebString.h" |
| 18 #include "third_party/WebKit/public/platform/WebThreadSafeData.h" | 18 #include "third_party/WebKit/public/platform/WebThreadSafeData.h" |
| 19 #include "third_party/WebKit/public/platform/WebURL.h" | 19 #include "third_party/WebKit/public/platform/WebURL.h" |
| 20 | 20 |
| 21 using blink::WebBlobData; | 21 using blink::WebBlobData; |
| 22 using blink::WebString; | 22 using blink::WebString; |
| 23 using blink::WebThreadSafeData; | 23 using blink::WebThreadSafeData; |
| 24 using blink::WebURL; | 24 using blink::WebURL; |
| 25 | 25 |
| 26 namespace content { | 26 namespace content { |
| 27 | 27 |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 const size_t kLargeThresholdBytes = 250 * 1024; | 30 const size_t kLargeThresholdBytes = 250 * 1024; |
| 31 const size_t kMaxSharedMemoryBytes = 10 * 1024 * 1024; | 31 const size_t kMaxSharedMemoryBytes = 10 * 1024 * 1024; |
| 32 | 32 |
| 33 } // namespace | 33 } // namespace |
| 34 | 34 |
| 35 WebBlobRegistryImpl::WebBlobRegistryImpl(ThreadSafeSender* sender) | 35 WebBlobRegistryImpl::WebBlobRegistryImpl(ThreadSafeSender* sender) |
| 36 : sender_(sender) { | 36 : sender_(sender) { |
| 37 // Record a dummy trace event on startup so the 'Storage' category shows up | |
| 38 // in the chrome://tracing viewer. | |
|
michaeln
2015/03/10 21:04:05
got it, thnx for the comment
| |
| 39 TRACE_EVENT0("Storage.Blob", "Init"); | |
| 37 } | 40 } |
| 38 | 41 |
| 39 WebBlobRegistryImpl::~WebBlobRegistryImpl() { | 42 WebBlobRegistryImpl::~WebBlobRegistryImpl() { |
| 40 } | 43 } |
| 41 | 44 |
| 42 void WebBlobRegistryImpl::registerBlobData( | 45 void WebBlobRegistryImpl::registerBlobData( |
| 43 const blink::WebString& uuid, const blink::WebBlobData& data) { | 46 const blink::WebString& uuid, const blink::WebBlobData& data) { |
| 47 TRACE_EVENT0("Storage.Blob", "RegisterBlobData"); | |
| 44 const std::string uuid_str(uuid.utf8()); | 48 const std::string uuid_str(uuid.utf8()); |
| 45 | 49 |
| 46 storage::DataElement data_buffer; | 50 storage::DataElement data_buffer; |
| 47 data_buffer.SetToEmptyBytes(); | 51 data_buffer.SetToEmptyBytes(); |
| 48 | 52 |
| 49 sender_->Send(new BlobHostMsg_StartBuilding(uuid_str)); | 53 sender_->Send(new BlobHostMsg_StartBuilding(uuid_str)); |
| 50 size_t i = 0; | 54 size_t i = 0; |
| 51 WebBlobData::Item data_item; | 55 WebBlobData::Item data_item; |
| 52 while (data.itemAt(i++, data_item)) { | 56 while (data.itemAt(i++, data_item)) { |
| 53 // NOTE: data_item.length == -1 when we want to use the whole file. This | 57 // NOTE: data_item.length == -1 when we want to use the whole file. This |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 143 const blink::WebThreadSafeData& data, | 147 const blink::WebThreadSafeData& data, |
| 144 storage::DataElement* data_buffer) { | 148 storage::DataElement* data_buffer) { |
| 145 size_t buffer_size = data_buffer->length(); | 149 size_t buffer_size = data_buffer->length(); |
| 146 size_t data_size = data.size(); | 150 size_t data_size = data.size(); |
| 147 DCHECK_NE(data_size, 0ul); | 151 DCHECK_NE(data_size, 0ul); |
| 148 if (buffer_size != 0 && buffer_size + data_size >= kLargeThresholdBytes) { | 152 if (buffer_size != 0 && buffer_size + data_size >= kLargeThresholdBytes) { |
| 149 FlushBlobItemBuffer(uuid_str, data_buffer); | 153 FlushBlobItemBuffer(uuid_str, data_buffer); |
| 150 buffer_size = 0; | 154 buffer_size = 0; |
| 151 } | 155 } |
| 152 if (data_size >= kLargeThresholdBytes) { | 156 if (data_size >= kLargeThresholdBytes) { |
| 157 TRACE_EVENT0("Storage.Blob", "SendOversizedBlobData"); | |
| 153 SendOversizedDataForBlob(uuid_str, data); | 158 SendOversizedDataForBlob(uuid_str, data); |
| 154 } else { | 159 } else { |
| 155 DCHECK_LT(buffer_size + data_size, kLargeThresholdBytes); | 160 DCHECK_LT(buffer_size + data_size, kLargeThresholdBytes); |
| 156 data_buffer->AppendBytes(data.data(), data_size); | 161 data_buffer->AppendBytes(data.data(), data_size); |
| 157 } | 162 } |
| 158 } | 163 } |
| 159 | 164 |
| 160 void WebBlobRegistryImpl::SendOversizedDataForBlob( | 165 void WebBlobRegistryImpl::SendOversizedDataForBlob( |
|
michaeln
2015/03/10 21:04:05
idk how strong the naming conventions are? you may
dmurph
2015/03/11 22:28:36
I like "Blob" better.
| |
| 161 const std::string& uuid_str, | 166 const std::string& uuid_str, |
| 162 const blink::WebThreadSafeData& data) { | 167 const blink::WebThreadSafeData& data) { |
| 163 DCHECK_GE(data.size(), kLargeThresholdBytes); | 168 DCHECK_GE(data.size(), kLargeThresholdBytes); |
| 164 // We handle larger amounts of data via SharedMemory instead of | 169 // We handle larger amounts of data via SharedMemory instead of |
| 165 // writing it directly to the IPC channel. | 170 // writing it directly to the IPC channel. |
| 166 size_t shared_memory_size = std::min(data.size(), kMaxSharedMemoryBytes); | 171 size_t shared_memory_size = std::min(data.size(), kMaxSharedMemoryBytes); |
| 167 scoped_ptr<base::SharedMemory> shared_memory( | 172 scoped_ptr<base::SharedMemory> shared_memory( |
| 168 ChildThreadImpl::AllocateSharedMemory(shared_memory_size, sender_.get())); | 173 ChildThreadImpl::AllocateSharedMemory(shared_memory_size, sender_.get())); |
| 169 CHECK(shared_memory.get()); | 174 CHECK(shared_memory.get()); |
| 170 if (!shared_memory->Map(shared_memory_size)) | 175 if (!shared_memory->Map(shared_memory_size)) |
| 171 CHECK(false); | 176 CHECK(false); |
| 172 | 177 |
| 173 size_t data_size = data.size(); | 178 size_t data_size = data.size(); |
| 174 const char* data_ptr = data.data(); | 179 const char* data_ptr = data.data(); |
| 175 while (data_size) { | 180 while (data_size) { |
| 181 TRACE_EVENT0("Storage.Blob", "SendOversizedBlobItem"); | |
| 176 size_t chunk_size = std::min(data_size, shared_memory_size); | 182 size_t chunk_size = std::min(data_size, shared_memory_size); |
| 177 memcpy(shared_memory->memory(), data_ptr, chunk_size); | 183 memcpy(shared_memory->memory(), data_ptr, chunk_size); |
| 178 sender_->Send(new BlobHostMsg_SyncAppendSharedMemory( | 184 sender_->Send(new BlobHostMsg_SyncAppendSharedMemory( |
| 179 uuid_str, shared_memory->handle(), chunk_size)); | 185 uuid_str, shared_memory->handle(), chunk_size)); |
| 180 data_size -= chunk_size; | 186 data_size -= chunk_size; |
| 181 data_ptr += chunk_size; | 187 data_ptr += chunk_size; |
| 182 } | 188 } |
| 183 } | 189 } |
| 184 | 190 |
| 185 // ------ streams stuff ----- | 191 // ------ streams stuff ----- |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 244 DCHECK(ChildThreadImpl::current()); | 250 DCHECK(ChildThreadImpl::current()); |
| 245 sender_->Send(new StreamHostMsg_AbortBuilding(url)); | 251 sender_->Send(new StreamHostMsg_AbortBuilding(url)); |
| 246 } | 252 } |
| 247 | 253 |
| 248 void WebBlobRegistryImpl::unregisterStreamURL(const WebURL& url) { | 254 void WebBlobRegistryImpl::unregisterStreamURL(const WebURL& url) { |
| 249 DCHECK(ChildThreadImpl::current()); | 255 DCHECK(ChildThreadImpl::current()); |
| 250 sender_->Send(new StreamHostMsg_Remove(url)); | 256 sender_->Send(new StreamHostMsg_Remove(url)); |
| 251 } | 257 } |
| 252 | 258 |
| 253 } // namespace content | 259 } // namespace content |
| OLD | NEW |