blob: d17cc1d6513c6239dc8ed2dea502f2b630abc0b4 [file] [log] [blame]
// Copyright (c) 2012 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 <string>
#include <base/macros.h>
#include <base/time/time.h>
namespace cryptohome {
// Cache of last access timestamp for existing users.
class UserOldestActivityTimestampCache {
UserOldestActivityTimestampCache() : initialized_(false) {}
UserOldestActivityTimestampCache(const UserOldestActivityTimestampCache&) =
UserOldestActivityTimestampCache& operator=(
const UserOldestActivityTimestampCache&) = delete;
virtual ~UserOldestActivityTimestampCache() {}
// Initialize the cache. This must be done only once. No methods
// must be accessed before that. Chrome initializes cache and
// starts using it when hourly cleanup callback faces lack of disk
// space. If cryptohomed restarts for some reason, cache becomes
// uninitialized and will be re-initialized (and filled) again on
// the nearest convenience (cleanup callback).
virtual void Initialize();
virtual bool initialized() const { return initialized_; }
// Adds a user to the cache with specified oldest activity timestamp.
virtual void AddExistingUser(const std::string& user, base::Time timestamp);
// Updates a user in the cache with specified oldest activity timestamp.
virtual void UpdateExistingUser(const std::string& user,
base::Time timestamp);
// Remove a user from the cache.
virtual void RemoveUser(const std::string& user);
// Returns the last activity timestamp for a user. For users without a
// timestamp it returns a NULL time.
virtual base::Time GetLastUserActivityTimestamp(
const std::string& user) const;
std::map<std::string, base::Time> users_timestamp_lookup_;
bool initialized_;
} // namespace cryptohome