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, and is only used by |
21 // BlobStorageContext. This class contains both the blob data item and the uuids | 22 // BlobStorageContext. This class contains both the blob data item and the uuids |
22 // of all the blobs using this item. | 23 // of all the blobs using this item. |
23 // 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 |
24 // 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 |
25 // RAM vs file backed). | 26 // RAM vs file backed). |
26 class ShareableBlobDataItem : public base::RefCounted<ShareableBlobDataItem> { | 27 class STORAGE_EXPORT ShareableBlobDataItem |
| 28 : public base::RefCountedThreadSafe<ShareableBlobDataItem> { |
27 public: | 29 public: |
28 ShareableBlobDataItem(const std::string& blob_uuid, | 30 ShareableBlobDataItem(scoped_refptr<BlobDataItem> item); |
29 const scoped_refptr<BlobDataItem>& item); | |
30 | 31 |
31 const scoped_refptr<BlobDataItem>& item(); | 32 const scoped_refptr<BlobDataItem>& item() const; |
32 | 33 |
33 base::hash_set<std::string>& referencing_blobs() { | 34 // This is a unique auto-incrementing id assigned to this item on |
| 35 // construction. It is used to keep track of this item in an LRU data |
| 36 // structure for eviction to disk. |
| 37 uint64_t item_id() const { return item_id_; } |
| 38 |
| 39 const base::hash_set<std::string>& referencing_blobs() const { |
34 return referencing_blobs_; | 40 return referencing_blobs_; |
35 } | 41 } |
36 | 42 |
37 private: | 43 private: |
38 friend class base::RefCounted<ShareableBlobDataItem>; | 44 friend class base::RefCountedThreadSafe<ShareableBlobDataItem>; |
39 friend class InternalBlobData; | 45 friend class InternalBlobData; |
| 46 friend class BlobMemoryController; |
| 47 friend class BlobStorageContext; |
| 48 friend STORAGE_EXPORT void PrintTo(const ShareableBlobDataItem& x, |
| 49 ::std::ostream* os); |
| 50 |
40 ~ShareableBlobDataItem(); | 51 ~ShareableBlobDataItem(); |
41 | 52 |
| 53 // This is a unique identifier for this ShareableBlobDataItem. |
| 54 uint64_t item_id_; |
42 scoped_refptr<BlobDataItem> item_; | 55 scoped_refptr<BlobDataItem> item_; |
43 | 56 |
44 base::hash_set<std::string> referencing_blobs_; | 57 base::hash_set<std::string> referencing_blobs_; |
45 | 58 |
46 DISALLOW_COPY_AND_ASSIGN(ShareableBlobDataItem); | 59 DISALLOW_COPY_AND_ASSIGN(ShareableBlobDataItem); |
47 }; | 60 }; |
48 | 61 |
| 62 STORAGE_EXPORT bool operator==(const ShareableBlobDataItem& a, |
| 63 const ShareableBlobDataItem& b); |
| 64 STORAGE_EXPORT bool operator!=(const ShareableBlobDataItem& a, |
| 65 const ShareableBlobDataItem& b); |
| 66 |
49 } // namespace storage | 67 } // namespace storage |
50 #endif // STORAGE_BROWSER_BLOB_SHAREABLE_BLOB_DATA_ITEM_H_ | 68 #endif // STORAGE_BROWSER_BLOB_SHAREABLE_BLOB_DATA_ITEM_H_ |
OLD | NEW |