Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(91)

Unified Diff: storage/browser/blob/internal_blob_data.cc

Issue 895933007: [Storage] Blob items are now shared between blobs. Ready for disk swap. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleanup and added one more histogram Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « storage/browser/blob/internal_blob_data.h ('k') | storage/browser/blob/shareable_blob_data_item.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
new file mode 100644
index 0000000000000000000000000000000000000000..8107765c847c707d9e9bc2ad48d681b048470f53
--- /dev/null
+++ b/storage/browser/blob/internal_blob_data.cc
@@ -0,0 +1,110 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "storage/browser/blob/internal_blob_data.h"
+
+#include "base/containers/hash_tables.h"
+#include "base/metrics/histogram.h"
+#include "storage/browser/blob/blob_data_item.h"
+#include "storage/common/data_element.h"
+
+namespace storage {
+
+InternalBlobData::Builder::Builder() : data_(new InternalBlobData()) {
+}
+InternalBlobData::Builder::~Builder() {
+}
+
+void InternalBlobData::Builder::AppendSharedBlobItem(
+ 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);
+}
+
+void InternalBlobData::Builder::set_content_type(
+ const std::string& content_type) {
+ DCHECK(data_);
+ data_->content_type_ = content_type;
+}
+
+void InternalBlobData::Builder::set_content_disposition(
+ const std::string& content_disposition) {
+ DCHECK(data_);
+ data_->content_disposition_ = content_disposition;
+}
+
+size_t InternalBlobData::Builder::GetNonsharedMemoryUsage() const {
+ DCHECK(data_);
+ return data_->GetUnsharedMemoryUsage();
+}
+
+scoped_ptr<InternalBlobData> InternalBlobData::Builder::Build() {
+ DCHECK(data_);
+ return data_.Pass();
+}
+
+InternalBlobData::InternalBlobData() {
+}
+
+InternalBlobData::~InternalBlobData() {
+}
+
+const std::vector<scoped_refptr<ShareableBlobDataItem>>&
+InternalBlobData::items() const {
+ return items_;
+}
+const std::string& InternalBlobData::content_type() const {
+ return content_type_;
+}
+const std::string& InternalBlobData::content_disposition() const {
+ return content_disposition_;
+}
+
+void InternalBlobData::RemoveBlobFromShareableItems(
+ const std::string& blob_uuid) {
+ for (auto& data_item : items_) {
+ data_item->referencing_blobs().erase(blob_uuid);
+ }
+}
+
+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 ||
+ data_item->referencing_blobs().size() > 1 ||
+ seen_items.find(data_item.get()) != seen_items.end()) {
+ continue;
+ }
+ 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
« no previous file with comments | « storage/browser/blob/internal_blob_data.h ('k') | storage/browser/blob/shareable_blob_data_item.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698