Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: storage/browser/blob/internal_blob_data.h

Issue 2055053003: [BlobAsync] Disk support for blob storage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed layout tests, cleaned up test visibility Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/callback_forward.h"
14 #include "base/macros.h" 15 #include "base/macros.h"
15 #include "base/memory/ref_counted.h" 16 #include "base/memory/ref_counted.h"
16 #include "storage/browser/blob/shareable_blob_data_item.h" 17 #include "storage/browser/blob/blob_memory_controller.h"
18 #include "storage/browser/storage_browser_export.h"
17 19
18 namespace storage { 20 namespace storage {
21 class BlobDataHandle;
22 class ShareableBlobDataItem;
19 class ViewBlobInternalsJob; 23 class ViewBlobInternalsJob;
20 24
21 // This class represents a blob in the BlobStorageContext. It is constructed 25 // This class represents a blob. We export this only for unit tests.
22 // using the internal Builder class. 26 class STORAGE_EXPORT InternalBlobData {
23 class InternalBlobData {
24 public: 27 public:
28 struct STORAGE_EXPORT ItemCopyEntry {
29 ItemCopyEntry(scoped_refptr<ShareableBlobDataItem> source_item,
30 size_t source_item_offset,
31 scoped_refptr<ShareableBlobDataItem> dest_item);
32 ~ItemCopyEntry();
33 ItemCopyEntry(const ItemCopyEntry&);
34
35 scoped_refptr<ShareableBlobDataItem> source_item;
36 size_t source_item_offset = 0;
37 scoped_refptr<ShareableBlobDataItem> dest_item;
38 };
39
40 struct STORAGE_EXPORT BuildingState {
41 BuildingState();
42 ~BuildingState();
43
44 // Stored if the BlobDataBuilder we're given to construct has pending data,
45 // and we need to tell the user when to start populating this data.
46 BlobStatusCallback ready_for_user_population_callback;
47 bool waiting_for_user_population = false;
48
49 // Stores all blobs that we're depending on for building. This keeps the
50 // blobs alive while we build our blob.
51 std::vector<std::unique_ptr<BlobDataHandle>> dependent_blobs;
52 size_t dependent_blobs_building = 0;
53
54 // We change our status to PENDING_MEMORY_QUOTA when we populate this. If
55 // we need to cancel before our quota callback is triggered, then we use
56 // this entry to cancel our request in the memory controller.
57 BlobMemoryController::PendingConstructionEntry pending_copies_memory_entry;
58
59 // These are copies from a referenced blob item to our blob items. Some of
60 // these entries may have changed from bytes to files if they were paged.
61 std::vector<ItemCopyEntry> copies;
62
63 std::vector<BlobStatusCallback> build_completion_callbacks;
64 };
65
66 InternalBlobData(const std::string& content_type,
67 const std::string& content_disposition);
25 ~InternalBlobData(); 68 ~InternalBlobData();
26 69
27 protected: 70 // Appends the given shared blob data item to this object. We add |my_uuid|
28 friend class BlobStorageContext; 71 // to the shareable item's uuid set.
29 friend class BlobStorageRegistry; 72 void AppendSharedBlobItem(const std::string& my_uuid,
30 friend class ViewBlobInternalsJob; 73 scoped_refptr<ShareableBlobDataItem> item);
31 74
32 // Removes the given blob uuid from the internal ShareableBlobDataItems. 75 // Removes the given blob uuid from the internal ShareableBlobDataItems.
33 // This is called when this blob is being destroyed. 76 // This is called when this blob is being destroyed.
34 void RemoveBlobFromShareableItems(const std::string& blob_uuid); 77 void RemoveBlobFromShareableItems(const std::string& blob_uuid);
35 78
36 const std::vector<scoped_refptr<ShareableBlobDataItem>>& items() const;
37
38 // Gets the memory used by this blob that is not shared by other blobs. This 79 // Gets the memory used by this blob that is not shared by other blobs. This
39 // also doesn't count duplicate items. 80 // also doesn't count duplicate items.
40 size_t GetUnsharedMemoryUsage() const; 81 size_t GetUnsharedMemoryUsage() const;
41 82
42 // Gets the memory used by this blob. Total memory includes memory of items 83 BlobStatus status() const { return status_; }
43 // possibly shared with other blobs, or items that appear multiple times in 84
44 // this blob. Unshared memory is memory used by this blob that is not shared 85 size_t refcount() const { return refcount_; }
45 // by other blobs. 86
46 void GetMemoryUsage(size_t* total_memory, size_t* unshared_memory); 87 const std::string& content_type() const { return content_type_; }
88
89 const std::string& content_disposition() const {
90 return content_disposition_;
91 }
92
93 // Total size of this blob in bytes.
94 uint64_t total_size() const { return size_; };
95
96 const std::vector<uint64_t>& offsets() const { return offsets_; }
97
98 const std::vector<scoped_refptr<ShareableBlobDataItem>>& items() const;
47 99
48 private: 100 private:
49 friend class Builder; 101 friend class BlobStorageContext;
50 InternalBlobData();
51 102
103 BlobStatus status_ = BlobStatus::PENDING_MEMORY_REQUEST;
104 size_t refcount_ = 0;
105
106 // Metadata.
52 std::string content_type_; 107 std::string content_type_;
53 std::string content_disposition_; 108 std::string content_disposition_;
109
54 std::vector<scoped_refptr<ShareableBlobDataItem>> items_; 110 std::vector<scoped_refptr<ShareableBlobDataItem>> items_;
55 111
56 class Builder { 112 // Size in bytes. IFF we're a single file then this can be uint64_max.
57 public: 113 uint64_t size_ = 0;
58 Builder();
59 ~Builder();
60 114
61 void AppendSharedBlobItem(scoped_refptr<ShareableBlobDataItem> item); 115 // Only populated if len(items_) > 1. Used for binary search.
116 // Since the offset of the first item is always 0, we exclude this.
117 std::vector<uint64_t> offsets_;
62 118
63 // Gets the memory used by this builder that is not shared with other blobs. 119 // Only populated if our status is PENDING_*.
64 size_t GetNonsharedMemoryUsage() const; 120 std::unique_ptr<BuildingState> building_state_;
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 121
79 DISALLOW_COPY_AND_ASSIGN(InternalBlobData); 122 DISALLOW_COPY_AND_ASSIGN(InternalBlobData);
80 }; 123 };
81 124
82 } // namespace storage 125 } // namespace storage
83 #endif // STORAGE_BROWSER_BLOB_INTERNAL_BLOB_DATA_H_ 126 #endif // STORAGE_BROWSER_BLOB_INTERNAL_BLOB_DATA_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698