| 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 24 matching lines...) Expand all Loading... |
| 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) | 42 if (data_item.data.size() == 0) |
| 43 break; | 43 break; |
| 44 if (data_item.data.size() < kLargeThresholdBytes) { | 44 if (data_item.data.size() < kLargeThresholdBytes) { |
| 45 item.SetToData(data_item.data.data(), data_item.data.size()); | 45 item.SetToBytes(data_item.data.data(), data_item.data.size()); |
| 46 child_thread_->Send(new BlobHostMsg_AppendBlobDataItem(url, item)); | 46 child_thread_->Send(new BlobHostMsg_AppendBlobDataItem(url, item)); |
| 47 } else { | 47 } else { |
| 48 // We handle larger amounts of data via SharedMemory instead of | 48 // We handle larger amounts of data via SharedMemory instead of |
| 49 // writing it directly to the IPC channel. | 49 // writing it directly to the IPC channel. |
| 50 size_t data_size = data_item.data.size(); | 50 size_t data_size = data_item.data.size(); |
| 51 const char* data_ptr = data_item.data.data(); | 51 const char* data_ptr = data_item.data.data(); |
| 52 size_t shared_memory_size = std::min( | 52 size_t shared_memory_size = std::min( |
| 53 data_size, kMaxSharedMemoryBytes); | 53 data_size, kMaxSharedMemoryBytes); |
| 54 scoped_ptr<base::SharedMemory> shared_memory( | 54 scoped_ptr<base::SharedMemory> shared_memory( |
| 55 child_thread_->AllocateSharedMemory(shared_memory_size)); | 55 child_thread_->AllocateSharedMemory(shared_memory_size)); |
| 56 CHECK(shared_memory.get()); | 56 CHECK(shared_memory.get()); |
| 57 while (data_size) { | 57 while (data_size) { |
| 58 size_t chunk_size = std::min(data_size, shared_memory_size); | 58 size_t chunk_size = std::min(data_size, shared_memory_size); |
| 59 memcpy(shared_memory->memory(), data_ptr, chunk_size); | 59 memcpy(shared_memory->memory(), data_ptr, chunk_size); |
| 60 child_thread_->Send(new BlobHostMsg_SyncAppendSharedMemory( | 60 child_thread_->Send(new BlobHostMsg_SyncAppendSharedMemory( |
| 61 url, shared_memory->handle(), chunk_size)); | 61 url, shared_memory->handle(), chunk_size)); |
| 62 data_size -= chunk_size; | 62 data_size -= chunk_size; |
| 63 data_ptr += chunk_size; | 63 data_ptr += chunk_size; |
| 64 } | 64 } |
| 65 } | 65 } |
| 66 break; | 66 break; |
| 67 } | 67 } |
| 68 case WebBlobData::Item::TypeFile: | 68 case WebBlobData::Item::TypeFile: |
| 69 if (data_item.length) { | 69 if (data_item.length) { |
| 70 item.SetToFile( | 70 item.SetToFilePathRange( |
| 71 webkit_glue::WebStringToFilePath(data_item.filePath), | 71 webkit_glue::WebStringToFilePath(data_item.filePath), |
| 72 static_cast<uint64>(data_item.offset), | 72 static_cast<uint64>(data_item.offset), |
| 73 static_cast<uint64>(data_item.length), | 73 static_cast<uint64>(data_item.length), |
| 74 base::Time::FromDoubleT(data_item.expectedModificationTime)); | 74 base::Time::FromDoubleT(data_item.expectedModificationTime)); |
| 75 child_thread_->Send(new BlobHostMsg_AppendBlobDataItem(url, item)); | 75 child_thread_->Send(new BlobHostMsg_AppendBlobDataItem(url, item)); |
| 76 } | 76 } |
| 77 break; | 77 break; |
| 78 case WebBlobData::Item::TypeBlob: | 78 case WebBlobData::Item::TypeBlob: |
| 79 if (data_item.length) { | 79 if (data_item.length) { |
| 80 item.SetToBlob( | 80 item.SetToBlobUrlRange( |
| 81 data_item.blobURL, | 81 data_item.blobURL, |
| 82 static_cast<uint64>(data_item.offset), | 82 static_cast<uint64>(data_item.offset), |
| 83 static_cast<uint64>(data_item.length)); | 83 static_cast<uint64>(data_item.length)); |
| 84 child_thread_->Send(new BlobHostMsg_AppendBlobDataItem(url, item)); | 84 child_thread_->Send(new BlobHostMsg_AppendBlobDataItem(url, item)); |
| 85 } | 85 } |
| 86 break; | 86 break; |
| 87 default: | 87 default: |
| 88 NOTREACHED(); | 88 NOTREACHED(); |
| 89 } | 89 } |
| 90 } | 90 } |
| 91 child_thread_->Send(new BlobHostMsg_FinishBuildingBlob( | 91 child_thread_->Send(new BlobHostMsg_FinishBuildingBlob( |
| 92 url, data.contentType().utf8().data())); | 92 url, data.contentType().utf8().data())); |
| 93 } | 93 } |
| 94 | 94 |
| 95 void WebBlobRegistryImpl::registerBlobURL( | 95 void WebBlobRegistryImpl::registerBlobURL( |
| 96 const WebURL& url, const WebURL& src_url) { | 96 const WebURL& url, const WebURL& src_url) { |
| 97 child_thread_->Send(new BlobHostMsg_CloneBlob(url, src_url)); | 97 child_thread_->Send(new BlobHostMsg_CloneBlob(url, src_url)); |
| 98 } | 98 } |
| 99 | 99 |
| 100 void WebBlobRegistryImpl::unregisterBlobURL(const WebURL& url) { | 100 void WebBlobRegistryImpl::unregisterBlobURL(const WebURL& url) { |
| 101 child_thread_->Send(new BlobHostMsg_RemoveBlob(url)); | 101 child_thread_->Send(new BlobHostMsg_RemoveBlob(url)); |
| 102 } | 102 } |
| OLD | NEW |