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

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

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

Powered by Google App Engine
This is Rietveld 408576698