| 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/blob_storage/webblobregistry_impl.h" | 5 #include "content/child/blob_storage/webblobregistry_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/guid.h" | 9 #include "base/guid.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/shared_memory.h" | 13 #include "base/memory/shared_memory.h" |
| 14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
| 15 #include "base/numerics/safe_conversions.h" | 15 #include "base/numerics/safe_conversions.h" |
| 16 #include "base/trace_event/trace_event.h" | 16 #include "base/trace_event/trace_event.h" |
| 17 #include "content/child/blob_storage/blob_consolidation.h" | 17 #include "content/child/blob_storage/blob_consolidation.h" |
| 18 #include "content/child/blob_storage/blob_transport_controller.h" | 18 #include "content/child/blob_storage/blob_transport_controller.h" |
| 19 #include "content/child/child_thread_impl.h" | 19 #include "content/child/child_thread_impl.h" |
| 20 #include "content/child/thread_safe_sender.h" | 20 #include "content/child/thread_safe_sender.h" |
| 21 #include "content/common/fileapi/webblob_messages.h" | 21 #include "content/common/fileapi/webblob_messages.h" |
| 22 #include "storage/common/blob_storage/blob_storage_constants.h" | |
| 23 #include "third_party/WebKit/public/platform/FilePathConversion.h" | 22 #include "third_party/WebKit/public/platform/FilePathConversion.h" |
| 24 #include "third_party/WebKit/public/platform/WebBlobData.h" | 23 #include "third_party/WebKit/public/platform/WebBlobData.h" |
| 25 #include "third_party/WebKit/public/platform/WebString.h" | 24 #include "third_party/WebKit/public/platform/WebString.h" |
| 26 #include "third_party/WebKit/public/platform/WebThreadSafeData.h" | 25 #include "third_party/WebKit/public/platform/WebThreadSafeData.h" |
| 27 #include "third_party/WebKit/public/platform/WebURL.h" | 26 #include "third_party/WebKit/public/platform/WebURL.h" |
| 28 | 27 |
| 29 using blink::WebBlobData; | 28 using blink::WebBlobData; |
| 30 using blink::WebString; | 29 using blink::WebString; |
| 31 using blink::WebThreadSafeData; | 30 using blink::WebThreadSafeData; |
| 32 using blink::WebURL; | 31 using blink::WebURL; |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 DCHECK(ChildThreadImpl::current()); | 131 DCHECK(ChildThreadImpl::current()); |
| 133 sender_->Send(new StreamHostMsg_Clone(url, src_url)); | 132 sender_->Send(new StreamHostMsg_Clone(url, src_url)); |
| 134 } | 133 } |
| 135 | 134 |
| 136 void WebBlobRegistryImpl::addDataToStream(const WebURL& url, | 135 void WebBlobRegistryImpl::addDataToStream(const WebURL& url, |
| 137 const char* data, | 136 const char* data, |
| 138 size_t length) { | 137 size_t length) { |
| 139 DCHECK(ChildThreadImpl::current()); | 138 DCHECK(ChildThreadImpl::current()); |
| 140 if (length == 0) | 139 if (length == 0) |
| 141 return; | 140 return; |
| 142 if (length < storage::kBlobStorageIPCThresholdBytes) { | 141 if (length <= limits_.max_ipc_memory_size) { |
| 143 DataElement item; | 142 DataElement item; |
| 144 item.SetToBytes(data, length); | 143 item.SetToBytes(data, length); |
| 145 sender_->Send(new StreamHostMsg_AppendBlobDataItem(url, item)); | 144 sender_->Send(new StreamHostMsg_AppendBlobDataItem(url, item)); |
| 146 } else { | 145 } else { |
| 147 // We handle larger amounts of data via SharedMemory instead of | 146 // We handle larger amounts of data via SharedMemory instead of |
| 148 // writing it directly to the IPC channel. | 147 // writing it directly to the IPC channel. |
| 149 size_t shared_memory_size = | 148 size_t shared_memory_size = |
| 150 std::min(length, storage::kBlobStorageMaxSharedMemoryBytes); | 149 std::min(length, limits_.max_shared_memory_size); |
| 151 std::unique_ptr<base::SharedMemory> shared_memory( | 150 std::unique_ptr<base::SharedMemory> shared_memory( |
| 152 ChildThreadImpl::AllocateSharedMemory(shared_memory_size, | 151 ChildThreadImpl::AllocateSharedMemory(shared_memory_size, |
| 153 sender_.get(), nullptr)); | 152 sender_.get(), nullptr)); |
| 154 CHECK(shared_memory.get()); | 153 CHECK(shared_memory.get()); |
| 155 if (!shared_memory->Map(shared_memory_size)) | 154 if (!shared_memory->Map(shared_memory_size)) |
| 156 CHECK(false); | 155 CHECK(false); |
| 157 | 156 |
| 158 size_t remaining_bytes = length; | 157 size_t remaining_bytes = length; |
| 159 const char* current_ptr = data; | 158 const char* current_ptr = data; |
| 160 while (remaining_bytes) { | 159 while (remaining_bytes) { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 expected_modification_time); | 234 expected_modification_time); |
| 236 } | 235 } |
| 237 | 236 |
| 238 void WebBlobRegistryImpl::BuilderImpl::build() { | 237 void WebBlobRegistryImpl::BuilderImpl::build() { |
| 239 BlobTransportController::InitiateBlobTransfer( | 238 BlobTransportController::InitiateBlobTransfer( |
| 240 uuid_, content_type_, std::move(consolidation_), sender_, | 239 uuid_, content_type_, std::move(consolidation_), sender_, |
| 241 io_runner_.get(), main_runner_); | 240 io_runner_.get(), main_runner_); |
| 242 } | 241 } |
| 243 | 242 |
| 244 } // namespace content | 243 } // namespace content |
| OLD | NEW |