Index: storage/browser/blob/blob_flattener.cc |
diff --git a/storage/browser/blob/blob_flattener.cc b/storage/browser/blob/blob_flattener.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..c069966884249dcf5ee5f285b53b4535a6ce2bbf |
--- /dev/null |
+++ b/storage/browser/blob/blob_flattener.cc |
@@ -0,0 +1,81 @@ |
+// TODO: Insert description here. (generated by dmurph) |
+ |
+#include "storage/browser/blob/blob_flattener.h" |
+ |
+#include <utility> |
+ |
+#include "storage/browser/blob/blob_async_transport_request_builder.h" |
+#include "storage/browser/blob/blob_data_builder.h" |
+#include "storage/browser/blob/blob_storage_context.h" |
+#include "storage/browser/blob/blob_storage_registry.h" |
+#include "storage/browser/blob/shareable_blob_data_item.h" |
+ |
+namespace storage { |
+namespace { |
+using ItemCopyEntry = BlobStorageRegistry::ItemCopyEntry; |
+ |
+bool IsBytes(DataElement::Type type) { |
+ return type == DataElement::TYPE_BYTES || |
+ type == DataElement::TYPE_BYTES_DESCRIPTION; |
+} |
+ |
+} // namespace |
+ |
+void BlobFlattener::FlattenBlob( |
+ const std::string& uuid, |
+ InternalBlobData* output_blob, |
+ std::vector<BlobStorageRegistry::ItemCopyEntry>* copies_from_built_ref, |
+ std::vector<BlobStorageRegistry::ItemCopyEntry>* copies_from_pending_ref, |
+ std::map<std::string, BlobSlice> slice_map, |
+ const BlobDataBuilder& transportation_result) { |
+ const std::vector<scoped_refptr<BlobDataItem>>& transport_items = |
+ transportation_result.items_; |
+ |
+ size_t blob_flattening_index_offset = 0; |
Marijn Kruisselbrink
2016/06/29 22:42:21
You're not using this for anything?
dmurph
2016/07/06 23:44:29
Removed thanks.
|
+ size_t current_browser_index = 0; |
+ for (size_t transport_item_index = 0; |
+ transport_item_index < transport_items.size(); transport_item_index++) { |
+ scoped_refptr<BlobDataItem> transport_item = |
+ transport_items[transport_item_index]; |
+ |
+ if (IsBytes(transport_item->type())) { |
+ output_blob->AppendSharedBlobItem( |
+ uuid, |
+ new ShareableBlobDataItem(BlobStorageContext::GetAndIncrementItemId(), |
+ std::move(transport_item))); |
+ current_browser_index++; |
+ } else if (transport_item->type() == DataElement::TYPE_BLOB) { |
+ BlobSlice& slice = slice_map[transport_item->blob_uuid()]; |
+ std::vector<BlobStorageRegistry::ItemCopyEntry>* copies = |
+ slice.done_building() ? copies_from_built_ref |
Marijn Kruisselbrink
2016/06/29 22:42:21
is done_building() her the right thing to do? Or c
dmurph
2016/07/06 23:44:29
I can remove this now, especially because I no lon
|
+ : copies_from_pending_ref; |
+ if (slice.has_sliced_first_memory_item()) { |
+ copies->push_back(ItemCopyEntry( |
+ transport_item->blob_uuid(), slice.first_item_index(), |
+ slice.first_item_slice_offset(), current_browser_index, |
+ slice.items().front()->item()->length())); |
+ } |
+ |
+ for (const auto& shareable_item : slice.items()) { |
+ output_blob->AppendSharedBlobItem(uuid, std::move(shareable_item)); |
+ ++current_browser_index; |
+ ++blob_flattening_index_offset; |
+ } |
+ --blob_flattening_index_offset; |
+ |
+ if (slice.has_sliced_last_memory_item()) { |
+ copies->push_back(ItemCopyEntry( |
+ transport_item->blob_uuid(), slice.last_item_index(), 0, |
+ current_browser_index - 1, slice.items().back()->item()->length())); |
+ } |
+ } else { |
+ output_blob->AppendSharedBlobItem( |
+ uuid, |
+ new ShareableBlobDataItem(BlobStorageContext::GetAndIncrementItemId(), |
+ std::move(transport_item))); |
+ current_browser_index++; |
+ } |
+ } |
+} |
+ |
+} // namespace storage |