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/blob_entry.cc

Issue 2448353002: [BlobAsync] Moving async handling into BlobStorageContext & quota out. (Closed)
Patch Set: comments Created 4 years, 1 month 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 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <utility>
6
7 #include "base/callback.h"
8 #include "base/containers/hash_tables.h"
9 #include "base/metrics/histogram.h"
10 #include "storage/browser/blob/blob_data_handle.h"
11 #include "storage/browser/blob/blob_data_item.h"
12 #include "storage/browser/blob/blob_entry.h"
13 #include "storage/browser/blob/shareable_blob_data_item.h"
14 #include "storage/common/data_element.h"
15
16 namespace storage {
17 namespace {
18 bool IsBytes(DataElement::Type type) {
19 return type == DataElement::TYPE_BYTES ||
20 type == DataElement::TYPE_BYTES_DESCRIPTION;
21 }
22 } // namespace
23
24 BlobEntry::ItemCopyEntry::ItemCopyEntry(
25 scoped_refptr<ShareableBlobDataItem> source_item,
26 size_t source_item_offset,
27 scoped_refptr<ShareableBlobDataItem> dest_item)
28 : source_item(std::move(source_item)),
29 source_item_offset(source_item_offset),
30 dest_item(std::move(dest_item)) {}
31
32 BlobEntry::ItemCopyEntry::ItemCopyEntry(ItemCopyEntry&& other) = default;
33 BlobEntry::ItemCopyEntry& BlobEntry::ItemCopyEntry::operator=(
34 BlobEntry::ItemCopyEntry&& rhs) = default;
35 BlobEntry::ItemCopyEntry::~ItemCopyEntry() {}
36
37 BlobEntry::BuildingState::BuildingState(
38 bool transport_items_present,
39 TransportAllowedCallback transport_allowed_callback,
40 size_t num_building_dependent_blobs)
41 : transport_items_present(transport_items_present),
42 transport_allowed_callback(transport_allowed_callback),
43 num_building_dependent_blobs(num_building_dependent_blobs) {}
44
45 BlobEntry::BuildingState::~BuildingState() {}
46
47 BlobEntry::BlobEntry(const std::string& content_type,
48 const std::string& content_disposition)
49 : content_type_(content_type), content_disposition_(content_disposition) {}
50 BlobEntry::~BlobEntry() {}
51
52 void BlobEntry::AppendSharedBlobItem(
53 const std::string& my_uuid,
54 scoped_refptr<ShareableBlobDataItem> item) {
55 DCHECK(item);
56 if (!items_.empty()) {
57 offsets_.push_back(size_);
58 }
59 size_ += item->item()->length();
60 item->referencing_blobs_mutable()->insert(my_uuid);
61 items_.push_back(std::move(item));
62 }
63
64 const std::vector<scoped_refptr<ShareableBlobDataItem>>& BlobEntry::items()
65 const {
66 return items_;
67 }
68
69 void BlobEntry::RemoveBlobFromShareableItems(const std::string& blob_uuid) {
70 for (auto& data_item : items_) {
71 data_item->referencing_blobs_mutable()->erase(blob_uuid);
72 }
73 }
74
75 size_t BlobEntry::GetUnsharedMemoryUsage() const {
76 size_t memory = 0;
77 base::hash_set<void*> seen_items;
78 for (const auto& data_item : items_) {
79 if (!IsBytes(data_item->item()->type()) ||
80 data_item->referencing_blobs().size() > 1 ||
81 seen_items.find(data_item.get()) != seen_items.end()) {
82 continue;
83 }
84 memory += data_item->item()->length();
85 seen_items.insert(data_item.get());
86 }
87 return memory;
88 }
89
90 void BlobEntry::ClearItems() {
91 items_.clear();
92 }
93
94 void BlobEntry::ClearOffsets() {
95 offsets_.clear();
96 }
97
98 } // namespace storage
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698