blob: 77a5e1b58340b20fa2fbe8b40d138c4633c25e1c [file] [log] [blame]
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_OPTIMIZATION_GUIDE_MEMORY_HINT_H_
#define COMPONENTS_OPTIMIZATION_GUIDE_MEMORY_HINT_H_
#include "base/optional.h"
#include "base/time/time.h"
#include "components/optimization_guide/proto/hint_cache.pb.h"
#include "components/optimization_guide/proto/hints.pb.h"
namespace optimization_guide {
// A representation of a hint to be used by in-memory caches.
class MemoryHint {
public:
MemoryHint(const base::Optional<base::Time>& expiry_time,
std::unique_ptr<proto::Hint> hint);
MemoryHint(base::Time expiry_time, proto::Hint&& hint);
MemoryHint(const MemoryHint&) = delete;
MemoryHint& operator=(const MemoryHint&) = delete;
~MemoryHint();
// This value is not available if |hint_| was sourced from the Optimization
// Hints component. Otherwise, it is set.
const base::Optional<base::Time> expiry_time() const { return expiry_time_; }
// It is the responsibility of the callers to avoid use-after-free references
// that may occur if the containing object is evicted from an in-memory
// cache.
optimization_guide::proto::Hint* hint() const { return hint_.get(); }
private:
base::Optional<base::Time> expiry_time_;
std::unique_ptr<proto::Hint> hint_;
};
} // namespace optimization_guide
#endif // COMPONENTS_OPTIMIZATION_GUIDE_MEMORY_HINT_H_