| Index: storage/browser/blob/blob_storage_context.cc
|
| diff --git a/storage/browser/blob/blob_storage_context.cc b/storage/browser/blob/blob_storage_context.cc
|
| index cf190aaba43e8d7370209e295da81f23a9758fb5..53924642ffdfd749a153f4ad2e775916663b0763 100644
|
| --- a/storage/browser/blob/blob_storage_context.cc
|
| +++ b/storage/browser/blob/blob_storage_context.cc
|
| @@ -27,7 +27,13 @@ namespace storage {
|
| using BlobRegistryEntry = BlobStorageRegistry::Entry;
|
| using BlobState = BlobStorageRegistry::BlobState;
|
|
|
| -BlobStorageContext::BlobStorageContext() : memory_usage_(0) {}
|
| +BlobStorageContext::BlobStorageContext() {}
|
| +
|
| +BlobStorageContext::BlobStorageContext(
|
| + bool enable_disk,
|
| + const base::FilePath& blob_storage_dir,
|
| + scoped_refptr<base::TaskRunner> file_runner)
|
| + : memory_controller_(enable_disk, blob_storage_dir, file_runner) {}
|
|
|
| BlobStorageContext::~BlobStorageContext() {
|
| }
|
| @@ -221,6 +227,11 @@ void BlobStorageContext::DecrementBlobRefCount(const std::string& uuid) {
|
| }
|
| DCHECK_LE(memory_freeing, memory_usage_);
|
| memory_usage_ -= memory_freeing;
|
| + for (const auto& item_refptr : entry->data->items_) {
|
| + if (item_refptr->num_referencing_blob() == 0) {
|
| + memory_controller_.RemoveBlobItemInRecents(item_refptr->item_id());
|
| + }
|
| + }
|
| registry_.DeleteEntry(uuid);
|
| }
|
| }
|
| @@ -268,8 +279,8 @@ bool BlobStorageContext::AppendAllocatedBlobItem(
|
| break;
|
| }
|
| memory_usage_ += length;
|
| - target_blob_builder->AppendSharedBlobItem(
|
| - new ShareableBlobDataItem(target_blob_uuid, blob_item));
|
| + target_blob_builder->AppendSharedBlobItem(new ShareableBlobDataItem(
|
| + target_blob_uuid, GetAndIncrementItemId(), blob_item));
|
| break;
|
| case DataElement::TYPE_FILE: {
|
| bool full_file = (length == std::numeric_limits<uint64>::max());
|
| @@ -278,8 +289,8 @@ bool BlobStorageContext::AppendAllocatedBlobItem(
|
| UMA_HISTOGRAM_COUNTS("Storage.BlobItemSize.File",
|
| (length - offset) / 1024);
|
| }
|
| - target_blob_builder->AppendSharedBlobItem(
|
| - new ShareableBlobDataItem(target_blob_uuid, blob_item));
|
| + target_blob_builder->AppendSharedBlobItem(new ShareableBlobDataItem(
|
| + target_blob_uuid, GetAndIncrementItemId(), blob_item));
|
| break;
|
| }
|
| case DataElement::TYPE_FILE_FILESYSTEM: {
|
| @@ -290,8 +301,8 @@ bool BlobStorageContext::AppendAllocatedBlobItem(
|
| UMA_HISTOGRAM_COUNTS("Storage.BlobItemSize.FileSystem",
|
| (length - offset) / 1024);
|
| }
|
| - target_blob_builder->AppendSharedBlobItem(
|
| - new ShareableBlobDataItem(target_blob_uuid, blob_item));
|
| + target_blob_builder->AppendSharedBlobItem(new ShareableBlobDataItem(
|
| + target_blob_uuid, GetAndIncrementItemId(), blob_item));
|
| break;
|
| }
|
| case DataElement::TYPE_BLOB: {
|
| @@ -312,8 +323,8 @@ bool BlobStorageContext::AppendAllocatedBlobItem(
|
| case DataElement::TYPE_DISK_CACHE_ENTRY: {
|
| UMA_HISTOGRAM_COUNTS("Storage.BlobItemSize.CacheEntry",
|
| (length - offset) / 1024);
|
| - target_blob_builder->AppendSharedBlobItem(
|
| - new ShareableBlobDataItem(target_blob_uuid, blob_item));
|
| + target_blob_builder->AppendSharedBlobItem(new ShareableBlobDataItem(
|
| + target_blob_uuid, GetAndIncrementItemId(), blob_item));
|
| break;
|
| }
|
| case DataElement::TYPE_BYTES_DESCRIPTION:
|
| @@ -378,8 +389,9 @@ bool BlobStorageContext::AppendBlob(
|
| element->SetToBytes(item.bytes() + offset,
|
| static_cast<int64>(new_length));
|
| memory_usage_ += new_length;
|
| - target_blob_builder->AppendSharedBlobItem(new ShareableBlobDataItem(
|
| - target_blob_uuid, new BlobDataItem(element.Pass())));
|
| + target_blob_builder->AppendSharedBlobItem(
|
| + new ShareableBlobDataItem(target_blob_uuid, GetAndIncrementItemId(),
|
| + new BlobDataItem(element.Pass())));
|
| } break;
|
| case DataElement::TYPE_FILE: {
|
| DCHECK_NE(item.length(), std::numeric_limits<uint64>::max())
|
| @@ -391,7 +403,7 @@ bool BlobStorageContext::AppendBlob(
|
| new_length,
|
| item.expected_modification_time());
|
| target_blob_builder->AppendSharedBlobItem(new ShareableBlobDataItem(
|
| - target_blob_uuid,
|
| + target_blob_uuid, GetAndIncrementItemId(),
|
| new BlobDataItem(element.Pass(), item.data_handle_)));
|
| } break;
|
| case DataElement::TYPE_FILE_FILESYSTEM: {
|
| @@ -401,15 +413,16 @@ bool BlobStorageContext::AppendBlob(
|
| element->SetToFileSystemUrlRange(item.filesystem_url(),
|
| item.offset() + offset, new_length,
|
| item.expected_modification_time());
|
| - target_blob_builder->AppendSharedBlobItem(new ShareableBlobDataItem(
|
| - target_blob_uuid, new BlobDataItem(element.Pass())));
|
| + target_blob_builder->AppendSharedBlobItem(
|
| + new ShareableBlobDataItem(target_blob_uuid, GetAndIncrementItemId(),
|
| + new BlobDataItem(element.Pass())));
|
| } break;
|
| case DataElement::TYPE_DISK_CACHE_ENTRY: {
|
| scoped_ptr<DataElement> element(new DataElement());
|
| element->SetToDiskCacheEntryRange(item.offset() + offset,
|
| new_length);
|
| target_blob_builder->AppendSharedBlobItem(new ShareableBlobDataItem(
|
| - target_blob_uuid,
|
| + target_blob_uuid, GetAndIncrementItemId(),
|
| new BlobDataItem(element.Pass(), item.data_handle_,
|
| item.disk_cache_entry(),
|
| item.disk_cache_stream_index())));
|
| @@ -476,4 +489,14 @@ bool BlobStorageContext::CleanupCanceledAsyncBlobTransfer(
|
| return true;
|
| }
|
|
|
| +uint64_t BlobStorageContext::GetAndIncrementItemId() {
|
| + return next_item_id_++;
|
| +}
|
| +
|
| +void BlobStorageContext::UpdateItemsInRecents(BlobRegistryEntry* entry) {
|
| + for (const auto& item_refptr : entry->data->items_) {
|
| + memory_controller_.UpdateBlobItemInRecents(item_refptr.get());
|
| + }
|
| +}
|
| +
|
| } // namespace storage
|
|
|