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

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

Issue 2516713002: [BlobStorage] Implementing disk. (Closed)
Patch Set: comments, and hopefully browsertest cleanup Created 4 years 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_BLOB_ENTRY_H_ 5 #ifndef STORAGE_BROWSER_BLOB_BLOB_ENTRY_H_
6 #define STORAGE_BROWSER_BLOB_BLOB_ENTRY_H_ 6 #define STORAGE_BROWSER_BLOB_BLOB_ENTRY_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/callback_forward.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/memory/ref_counted.h" 16 #include "base/memory/ref_counted.h"
17 #include "base/memory/weak_ptr.h" 17 #include "base/memory/weak_ptr.h"
18 #include "base/optional.h" 18 #include "base/optional.h"
19 #include "storage/browser/blob/blob_memory_controller.h" 19 #include "storage/browser/blob/blob_memory_controller.h"
20 #include "storage/browser/storage_browser_export.h" 20 #include "storage/browser/storage_browser_export.h"
21 21
22 namespace storage { 22 namespace storage {
23 class BlobDataHandle; 23 class BlobDataHandle;
24 class ShareableBlobDataItem; 24 class ShareableBlobDataItem;
25 class ViewBlobInternalsJob; 25 class ViewBlobInternalsJob;
26 26
27 // This class represents a blob in BlobStorageRegistry. We export this only for 27 // Represents a blob in BlobStorageRegistry. Exported only for unit tests.
28 // unit tests.
29 class STORAGE_EXPORT BlobEntry { 28 class STORAGE_EXPORT BlobEntry {
30 public: 29 public:
31 using TransportAllowedCallback = 30 using TransportAllowedCallback =
32 base::Callback<void(BlobStatus, 31 base::Callback<void(BlobStatus,
33 std::vector<BlobMemoryController::FileCreationInfo>)>; 32 std::vector<BlobMemoryController::FileCreationInfo>)>;
34 33
35 // This records a copy from a referenced blob. When we finish building our 34 // Records a copy from a referenced blob. Copies happen after referenced blobs
36 // blob we perform all of these copies. 35 // are complete & quota for the copies is granted.
37 struct STORAGE_EXPORT ItemCopyEntry { 36 struct STORAGE_EXPORT ItemCopyEntry {
38 ItemCopyEntry(scoped_refptr<ShareableBlobDataItem> source_item, 37 ItemCopyEntry(scoped_refptr<ShareableBlobDataItem> source_item,
39 size_t source_item_offset, 38 size_t source_item_offset,
40 scoped_refptr<ShareableBlobDataItem> dest_item); 39 scoped_refptr<ShareableBlobDataItem> dest_item);
41 ~ItemCopyEntry(); 40 ~ItemCopyEntry();
42 ItemCopyEntry(ItemCopyEntry&& other); 41 ItemCopyEntry(ItemCopyEntry&& other);
43 BlobEntry::ItemCopyEntry& operator=(BlobEntry::ItemCopyEntry&& rhs); 42 BlobEntry::ItemCopyEntry& operator=(BlobEntry::ItemCopyEntry&& rhs);
44 43
45 scoped_refptr<ShareableBlobDataItem> source_item; 44 scoped_refptr<ShareableBlobDataItem> source_item;
46 size_t source_item_offset = 0; 45 size_t source_item_offset = 0;
47 scoped_refptr<ShareableBlobDataItem> dest_item; 46 scoped_refptr<ShareableBlobDataItem> dest_item;
48 47
49 private: 48 private:
50 DISALLOW_COPY_AND_ASSIGN(ItemCopyEntry); 49 DISALLOW_COPY_AND_ASSIGN(ItemCopyEntry);
51 }; 50 };
52 51
53 // This keeps track of our building state for our blob. While building, four 52 // Building state for pending blobs. State can include:
54 // things can be happening mostly simultaneously: 53 // 1. Waiting for quota to be granted for transport data (PENDING_QUOTA)
55 // 1. Waiting for quota to be reserved for memory needed (PENDING_QUOTA)
56 // 2. Waiting for user population of data after quota (PENDING_TRANSPORT) 54 // 2. Waiting for user population of data after quota (PENDING_TRANSPORT)
57 // 3. Waiting for blobs we reference to complete (PENDING_INTERNALS) 55 // 3. Waiting for blobs we reference to complete & quota granted for possible
56 // copies. (PENDING_INTERNALS)
pwnall 2016/12/01 01:12:14 Based on the description here and in blob_storage_
dmurph 2016/12/01 20:40:59 Yeah I'll do that in a follow up cl. crbug/670398
58 struct STORAGE_EXPORT BuildingState { 57 struct STORAGE_EXPORT BuildingState {
59 // |transport_allowed_callback| is not null when data needs population. See 58 // |transport_allowed_callback| is not null when data needs population. See
60 // BlobStorageContext::BuildBlob for when the callback is called. 59 // BlobStorageContext::BuildBlob for when the callback is called.
61 BuildingState(bool transport_items_present, 60 BuildingState(bool transport_items_present,
62 TransportAllowedCallback transport_allowed_callback, 61 TransportAllowedCallback transport_allowed_callback,
63 size_t num_building_dependent_blobs); 62 size_t num_building_dependent_blobs);
64 ~BuildingState(); 63 ~BuildingState();
65 64
66 const bool transport_items_present; 65 const bool transport_items_present;
67 // We can have trasnport data that's either populated or unpopulated. If we 66 // We can have trasnport data that's either populated or unpopulated. If we
68 // need population, this is populated. 67 // need population, this is populated.
69 TransportAllowedCallback transport_allowed_callback; 68 TransportAllowedCallback transport_allowed_callback;
70 std::vector<ShareableBlobDataItem*> transport_items; 69 std::vector<ShareableBlobDataItem*> transport_items;
71 70
72 // Stores all blobs that we're depending on for building. This keeps the 71 // Stores all blobs that we're depending on for building. This keeps the
73 // blobs alive while we build our blob. 72 // blobs alive while we build our blob.
74 std::vector<std::unique_ptr<BlobDataHandle>> dependent_blobs; 73 std::vector<std::unique_ptr<BlobDataHandle>> dependent_blobs;
75 size_t num_building_dependent_blobs; 74 size_t num_building_dependent_blobs;
76 75
77 base::WeakPtr<BlobMemoryController::QuotaAllocationTask> 76 base::WeakPtr<BlobMemoryController::QuotaAllocationTask>
78 memory_quota_request; 77 transport_quota_request;
78
79 // Copy quota is always memory.
80 base::WeakPtr<BlobMemoryController::QuotaAllocationTask> copy_quota_request;
79 81
80 // These are copies from a referenced blob item to our blob items. Some of 82 // These are copies from a referenced blob item to our blob items. Some of
81 // these entries may have changed from bytes to files if they were paged. 83 // these entries may have changed from bytes to files if they were paged.
82 std::vector<ItemCopyEntry> copies; 84 std::vector<ItemCopyEntry> copies;
83 85
84 // When our blob finishes building these callbacks are called. 86 // When our blob finishes building these callbacks are called.
85 std::vector<BlobStatusCallback> build_completion_callbacks; 87 std::vector<BlobStatusCallback> build_completion_callbacks;
86 88
87 private: 89 private:
88 DISALLOW_COPY_AND_ASSIGN(BuildingState); 90 DISALLOW_COPY_AND_ASSIGN(BuildingState);
89 }; 91 };
90 92
91 BlobEntry(const std::string& content_type, 93 BlobEntry(const std::string& content_type,
92 const std::string& content_disposition); 94 const std::string& content_disposition);
93 ~BlobEntry(); 95 ~BlobEntry();
94 96
95 // Appends the given shared blob data item to this object. 97 // Appends the given shared blob data item to this object.
96 void AppendSharedBlobItem(scoped_refptr<ShareableBlobDataItem> item); 98 void AppendSharedBlobItem(scoped_refptr<ShareableBlobDataItem> item);
97 99
98 // Returns if we're a pending blob that can finish building. 100 // Returns if we're a pending blob that can finish building.
99 bool CanFinishBuilding() const { 101 bool CanFinishBuilding() const {
100 return status_ == BlobStatus::PENDING_INTERNALS && 102 return status_ == BlobStatus::PENDING_INTERNALS && building_state_ &&
103 !building_state_->copy_quota_request &&
101 building_state_->num_building_dependent_blobs == 0; 104 building_state_->num_building_dependent_blobs == 0;
102 } 105 }
103 106
104 BlobStatus status() const { return status_; } 107 BlobStatus status() const { return status_; }
105 108
106 size_t refcount() const { return refcount_; } 109 size_t refcount() const { return refcount_; }
107 110
108 const std::string& content_type() const { return content_type_; } 111 const std::string& content_type() const { return content_type_; }
109 112
110 const std::string& content_disposition() const { 113 const std::string& content_disposition() const {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 std::vector<uint64_t> offsets_; 158 std::vector<uint64_t> offsets_;
156 159
157 // Only populated if our status is PENDING_*. 160 // Only populated if our status is PENDING_*.
158 std::unique_ptr<BuildingState> building_state_; 161 std::unique_ptr<BuildingState> building_state_;
159 162
160 DISALLOW_COPY_AND_ASSIGN(BlobEntry); 163 DISALLOW_COPY_AND_ASSIGN(BlobEntry);
161 }; 164 };
162 165
163 } // namespace storage 166 } // namespace storage
164 #endif // STORAGE_BROWSER_BLOB_BLOB_ENTRY_H_ 167 #endif // STORAGE_BROWSER_BLOB_BLOB_ENTRY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698