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 is 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 ShareableBlobDataItem(scoped_refptr<BlobDataItem> item); |
29 const scoped_refptr<BlobDataItem>& item); | |
30 | 32 |
31 const scoped_refptr<BlobDataItem>& item(); | 33 const scoped_refptr<BlobDataItem>& item() const; |
32 | 34 |
33 base::hash_set<std::string>& referencing_blobs() { | 35 // This is a unique auto-incrementing id assigned to this item on |
36 // construction. It is used to keep track of this item in an LRU data | |
37 // structure for eviction to disk. | |
38 uint64_t item_id() const { return item_id_; } | |
39 | |
40 const base::hash_set<std::string>& referencing_blobs() const { | |
34 return referencing_blobs_; | 41 return referencing_blobs_; |
35 } | 42 } |
36 | 43 |
37 private: | 44 private: |
38 friend class base::RefCounted<ShareableBlobDataItem>; | 45 friend class base::RefCountedThreadSafe<ShareableBlobDataItem>; |
39 friend class InternalBlobData; | 46 friend class InternalBlobData; |
47 friend class BlobMemoryController; | |
48 friend class BlobStorageContext; | |
49 friend STORAGE_EXPORT void PrintTo(const ShareableBlobDataItem& x, | |
50 ::std::ostream* os); | |
51 | |
40 ~ShareableBlobDataItem(); | 52 ~ShareableBlobDataItem(); |
41 | 53 |
54 // This is a unique identifier for this ShareableBlobDataItem. | |
55 uint64_t item_id_; | |
kinuko
2016/07/17 16:15:47
const
dmurph
2016/07/19 02:26:28
Done.
| |
42 scoped_refptr<BlobDataItem> item_; | 56 scoped_refptr<BlobDataItem> item_; |
43 | 57 |
44 base::hash_set<std::string> referencing_blobs_; | 58 base::hash_set<std::string> referencing_blobs_; |
45 | 59 |
46 DISALLOW_COPY_AND_ASSIGN(ShareableBlobDataItem); | 60 DISALLOW_COPY_AND_ASSIGN(ShareableBlobDataItem); |
47 }; | 61 }; |
48 | 62 |
63 STORAGE_EXPORT bool operator==(const ShareableBlobDataItem& a, | |
64 const ShareableBlobDataItem& b); | |
65 STORAGE_EXPORT bool operator!=(const ShareableBlobDataItem& a, | |
66 const ShareableBlobDataItem& b); | |
67 | |
49 } // namespace storage | 68 } // namespace storage |
50 #endif // STORAGE_BROWSER_BLOB_SHAREABLE_BLOB_DATA_ITEM_H_ | 69 #endif // STORAGE_BROWSER_BLOB_SHAREABLE_BLOB_DATA_ITEM_H_ |
OLD | NEW |