Extend ScopedReservation
Bug:b:233089187
Bug:b:237811834
Make it possible to have 0-sized scoped reservation unattached to resource interface.
When adding a "real" reservation to it, copy the interface too.
Change-Id: I1d0a453b48b66ce29d1140b8f391c45b6c956ceb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3749092
Commit-Queue: Leonid Baraz <[email protected]>
Auto-Submit: Leonid Baraz <[email protected]>
Reviewed-by: Hong Xu <[email protected]>
Commit-Queue: Hong Xu <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1021451}
diff --git a/components/reporting/resources/resource_interface.h b/components/reporting/resources/resource_interface.h
index 56fd3bce..a3fb0fb 100644
--- a/components/reporting/resources/resource_interface.h
+++ b/components/reporting/resources/resource_interface.h
@@ -57,9 +57,22 @@
// ...
// } // Automatically discarded.
//
-// Can be handed over to another owner.
+// Can be handed over to another owner by move-constructor or using HandOver
+// method:
+// {
+// ScopedReservation summary;
+// for (const uint64_t size : sizes) {
+// ScopedReservation single_reservation(size, resource);
+// ...
+// summary.HandOver(single_reservation);
+// }
+// }
class ScopedReservation {
public:
+ // Zero-size reservation with no resource interface attached.
+ // reserved() returns false.
+ ScopedReservation() noexcept;
+ // Specified reservation, must have resource interface attached.
ScopedReservation(
uint64_t size,
scoped_refptr<ResourceInterface> resource_interface) noexcept;
@@ -81,7 +94,7 @@
void HandOver(ScopedReservation& other);
private:
- const scoped_refptr<ResourceInterface> resource_interface_;
+ scoped_refptr<ResourceInterface> resource_interface_;
absl::optional<uint64_t> size_;
};