blob: ad2d99426417e29effcafbfbd28c6daca3ed46ba [file] [log] [blame]
Yao Xiaodcda72b2020-05-18 23:05:371// Copyright 2020 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef COMPONENTS_FEDERATED_LEARNING_FLOC_ID_H_
6#define COMPONENTS_FEDERATED_LEARNING_FLOC_ID_H_
7
8#include "base/optional.h"
9
10#include <stdint.h>
11
12#include <string>
13#include <unordered_set>
14
15namespace federated_learning {
16
17// ID used to represent a cohort of people with similar browsing habits. For
18// more context, see the explainer at
19// https://github.com/jkarlin/floc/blob/master/README.md
20class FlocId {
21 public:
22 static FlocId CreateFromHistory(
23 const std::unordered_set<std::string>& domains);
24
25 FlocId();
26 explicit FlocId(uint64_t id);
27 FlocId(const FlocId& id);
28
29 ~FlocId();
30 FlocId& operator=(const FlocId& id);
31 FlocId& operator=(FlocId&& id);
32
33 bool IsValid() const;
34 uint64_t ToUint64() const;
35
36 std::string ToDebugHeaderValue() const;
37
38 private:
39 std::string ToHeaderValue() const;
40
41 base::Optional<uint64_t> id_;
42};
43
44} // namespace federated_learning
45
46#endif // COMPONENTS_FEDERATED_LEARNING_FLOC_ID_H_