OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef STORAGE_BROWSER_BLOB_INTERNAL_BLOB_DATA_H_ |
| 6 #define STORAGE_BROWSER_BLOB_INTERNAL_BLOB_DATA_H_ |
| 7 |
| 8 #include <string> |
| 9 #include <vector> |
| 10 |
| 11 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted.h" |
| 13 #include "storage/browser/blob/shareable_blob_data_item.h" |
| 14 |
| 15 namespace storage { |
| 16 class ViewBlobInternalsJob; |
| 17 |
| 18 // This class represents a blob in the BlobStorageContext. It is constructed |
| 19 // using the internal Builder class. |
| 20 class InternalBlobData { |
| 21 public: |
| 22 ~InternalBlobData(); |
| 23 |
| 24 protected: |
| 25 friend class BlobStorageContext; |
| 26 friend class ViewBlobInternalsJob; |
| 27 |
| 28 // Removes the given blob uuid from the internal ShareableBlobDataItems. |
| 29 // This is called when this blob is being destroyed. |
| 30 void RemoveBlobFromShareableItems(const std::string& blob_uuid); |
| 31 |
| 32 const std::vector<scoped_refptr<ShareableBlobDataItem>>& items() const; |
| 33 const std::string& content_type() const; |
| 34 const std::string& content_disposition() const; |
| 35 |
| 36 // Gets the memory used by this blob that is not shared by other blobs. This |
| 37 // also doesn't count duplicate items. |
| 38 size_t GetUnsharedMemoryUsage() const; |
| 39 |
| 40 // Gets the memory used by this blob. Total memory includes memory of items |
| 41 // possibly shared with other blobs, or items that appear multiple times in |
| 42 // this blob. Unshared memory is memory used by this blob that is not shared |
| 43 // by other blobs. |
| 44 void GetMemoryUsage(size_t* total_memory, size_t* unshared_memory); |
| 45 |
| 46 private: |
| 47 friend class Builder; |
| 48 InternalBlobData(); |
| 49 |
| 50 std::string content_type_; |
| 51 std::string content_disposition_; |
| 52 std::vector<scoped_refptr<ShareableBlobDataItem>> items_; |
| 53 |
| 54 class Builder { |
| 55 public: |
| 56 Builder(); |
| 57 ~Builder(); |
| 58 |
| 59 void AppendSharedBlobItem(scoped_refptr<ShareableBlobDataItem> item); |
| 60 void set_content_type(const std::string& content_type); |
| 61 void set_content_disposition(const std::string& content_disposition); |
| 62 |
| 63 // Gets the memory used by this builder that is not shared with other blobs. |
| 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 scoped_ptr<::storage::InternalBlobData> Build(); |
| 72 |
| 73 private: |
| 74 scoped_ptr<::storage::InternalBlobData> data_; |
| 75 |
| 76 DISALLOW_COPY_AND_ASSIGN(Builder); |
| 77 }; |
| 78 |
| 79 DISALLOW_COPY_AND_ASSIGN(InternalBlobData); |
| 80 }; |
| 81 |
| 82 } // namespace storage |
| 83 #endif // STORAGE_BROWSER_BLOB_INTERNAL_BLOB_DATA_H_ |
OLD | NEW |