blob: 81701b4ed191e43c16e5edce665b32bcf2d0c4ca [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
Yao Xiao95d20682020-08-18 20:30:2133 bool operator==(const FlocId& other) const;
34 bool operator!=(const FlocId& other) const;
35
Yao Xiaodcda72b2020-05-18 23:05:3736 bool IsValid() const;
37 uint64_t ToUint64() const;
38
Yao Xiaoebed8c12020-09-26 07:51:2039 // The id followed by a version number. "null" if |id_| is invalid. To be
40 // deprecated soon.
Yao Xiaodcda72b2020-05-18 23:05:3741 std::string ToDebugHeaderValue() const;
42
Yao Xiaoebed8c12020-09-26 07:51:2043 // The id followed by a version number, which is the format be exposed to HTTP
44 // headers or JS API. Precondition: |id_| must be valid.
45 std::string ToString() const;
Yao Xiaodcda72b2020-05-18 23:05:3746
Yao Xiaoebed8c12020-09-26 07:51:2047 private:
Yao Xiaodcda72b2020-05-18 23:05:3748 base::Optional<uint64_t> id_;
49};
50
51} // namespace federated_learning
52
53#endif // COMPONENTS_FEDERATED_LEARNING_FLOC_ID_H_