Chromium Code Reviews| 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 |
|
pwnall
2016/09/21 09:03:35
references are passed
dmurph
2016/09/21 23:45:52
Done.
| |
| 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 struct BlobFlattener; | |
|
pwnall
2016/09/21 09:03:35
These are a lot of friends. Would it make more sen
dmurph
2016/09/21 23:45:52
Mmmm it's actually for state and item modification
| |
| 69 friend class BlobMemoryController; | |
| 70 friend class BlobMemoryControllerTest; | |
| 71 friend class BlobStorageContext; | |
| 39 friend class InternalBlobData; | 72 friend class InternalBlobData; |
| 73 friend STORAGE_EXPORT void PrintTo(const ShareableBlobDataItem& x, | |
| 74 ::std::ostream* os); | |
| 75 | |
| 40 ~ShareableBlobDataItem(); | 76 ~ShareableBlobDataItem(); |
| 41 | 77 |
| 78 // This is a unique identifier for this ShareableBlobDataItem. | |
| 79 const uint64_t item_id_; | |
| 80 State state_; | |
| 42 scoped_refptr<BlobDataItem> item_; | 81 scoped_refptr<BlobDataItem> item_; |
| 43 | |
| 44 base::hash_set<std::string> referencing_blobs_; | 82 base::hash_set<std::string> referencing_blobs_; |
| 45 | 83 |
| 46 DISALLOW_COPY_AND_ASSIGN(ShareableBlobDataItem); | 84 DISALLOW_COPY_AND_ASSIGN(ShareableBlobDataItem); |
| 47 }; | 85 }; |
| 48 | 86 |
| 87 STORAGE_EXPORT bool operator==(const ShareableBlobDataItem& a, | |
| 88 const ShareableBlobDataItem& b); | |
| 89 STORAGE_EXPORT bool operator!=(const ShareableBlobDataItem& a, | |
| 90 const ShareableBlobDataItem& b); | |
| 91 | |
| 49 } // namespace storage | 92 } // namespace storage |
| 50 #endif // STORAGE_BROWSER_BLOB_SHAREABLE_BLOB_DATA_ITEM_H_ | 93 #endif // STORAGE_BROWSER_BLOB_SHAREABLE_BLOB_DATA_ITEM_H_ |
| OLD | NEW |