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 TransportAllowedCallback transport_allowed_callback, |
| 40 size_t num_building_dependent_blobs, |
| 41 bool memory_quota_needed) |
| 42 : transport_items_present(transport_items_present), |
| 43 transport_allowed_callback(transport_allowed_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>>& BlobEntry::items() |
| 68 const { |
| 69 return items_; |
| 70 } |
| 71 |
| 72 void BlobEntry::RemoveBlobFromShareableItems(const std::string& blob_uuid) { |
| 73 for (auto& data_item : items_) { |
| 74 data_item->referencing_blobs_mutable()->erase(blob_uuid); |
| 75 } |
| 76 } |
| 77 |
| 78 size_t BlobEntry::GetUnsharedMemoryUsage() const { |
| 79 size_t memory = 0; |
| 80 base::hash_set<void*> seen_items; |
| 81 for (const auto& data_item : items_) { |
| 82 if (!IsBytes(data_item->item()->type()) || |
| 83 data_item->referencing_blobs().size() > 1 || |
| 84 seen_items.find(data_item.get()) != seen_items.end()) { |
| 85 continue; |
| 86 } |
| 87 memory += data_item->item()->length(); |
| 88 seen_items.insert(data_item.get()); |
| 89 } |
| 90 return memory; |
| 91 } |
| 92 |
| 93 } // namespace storage |
OLD | NEW |