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/callback_helpers.h" | |
| 10 #include "base/containers/hash_tables.h" | 11 #include "base/containers/hash_tables.h" |
| 11 #include "base/hash.h" | 12 #include "base/hash.h" |
| 12 #include "base/macros.h" | 13 #include "base/macros.h" |
| 13 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "storage/browser/blob/blob_memory_controller.h" | |
| 16 #include "storage/browser/storage_browser_export.h" | |
| 14 #include "storage/common/data_element.h" | 17 #include "storage/common/data_element.h" |
| 15 | 18 |
| 16 namespace storage { | 19 namespace storage { |
| 17 class BlobDataItem; | 20 class BlobDataItem; |
| 18 class InternalBlobData; | 21 class InternalBlobData; |
| 19 | 22 |
| 20 // This class allows blob items to be shared between blobs, and is only used by | 23 // 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 | 24 // 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 | 25 // 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 | 26 // swapped out with an item with the same data but a different backing (think |
| 25 // RAM vs file backed). | 27 // RAM vs file backed). |
| 26 class ShareableBlobDataItem : public base::RefCounted<ShareableBlobDataItem> { | 28 // We also allow the storage of a deletion closure which is used for memory |
| 29 // quota reclamation. | |
| 30 class STORAGE_EXPORT ShareableBlobDataItem | |
| 31 : public base::RefCounted<ShareableBlobDataItem> { | |
| 27 public: | 32 public: |
| 28 ShareableBlobDataItem(const std::string& blob_uuid, | 33 enum State { |
| 29 const scoped_refptr<BlobDataItem>& item); | 34 // We're an item that needs quota (either disk or memory). |
| 35 QUOTA_NEEDED, | |
| 36 // We have requested quota from the BlobMemoryController. | |
| 37 QUOTA_REQUESTED, | |
| 38 // Space has been allocated for this item in the BlobMemoryController, but | |
| 39 // it may not yet be populated. | |
| 40 QUOTA_GRANTED, | |
| 41 // We're a populated item that needed quota. | |
| 42 POPULATED_WITH_QUOTA, | |
| 43 // We're a populated item that didn't need quota. | |
| 44 POPULATED_WITHOUT_QUOTA | |
| 45 }; | |
| 30 | 46 |
| 31 const scoped_refptr<BlobDataItem>& item(); | 47 ShareableBlobDataItem(const std::string& referencing_blob_uuid, |
| 48 scoped_refptr<BlobDataItem> item, | |
| 49 State state); | |
| 32 | 50 |
| 33 base::hash_set<std::string>& referencing_blobs() { | 51 const scoped_refptr<BlobDataItem>& item() const { return item_; } |
| 52 | |
| 53 scoped_refptr<BlobDataItem>* item_mutable() { return &item_; } | |
| 54 | |
| 55 void set_item(scoped_refptr<BlobDataItem> item); | |
| 56 | |
| 57 // This is a unique auto-incrementing id assigned to this item on | |
| 58 // construction. It is used to keep track of this item in an LRU data | |
| 59 // structure for eviction to disk. | |
| 60 uint64_t item_id() const { return item_id_; } | |
| 61 | |
| 62 const base::hash_set<std::string>& referencing_blobs() const { | |
| 34 return referencing_blobs_; | 63 return referencing_blobs_; |
| 35 } | 64 } |
| 36 | 65 |
| 66 base::hash_set<std::string>* referencing_blobs_mutable() { | |
| 67 return &referencing_blobs_; | |
| 68 } | |
| 69 | |
| 70 State state() const { return state_; } | |
| 71 | |
| 72 void set_state(State state) { state_ = state; } | |
| 73 | |
| 74 bool IsPopulated() const { | |
| 75 return state_ == POPULATED_WITH_QUOTA || state_ == POPULATED_WITHOUT_QUOTA; | |
| 76 } | |
| 77 | |
| 78 bool HasGrantedQuota() const { | |
| 79 return state_ == POPULATED_WITH_QUOTA || state_ == QUOTA_GRANTED; | |
| 80 } | |
| 81 | |
| 37 private: | 82 private: |
| 83 friend class BlobMemoryController; | |
| 38 friend class base::RefCounted<ShareableBlobDataItem>; | 84 friend class base::RefCounted<ShareableBlobDataItem>; |
| 39 friend class InternalBlobData; | 85 friend STORAGE_EXPORT void PrintTo(const ShareableBlobDataItem& x, |
| 86 ::std::ostream* os); | |
| 87 | |
| 40 ~ShareableBlobDataItem(); | 88 ~ShareableBlobDataItem(); |
| 41 | 89 |
| 90 void set_memory_quota_allocation( | |
| 91 BlobMemoryController::MemoryAllocation quota_release_callback) { | |
| 92 memory_quota_allocation_ = std::move(quota_release_callback); | |
| 93 } | |
| 94 | |
| 95 BlobMemoryController::MemoryAllocation* memory_quota_allocation() { | |
| 96 return &memory_quota_allocation_; | |
| 97 } | |
| 98 | |
| 99 // This is a unique identifier for this ShareableBlobDataItem. | |
| 100 const uint64_t item_id_; | |
| 101 State state_; | |
| 42 scoped_refptr<BlobDataItem> item_; | 102 scoped_refptr<BlobDataItem> item_; |
| 43 | |
| 44 base::hash_set<std::string> referencing_blobs_; | 103 base::hash_set<std::string> referencing_blobs_; |
| 104 BlobMemoryController::MemoryAllocation memory_quota_allocation_; | |
|
michaeln
2016/10/14 01:53:26
very opaque and mysterious data member?
dmurph
2016/10/14 23:31:48
Done.
| |
| 45 | 105 |
| 46 DISALLOW_COPY_AND_ASSIGN(ShareableBlobDataItem); | 106 DISALLOW_COPY_AND_ASSIGN(ShareableBlobDataItem); |
| 47 }; | 107 }; |
| 48 | 108 |
| 109 STORAGE_EXPORT bool operator==(const ShareableBlobDataItem& a, | |
| 110 const ShareableBlobDataItem& b); | |
| 111 STORAGE_EXPORT bool operator!=(const ShareableBlobDataItem& a, | |
| 112 const ShareableBlobDataItem& b); | |
| 113 | |
| 49 } // namespace storage | 114 } // namespace storage |
| 50 #endif // STORAGE_BROWSER_BLOB_SHAREABLE_BLOB_DATA_ITEM_H_ | 115 #endif // STORAGE_BROWSER_BLOB_SHAREABLE_BLOB_DATA_ITEM_H_ |
| OLD | NEW |