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

Side by Side Diff: storage/browser/blob/shareable_blob_data_item.cc

Issue 2339933004: [BlobStorage] BlobMemoryController & tests (Closed)
Patch Set: rebase Created 4 years, 3 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 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/shareable_blob_data_item.h" 5 #include "storage/browser/blob/shareable_blob_data_item.h"
6 6
7 #include "storage/browser/blob/blob_data_item.h" 7 #include "storage/browser/blob/blob_data_item.h"
8 8
9 namespace storage { 9 namespace storage {
10 namespace {
10 11
11 ShareableBlobDataItem::ShareableBlobDataItem( 12 uint64_t GetAndIncrementItemId() {
12 const std::string& blob_uuid, 13 static uint64_t sNextItemId = 0;
13 const scoped_refptr<BlobDataItem>& item) 14 return sNextItemId++;
14 : item_(item) { 15 }
16
17 } // namespace
18
19 ShareableBlobDataItem::ShareableBlobDataItem(const std::string& target_uuid,
20 scoped_refptr<BlobDataItem> item,
21 ShareableBlobDataItem::State state)
22 : item_id_(GetAndIncrementItemId()), state_(state), item_(std::move(item)) {
15 DCHECK_NE(item_->type(), DataElement::TYPE_BLOB); 23 DCHECK_NE(item_->type(), DataElement::TYPE_BLOB);
16 referencing_blobs_.insert(blob_uuid); 24 referencing_blobs_.insert(target_uuid);
17 } 25 }
18 26
19 ShareableBlobDataItem::~ShareableBlobDataItem() { 27 ShareableBlobDataItem::~ShareableBlobDataItem() {
20 } 28 }
21 29
22 const scoped_refptr<BlobDataItem>& ShareableBlobDataItem::item() { 30 const scoped_refptr<BlobDataItem>& ShareableBlobDataItem::item() const {
23 return item_; 31 return item_;
24 } 32 }
25 33
34 void PrintTo(const ShareableBlobDataItem& x, ::std::ostream* os) {
35 *os << "<ShareableBlobDataItem>{ item_id: " << x.item_id_
36 << ", state: " << x.state_ << ", item: ";
37 PrintTo(*x.item_, os);
38 *os << ", referencing_blobs: [";
39 for (const std::string& uuid : x.referencing_blobs_) {
pwnall 2016/09/21 09:03:35 Why do you need non-const access (referencing_blob
dmurph 2016/09/21 23:45:52 Done.
40 *os << uuid << ", ";
41 }
42 *os << "]}";
43 }
44
45 bool operator==(const ShareableBlobDataItem& a,
46 const ShareableBlobDataItem& b) {
47 return a.item_id() == b.item_id() && *a.item() == *b.item() &&
48 a.referencing_blobs() == b.referencing_blobs();
49 }
50
51 bool operator!=(const ShareableBlobDataItem& a,
52 const ShareableBlobDataItem& b) {
53 return !(a == b);
54 }
55
26 } // namespace storage 56 } // namespace storage
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698