Yao Xiao | dcda72b | 2020-05-18 23:05:37 | [diff] [blame] | 1 | // 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 | |
| 15 | namespace 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 |
| 20 | class 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 Xiao | 95d2068 | 2020-08-18 20:30:21 | [diff] [blame] | 33 | bool operator==(const FlocId& other) const; |
| 34 | bool operator!=(const FlocId& other) const; |
| 35 | |
Yao Xiao | dcda72b | 2020-05-18 23:05:37 | [diff] [blame] | 36 | bool IsValid() const; |
| 37 | uint64_t ToUint64() const; |
| 38 | |
Yao Xiao | ebed8c1 | 2020-09-26 07:51:20 | [diff] [blame^] | 39 | // The id followed by a version number. "null" if |id_| is invalid. To be |
| 40 | // deprecated soon. |
Yao Xiao | dcda72b | 2020-05-18 23:05:37 | [diff] [blame] | 41 | std::string ToDebugHeaderValue() const; |
| 42 | |
Yao Xiao | ebed8c1 | 2020-09-26 07:51:20 | [diff] [blame^] | 43 | // 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 Xiao | dcda72b | 2020-05-18 23:05:37 | [diff] [blame] | 46 | |
Yao Xiao | ebed8c1 | 2020-09-26 07:51:20 | [diff] [blame^] | 47 | private: |
Yao Xiao | dcda72b | 2020-05-18 23:05:37 | [diff] [blame] | 48 | base::Optional<uint64_t> id_; |
| 49 | }; |
| 50 | |
| 51 | } // namespace federated_learning |
| 52 | |
| 53 | #endif // COMPONENTS_FEDERATED_LEARNING_FLOC_ID_H_ |