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. |
| 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; |
| 50 |
| 51 // This is a unique auto-incrementing id assigned to this item on |
| 52 // construction. It is used to keep track of this item in an LRU data |
| 53 // structure for eviction to disk. |
| 54 uint64_t item_id() const { return item_id_; } |
| 55 |
| 56 const base::hash_set<std::string>& referencing_blobs() const { |
34 return referencing_blobs_; | 57 return referencing_blobs_; |
35 } | 58 } |
36 | 59 |
| 60 bool IsPopulated() const { |
| 61 return state_ == POPULATED_WITH_QUOTA || state_ == POPULATED_WITHOUT_QUOTA; |
| 62 } |
| 63 |
| 64 State state() const { return state_; } |
| 65 |
37 private: | 66 private: |
38 friend class base::RefCounted<ShareableBlobDataItem>; | 67 friend class base::RefCountedThreadSafe<ShareableBlobDataItem>; |
| 68 friend class BlobMemoryController; |
| 69 friend class BlobMemoryControllerTest; |
| 70 friend class BlobStorageContext; |
39 friend class InternalBlobData; | 71 friend class InternalBlobData; |
| 72 friend STORAGE_EXPORT void PrintTo(const ShareableBlobDataItem& x, |
| 73 ::std::ostream* os); |
| 74 |
40 ~ShareableBlobDataItem(); | 75 ~ShareableBlobDataItem(); |
41 | 76 |
| 77 // This is a unique identifier for this ShareableBlobDataItem. |
| 78 const uint64_t item_id_; |
| 79 State state_; |
42 scoped_refptr<BlobDataItem> item_; | 80 scoped_refptr<BlobDataItem> item_; |
43 | |
44 base::hash_set<std::string> referencing_blobs_; | 81 base::hash_set<std::string> referencing_blobs_; |
45 | 82 |
46 DISALLOW_COPY_AND_ASSIGN(ShareableBlobDataItem); | 83 DISALLOW_COPY_AND_ASSIGN(ShareableBlobDataItem); |
47 }; | 84 }; |
48 | 85 |
| 86 STORAGE_EXPORT bool operator==(const ShareableBlobDataItem& a, |
| 87 const ShareableBlobDataItem& b); |
| 88 STORAGE_EXPORT bool operator!=(const ShareableBlobDataItem& a, |
| 89 const ShareableBlobDataItem& b); |
| 90 |
49 } // namespace storage | 91 } // namespace storage |
50 #endif // STORAGE_BROWSER_BLOB_SHAREABLE_BLOB_DATA_ITEM_H_ | 92 #endif // STORAGE_BROWSER_BLOB_SHAREABLE_BLOB_DATA_ITEM_H_ |
OLD | NEW |