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

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

Issue 2339933004: [BlobStorage] BlobMemoryController & tests (Closed)
Patch Set: Fix android & windows build errors 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 #ifndef STORAGE_BROWSER_BLOB_SHAREABLE_BLOB_DATA_ITEM_H_ 5 #ifndef STORAGE_BROWSER_BLOB_SHAREABLE_BLOB_DATA_ITEM_H_
6 #define STORAGE_BROWSER_BLOB_SHAREABLE_BLOB_DATA_ITEM_H_ 6 #define STORAGE_BROWSER_BLOB_SHAREABLE_BLOB_DATA_ITEM_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/containers/hash_tables.h" 10 #include "base/containers/hash_tables.h"
11 #include "base/hash.h" 11 #include "base/hash.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "storage/browser/storage_browser_export.h"
14 #include "storage/common/data_element.h" 15 #include "storage/common/data_element.h"
15 16
16 namespace storage { 17 namespace storage {
17 class BlobDataItem; 18 class BlobDataItem;
18 class InternalBlobData; 19 class InternalBlobData;
19 20
20 // This class allows blob items to be shared between blobs, and is only used by 21 // This class allows blob items to be shared between blobs. This class contains
21 // BlobStorageContext. This class contains both the blob data item and the uuids 22 // both the blob data item and the uuids of all the blobs using this item.
22 // of all the blobs using this item.
23 // The data in this class (the item) is immutable, but the item itself can be 23 // The data in this class (the item) is immutable, but the item itself can be
24 // swapped out with an item with the same data but a different backing (think 24 // swapped out with an item with the same data but a different backing (think
25 // RAM vs file backed). 25 // RAM vs file backed).
26 class ShareableBlobDataItem : public base::RefCounted<ShareableBlobDataItem> { 26 // We need to be RefCountedThreadSafe as references of this item are passed to a
michaeln 2016/10/11 20:55:24 comment is stale
dmurph 2016/10/13 00:39:31 Done.
27 // file thread to save old memory items to disk.
28 class STORAGE_EXPORT ShareableBlobDataItem
29 : public base::RefCounted<ShareableBlobDataItem> {
27 public: 30 public:
28 ShareableBlobDataItem(const std::string& blob_uuid, 31 enum State {
29 const scoped_refptr<BlobDataItem>& item); 32 // We're an item that needs quota (either disk or memory).
33 QUOTA_NEEDED,
34 // We have requested quota from the BlobMemoryController.
35 QUOTA_REQUESTED,
36 // Space has been allocated for this item in the BlobMemoryController, but
37 // it may not yet be populated.
38 QUOTA_GRANTED,
39 // We're a populated item that needed quota.
40 POPULATED_WITH_QUOTA,
41 // We're a populated item that didn't need quota.
42 POPULATED_WITHOUT_QUOTA
43 };
30 44
31 const scoped_refptr<BlobDataItem>& item(); 45 ShareableBlobDataItem(const std::string& referencing_blob_uuid,
46 scoped_refptr<BlobDataItem> item,
47 State state);
32 48
33 base::hash_set<std::string>& referencing_blobs() { 49 const scoped_refptr<BlobDataItem>& item() const { return item_; }
50
51 scoped_refptr<BlobDataItem>* item_mutable() { return &item_; }
52
53 void set_item(scoped_refptr<BlobDataItem> item);
54
55 // This is a unique auto-incrementing id assigned to this item on
56 // construction. It is used to keep track of this item in an LRU data
57 // structure for eviction to disk.
58 uint64_t item_id() const { return item_id_; }
59
60 const base::hash_set<std::string>& referencing_blobs() const {
34 return referencing_blobs_; 61 return referencing_blobs_;
35 } 62 }
36 63
64 base::hash_set<std::string>* referencing_blobs_mutable() {
65 return &referencing_blobs_;
66 }
67
68 State state() const { return state_; }
69
70 void set_state(State state) { state_ = state; }
71
72 bool IsPopulated() const {
73 return state_ == POPULATED_WITH_QUOTA || state_ == POPULATED_WITHOUT_QUOTA;
74 }
75
76 bool HasGrantedQuota() const {
77 return state_ == POPULATED_WITH_QUOTA || state_ == QUOTA_GRANTED;
78 }
79
37 private: 80 private:
38 friend class base::RefCounted<ShareableBlobDataItem>; 81 friend class base::RefCounted<ShareableBlobDataItem>;
39 friend class InternalBlobData; 82 friend STORAGE_EXPORT void PrintTo(const ShareableBlobDataItem& x,
83 ::std::ostream* os);
84
40 ~ShareableBlobDataItem(); 85 ~ShareableBlobDataItem();
41 86
87 // This is a unique identifier for this ShareableBlobDataItem.
88 const uint64_t item_id_;
89 State state_;
42 scoped_refptr<BlobDataItem> item_; 90 scoped_refptr<BlobDataItem> item_;
43
44 base::hash_set<std::string> referencing_blobs_; 91 base::hash_set<std::string> referencing_blobs_;
45 92
46 DISALLOW_COPY_AND_ASSIGN(ShareableBlobDataItem); 93 DISALLOW_COPY_AND_ASSIGN(ShareableBlobDataItem);
47 }; 94 };
48 95
96 STORAGE_EXPORT bool operator==(const ShareableBlobDataItem& a,
97 const ShareableBlobDataItem& b);
98 STORAGE_EXPORT bool operator!=(const ShareableBlobDataItem& a,
99 const ShareableBlobDataItem& b);
100
49 } // namespace storage 101 } // namespace storage
50 #endif // STORAGE_BROWSER_BLOB_SHAREABLE_BLOB_DATA_ITEM_H_ 102 #endif // STORAGE_BROWSER_BLOB_SHAREABLE_BLOB_DATA_ITEM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698