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

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

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

Powered by Google App Engine
This is Rietveld 408576698