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

Side by Side 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: 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 unified diff | Download patch
OLDNEW
(Empty)
1 // TODO: Insert description here. (generated by dmurph)
2
3 #include "storage/browser/blob/internal_blob_data.h"
4
5 #include "base/containers/hash_tables.h"
6 #include "base/metrics/histogram.h"
7 #include "storage/browser/blob/blob_data_item.h"
8 #include "storage/common/data_element.h"
9
10 namespace storage {
11 namespace {
12 size_t GetNonsharedMemoryUsage(
13 const std::vector<scoped_refptr<ShareableBlobDataItem>>& items) {
14 size_t memory = 0;
15 base::hash_set<void*> seen_items;
16 for (const auto& data_item : items) {
17 if (data_item->item()->type() == DataElement::TYPE_BYTES &&
18 data_item->referencing_blobs().size() == 1) {
19 if (seen_items.find(data_item.get()) != seen_items.end()) {
20 continue;
21 }
22 memory += data_item->item()->length();
23 seen_items.insert(data_item.get());
24 }
25 }
26 return memory;
27 }
28 void RemoveBlobFromShareableItems(
29 const std::string& blob_uuid,
30 std::vector<scoped_refptr<ShareableBlobDataItem>>& items) {
31 for (auto& data_item : items) {
32 data_item->referencing_blobs().erase(blob_uuid);
33 }
34 }
35 } // namespace
36
37 InternalBlobData::Builder::Builder() {
38 }
39 InternalBlobData::Builder::~Builder() {
40 }
41
42 void InternalBlobData::Builder::AppendSharedBlobItem(
43 scoped_refptr<ShareableBlobDataItem> item) {
44 DCHECK(item);
45 items_.push_back(item);
46 }
47
48 void InternalBlobData::Builder::RemoveBlobFromShareableItems(
49 const std::string& blob_uuid) {
50 ::storage::RemoveBlobFromShareableItems(blob_uuid, items_);
51 }
52
53 size_t InternalBlobData::Builder::GetNonsharedMemoryUsage() const {
54 return ::storage::GetNonsharedMemoryUsage(items_);
55 }
56
57 InternalBlobData::InternalBlobData(scoped_ptr<Builder> builder) {
58 content_type_.swap(builder->content_type_);
59 content_disposition_.swap(builder->content_disposition_);
60 items_.swap(builder->items_);
61 }
62
63 InternalBlobData::~InternalBlobData() {
64 }
65
66 const std::vector<scoped_refptr<ShareableBlobDataItem>>&
67 InternalBlobData::items() const {
68 return items_;
69 }
70 const std::string& InternalBlobData::content_type() const {
71 return content_type_;
72 }
73 const std::string& InternalBlobData::content_disposition() const {
74 return content_disposition_;
75 }
76
77 void InternalBlobData::RemoveBlobFromShareableItems(
78 const std::string& blob_uuid) {
79 ::storage::RemoveBlobFromShareableItems(blob_uuid, items_);
80 }
81
82 size_t InternalBlobData::GetNonsharedMemoryUsage() const {
83 return ::storage::GetNonsharedMemoryUsage(items_);
84 }
85
86 } // namespace storage
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698