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

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

Issue 2339933004: [BlobStorage] BlobMemoryController & tests (Closed)
Patch Set: format and hopefully windows fix Created 4 years, 2 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 {
11
12 uint64_t GetAndIncrementItemId() {
13 static uint64_t sNextItemId = 0;
14 return sNextItemId++;
15 }
16
17 } // namespace
10 18
11 ShareableBlobDataItem::ShareableBlobDataItem( 19 ShareableBlobDataItem::ShareableBlobDataItem(
12 const std::string& blob_uuid, 20 const std::string& referencing_blob_uuid,
13 const scoped_refptr<BlobDataItem>& item) 21 scoped_refptr<BlobDataItem> item,
14 : item_(item) { 22 ShareableBlobDataItem::State state)
23 : item_id_(GetAndIncrementItemId()), state_(state), item_(std::move(item)) {
15 DCHECK_NE(item_->type(), DataElement::TYPE_BLOB); 24 DCHECK_NE(item_->type(), DataElement::TYPE_BLOB);
16 referencing_blobs_.insert(blob_uuid); 25 referencing_blobs_.insert(referencing_blob_uuid);
17 } 26 }
18 27
19 ShareableBlobDataItem::~ShareableBlobDataItem() { 28 ShareableBlobDataItem::~ShareableBlobDataItem() {
20 } 29 }
21 30
22 const scoped_refptr<BlobDataItem>& ShareableBlobDataItem::item() { 31 void ShareableBlobDataItem::set_item(scoped_refptr<BlobDataItem> item) {
23 return item_; 32 item_ = std::move(item);
33 }
34
35 void PrintTo(const ShareableBlobDataItem& x, ::std::ostream* os) {
36 *os << "<ShareableBlobDataItem>{ item_id: " << x.item_id_
37 << ", state: " << x.state_ << ", item: ";
38 PrintTo(*x.item_, os);
39 *os << ", referencing_blobs: [";
40 for (const std::string& uuid : x.referencing_blobs()) {
41 *os << uuid << ", ";
42 }
43 *os << "]}";
44 }
45
46 bool operator==(const ShareableBlobDataItem& a,
47 const ShareableBlobDataItem& b) {
48 return a.item_id() == b.item_id() && *a.item() == *b.item() &&
49 a.referencing_blobs() == b.referencing_blobs();
50 }
51
52 bool operator!=(const ShareableBlobDataItem& a,
53 const ShareableBlobDataItem& b) {
54 return !(a == b);
24 } 55 }
25 56
26 } // namespace storage 57 } // namespace storage
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698