summaryrefslogtreecommitdiff
path: root/chromium/components/federated_learning/floc_id.h
blob: ad2d99426417e29effcafbfbd28c6daca3ed46ba (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
// 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_FEDERATED_LEARNING_FLOC_ID_H_
#define COMPONENTS_FEDERATED_LEARNING_FLOC_ID_H_

#include "base/optional.h"

#include <stdint.h>

#include <string>
#include <unordered_set>

namespace federated_learning {

// ID used to represent a cohort of people with similar browsing habits. For
// more context, see the explainer at
// https://github.com/jkarlin/floc/blob/master/README.md
class FlocId {
 public:
  static FlocId CreateFromHistory(
      const std::unordered_set<std::string>& domains);

  FlocId();
  explicit FlocId(uint64_t id);
  FlocId(const FlocId& id);

  ~FlocId();
  FlocId& operator=(const FlocId& id);
  FlocId& operator=(FlocId&& id);

  bool IsValid() const;
  uint64_t ToUint64() const;

  std::string ToDebugHeaderValue() const;

 private:
  std::string ToHeaderValue() const;

  base::Optional<uint64_t> id_;
};

}  // namespace federated_learning

#endif  // COMPONENTS_FEDERATED_LEARNING_FLOC_ID_H_