OLD | NEW |
---|---|
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 |
27 // file thread to save old memory items to disk. | |
michaeln
2016/09/27 00:09:30
I understand the file created/deletion has to happ
dmurph
2016/09/29 00:44:23
Done. Thanks for the discussion, I'm glad we could
michaeln
2016/10/04 00:11:54
woot!
| |
28 class STORAGE_EXPORT ShareableBlobDataItem | |
29 : public base::RefCountedThreadSafe<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& target_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 // This is a unique auto-incrementing id assigned to this item on | |
54 // construction. It is used to keep track of this item in an LRU data | |
55 // structure for eviction to disk. | |
56 uint64_t item_id() const { return item_id_; } | |
57 | |
58 const base::hash_set<std::string>& referencing_blobs() const { | |
34 return referencing_blobs_; | 59 return referencing_blobs_; |
35 } | 60 } |
36 | 61 |
62 base::hash_set<std::string>* referencing_blobs_mutable() { | |
63 return &referencing_blobs_; | |
64 } | |
65 | |
66 State state() const { return state_; } | |
67 | |
68 void set_state(State state) { state_ = state; } | |
69 | |
70 bool IsPopulated() const { | |
71 return state_ == POPULATED_WITH_QUOTA || state_ == POPULATED_WITHOUT_QUOTA; | |
72 } | |
73 | |
37 private: | 74 private: |
38 friend class base::RefCounted<ShareableBlobDataItem>; | 75 friend class base::RefCountedThreadSafe<ShareableBlobDataItem>; |
39 friend class InternalBlobData; | 76 friend STORAGE_EXPORT void PrintTo(const ShareableBlobDataItem& x, |
77 ::std::ostream* os); | |
78 | |
40 ~ShareableBlobDataItem(); | 79 ~ShareableBlobDataItem(); |
41 | 80 |
81 // This is a unique identifier for this ShareableBlobDataItem. | |
82 const uint64_t item_id_; | |
83 State state_; | |
42 scoped_refptr<BlobDataItem> item_; | 84 scoped_refptr<BlobDataItem> item_; |
43 | |
44 base::hash_set<std::string> referencing_blobs_; | 85 base::hash_set<std::string> referencing_blobs_; |
45 | 86 |
46 DISALLOW_COPY_AND_ASSIGN(ShareableBlobDataItem); | 87 DISALLOW_COPY_AND_ASSIGN(ShareableBlobDataItem); |
47 }; | 88 }; |
48 | 89 |
90 STORAGE_EXPORT bool operator==(const ShareableBlobDataItem& a, | |
91 const ShareableBlobDataItem& b); | |
92 STORAGE_EXPORT bool operator!=(const ShareableBlobDataItem& a, | |
93 const ShareableBlobDataItem& b); | |
94 | |
49 } // namespace storage | 95 } // namespace storage |
50 #endif // STORAGE_BROWSER_BLOB_SHAREABLE_BLOB_DATA_ITEM_H_ | 96 #endif // STORAGE_BROWSER_BLOB_SHAREABLE_BLOB_DATA_ITEM_H_ |
OLD | NEW |