OLD | NEW |
---|---|
(Empty) | |
1 // TODO: Insert description here. (generated by dmurph) | |
2 | |
3 #include "storage/browser/blob/blob_flattener.h" | |
4 | |
5 #include <limits> | |
6 #include <set> | |
7 #include <utility> | |
8 | |
9 #include "storage/browser/blob/blob_async_transport_request_builder.h" | |
10 #include "storage/browser/blob/blob_data_builder.h" | |
11 #include "storage/browser/blob/blob_storage_context.h" | |
12 #include "storage/browser/blob/blob_storage_registry.h" | |
13 #include "storage/browser/blob/shareable_blob_data_item.h" | |
14 | |
15 namespace storage { | |
16 namespace { | |
17 using ItemCopyEntry = BlobStorageRegistry::ItemCopyEntry; | |
18 using BlobEntry = BlobStorageRegistry::Entry; | |
19 | |
20 bool IsBytes(DataElement::Type type) { | |
21 return type == DataElement::TYPE_BYTES || | |
22 type == DataElement::TYPE_BYTES_DESCRIPTION; | |
23 } | |
24 | |
25 } // namespace | |
26 | |
27 // static | |
28 BlobFlattener::BlobFlattener(const BlobDataBuilder& transportation_result, | |
29 InternalBlobData* output_blob, | |
30 BlobStorageRegistry* registry) { | |
31 const std::vector<scoped_refptr<BlobDataItem>>& transport_items = | |
32 transportation_result.items_; | |
33 const std::string& uuid = transportation_result.uuid_; | |
34 | |
35 size_t current_browser_index = 0; | |
Marijn Kruisselbrink
2016/07/08 23:37:37
You're never reading from this variable?
dmurph
2016/07/11 23:33:28
Done.
| |
36 std::set<std::string> dependent_blob_uuids; | |
37 for (size_t transport_item_index = 0; | |
38 transport_item_index < transport_items.size(); transport_item_index++) { | |
39 scoped_refptr<BlobDataItem> transport_item = | |
40 transport_items[transport_item_index]; | |
41 | |
42 DataElement::Type type = transport_item->type(); | |
43 contains_pending_content |= type == DataElement::TYPE_BYTES_DESCRIPTION; | |
44 | |
45 if (IsBytes(type)) { | |
46 memory_needed += transport_item->length(); | |
47 total_size += transport_item->length(); | |
48 output_blob->AppendSharedBlobItem( | |
49 uuid, | |
50 new ShareableBlobDataItem(BlobStorageContext::GetAndIncrementItemId(), | |
51 std::move(transport_item))); | |
52 current_browser_index++; | |
53 } else if (type == DataElement::TYPE_BLOB) { | |
54 BlobEntry* ref_entry = registry->GetEntry(transport_item->blob_uuid()); | |
55 | |
56 if (!ref_entry || BlobStatusIsError(ref_entry->status) || | |
57 transport_item->blob_uuid() == uuid) { | |
58 contains_broken_references = true; | |
59 return; | |
60 } | |
61 | |
62 if (ref_entry->status == BlobStatus::PENDING && | |
63 dependent_blob_uuids.find(transport_item->blob_uuid()) == | |
64 dependent_blob_uuids.end()) { | |
65 pending_dependent_blobs.push_back( | |
66 std::make_pair(transport_item->blob_uuid(), ref_entry)); | |
67 dependent_blob_uuids.insert(transport_item->blob_uuid()); | |
68 } | |
69 | |
70 uint64_t length = | |
71 transport_item->length() == std::numeric_limits<uint64_t>::max() | |
72 ? ref_entry->data.total_size() | |
73 : transport_item->length(); | |
74 | |
75 total_size += length; | |
76 | |
77 // If we're referencing the whole blob, then we don't need to slice. | |
78 if (transport_item->offset() == 0 && | |
79 length == ref_entry->data.total_size()) { | |
80 for (const auto& shareable_item : ref_entry->data.items()) { | |
81 output_blob->AppendSharedBlobItem(uuid, shareable_item); | |
82 ++current_browser_index; | |
83 } | |
84 continue; | |
85 } | |
86 | |
87 BlobSlice slice(ref_entry->data, transport_item->offset(), | |
88 transport_item->length()); | |
89 | |
90 if (slice.has_sliced_first_memory_item) { | |
91 copies.push_back(ItemCopyEntry(slice.first_source_item, | |
92 slice.first_item_slice_offset, | |
93 slice.dest_items.front())); | |
94 } | |
95 | |
96 memory_needed += slice.copying_memory_size; | |
97 for (const auto& shareable_item : slice.dest_items) { | |
98 output_blob->AppendSharedBlobItem(uuid, std::move(shareable_item)); | |
Marijn Kruisselbrink
2016/07/08 23:37:37
This std::move does nothing, as shareable_item is
dmurph
2016/07/11 23:33:28
I wish there was a compiler warning for this haha.
Marijn Kruisselbrink
2016/07/12 21:33:06
There is http://clang.llvm.org/extra/clang-tidy/ch
| |
99 ++current_browser_index; | |
100 } | |
101 | |
102 if (slice.has_sliced_last_memory_item) { | |
103 copies.push_back( | |
104 ItemCopyEntry(slice.last_source_item, 0, slice.dest_items.back())); | |
105 } | |
106 } else { | |
107 if (type == DataElement::TYPE_FILE) { | |
108 contains_pending_content = | |
109 transport_item->path().value() == | |
110 BlobDataBuilder::kAppendFutureFileTemporaryFileName; | |
111 } | |
112 total_size += transport_item->length(); | |
113 output_blob->AppendSharedBlobItem( | |
114 uuid, | |
115 new ShareableBlobDataItem(BlobStorageContext::GetAndIncrementItemId(), | |
116 std::move(transport_item))); | |
117 current_browser_index++; | |
118 } | |
119 } | |
120 } | |
121 | |
122 BlobFlattener::~BlobFlattener() {} | |
123 | |
124 } // namespace storage | |
OLD | NEW |