| 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 "content/child/child_thread.h" | 12 #include "content/child/child_thread.h" |
| 13 #include "content/child/thread_safe_sender.h" | 13 #include "content/child/thread_safe_sender.h" |
| 14 #include "content/common/fileapi/webblob_messages.h" | 14 #include "content/common/fileapi/webblob_messages.h" |
| 15 #include "storage/common/blob/blob_data.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 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 49 while (data.itemAt(i++, data_item)) { | 49 while (data.itemAt(i++, data_item)) { |
| 50 switch (data_item.type) { | 50 switch (data_item.type) { |
| 51 case WebBlobData::Item::TypeData: { | 51 case WebBlobData::Item::TypeData: { |
| 52 // WebBlobData does not allow partial data items. | 52 // WebBlobData does not allow partial data items. |
| 53 DCHECK(!data_item.offset && data_item.length == -1); | 53 DCHECK(!data_item.offset && data_item.length == -1); |
| 54 SendDataForBlob(uuid_str, data_item.data); | 54 SendDataForBlob(uuid_str, data_item.data); |
| 55 break; | 55 break; |
| 56 } | 56 } |
| 57 case WebBlobData::Item::TypeFile: | 57 case WebBlobData::Item::TypeFile: |
| 58 if (data_item.length) { | 58 if (data_item.length) { |
| 59 storage::BlobData::Item item; | 59 storage::DataElement item; |
| 60 item.SetToFilePathRange( | 60 item.SetToFilePathRange( |
| 61 base::FilePath::FromUTF16Unsafe(data_item.filePath), | 61 base::FilePath::FromUTF16Unsafe(data_item.filePath), |
| 62 static_cast<uint64>(data_item.offset), | 62 static_cast<uint64>(data_item.offset), |
| 63 static_cast<uint64>(data_item.length), | 63 static_cast<uint64>(data_item.length), |
| 64 base::Time::FromDoubleT(data_item.expectedModificationTime)); | 64 base::Time::FromDoubleT(data_item.expectedModificationTime)); |
| 65 sender_->Send( | 65 sender_->Send( |
| 66 new BlobHostMsg_AppendBlobDataItem(uuid_str, item)); | 66 new BlobHostMsg_AppendBlobDataItem(uuid_str, item)); |
| 67 } | 67 } |
| 68 break; | 68 break; |
| 69 case WebBlobData::Item::TypeBlob: | 69 case WebBlobData::Item::TypeBlob: |
| 70 if (data_item.length) { | 70 if (data_item.length) { |
| 71 storage::BlobData::Item item; | 71 storage::DataElement item; |
| 72 item.SetToBlobRange( | 72 item.SetToBlobRange( |
| 73 data_item.blobUUID.utf8(), | 73 data_item.blobUUID.utf8(), |
| 74 static_cast<uint64>(data_item.offset), | 74 static_cast<uint64>(data_item.offset), |
| 75 static_cast<uint64>(data_item.length)); | 75 static_cast<uint64>(data_item.length)); |
| 76 sender_->Send( | 76 sender_->Send( |
| 77 new BlobHostMsg_AppendBlobDataItem(uuid_str, item)); | 77 new BlobHostMsg_AppendBlobDataItem(uuid_str, item)); |
| 78 } | 78 } |
| 79 break; | 79 break; |
| 80 case WebBlobData::Item::TypeFileSystemURL: | 80 case WebBlobData::Item::TypeFileSystemURL: |
| 81 if (data_item.length) { | 81 if (data_item.length) { |
| 82 // We only support filesystem URL as of now. | 82 // We only support filesystem URL as of now. |
| 83 DCHECK(GURL(data_item.fileSystemURL).SchemeIsFileSystem()); | 83 DCHECK(GURL(data_item.fileSystemURL).SchemeIsFileSystem()); |
| 84 storage::BlobData::Item item; | 84 storage::DataElement item; |
| 85 item.SetToFileSystemUrlRange( | 85 item.SetToFileSystemUrlRange( |
| 86 data_item.fileSystemURL, | 86 data_item.fileSystemURL, |
| 87 static_cast<uint64>(data_item.offset), | 87 static_cast<uint64>(data_item.offset), |
| 88 static_cast<uint64>(data_item.length), | 88 static_cast<uint64>(data_item.length), |
| 89 base::Time::FromDoubleT(data_item.expectedModificationTime)); | 89 base::Time::FromDoubleT(data_item.expectedModificationTime)); |
| 90 sender_->Send( | 90 sender_->Send( |
| 91 new BlobHostMsg_AppendBlobDataItem(uuid_str, item)); | 91 new BlobHostMsg_AppendBlobDataItem(uuid_str, item)); |
| 92 } | 92 } |
| 93 break; | 93 break; |
| 94 default: | 94 default: |
| (...skipping 20 matching lines...) Expand all Loading... |
| 115 void WebBlobRegistryImpl::revokePublicBlobURL(const WebURL& url) { | 115 void WebBlobRegistryImpl::revokePublicBlobURL(const WebURL& url) { |
| 116 sender_->Send(new BlobHostMsg_RevokePublicURL(url)); | 116 sender_->Send(new BlobHostMsg_RevokePublicURL(url)); |
| 117 } | 117 } |
| 118 | 118 |
| 119 void WebBlobRegistryImpl::SendDataForBlob(const std::string& uuid_str, | 119 void WebBlobRegistryImpl::SendDataForBlob(const std::string& uuid_str, |
| 120 const WebThreadSafeData& data) { | 120 const WebThreadSafeData& data) { |
| 121 | 121 |
| 122 if (data.size() == 0) | 122 if (data.size() == 0) |
| 123 return; | 123 return; |
| 124 if (data.size() < kLargeThresholdBytes) { | 124 if (data.size() < kLargeThresholdBytes) { |
| 125 storage::BlobData::Item item; | 125 storage::DataElement item; |
| 126 item.SetToBytes(data.data(), data.size()); | 126 item.SetToBytes(data.data(), data.size()); |
| 127 sender_->Send(new BlobHostMsg_AppendBlobDataItem(uuid_str, item)); | 127 sender_->Send(new BlobHostMsg_AppendBlobDataItem(uuid_str, item)); |
| 128 } else { | 128 } else { |
| 129 // We handle larger amounts of data via SharedMemory instead of | 129 // We handle larger amounts of data via SharedMemory instead of |
| 130 // writing it directly to the IPC channel. | 130 // writing it directly to the IPC channel. |
| 131 size_t shared_memory_size = std::min( | 131 size_t shared_memory_size = std::min( |
| 132 data.size(), kMaxSharedMemoryBytes); | 132 data.size(), kMaxSharedMemoryBytes); |
| 133 scoped_ptr<base::SharedMemory> shared_memory( | 133 scoped_ptr<base::SharedMemory> shared_memory( |
| 134 ChildThread::AllocateSharedMemory(shared_memory_size, | 134 ChildThread::AllocateSharedMemory(shared_memory_size, |
| 135 sender_.get())); | 135 sender_.get())); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 163 DCHECK(ChildThread::current()); | 163 DCHECK(ChildThread::current()); |
| 164 sender_->Send(new StreamHostMsg_Clone(url, src_url)); | 164 sender_->Send(new StreamHostMsg_Clone(url, src_url)); |
| 165 } | 165 } |
| 166 | 166 |
| 167 void WebBlobRegistryImpl::addDataToStream(const WebURL& url, | 167 void WebBlobRegistryImpl::addDataToStream(const WebURL& url, |
| 168 const char* data, size_t length) { | 168 const char* data, size_t length) { |
| 169 DCHECK(ChildThread::current()); | 169 DCHECK(ChildThread::current()); |
| 170 if (length == 0) | 170 if (length == 0) |
| 171 return; | 171 return; |
| 172 if (length < kLargeThresholdBytes) { | 172 if (length < kLargeThresholdBytes) { |
| 173 storage::BlobData::Item item; | 173 storage::DataElement item; |
| 174 item.SetToBytes(data, length); | 174 item.SetToBytes(data, length); |
| 175 sender_->Send(new StreamHostMsg_AppendBlobDataItem(url, item)); | 175 sender_->Send(new StreamHostMsg_AppendBlobDataItem(url, item)); |
| 176 } else { | 176 } else { |
| 177 // We handle larger amounts of data via SharedMemory instead of | 177 // We handle larger amounts of data via SharedMemory instead of |
| 178 // writing it directly to the IPC channel. | 178 // writing it directly to the IPC channel. |
| 179 size_t shared_memory_size = std::min( | 179 size_t shared_memory_size = std::min( |
| 180 length, kMaxSharedMemoryBytes); | 180 length, kMaxSharedMemoryBytes); |
| 181 scoped_ptr<base::SharedMemory> shared_memory( | 181 scoped_ptr<base::SharedMemory> shared_memory( |
| 182 ChildThread::AllocateSharedMemory(shared_memory_size, | 182 ChildThread::AllocateSharedMemory(shared_memory_size, |
| 183 sender_.get())); | 183 sender_.get())); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 212 DCHECK(ChildThread::current()); | 212 DCHECK(ChildThread::current()); |
| 213 sender_->Send(new StreamHostMsg_AbortBuilding(url)); | 213 sender_->Send(new StreamHostMsg_AbortBuilding(url)); |
| 214 } | 214 } |
| 215 | 215 |
| 216 void WebBlobRegistryImpl::unregisterStreamURL(const WebURL& url) { | 216 void WebBlobRegistryImpl::unregisterStreamURL(const WebURL& url) { |
| 217 DCHECK(ChildThread::current()); | 217 DCHECK(ChildThread::current()); |
| 218 sender_->Send(new StreamHostMsg_Remove(url)); | 218 sender_->Send(new StreamHostMsg_Remove(url)); |
| 219 } | 219 } |
| 220 | 220 |
| 221 } // namespace content | 221 } // namespace content |
| OLD | NEW |