summaryrefslogtreecommitdiff
path: root/chromium/services/network/trust_tokens/in_memory_trust_token_persister.h
blob: 30203d9bc5d6a5de402cd16bbaed8aecfcc45df2 (plain)
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
// Copyright 2019 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 SERVICES_NETWORK_TRUST_TOKENS_IN_MEMORY_TRUST_TOKEN_PERSISTER_H_
#define SERVICES_NETWORK_TRUST_TOKENS_IN_MEMORY_TRUST_TOKEN_PERSISTER_H_

#include <map>
#include <memory>
#include <utility>

#include "base/callback.h"
#include "services/network/trust_tokens/proto/public.pb.h"
#include "services/network/trust_tokens/proto/storage.pb.h"
#include "services/network/trust_tokens/suitable_trust_token_origin.h"
#include "services/network/trust_tokens/trust_token_persister.h"

namespace network {

// An InMemoryTrustTokenPersister stores Trust Tokens state during its lifetime,
// but does not write it through to a backend. It is suitable for use in tests
// (as a fake) and in environments without access to SQL.
class InMemoryTrustTokenPersister : public TrustTokenPersister {
 public:
  InMemoryTrustTokenPersister();
  ~InMemoryTrustTokenPersister() override;

  // TrustTokenPersister implementation:
  std::unique_ptr<TrustTokenIssuerConfig> GetIssuerConfig(
      const SuitableTrustTokenOrigin& issuer) override;
  std::unique_ptr<TrustTokenToplevelConfig> GetToplevelConfig(
      const SuitableTrustTokenOrigin& toplevel) override;
  std::unique_ptr<TrustTokenIssuerToplevelPairConfig>
  GetIssuerToplevelPairConfig(
      const SuitableTrustTokenOrigin& issuer,
      const SuitableTrustTokenOrigin& toplevel) override;

  void SetIssuerConfig(const SuitableTrustTokenOrigin& issuer,
                       std::unique_ptr<TrustTokenIssuerConfig> config) override;
  void SetToplevelConfig(
      const SuitableTrustTokenOrigin& toplevel,
      std::unique_ptr<TrustTokenToplevelConfig> config) override;
  void SetIssuerToplevelPairConfig(
      const SuitableTrustTokenOrigin& issuer,
      const SuitableTrustTokenOrigin& toplevel,
      std::unique_ptr<TrustTokenIssuerToplevelPairConfig> config) override;

  bool DeleteForOrigins(
      base::RepeatingCallback<bool(const SuitableTrustTokenOrigin&)> matcher)
      override;

 private:
  std::map<SuitableTrustTokenOrigin, std::unique_ptr<TrustTokenToplevelConfig>>
      toplevel_configs_;
  std::map<SuitableTrustTokenOrigin, std::unique_ptr<TrustTokenIssuerConfig>>
      issuer_configs_;
  std::map<std::pair<SuitableTrustTokenOrigin, SuitableTrustTokenOrigin>,
           std::unique_ptr<TrustTokenIssuerToplevelPairConfig>>
      issuer_toplevel_pair_configs_;
};

}  // namespace network

#endif  // SERVICES_NETWORK_TRUST_TOKENS_IN_MEMORY_TRUST_TOKEN_PERSISTER_H_