OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include <utility> |
| 6 |
| 7 #include "base/callback.h" |
| 8 #include "base/containers/hash_tables.h" |
| 9 #include "base/metrics/histogram.h" |
| 10 #include "storage/browser/blob/blob_data_handle.h" |
| 11 #include "storage/browser/blob/blob_data_item.h" |
| 12 #include "storage/browser/blob/blob_entry.h" |
| 13 #include "storage/browser/blob/shareable_blob_data_item.h" |
| 14 #include "storage/common/data_element.h" |
| 15 |
| 16 namespace storage { |
| 17 namespace { |
| 18 bool IsBytes(DataElement::Type type) { |
| 19 return type == DataElement::TYPE_BYTES || |
| 20 type == DataElement::TYPE_BYTES_DESCRIPTION; |
| 21 } |
| 22 } // namespace |
| 23 |
| 24 BlobEntry::ItemCopyEntry::ItemCopyEntry( |
| 25 scoped_refptr<ShareableBlobDataItem> source_item, |
| 26 size_t source_item_offset, |
| 27 scoped_refptr<ShareableBlobDataItem> dest_item) |
| 28 : source_item(std::move(source_item)), |
| 29 source_item_offset(source_item_offset), |
| 30 dest_item(std::move(dest_item)) {} |
| 31 |
| 32 BlobEntry::ItemCopyEntry::ItemCopyEntry(ItemCopyEntry&& other) = default; |
| 33 BlobEntry::ItemCopyEntry& BlobEntry::ItemCopyEntry::operator=( |
| 34 BlobEntry::ItemCopyEntry&& rhs) = default; |
| 35 BlobEntry::ItemCopyEntry::~ItemCopyEntry() {} |
| 36 |
| 37 BlobEntry::BuildingState::BuildingState( |
| 38 bool transport_items_present, |
| 39 PopulatationAllowedCallback can_populate_callback, |
| 40 size_t num_building_dependent_blobs, |
| 41 bool memory_quota_needed) |
| 42 : transport_items_present(transport_items_present), |
| 43 can_populate_callback(can_populate_callback), |
| 44 dependent_building_blobs_present(num_building_dependent_blobs > 0), |
| 45 num_building_dependent_blobs(num_building_dependent_blobs), |
| 46 memory_quota_needed(memory_quota_needed) {} |
| 47 |
| 48 BlobEntry::BuildingState::~BuildingState() {} |
| 49 |
| 50 BlobEntry::BlobEntry(const std::string& content_type, |
| 51 const std::string& content_disposition) |
| 52 : content_type_(content_type), content_disposition_(content_disposition) {} |
| 53 BlobEntry::~BlobEntry() {} |
| 54 |
| 55 void BlobEntry::AppendSharedBlobItem( |
| 56 const std::string& my_uuid, |
| 57 scoped_refptr<ShareableBlobDataItem> item) { |
| 58 DCHECK(item); |
| 59 if (!items_.empty()) { |
| 60 offsets_.push_back(size_); |
| 61 } |
| 62 size_ += item->item()->length(); |
| 63 item->referencing_blobs_mutable()->insert(my_uuid); |
| 64 items_.push_back(std::move(item)); |
| 65 } |
| 66 |
| 67 const std::vector<scoped_refptr<ShareableBlobDataItem>>& |
| 68 BlobEntry::items() const { |
| 69 return items_; |
| 70 } |
| 71 |
| 72 void BlobEntry::RemoveBlobFromShareableItems( |
| 73 const std::string& blob_uuid) { |
| 74 for (auto& data_item : items_) { |
| 75 data_item->referencing_blobs_mutable()->erase(blob_uuid); |
| 76 } |
| 77 } |
| 78 |
| 79 size_t BlobEntry::GetUnsharedMemoryUsage() const { |
| 80 size_t memory = 0; |
| 81 base::hash_set<void*> seen_items; |
| 82 for (const auto& data_item : items_) { |
| 83 if (!IsBytes(data_item->item()->type()) || |
| 84 data_item->referencing_blobs().size() > 1 || |
| 85 seen_items.find(data_item.get()) != seen_items.end()) { |
| 86 continue; |
| 87 } |
| 88 memory += data_item->item()->length(); |
| 89 seen_items.insert(data_item.get()); |
| 90 } |
| 91 return memory; |
| 92 } |
| 93 |
| 94 } // namespace storage |
OLD | NEW |