Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "storage/browser/blob/blob_memory_controller.h" | 5 #include "storage/browser/blob/blob_memory_controller.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| (...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 485 std::vector<scoped_refptr<ShareableBlobDataItem>> unreserved_file_items, | 485 std::vector<scoped_refptr<ShareableBlobDataItem>> unreserved_file_items, |
| 486 const FileQuotaRequestCallback& done_callback) { | 486 const FileQuotaRequestCallback& done_callback) { |
| 487 pending_file_quota_tasks_.push_back(base::MakeUnique<FileQuotaAllocationTask>( | 487 pending_file_quota_tasks_.push_back(base::MakeUnique<FileQuotaAllocationTask>( |
| 488 this, std::move(unreserved_file_items), done_callback)); | 488 this, std::move(unreserved_file_items), done_callback)); |
| 489 pending_file_quota_tasks_.back()->set_my_list_position( | 489 pending_file_quota_tasks_.back()->set_my_list_position( |
| 490 --pending_file_quota_tasks_.end()); | 490 --pending_file_quota_tasks_.end()); |
| 491 return pending_file_quota_tasks_.back()->GetWeakPtr(); | 491 return pending_file_quota_tasks_.back()->GetWeakPtr(); |
| 492 } | 492 } |
| 493 | 493 |
| 494 void BlobMemoryController::NotifyMemoryItemsUsed( | 494 void BlobMemoryController::NotifyMemoryItemsUsed( |
| 495 std::vector<scoped_refptr<ShareableBlobDataItem>>& items) { | 495 const std::vector<scoped_refptr<ShareableBlobDataItem>>& items) { |
| 496 for (const auto& item : items) { | 496 for (const auto& item : items) { |
| 497 DCHECK_EQ(DataElement::TYPE_BYTES, item->item()->type()); | 497 if (item->item()->type() != DataElement::TYPE_BYTES || |
| 498 DCHECK_EQ(ShareableBlobDataItem::POPULATED_WITH_QUOTA, item->state()); | 498 item->state() != ShareableBlobDataItem::POPULATED_WITH_QUOTA) { |
| 499 continue; | |
| 500 } | |
| 499 // We don't want to re-add the item if we're currently paging it to disk. | 501 // We don't want to re-add the item if we're currently paging it to disk. |
| 500 if (items_paging_to_file_.find(item->item_id()) != | 502 if (items_paging_to_file_.find(item->item_id()) != |
| 501 items_paging_to_file_.end()) { | 503 items_paging_to_file_.end()) { |
| 502 return; | 504 return; |
| 503 } | 505 } |
| 504 auto iterator = populated_memory_items_.Get(item->item_id()); | 506 auto iterator = populated_memory_items_.Get(item->item_id()); |
| 505 if (iterator == populated_memory_items_.end()) { | 507 if (iterator == populated_memory_items_.end()) { |
| 506 populated_memory_items_bytes_ += | 508 populated_memory_items_bytes_ += |
| 507 static_cast<size_t>(item->item()->length()); | 509 static_cast<size_t>(item->item()->length()); |
| 508 populated_memory_items_.Put(item->item_id(), item.get()); | 510 populated_memory_items_.Put(item->item_id(), item.get()); |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 692 pending_memory_quota_total_size_ - in_flight_memory_used_; | 694 pending_memory_quota_total_size_ - in_flight_memory_used_; |
| 693 } | 695 } |
| 694 if (limits_.max_blob_disk_space < total_disk_used) | 696 if (limits_.max_blob_disk_space < total_disk_used) |
| 695 return 0; | 697 return 0; |
| 696 return limits_.max_blob_disk_space - total_disk_used; | 698 return limits_.max_blob_disk_space - total_disk_used; |
| 697 } | 699 } |
| 698 | 700 |
| 699 void BlobMemoryController::GrantMemoryAllocations( | 701 void BlobMemoryController::GrantMemoryAllocations( |
| 700 std::vector<scoped_refptr<ShareableBlobDataItem>>* items, | 702 std::vector<scoped_refptr<ShareableBlobDataItem>>* items, |
| 701 size_t total_bytes) { | 703 size_t total_bytes) { |
| 704 // These metrics let us calculate the global distribution of blob storage by | |
| 705 // subtracting the histograms. | |
| 706 UMA_HISTOGRAM_COUNTS("Storage.Blob.StorageSizeBeforeAppend", | |
| 707 blob_memory_used_ / 1024); | |
| 702 blob_memory_used_ += total_bytes; | 708 blob_memory_used_ += total_bytes; |
| 709 UMA_HISTOGRAM_COUNTS("Storage.Blob.StorageSizeAfterAppend", | |
| 710 blob_memory_used_ / 1024); | |
|
kinuko
2016/11/17 07:53:01
Hmm, "BeforeAppend" and "AfterAppend" now look a b
dmurph
2016/11/17 18:05:23
I'll update the histograms in a follow up CL.
| |
| 711 | |
| 703 for (auto& item : *items) { | 712 for (auto& item : *items) { |
| 704 item->set_state(ShareableBlobDataItem::QUOTA_GRANTED); | 713 item->set_state(ShareableBlobDataItem::QUOTA_GRANTED); |
| 705 item->set_memory_allocation(base::MakeUnique<MemoryAllocation>( | 714 item->set_memory_allocation(base::MakeUnique<MemoryAllocation>( |
| 706 weak_factory_.GetWeakPtr(), item->item_id(), | 715 weak_factory_.GetWeakPtr(), item->item_id(), |
| 707 base::checked_cast<size_t>(item->item()->length()))); | 716 base::checked_cast<size_t>(item->item()->length()))); |
| 708 } | 717 } |
| 709 } | 718 } |
| 710 | 719 |
| 711 void BlobMemoryController::RevokeMemoryAllocation(uint64_t item_id, | 720 void BlobMemoryController::RevokeMemoryAllocation(uint64_t item_id, |
| 712 size_t length) { | 721 size_t length) { |
| 713 DCHECK_LE(length, blob_memory_used_); | 722 DCHECK_LE(length, blob_memory_used_); |
| 723 | |
| 724 // These metrics let us calculate the global distribution of blob storage by | |
| 725 // subtracting the histograms. | |
| 726 UMA_HISTOGRAM_COUNTS("Storage.Blob.StorageSizeBeforeAppend", | |
| 727 blob_memory_used_ / 1024); | |
| 714 blob_memory_used_ -= length; | 728 blob_memory_used_ -= length; |
| 729 UMA_HISTOGRAM_COUNTS("Storage.Blob.StorageSizeAfterAppend", | |
| 730 blob_memory_used_ / 1024); | |
| 731 | |
| 715 auto iterator = populated_memory_items_.Get(item_id); | 732 auto iterator = populated_memory_items_.Get(item_id); |
| 716 if (iterator != populated_memory_items_.end()) { | 733 if (iterator != populated_memory_items_.end()) { |
| 717 DCHECK_GE(populated_memory_items_bytes_, length); | 734 DCHECK_GE(populated_memory_items_bytes_, length); |
| 718 populated_memory_items_bytes_ -= length; | 735 populated_memory_items_bytes_ -= length; |
| 719 populated_memory_items_.Erase(iterator); | 736 populated_memory_items_.Erase(iterator); |
| 720 } | 737 } |
| 721 MaybeGrantPendingMemoryRequests(); | 738 MaybeGrantPendingMemoryRequests(); |
| 722 } | 739 } |
| 723 | 740 |
| 724 void BlobMemoryController::OnBlobFileDelete(uint64_t size, | 741 void BlobMemoryController::OnBlobFileDelete(uint64_t size, |
| 725 const FilePath& path) { | 742 const FilePath& path) { |
| 726 DCHECK_LE(size, disk_used_); | 743 DCHECK_LE(size, disk_used_); |
| 727 disk_used_ -= size; | 744 disk_used_ -= size; |
| 728 } | 745 } |
| 729 | 746 |
| 730 } // namespace storage | 747 } // namespace storage |
| OLD | NEW |