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

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

Powered by Google App Engine
This is Rietveld 408576698