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/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/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/memory/scoped_ptr.h" | |
13 #include "base/memory/shared_memory.h" | 12 #include "base/memory/shared_memory.h" |
14 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
15 #include "base/numerics/safe_conversions.h" | 14 #include "base/numerics/safe_conversions.h" |
16 #include "base/trace_event/trace_event.h" | 15 #include "base/trace_event/trace_event.h" |
17 #include "content/child/blob_storage/blob_consolidation.h" | 16 #include "content/child/blob_storage/blob_consolidation.h" |
18 #include "content/child/blob_storage/blob_transport_controller.h" | 17 #include "content/child/blob_storage/blob_transport_controller.h" |
19 #include "content/child/child_thread_impl.h" | 18 #include "content/child/child_thread_impl.h" |
20 #include "content/child/thread_safe_sender.h" | 19 #include "content/child/thread_safe_sender.h" |
21 #include "content/common/fileapi/webblob_messages.h" | 20 #include "content/common/fileapi/webblob_messages.h" |
22 #include "storage/common/blob_storage/blob_storage_constants.h" | 21 #include "storage/common/blob_storage/blob_storage_constants.h" |
(...skipping 30 matching lines...) Expand all Loading... |
53 blink::WebBlobRegistry::Builder* WebBlobRegistryImpl::createBuilder( | 52 blink::WebBlobRegistry::Builder* WebBlobRegistryImpl::createBuilder( |
54 const blink::WebString& uuid, | 53 const blink::WebString& uuid, |
55 const blink::WebString& content_type) { | 54 const blink::WebString& content_type) { |
56 return new BuilderImpl(uuid, content_type, sender_.get(), io_runner_, | 55 return new BuilderImpl(uuid, content_type, sender_.get(), io_runner_, |
57 main_runner_); | 56 main_runner_); |
58 } | 57 } |
59 | 58 |
60 void WebBlobRegistryImpl::registerBlobData(const blink::WebString& uuid, | 59 void WebBlobRegistryImpl::registerBlobData(const blink::WebString& uuid, |
61 const blink::WebBlobData& data) { | 60 const blink::WebBlobData& data) { |
62 TRACE_EVENT0("Blob", "Registry::RegisterBlob"); | 61 TRACE_EVENT0("Blob", "Registry::RegisterBlob"); |
63 scoped_ptr<Builder> builder(createBuilder(uuid, data.contentType())); | 62 std::unique_ptr<Builder> builder(createBuilder(uuid, data.contentType())); |
64 | 63 |
65 // This is temporary until we move to createBuilder() as our blob creation | 64 // This is temporary until we move to createBuilder() as our blob creation |
66 // method. | 65 // method. |
67 size_t i = 0; | 66 size_t i = 0; |
68 WebBlobData::Item data_item; | 67 WebBlobData::Item data_item; |
69 while (data.itemAt(i++, data_item)) { | 68 while (data.itemAt(i++, data_item)) { |
70 if (data_item.length == 0) { | 69 if (data_item.length == 0) { |
71 continue; | 70 continue; |
72 } | 71 } |
73 switch (data_item.type) { | 72 switch (data_item.type) { |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 return; | 140 return; |
142 if (length < storage::kBlobStorageIPCThresholdBytes) { | 141 if (length < storage::kBlobStorageIPCThresholdBytes) { |
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, storage::kBlobStorageMaxSharedMemoryBytes); |
151 scoped_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())); | 152 sender_.get())); |
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) { |
161 size_t chunk_size = std::min(remaining_bytes, shared_memory_size); | 160 size_t chunk_size = std::min(remaining_bytes, shared_memory_size); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 uuid_, content_type_, "", consolidation_->referenced_blobs())); | 239 uuid_, content_type_, "", consolidation_->referenced_blobs())); |
241 io_runner_->PostTask( | 240 io_runner_->PostTask( |
242 FROM_HERE, | 241 FROM_HERE, |
243 base::Bind(&WebBlobRegistryImpl::StartBlobAsyncConstruction, uuid_, | 242 base::Bind(&WebBlobRegistryImpl::StartBlobAsyncConstruction, uuid_, |
244 base::Passed(&consolidation_), sender_, main_runner_)); | 243 base::Passed(&consolidation_), sender_, main_runner_)); |
245 } | 244 } |
246 | 245 |
247 /* static */ | 246 /* static */ |
248 void WebBlobRegistryImpl::StartBlobAsyncConstruction( | 247 void WebBlobRegistryImpl::StartBlobAsyncConstruction( |
249 const std::string& uuid, | 248 const std::string& uuid, |
250 scoped_ptr<BlobConsolidation> consolidation, | 249 std::unique_ptr<BlobConsolidation> consolidation, |
251 scoped_refptr<ThreadSafeSender> sender, | 250 scoped_refptr<ThreadSafeSender> sender, |
252 scoped_refptr<base::SingleThreadTaskRunner> main_runner) { | 251 scoped_refptr<base::SingleThreadTaskRunner> main_runner) { |
253 BlobTransportController::GetInstance()->InitiateBlobTransfer( | 252 BlobTransportController::GetInstance()->InitiateBlobTransfer( |
254 uuid, std::move(consolidation), sender.get(), std::move(main_runner)); | 253 uuid, std::move(consolidation), sender.get(), std::move(main_runner)); |
255 } | 254 } |
256 | 255 |
257 } // namespace content | 256 } // namespace content |
OLD | NEW |