Index: storage/browser/blob/internal_blob_data.cc |
diff --git a/storage/browser/blob/internal_blob_data.cc b/storage/browser/blob/internal_blob_data.cc |
index f52d41c639f98ddc4326aac5de8fbab03e194aad..158aa6e39206c21633867c4b48c2ea106fbb70ef 100644 |
--- a/storage/browser/blob/internal_blob_data.cc |
+++ b/storage/browser/blob/internal_blob_data.cc |
@@ -4,50 +4,63 @@ |
#include "storage/browser/blob/internal_blob_data.h" |
-#include <stddef.h> |
- |
-#include <memory> |
#include <utility> |
+#include "base/callback.h" |
#include "base/containers/hash_tables.h" |
#include "base/metrics/histogram.h" |
+#include "storage/browser/blob/blob_data_handle.h" |
#include "storage/browser/blob/blob_data_item.h" |
+#include "storage/browser/blob/shareable_blob_data_item.h" |
#include "storage/common/data_element.h" |
namespace storage { |
- |
-InternalBlobData::Builder::Builder() : data_(new InternalBlobData()) { |
-} |
-InternalBlobData::Builder::~Builder() { |
+namespace { |
+bool IsBytes(DataElement::Type type) { |
+ return type == DataElement::TYPE_BYTES || |
+ type == DataElement::TYPE_BYTES_DESCRIPTION; |
} |
- |
-void InternalBlobData::Builder::AppendSharedBlobItem( |
+} // namespace |
+ |
+InternalBlobData::ItemCopyEntry::ItemCopyEntry( |
+ scoped_refptr<ShareableBlobDataItem> source_item, |
+ size_t source_item_offset, |
+ scoped_refptr<ShareableBlobDataItem> dest_item) |
+ : source_item(std::move(source_item)), |
+ source_item_offset(source_item_offset), |
+ dest_item(std::move(dest_item)) {} |
+InternalBlobData::ItemCopyEntry::ItemCopyEntry(const ItemCopyEntry&) = default; |
+InternalBlobData::ItemCopyEntry::~ItemCopyEntry() {} |
+ |
+InternalBlobData::BuildingState::BuildingState( |
+ TransportState transport_state, |
+ PopulatationAllowedCallback user_data_population_callback, |
+ size_t num_building_dependent_blobs, |
+ bool memory_quota_needed, |
+ bool file_quota_needed) |
+ : transport_state(transport_state), |
+ user_data_population_callback(user_data_population_callback), |
+ dependent_building_blobs_present(num_building_dependent_blobs > 0), |
+ num_building_dependent_blobs(num_building_dependent_blobs), |
+ memory_quota_needed(memory_quota_needed), |
+ file_quota_needed(file_quota_needed) {} |
+ |
+InternalBlobData::BuildingState::~BuildingState() {} |
+ |
+InternalBlobData::InternalBlobData(const std::string& content_type, |
+ const std::string& content_disposition) |
+ : content_type_(content_type), content_disposition_(content_disposition) {} |
+InternalBlobData::~InternalBlobData() {} |
+ |
+void InternalBlobData::AppendSharedBlobItem( |
+ const std::string& my_uuid, |
scoped_refptr<ShareableBlobDataItem> item) { |
- DCHECK(item); |
- DCHECK(data_); |
- data_->items_.push_back(item); |
-} |
- |
-void InternalBlobData::Builder::RemoveBlobFromShareableItems( |
- const std::string& blob_uuid) { |
- DCHECK(data_); |
- data_->RemoveBlobFromShareableItems(blob_uuid); |
-} |
- |
-size_t InternalBlobData::Builder::GetNonsharedMemoryUsage() const { |
- DCHECK(data_); |
- return data_->GetUnsharedMemoryUsage(); |
-} |
- |
-std::unique_ptr<InternalBlobData> InternalBlobData::Builder::Build() { |
- DCHECK(data_); |
- return std::move(data_); |
-} |
- |
-InternalBlobData::InternalBlobData() { |
-} |
- |
-InternalBlobData::~InternalBlobData() { |
+ if (!items_.empty()) { |
+ offsets_.push_back(size_); |
+ } |
+ size_ += item->item()->length(); |
+ item->referencing_blobs_mutable()->insert(my_uuid); |
+ items_.push_back(std::move(item)); |
} |
const std::vector<scoped_refptr<ShareableBlobDataItem>>& |
@@ -66,32 +79,16 @@ size_t InternalBlobData::GetUnsharedMemoryUsage() const { |
size_t memory = 0; |
base::hash_set<void*> seen_items; |
for (const auto& data_item : items_) { |
- if (data_item->item()->type() != DataElement::TYPE_BYTES || |
+ if (!IsBytes(data_item->item()->type()) || |
data_item->referencing_blobs().size() > 1 || |
seen_items.find(data_item.get()) != seen_items.end()) { |
continue; |
} |
+ LOG(ERROR) << "no one else has item " << data_item->item_id(); |
memory += data_item->item()->length(); |
seen_items.insert(data_item.get()); |
} |
return memory; |
} |
-void InternalBlobData::GetMemoryUsage(size_t* total_memory, |
- size_t* unshared_memory) { |
- *total_memory = 0; |
- *unshared_memory = 0; |
- base::hash_set<void*> seen_items; |
- for (const auto& data_item : items_) { |
- if (data_item->item()->type() == DataElement::TYPE_BYTES) { |
- *total_memory += data_item->item()->length(); |
- if (data_item->referencing_blobs().size() == 1 && |
- seen_items.find(data_item.get()) == seen_items.end()) { |
- *unshared_memory += data_item->item()->length(); |
- seen_items.insert(data_item.get()); |
- } |
- } |
- } |
-} |
- |
} // namespace storage |