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

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

Issue 2448353002: [BlobAsync] Moving async handling into BlobStorageContext & quota out. (Closed)
Patch Set: hopefully fixed android/windows compile, and comments Created 4 years, 1 month 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
(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_BLOB_ENTRY_H_
6 #define STORAGE_BROWSER_BLOB_BLOB_ENTRY_H_
7
8 #include <stddef.h>
9
10 #include <memory>
11 #include <string>
12 #include <vector>
13
14 #include "base/callback_forward.h"
15 #include "base/macros.h"
16 #include "base/memory/ref_counted.h"
17 #include "base/memory/weak_ptr.h"
18 #include "base/optional.h"
19 #include "storage/browser/blob/blob_memory_controller.h"
20 #include "storage/browser/storage_browser_export.h"
21
22 namespace storage {
23 class BlobDataHandle;
24 class ShareableBlobDataItem;
25 class ViewBlobInternalsJob;
26
27 // This class represents a blob. We export this only for unit tests.
28 class STORAGE_EXPORT BlobEntry {
29 public:
30 using PopulatationAllowedCallback =
31 base::Callback<void(BlobStatus,
32 std::vector<BlobMemoryController::FileCreationInfo>)>;
33
34 // This records a copy from a referenced blob. When we finish building our
35 // blob we perform all of these copies.
36 struct STORAGE_EXPORT ItemCopyEntry {
37 ItemCopyEntry(scoped_refptr<ShareableBlobDataItem> source_item,
38 size_t source_item_offset,
39 scoped_refptr<ShareableBlobDataItem> dest_item);
40 ~ItemCopyEntry();
41 ItemCopyEntry(ItemCopyEntry&& other);
42 BlobEntry::ItemCopyEntry& operator=(BlobEntry::ItemCopyEntry&& rhs);
43
44 scoped_refptr<ShareableBlobDataItem> source_item;
45 size_t source_item_offset = 0;
46 scoped_refptr<ShareableBlobDataItem> dest_item;
47
48 private:
49 DISALLOW_COPY_AND_ASSIGN(ItemCopyEntry);
50 };
51
52 // This keeps track of our building state for our blob. While building, four
53 // things can be happening mostly simultaneously:
54 // 1. Waiting for blobs we reference to complete,
55 // 2. Waiting for quota to be reserved for memory needed, and
56 // 3. Waiting for quota to be reserved (and files created) for files,
57 // 4. Waiting for user population of data after quota.
58 struct STORAGE_EXPORT BuildingState {
59 // |user_data_population_callback| is !null when user data needs population.
60 BuildingState(bool transport_items_present,
61 PopulatationAllowedCallback can_populate_callback,
62 size_t num_building_dependent_blobs,
63 bool memory_quota_needed);
64 ~BuildingState();
65
66 const bool transport_items_present;
67 // We can have user data that's either populated or unpopulated. If we need
68 // population, this is populated.
69 PopulatationAllowedCallback can_populate_callback;
70 std::vector<ShareableBlobDataItem*> user_items;
71
72 const bool dependent_building_blobs_present;
73 // Stores all blobs that we're depending on for building. This keeps the
74 // blobs alive while we build our blob.
75 std::vector<std::unique_ptr<BlobDataHandle>> dependent_blobs;
76 size_t num_building_dependent_blobs;
77
78 const bool memory_quota_needed;
79 base::WeakPtr<BlobMemoryController::QuotaAllocationTask>
80 memory_quota_request;
81
82 // These are copies from a referenced blob item to our blob items. Some of
83 // these entries may have changed from bytes to files if they were paged.
84 std::vector<ItemCopyEntry> copies;
85
86 // When our blob finishes building these callbacks are called.
87 std::vector<BlobStatusCallback> build_completion_callbacks;
88
89 private:
90 DISALLOW_COPY_AND_ASSIGN(BuildingState);
91 };
92
93 BlobEntry(const std::string& content_type,
94 const std::string& content_disposition);
95 ~BlobEntry();
96
97 // Appends the given shared blob data item to this object. We add |my_uuid|
98 // to the shareable item's uuid set.
99 void AppendSharedBlobItem(const std::string& my_uuid,
100 scoped_refptr<ShareableBlobDataItem> item);
101
102 // Removes the given blob uuid from the internal ShareableBlobDataItems.
103 // This is called when this blob is being destroyed.
104 void RemoveBlobFromShareableItems(const std::string& blob_uuid);
105
106 // Gets the memory used by this blob that is not shared by other blobs. This
107 // also doesn't count duplicate items.
108 size_t GetUnsharedMemoryUsage() const;
109
110 // Returns if we're a pending blob that can finish building.
111 bool CanFinishBuilding() const {
112 return status_ == BlobStatus::PENDING_INTERNALS &&
113 building_state_->num_building_dependent_blobs == 0;
114 }
115
116 BlobStatus status() const { return status_; }
117
118 size_t refcount() const { return refcount_; }
119
120 const std::string& content_type() const { return content_type_; }
121
122 const std::string& content_disposition() const {
123 return content_disposition_;
124 }
125
126 // Total size of this blob in bytes.
127 uint64_t total_size() const { return size_; };
128
129 // We record the cumulative offsets of each blob item (except for the first,
130 // which would always be 0) to enable binary searching for an item at a
131 // specific byte offset.
132 const std::vector<uint64_t>& offsets() const { return offsets_; }
133
134 const std::vector<scoped_refptr<ShareableBlobDataItem>>& items() const;
135
136 private:
137 friend class BlobStorageContext;
138
139 BlobStatus status_ = BlobStatus::PENDING_QUOTA;
140 size_t refcount_ = 0;
141
142 // Metadata.
143 std::string content_type_;
144 std::string content_disposition_;
145
146 std::vector<scoped_refptr<ShareableBlobDataItem>> items_;
147
148 // Size in bytes. IFF we're a single file then this can be uint64_max.
149 uint64_t size_ = 0;
150
151 // Only populated if len(items_) > 1. Used for binary search.
152 // Since the offset of the first item is always 0, we exclude this.
153 std::vector<uint64_t> offsets_;
154
155 // Only populated if our status is PENDING_*.
156 std::unique_ptr<BuildingState> building_state_;
157
158 DISALLOW_COPY_AND_ASSIGN(BlobEntry);
159 };
160
161 } // namespace storage
162 #endif // STORAGE_BROWSER_BLOB_BLOB_ENTRY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698