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_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 // Represents a blob in BlobStorageRegistry. Exported only for unit tests. | 27 // This class represents a blob in BlobStorageRegistry. We export this only for |
| 28 // unit tests. |
28 class STORAGE_EXPORT BlobEntry { | 29 class STORAGE_EXPORT BlobEntry { |
29 public: | 30 public: |
30 using TransportAllowedCallback = | 31 using TransportAllowedCallback = |
31 base::Callback<void(BlobStatus, | 32 base::Callback<void(BlobStatus, |
32 std::vector<BlobMemoryController::FileCreationInfo>)>; | 33 std::vector<BlobMemoryController::FileCreationInfo>)>; |
33 | 34 |
34 // Records a copy from a referenced blob. Copies happen after referenced blobs | 35 // This records a copy from a referenced blob. When we finish building our |
35 // are complete & quota for the copies is granted. | 36 // blob we perform all of these copies. |
36 struct STORAGE_EXPORT ItemCopyEntry { | 37 struct STORAGE_EXPORT ItemCopyEntry { |
37 ItemCopyEntry(scoped_refptr<ShareableBlobDataItem> source_item, | 38 ItemCopyEntry(scoped_refptr<ShareableBlobDataItem> source_item, |
38 size_t source_item_offset, | 39 size_t source_item_offset, |
39 scoped_refptr<ShareableBlobDataItem> dest_item); | 40 scoped_refptr<ShareableBlobDataItem> dest_item); |
40 ~ItemCopyEntry(); | 41 ~ItemCopyEntry(); |
41 ItemCopyEntry(ItemCopyEntry&& other); | 42 ItemCopyEntry(ItemCopyEntry&& other); |
42 BlobEntry::ItemCopyEntry& operator=(BlobEntry::ItemCopyEntry&& rhs); | 43 BlobEntry::ItemCopyEntry& operator=(BlobEntry::ItemCopyEntry&& rhs); |
43 | 44 |
44 scoped_refptr<ShareableBlobDataItem> source_item; | 45 scoped_refptr<ShareableBlobDataItem> source_item; |
45 size_t source_item_offset = 0; | 46 size_t source_item_offset = 0; |
46 scoped_refptr<ShareableBlobDataItem> dest_item; | 47 scoped_refptr<ShareableBlobDataItem> dest_item; |
47 | 48 |
48 private: | 49 private: |
49 DISALLOW_COPY_AND_ASSIGN(ItemCopyEntry); | 50 DISALLOW_COPY_AND_ASSIGN(ItemCopyEntry); |
50 }; | 51 }; |
51 | 52 |
52 // Building state for pending blobs. State can include: | 53 // This keeps track of our building state for our blob. While building, four |
53 // 1. Waiting for quota to be granted for transport data (PENDING_QUOTA) | 54 // things can be happening mostly simultaneously: |
| 55 // 1. Waiting for quota to be reserved for memory needed (PENDING_QUOTA) |
54 // 2. Waiting for user population of data after quota (PENDING_TRANSPORT) | 56 // 2. Waiting for user population of data after quota (PENDING_TRANSPORT) |
55 // 3. Waiting for blobs we reference to complete & quota granted for possible | 57 // 3. Waiting for blobs we reference to complete (PENDING_INTERNALS) |
56 // copies. (PENDING_INTERNALS) | |
57 struct STORAGE_EXPORT BuildingState { | 58 struct STORAGE_EXPORT BuildingState { |
58 // |transport_allowed_callback| is not null when data needs population. See | 59 // |transport_allowed_callback| is not null when data needs population. See |
59 // BlobStorageContext::BuildBlob for when the callback is called. | 60 // BlobStorageContext::BuildBlob for when the callback is called. |
60 BuildingState(bool transport_items_present, | 61 BuildingState(bool transport_items_present, |
61 TransportAllowedCallback transport_allowed_callback, | 62 TransportAllowedCallback transport_allowed_callback, |
62 size_t num_building_dependent_blobs); | 63 size_t num_building_dependent_blobs); |
63 ~BuildingState(); | 64 ~BuildingState(); |
64 | 65 |
65 // Cancels pending memory or file requests. | |
66 void CancelRequests(); | |
67 | |
68 const bool transport_items_present; | 66 const bool transport_items_present; |
69 // We can have trasnport data that's either populated or unpopulated. If we | 67 // We can have trasnport data that's either populated or unpopulated. If we |
70 // need population, this is populated. | 68 // need population, this is populated. |
71 TransportAllowedCallback transport_allowed_callback; | 69 TransportAllowedCallback transport_allowed_callback; |
72 std::vector<ShareableBlobDataItem*> transport_items; | 70 std::vector<ShareableBlobDataItem*> transport_items; |
73 | 71 |
74 // Stores all blobs that we're depending on for building. This keeps the | 72 // Stores all blobs that we're depending on for building. This keeps the |
75 // blobs alive while we build our blob. | 73 // blobs alive while we build our blob. |
76 std::vector<std::unique_ptr<BlobDataHandle>> dependent_blobs; | 74 std::vector<std::unique_ptr<BlobDataHandle>> dependent_blobs; |
77 size_t num_building_dependent_blobs; | 75 size_t num_building_dependent_blobs; |
78 | 76 |
79 base::WeakPtr<BlobMemoryController::QuotaAllocationTask> | 77 base::WeakPtr<BlobMemoryController::QuotaAllocationTask> |
80 transport_quota_request; | 78 memory_quota_request; |
81 | |
82 // Copy quota is always memory. | |
83 base::WeakPtr<BlobMemoryController::QuotaAllocationTask> copy_quota_request; | |
84 | 79 |
85 // These are copies from a referenced blob item to our blob items. Some of | 80 // These are copies from a referenced blob item to our blob items. Some of |
86 // these entries may have changed from bytes to files if they were paged. | 81 // these entries may have changed from bytes to files if they were paged. |
87 std::vector<ItemCopyEntry> copies; | 82 std::vector<ItemCopyEntry> copies; |
88 | 83 |
89 // When our blob finishes building these callbacks are called. | 84 // When our blob finishes building these callbacks are called. |
90 std::vector<BlobStatusCallback> build_completion_callbacks; | 85 std::vector<BlobStatusCallback> build_completion_callbacks; |
91 | 86 |
92 private: | 87 private: |
93 DISALLOW_COPY_AND_ASSIGN(BuildingState); | 88 DISALLOW_COPY_AND_ASSIGN(BuildingState); |
94 }; | 89 }; |
95 | 90 |
96 BlobEntry(const std::string& content_type, | 91 BlobEntry(const std::string& content_type, |
97 const std::string& content_disposition); | 92 const std::string& content_disposition); |
98 ~BlobEntry(); | 93 ~BlobEntry(); |
99 | 94 |
100 // Appends the given shared blob data item to this object. | 95 // Appends the given shared blob data item to this object. |
101 void AppendSharedBlobItem(scoped_refptr<ShareableBlobDataItem> item); | 96 void AppendSharedBlobItem(scoped_refptr<ShareableBlobDataItem> item); |
102 | 97 |
103 // Returns if we're a pending blob that can finish building. | 98 // Returns if we're a pending blob that can finish building. |
104 bool CanFinishBuilding() const { | 99 bool CanFinishBuilding() const { |
105 // PENDING_INTERNALS means transport is finished. | 100 return status_ == BlobStatus::PENDING_INTERNALS && |
106 return status_ == BlobStatus::PENDING_INTERNALS && building_state_ && | |
107 !building_state_->copy_quota_request && | |
108 building_state_->num_building_dependent_blobs == 0; | 101 building_state_->num_building_dependent_blobs == 0; |
109 } | 102 } |
110 | 103 |
111 BlobStatus status() const { return status_; } | 104 BlobStatus status() const { return status_; } |
112 | 105 |
113 size_t refcount() const { return refcount_; } | 106 size_t refcount() const { return refcount_; } |
114 | 107 |
115 const std::string& content_type() const { return content_type_; } | 108 const std::string& content_type() const { return content_type_; } |
116 | 109 |
117 const std::string& content_disposition() const { | 110 const std::string& content_disposition() const { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 std::vector<uint64_t> offsets_; | 155 std::vector<uint64_t> offsets_; |
163 | 156 |
164 // Only populated if our status is PENDING_*. | 157 // Only populated if our status is PENDING_*. |
165 std::unique_ptr<BuildingState> building_state_; | 158 std::unique_ptr<BuildingState> building_state_; |
166 | 159 |
167 DISALLOW_COPY_AND_ASSIGN(BlobEntry); | 160 DISALLOW_COPY_AND_ASSIGN(BlobEntry); |
168 }; | 161 }; |
169 | 162 |
170 } // namespace storage | 163 } // namespace storage |
171 #endif // STORAGE_BROWSER_BLOB_BLOB_ENTRY_H_ | 164 #endif // STORAGE_BROWSER_BLOB_BLOB_ENTRY_H_ |
OLD | NEW |