| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/common/fileapi/webblobregistry_impl.h" | 5 #include "content/common/fileapi/webblobregistry_impl.h" |
| 6 | 6 |
| 7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
| 8 #include "base/shared_memory.h" | 8 #include "base/shared_memory.h" |
| 9 #include "content/common/child_thread.h" | 9 #include "content/common/child_thread.h" |
| 10 #include "content/common/fileapi/webblob_messages.h" | 10 #include "content/common/fileapi/webblob_messages.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 | 32 |
| 33 child_thread_->Send(new BlobHostMsg_StartBuildingBlob(url)); | 33 child_thread_->Send(new BlobHostMsg_StartBuildingBlob(url)); |
| 34 size_t i = 0; | 34 size_t i = 0; |
| 35 WebBlobData::Item data_item; | 35 WebBlobData::Item data_item; |
| 36 while (data.itemAt(i++, data_item)) { | 36 while (data.itemAt(i++, data_item)) { |
| 37 webkit_blob::BlobData::Item item; | 37 webkit_blob::BlobData::Item item; |
| 38 switch (data_item.type) { | 38 switch (data_item.type) { |
| 39 case WebBlobData::Item::TypeData: { | 39 case WebBlobData::Item::TypeData: { |
| 40 // WebBlobData does not allow partial data items. | 40 // WebBlobData does not allow partial data items. |
| 41 DCHECK(!data_item.offset && data_item.length == -1); | 41 DCHECK(!data_item.offset && data_item.length == -1); |
| 42 if (data_item.data.size() == 0) | |
| 43 break; | |
| 44 if (data_item.data.size() < kLargeThresholdBytes) { | 42 if (data_item.data.size() < kLargeThresholdBytes) { |
| 45 item.SetToData(data_item.data.data(), data_item.data.size()); | 43 item.SetToData(data_item.data.data(), data_item.data.size()); |
| 46 child_thread_->Send(new BlobHostMsg_AppendBlobDataItem(url, item)); | 44 child_thread_->Send(new BlobHostMsg_AppendBlobDataItem(url, item)); |
| 47 } else { | 45 } else { |
| 48 // We handle larger amounts of data via SharedMemory instead of | 46 // We handle larger amounts of data via SharedMemory instead of |
| 49 // writing it directly to the IPC channel. | 47 // writing it directly to the IPC channel. |
| 50 size_t data_size = data_item.data.size(); | 48 size_t data_size = data_item.data.size(); |
| 51 const char* data_ptr = data_item.data.data(); | 49 const char* data_ptr = data_item.data.data(); |
| 52 size_t shared_memory_size = std::min( | 50 size_t shared_memory_size = std::min( |
| 53 data_size, kMaxSharedMemoryBytes); | 51 data_size, kMaxSharedMemoryBytes); |
| 54 scoped_ptr<base::SharedMemory> shared_memory( | 52 scoped_ptr<base::SharedMemory> shared_memory( |
| 55 child_thread_->AllocateSharedMemory(shared_memory_size)); | 53 child_thread_->AllocateSharedMemory(shared_memory_size)); |
| 56 CHECK(shared_memory.get()); | 54 CHECK(shared_memory.get()); |
| 57 while (data_size) { | 55 while (data_size) { |
| 58 size_t chunk_size = std::min(data_size, shared_memory_size); | 56 size_t chunk_size = std::min(data_size, shared_memory_size); |
| 59 memcpy(shared_memory->memory(), data_ptr, chunk_size); | 57 memcpy(shared_memory->memory(), data_ptr, chunk_size); |
| 60 child_thread_->Send(new BlobHostMsg_SyncAppendSharedMemory( | 58 child_thread_->Send(new BlobHostMsg_SyncAppendSharedMemory( |
| 61 url, shared_memory->handle(), chunk_size)); | 59 url, shared_memory->handle(), chunk_size)); |
| 62 data_size -= chunk_size; | 60 data_size -= chunk_size; |
| 63 data_ptr += chunk_size; | 61 data_ptr += chunk_size; |
| 64 } | 62 } |
| 65 } | 63 } |
| 66 break; | 64 break; |
| 67 } | 65 } |
| 68 case WebBlobData::Item::TypeFile: | 66 case WebBlobData::Item::TypeFile: |
| 69 if (data_item.length) { | 67 item.SetToFile( |
| 70 item.SetToFile( | 68 webkit_glue::WebStringToFilePath(data_item.filePath), |
| 71 webkit_glue::WebStringToFilePath(data_item.filePath), | 69 static_cast<uint64>(data_item.offset), |
| 72 static_cast<uint64>(data_item.offset), | 70 static_cast<uint64>(data_item.length), |
| 73 static_cast<uint64>(data_item.length), | 71 base::Time::FromDoubleT(data_item.expectedModificationTime)); |
| 74 base::Time::FromDoubleT(data_item.expectedModificationTime)); | 72 child_thread_->Send(new BlobHostMsg_AppendBlobDataItem(url, item)); |
| 75 child_thread_->Send(new BlobHostMsg_AppendBlobDataItem(url, item)); | |
| 76 } | |
| 77 break; | 73 break; |
| 78 case WebBlobData::Item::TypeBlob: | 74 case WebBlobData::Item::TypeBlob: |
| 79 if (data_item.length) { | 75 if (data_item.length) { |
| 80 item.SetToBlob( | 76 item.SetToBlob( |
| 81 data_item.blobURL, | 77 data_item.blobURL, |
| 82 static_cast<uint64>(data_item.offset), | 78 static_cast<uint64>(data_item.offset), |
| 83 static_cast<uint64>(data_item.length)); | 79 static_cast<uint64>(data_item.length)); |
| 84 child_thread_->Send(new BlobHostMsg_AppendBlobDataItem(url, item)); | |
| 85 } | 80 } |
| 81 child_thread_->Send(new BlobHostMsg_AppendBlobDataItem(url, item)); |
| 86 break; | 82 break; |
| 87 default: | 83 default: |
| 88 NOTREACHED(); | 84 NOTREACHED(); |
| 89 } | 85 } |
| 90 } | 86 } |
| 91 child_thread_->Send(new BlobHostMsg_FinishBuildingBlob( | 87 child_thread_->Send(new BlobHostMsg_FinishBuildingBlob( |
| 92 url, data.contentType().utf8().data())); | 88 url, data.contentType().utf8().data())); |
| 93 } | 89 } |
| 94 | 90 |
| 95 void WebBlobRegistryImpl::registerBlobURL( | 91 void WebBlobRegistryImpl::registerBlobURL( |
| 96 const WebURL& url, const WebURL& src_url) { | 92 const WebURL& url, const WebURL& src_url) { |
| 97 child_thread_->Send(new BlobHostMsg_CloneBlob(url, src_url)); | 93 child_thread_->Send(new BlobHostMsg_CloneBlob(url, src_url)); |
| 98 } | 94 } |
| 99 | 95 |
| 100 void WebBlobRegistryImpl::unregisterBlobURL(const WebURL& url) { | 96 void WebBlobRegistryImpl::unregisterBlobURL(const WebURL& url) { |
| 101 child_thread_->Send(new BlobHostMsg_RemoveBlob(url)); | 97 child_thread_->Send(new BlobHostMsg_RemoveBlob(url)); |
| 102 } | 98 } |
| OLD | NEW |