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 THIRD_PARTY_BLINK_PUBLIC_COMMON_PRIVACY_BUDGET_IDENTIFIABILITY_SAMPLE_COLLECTOR_H_ 6 #define THIRD_PARTY_BLINK_PUBLIC_COMMON_PRIVACY_BUDGET_IDENTIFIABILITY_SAMPLE_COLLECTOR_H_ 7 8 #include <utility> 9 #include <vector> 10 11 #include "services/metrics/public/cpp/ukm_recorder.h" 12 #include "services/metrics/public/cpp/ukm_source_id.h" 13 #include "third_party/blink/public/common/common_export.h" 14 #include "third_party/blink/public/common/privacy_budget/identifiable_sample.h" 15 16 namespace blink { 17 18 // Do not use this directly. Don't report identifiability metrics directly via 19 // `UkmRecorder` either. 20 // 21 // `UkmRecorder` is not designed for the rate and volume with which 22 // identifiability metrics are generated. In addition, all of these metrics -- 23 // which aren't really metrics to begin with -- are only required to be recorded 24 // once per client. 25 // 26 // Therefore, rather than report identifiability samples directly to UKM, they 27 // should instead be funnelled through the global instance of 28 // `IdentifiabilitySampleCollector` which does the work of de-duplication and 29 // rate limiting.. 30 // 31 // `IdentifiabilityMetricBuilder` already uses `IdentifiabilitySampleCollector` 32 // internally. Look no further. 33 class BLINK_COMMON_EXPORT IdentifiabilitySampleCollector { 34 public: 35 virtual ~IdentifiabilitySampleCollector(); 36 37 // Gets the singleton per-process collector. Always returns a valid pointer. 38 static IdentifiabilitySampleCollector* Get(); 39 40 // Record a set of identifiability metrics. 41 virtual void Record(ukm::UkmRecorder* recorder, 42 ukm::SourceId source, 43 std::vector<IdentifiableSample> metrics) = 0; 44 45 // Unconditionally write out all pending metrics via `recorder`. 46 virtual void Flush(ukm::UkmRecorder* recorder) = 0; 47 48 // Unconditionally write out all pending metrics from `source` via `recorder`. 49 virtual void FlushSource(ukm::UkmRecorder* recorder, 50 ukm::SourceId source) = 0; 51 }; 52 53 } // namespace blink 54 55 #endif // THIRD_PARTY_BLINK_PUBLIC_COMMON_PRIVACY_BUDGET_IDENTIFIABILITY_SAMPLE_COLLECTOR_H_ 56