buffet: Fix issues in StateChangeQueue
Addressed additional code review issues brought after the original
code has been published.
- NotifyPropertiesUpdated() now takes timestamp and property set
as separate parameters to simplify implementation of StateManager.
- StateChangeQueue::max_queue_size_ is made 'const'
- StateChangeQueue now maintains a time-to-event map instead of
a vector of StateChange. This allows to keep the events sorted
by time stamp. Also adding discrete events with the same time stamp
coalesces the property changes.
- added a unit test for coalescing property set changes based on
the timestamp.
BUG=None
TEST=FEATURES=test emerge-link buffet
Change-Id: I309816d1f040558620fa68a844b05251d0e4319b
Reviewed-on: https://chromium-review.googlesource.com/226300
Reviewed-by: Christopher Wiley <wiley@chromium.org>
Reviewed-by: Anton Muhin <antonm@chromium.org>
Commit-Queue: Alex Vakulenko <avakulenko@chromium.org>
Tested-by: Alex Vakulenko <avakulenko@chromium.org>
diff --git a/buffet/states/state_change_queue_interface.h b/buffet/states/state_change_queue_interface.h
index 5810bff..84704dd 100644
--- a/buffet/states/state_change_queue_interface.h
+++ b/buffet/states/state_change_queue_interface.h
@@ -14,12 +14,14 @@
// A simple notification record event to track device state changes.
// The |timestamp| records the time of the state change.
-// |property_set| contains a property set with the new property values.
-// The property set contains only the properties updated at the time the event
-// was recorded.
+// |changed_properties| contains a property set with the new property values
+// which were updated at the time the event was recorded.
struct StateChange {
+ StateChange(base::Time time,
+ chromeos::VariantDictionary properties)
+ : timestamp(time), changed_properties(std::move(properties)) {}
base::Time timestamp;
- chromeos::VariantDictionary property_set;
+ chromeos::VariantDictionary changed_properties;
};
// An abstract interface to StateChangeQueue to record and retrieve state
@@ -30,7 +32,9 @@
virtual bool IsEmpty() const = 0;
// Called by StateManager when device state properties are updated.
- virtual bool NotifyPropertiesUpdated(const StateChange& change) = 0;
+ virtual bool NotifyPropertiesUpdated(
+ base::Time timestamp,
+ chromeos::VariantDictionary changed_properties) = 0;
// Returns the recorded state changes since last time this method was called.
virtual std::vector<StateChange> GetAndClearRecordedStateChanges() = 0;