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.h b/buffet/states/state_change_queue.h
index a5cde95..2ca46e6 100644
--- a/buffet/states/state_change_queue.h
+++ b/buffet/states/state_change_queue.h
@@ -5,6 +5,7 @@
 #ifndef BUFFET_STATES_STATE_CHANGE_QUEUE_H_
 #define BUFFET_STATES_STATE_CHANGE_QUEUE_H_
 
+#include <map>
 #include <vector>
 
 #include <base/macros.h>
@@ -21,7 +22,9 @@
 
   // Overrides from StateChangeQueueInterface.
   bool IsEmpty() const override { return state_changes_.empty(); }
-  bool NotifyPropertiesUpdated(const StateChange& change) override;
+  bool NotifyPropertiesUpdated(
+      base::Time timestamp,
+      chromeos::VariantDictionary changed_properties) override;
   std::vector<StateChange> GetAndClearRecordedStateChanges() override;
 
  private:
@@ -32,10 +35,10 @@
 
   // Maximum queue size. If it is full, the oldest state update records are
   // merged together until the queue size is within the size limit.
-  size_t max_queue_size_;
+  const size_t max_queue_size_;
 
   // Accumulated list of device state change notifications.
-  std::vector<StateChange> state_changes_;
+  std::map<base::Time, chromeos::VariantDictionary> state_changes_;
 
   DISALLOW_COPY_AND_ASSIGN(StateChangeQueue);
 };