blob: 9181ef4f06c115abeeebac7cbbf9ed162e6017a9 [file] [log] [blame]
// Copyright 2014 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <map>
#include <vector>
#include <base/macros.h>
#include <base/threading/thread_checker.h>
#include "buffet/states/state_change_queue_interface.h"
namespace buffet {
// An object to record and retrieve device state change notification events.
class StateChangeQueue : public StateChangeQueueInterface {
explicit StateChangeQueue(size_t max_queue_size);
// Overrides from StateChangeQueueInterface.
bool IsEmpty() const override { return state_changes_.empty(); }
bool NotifyPropertiesUpdated(
base::Time timestamp,
native_types::Object changed_properties) override;
std::vector<StateChange> GetAndClearRecordedStateChanges() override;
// To make sure we do not call NotifyPropertiesUpdated() and
// GetAndClearRecordedStateChanges() on different threads, |thread_checker_|
// is here to help us with verifying the single-threaded operation.
base::ThreadChecker thread_checker_;
// Maximum queue size. If it is full, the oldest state update records are
// merged together until the queue size is within the size limit.
const size_t max_queue_size_;
// Accumulated list of device state change notifications.
std::map<base::Time, native_types::Object> state_changes_;
} // namespace buffet