File: store_update_data.h

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (85 lines) | stat: -rw-r--r-- 2,906 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_OPTIMIZATION_GUIDE_CORE_STORE_UPDATE_DATA_H_
#define COMPONENTS_OPTIMIZATION_GUIDE_CORE_STORE_UPDATE_DATA_H_

#include <optional>
#include <string>

#include "base/sequence_checker.h"
#include "base/time/time.h"
#include "base/version.h"
#include "components/leveldb_proto/public/proto_database.h"

namespace optimization_guide {
namespace proto {
class Hint;
class StoreEntry;
}  // namespace proto

using EntryVector =
    leveldb_proto::ProtoDatabase<proto::StoreEntry>::KeyEntryVector;

// Holds hint data for updating the OptimizationGuideStore.
class StoreUpdateData {
 public:
  StoreUpdateData(const StoreUpdateData&) = delete;
  StoreUpdateData& operator=(const StoreUpdateData&) = delete;

  ~StoreUpdateData();

  // Creates an update data object for a component hint update.
  static std::unique_ptr<StoreUpdateData> CreateComponentStoreUpdateData(
      const base::Version& component_version);

  // Creates an update data object for a fetched hint update.
  static std::unique_ptr<StoreUpdateData> CreateFetchedStoreUpdateData(
      base::Time fetch_update_time);

  // Returns the component version of a component hint update.
  const std::optional<base::Version> component_version() const {
    return component_version_;
  }

  // Returns the next update time for the entries in the store update.
  const std::optional<base::Time> update_time() const { return update_time_; }

  // Returns the expiry time for the hints in a fetched hint update.
  const std::optional<base::Time> expiry_time() const { return expiry_time_; }

  // Moves |hint| into this update data. After MoveHintIntoUpdateData() is
  // called, |hint| is no longer valid.
  void MoveHintIntoUpdateData(proto::Hint&& hint);

  // Returns the store entry updates along with ownership to them.
  std::unique_ptr<EntryVector> TakeUpdateEntries();

 private:
  StoreUpdateData(std::optional<base::Version> component_version,
                  std::optional<base::Time> fetch_update_time,
                  std::optional<base::Time> expiry_time);

  // The component version of the update data for a component update.
  std::optional<base::Version> component_version_;

  // The time when the entries in this update need to be updated.
  std::optional<base::Time> update_time_;

  // The time when entries in this update expire.
  std::optional<base::Time> expiry_time_;

  // The prefix to add to the key of every store entry. It is set
  // during construction for appropriate type of update.
  std::string entry_key_prefix_;

  // The vector of entries to save.
  std::unique_ptr<EntryVector> entries_to_save_;

  SEQUENCE_CHECKER(sequence_checker_);
};

}  // namespace optimization_guide

#endif  // COMPONENTS_OPTIMIZATION_GUIDE_CORE_STORE_UPDATE_DATA_H_