| 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_INTERNAL_BLOB_DATA_H_ | 5 #ifndef STORAGE_BROWSER_BLOB_INTERNAL_BLOB_DATA_H_ |
| 6 #define STORAGE_BROWSER_BLOB_INTERNAL_BLOB_DATA_H_ | 6 #define STORAGE_BROWSER_BLOB_INTERNAL_BLOB_DATA_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <string> | 11 #include <string> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 16 #include "storage/browser/blob/shareable_blob_data_item.h" | 16 #include "storage/browser/blob/shareable_blob_data_item.h" |
| 17 | 17 |
| 18 namespace storage { | 18 namespace storage { |
| 19 class ViewBlobInternalsJob; | 19 class ViewBlobInternalsJob; |
| 20 | 20 |
| 21 // This class represents a blob in the BlobStorageContext. It is constructed | 21 // This class represents a blob in the BlobStorageContext. |
| 22 // using the internal Builder class. | |
| 23 class InternalBlobData { | 22 class InternalBlobData { |
| 24 public: | 23 public: |
| 25 ~InternalBlobData(); | 24 ~InternalBlobData(); |
| 26 | 25 |
| 27 protected: | 26 protected: |
| 28 friend class BlobStorageContext; | 27 friend class BlobStorageContext; |
| 29 friend class BlobStorageRegistry; | 28 friend class BlobStorageRegistry; |
| 30 friend class ViewBlobInternalsJob; | 29 friend class ViewBlobInternalsJob; |
| 30 friend class BlobFlattener; |
| 31 friend class BlobSlice; |
| 32 |
| 33 InternalBlobData(); |
| 34 |
| 35 // Appends |
| 36 void AppendSharedBlobItem(const std::string& my_uuid, |
| 37 scoped_refptr<ShareableBlobDataItem> item); |
| 31 | 38 |
| 32 // Removes the given blob uuid from the internal ShareableBlobDataItems. | 39 // Removes the given blob uuid from the internal ShareableBlobDataItems. |
| 33 // This is called when this blob is being destroyed. | 40 // This is called when this blob is being destroyed. |
| 34 void RemoveBlobFromShareableItems(const std::string& blob_uuid); | 41 void RemoveBlobFromShareableItems(const std::string& blob_uuid); |
| 35 | 42 |
| 36 const std::vector<scoped_refptr<ShareableBlobDataItem>>& items() const; | 43 const std::vector<scoped_refptr<ShareableBlobDataItem>>& items() const; |
| 44 const std::vector<size_t>& offsets() const { return offsets_; } |
| 37 | 45 |
| 38 // Gets the memory used by this blob that is not shared by other blobs. This | 46 // Gets the memory used by this blob that is not shared by other blobs. This |
| 39 // also doesn't count duplicate items. | 47 // also doesn't count duplicate items. |
| 40 size_t GetUnsharedMemoryUsage() const; | 48 size_t GetUnsharedMemoryUsage() const; |
| 41 | 49 |
| 42 // Gets the memory used by this blob. Total memory includes memory of items | 50 // Total size of this blob in bytes. |
| 43 // possibly shared with other blobs, or items that appear multiple times in | 51 uint64_t total_size() { return size_; }; |
| 44 // this blob. Unshared memory is memory used by this blob that is not shared | 52 |
| 45 // by other blobs. | 53 // Size of this blob that isn't shared from another blob. |
| 46 void GetMemoryUsage(size_t* total_memory, size_t* unshared_memory); | 54 uint64_t unique_size() { return size_; }; |
| 47 | 55 |
| 48 private: | 56 private: |
| 49 friend class Builder; | 57 friend class Builder; |
| 50 InternalBlobData(); | 58 friend class BlobStorageContext; |
| 51 | 59 |
| 52 std::string content_type_; | |
| 53 std::string content_disposition_; | |
| 54 std::vector<scoped_refptr<ShareableBlobDataItem>> items_; | 60 std::vector<scoped_refptr<ShareableBlobDataItem>> items_; |
| 55 | 61 |
| 56 class Builder { | 62 // Size in bytes. If we're a single file then this can be uint64_max. |
| 57 public: | 63 uint64_t size_ = 0; |
| 58 Builder(); | 64 // Size of the data copying from other blobs. |
| 59 ~Builder(); | 65 uint64_t copying_size_ = 0; |
| 60 | 66 |
| 61 void AppendSharedBlobItem(scoped_refptr<ShareableBlobDataItem> item); | 67 // Only populated if len(items_) > 1. Used for binary search. |
| 62 | 68 // Since the offset of the first item is always 0, we exclude this. |
| 63 // Gets the memory used by this builder that is not shared with other blobs. | 69 std::vector<uint64_t> offsets_; |
| 64 size_t GetNonsharedMemoryUsage() const; | |
| 65 | |
| 66 // Removes the given blob uuid from the internal ShareableBlobDataItems. | |
| 67 // This is called on destruction of the blob if we're still building it. | |
| 68 void RemoveBlobFromShareableItems(const std::string& blob_uuid); | |
| 69 | |
| 70 // The builder is invalid after calling this method. | |
| 71 std::unique_ptr<::storage::InternalBlobData> Build(); | |
| 72 | |
| 73 private: | |
| 74 std::unique_ptr<::storage::InternalBlobData> data_; | |
| 75 | |
| 76 DISALLOW_COPY_AND_ASSIGN(Builder); | |
| 77 }; | |
| 78 | 70 |
| 79 DISALLOW_COPY_AND_ASSIGN(InternalBlobData); | 71 DISALLOW_COPY_AND_ASSIGN(InternalBlobData); |
| 80 }; | 72 }; |
| 81 | 73 |
| 82 } // namespace storage | 74 } // namespace storage |
| 83 #endif // STORAGE_BROWSER_BLOB_INTERNAL_BLOB_DATA_H_ | 75 #endif // STORAGE_BROWSER_BLOB_INTERNAL_BLOB_DATA_H_ |
| OLD | NEW |