summaryrefslogtreecommitdiff
path: root/chromium/base/metrics
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2021-03-12 09:13:00 +0100
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2021-03-16 09:58:26 +0000
commit03561cae90f1d99b5c54b1ef3be69f10e882b25e (patch)
treecc5f0958e823c044e7ae51cc0117fe51432abe5e /chromium/base/metrics
parentfa98118a45f7e169f8846086dc2c22c49a8ba310 (diff)
downloadqtwebengine-chromium-03561cae90f1d99b5c54b1ef3be69f10e882b25e.tar.gz
BASELINE: Update Chromium to 88.0.4324.208
Change-Id: I3ae87d23e4eff4b4a469685658740a213600c667 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/base/metrics')
-rw-r--r--chromium/base/metrics/DIR_METADATA3
-rw-r--r--chromium/base/metrics/OWNERS2
-rw-r--r--chromium/base/metrics/field_trial_params.h31
-rw-r--r--chromium/base/metrics/histogram.cc15
-rw-r--r--chromium/base/metrics/histogram_base.h14
-rw-r--r--chromium/base/metrics/histogram_functions.cc11
-rw-r--r--chromium/base/metrics/histogram_functions.h10
-rw-r--r--chromium/base/metrics/histogram_functions_unittest.cc19
-rw-r--r--chromium/base/metrics/sparse_histogram_unittest.cc14
-rw-r--r--chromium/base/metrics/statistics_recorder.cc24
-rw-r--r--chromium/base/metrics/statistics_recorder.h2
-rw-r--r--chromium/base/metrics/ukm_source_id.cc65
-rw-r--r--chromium/base/metrics/ukm_source_id.h111
13 files changed, 101 insertions, 220 deletions
diff --git a/chromium/base/metrics/DIR_METADATA b/chromium/base/metrics/DIR_METADATA
new file mode 100644
index 00000000000..540f41c94fe
--- /dev/null
+++ b/chromium/base/metrics/DIR_METADATA
@@ -0,0 +1,3 @@
+monorail {
+ component: "Internals>Metrics"
+}
diff --git a/chromium/base/metrics/OWNERS b/chromium/base/metrics/OWNERS
index 7134ec98bcf..6a0bb2abdf7 100644
--- a/chromium/base/metrics/OWNERS
+++ b/chromium/base/metrics/OWNERS
@@ -11,5 +11,3 @@ isherman@chromium.org
jwd@chromium.org
mpearson@chromium.org
rkaplow@chromium.org
-
-# COMPONENT: Internals>Metrics
diff --git a/chromium/base/metrics/field_trial_params.h b/chromium/base/metrics/field_trial_params.h
index c44e7192da4..577c3416535 100644
--- a/chromium/base/metrics/field_trial_params.h
+++ b/chromium/base/metrics/field_trial_params.h
@@ -121,6 +121,9 @@ BASE_EXPORT bool GetFieldTrialParamByFeatureAsBool(
//
// See the individual definitions below for the appropriate interfaces.
// Attempting to use it with any other type is a compile error.
+//
+// Getting a param value from a FeatureParam<T> will have the same semantics as
+// GetFieldTrialParamValueByFeature(), see that function's comments for details.
template <typename T, bool IsEnum = std::is_enum<T>::value>
struct FeatureParam {
// Prevent use of FeatureParam<> with unsupported types (e.g. void*). Uses T
@@ -134,8 +137,8 @@ struct FeatureParam {
// constexpr FeatureParam<string> kAssistantName{
// &kAssistantFeature, "assistant_name", "HAL"};
//
-// If the feature is not set, or set to the empty string, then Get() will return
-// the default value.
+// If the parameter is not set, or set to the empty string, then Get() will
+// return the default value.
template <>
struct FeatureParam<std::string> {
constexpr FeatureParam(const Feature* feature,
@@ -143,6 +146,8 @@ struct FeatureParam<std::string> {
const char* default_value)
: feature(feature), name(name), default_value(default_value) {}
+ // Calling Get() will activate the field trial associated with |feature|. See
+ // GetFieldTrialParamValueByFeature() for more details.
BASE_EXPORT std::string Get() const;
const Feature* const feature;
@@ -155,8 +160,8 @@ struct FeatureParam<std::string> {
// constexpr FeatureParam<double> kAssistantTriggerThreshold{
// &kAssistantFeature, "trigger_threshold", 0.10};
//
-// If the feature is not set, or set to an invalid double value, then Get() will
-// return the default value.
+// If the parameter is not set, or set to an invalid double value, then Get()
+// will return the default value.
template <>
struct FeatureParam<double> {
constexpr FeatureParam(const Feature* feature,
@@ -164,6 +169,8 @@ struct FeatureParam<double> {
double default_value)
: feature(feature), name(name), default_value(default_value) {}
+ // Calling Get() will activate the field trial associated with |feature|. See
+ // GetFieldTrialParamValueByFeature() for more details.
BASE_EXPORT double Get() const;
const Feature* const feature;
@@ -176,7 +183,7 @@ struct FeatureParam<double> {
// constexpr FeatureParam<int> kAssistantParallelism{
// &kAssistantFeature, "parallelism", 4};
//
-// If the feature is not set, or set to an invalid int value, then Get() will
+// If the parameter is not set, or set to an invalid int value, then Get() will
// return the default value.
template <>
struct FeatureParam<int> {
@@ -185,6 +192,8 @@ struct FeatureParam<int> {
int default_value)
: feature(feature), name(name), default_value(default_value) {}
+ // Calling Get() will activate the field trial associated with |feature|. See
+ // GetFieldTrialParamValueByFeature() for more details.
BASE_EXPORT int Get() const;
const Feature* const feature;
@@ -197,8 +206,8 @@ struct FeatureParam<int> {
// constexpr FeatureParam<int> kAssistantIsHelpful{
// &kAssistantFeature, "is_helpful", true};
//
-// If the feature is not set, or set to value other than "true" or "false", then
-// Get() will return the default value.
+// If the parameter is not set, or set to value other than "true" or "false",
+// then Get() will return the default value.
template <>
struct FeatureParam<bool> {
constexpr FeatureParam(const Feature* feature,
@@ -206,6 +215,8 @@ struct FeatureParam<bool> {
bool default_value)
: feature(feature), name(name), default_value(default_value) {}
+ // Calling Get() will activate the field trial associated with |feature|. See
+ // GetFieldTrialParamValueByFeature() for more details.
BASE_EXPORT bool Get() const;
const Feature* const feature;
@@ -218,7 +229,7 @@ struct FeatureParam<bool> {
// constexpr base::FeatureParam<base::TimeDelta> kPerAgentDelayMs{
// &kPerAgentSchedulingExperiments, "delay_ms", base::TimeDelta()};
//
-// If the feature is not set, or set to an invalid value (as defined by
+// If the parameter is not set, or set to an invalid value (as defined by
// base::TimeDelta::FromString()), then Get() will return the default value.
template <>
struct FeatureParam<base::TimeDelta> {
@@ -227,6 +238,8 @@ struct FeatureParam<base::TimeDelta> {
base::TimeDelta default_value)
: feature(feature), name(name), default_value(default_value) {}
+ // Calling Get() will activate the field trial associated with |feature|. See
+ // GetFieldTrialParamValueByFeature() for more details.
BASE_EXPORT base::TimeDelta Get() const;
const Feature* const feature;
@@ -274,6 +287,8 @@ struct FeatureParam<Enum, true> {
static_assert(option_count >= 1, "FeatureParam<enum> has no options");
}
+ // Calling Get() will activate the field trial associated with |feature|. See
+ // GetFieldTrialParamValueByFeature() for more details.
Enum Get() const {
std::string value = GetFieldTrialParamValueByFeature(*feature, name);
if (value.empty())
diff --git a/chromium/base/metrics/histogram.cc b/chromium/base/metrics/histogram.cc
index e28233b7706..99524406ed0 100644
--- a/chromium/base/metrics/histogram.cc
+++ b/chromium/base/metrics/histogram.cc
@@ -13,7 +13,6 @@
#include <limits.h>
#include <math.h>
-#include <algorithm>
#include <string>
#include <utility>
@@ -29,6 +28,7 @@
#include "base/metrics/sample_vector.h"
#include "base/metrics/statistics_recorder.h"
#include "base/pickle.h"
+#include "base/ranges/algorithm.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
@@ -454,13 +454,10 @@ bool Histogram::InspectConstructionArguments(StringPiece name,
UmaHistogramSparse("Histogram.TooManyBuckets.1000",
static_cast<Sample>(HashMetricName(name)));
- // TODO(bcwhite): Clean these up as bugs get fixed. Also look at injecting
- // whitelist (using hashes) from a higher layer rather than hardcoding
- // them here.
+ // TODO(bcwhite): Look at injecting allowlist (using hashes) from a higher
+ // layer rather than hardcoding them here.
// Blink.UseCounter legitimately has more than 1000 entries in its enum.
- // Arc.OOMKills: https://crbug.com/916757
- if (!StartsWith(name, "Blink.UseCounter") &&
- !StartsWith(name, "Arc.OOMKills.")) {
+ if (!StartsWith(name, "Blink.UseCounter")) {
DVLOG(1) << "Histogram: " << name
<< " has bad bucket_count: " << *bucket_count << " (limit "
<< kBucketCount_MAX << ")";
@@ -1248,8 +1245,8 @@ class CustomHistogram::Factory : public Histogram::Factory {
std::vector<int> ranges = *custom_ranges_;
ranges.push_back(0); // Ensure we have a zero value.
ranges.push_back(HistogramBase::kSampleType_MAX);
- std::sort(ranges.begin(), ranges.end());
- ranges.erase(std::unique(ranges.begin(), ranges.end()), ranges.end());
+ ranges::sort(ranges);
+ ranges.erase(ranges::unique(ranges), ranges.end());
BucketRanges* bucket_ranges = new BucketRanges(ranges.size());
for (uint32_t i = 0; i < ranges.size(); i++) {
diff --git a/chromium/base/metrics/histogram_base.h b/chromium/base/metrics/histogram_base.h
index 7a12fc1989e..e38085988f1 100644
--- a/chromium/base/metrics/histogram_base.h
+++ b/chromium/base/metrics/histogram_base.h
@@ -213,6 +213,16 @@ class BASE_EXPORT HistogramBase {
virtual uint32_t FindCorruption(const HistogramSamples& samples) const;
// Snapshot the current complete set of sample data.
+ // Note that histogram data is stored per-process. The browser process
+ // periodically injests data from subprocesses. As such, the browser
+ // process can see histogram data from any process but other processes
+ // can only see histogram data recorded in the subprocess.
+ // Moreover, the data returned here may not be up to date:
+ // - this function does not use a lock so data might not be synced
+ // (e.g., across cpu caches)
+ // - in the browser process, the data from subprocesses may not have
+ // synced data from subprocesses via MergeHistogramDeltas() recently.
+ //
// Override with atomic/locked snapshot if needed.
// NOTE: this data can overflow for long-running sessions. It should be
// handled with care and this method is recommended to be used only
@@ -222,6 +232,8 @@ class BASE_EXPORT HistogramBase {
// Calculate the change (delta) in histogram counts since the previous call
// to this method. Each successive call will return only those counts
// changed since the last call.
+ //
+ // See additional caveats by SnapshotSamples().
virtual std::unique_ptr<HistogramSamples> SnapshotDelta() = 0;
// Calculate the change (delta) in histogram counts since the previous call
@@ -231,6 +243,8 @@ class BASE_EXPORT HistogramBase {
// data previously returned. Because no internal data is changed, this call
// can be made on "const" histograms such as those with data held in
// read-only memory.
+ //
+ // See additional caveats by SnapshotSamples().
virtual std::unique_ptr<HistogramSamples> SnapshotFinalDelta() const = 0;
// The following method provides graphical histogram displays.
diff --git a/chromium/base/metrics/histogram_functions.cc b/chromium/base/metrics/histogram_functions.cc
index 3aa89e39fc6..99789a7e00a 100644
--- a/chromium/base/metrics/histogram_functions.cc
+++ b/chromium/base/metrics/histogram_functions.cc
@@ -40,10 +40,19 @@ void UmaHistogramExactLinear(const char* name, int sample, int value_max) {
}
void UmaHistogramPercentage(const std::string& name, int percent) {
- UmaHistogramExactLinear(name, percent, 100);
+ UmaHistogramExactLinear(name, percent, 101);
}
void UmaHistogramPercentage(const char* name, int percent) {
+ UmaHistogramExactLinear(name, percent, 101);
+}
+
+void UmaHistogramPercentageObsoleteDoNotUse(const std::string& name,
+ int percent) {
+ UmaHistogramExactLinear(name, percent, 100);
+}
+
+void UmaHistogramPercentageObsoleteDoNotUse(const char* name, int percent) {
UmaHistogramExactLinear(name, percent, 100);
}
diff --git a/chromium/base/metrics/histogram_functions.h b/chromium/base/metrics/histogram_functions.h
index 1eae16d38d2..46143024ba5 100644
--- a/chromium/base/metrics/histogram_functions.h
+++ b/chromium/base/metrics/histogram_functions.h
@@ -125,13 +125,19 @@ void UmaHistogramEnumeration(const char* name, T sample, T enum_size) {
BASE_EXPORT void UmaHistogramBoolean(const std::string& name, bool sample);
BASE_EXPORT void UmaHistogramBoolean(const char* name, bool sample);
-// For adding histogram with percent.
-// Percents are integer between 1 and 100.
+// For adding histogram sample denoting a percentage.
+// Percents are integers between 1 and 100, inclusively.
// Sample usage:
// base::UmaHistogramPercentage("My.Percent", 69)
BASE_EXPORT void UmaHistogramPercentage(const std::string& name, int percent);
BASE_EXPORT void UmaHistogramPercentage(const char* name, int percent);
+// Obsolete. Use |UmaHistogramPercentage| instead. See crbug/1121318.
+BASE_EXPORT void UmaHistogramPercentageObsoleteDoNotUse(const std::string& name,
+ int percent);
+BASE_EXPORT void UmaHistogramPercentageObsoleteDoNotUse(const char* name,
+ int percent);
+
// For adding counts histogram.
// Sample usage:
// base::UmaHistogramCustomCounts("My.Counts", some_value, 1, 600, 30)
diff --git a/chromium/base/metrics/histogram_functions_unittest.cc b/chromium/base/metrics/histogram_functions_unittest.cc
index 32f439469bd..4c0a0408300 100644
--- a/chromium/base/metrics/histogram_functions_unittest.cc
+++ b/chromium/base/metrics/histogram_functions_unittest.cc
@@ -67,12 +67,25 @@ TEST(HistogramFunctionsTest, Boolean) {
TEST(HistogramFunctionsTest, Percentage) {
std::string histogram("Testing.UMA.HistogramPercentage");
HistogramTester tester;
+ UmaHistogramPercentage(histogram, 1);
+ tester.ExpectBucketCount(histogram, 1, 1);
+ tester.ExpectTotalCount(histogram, 1);
+
UmaHistogramPercentage(histogram, 50);
- tester.ExpectUniqueSample(histogram, 50, 1);
+ tester.ExpectBucketCount(histogram, 50, 1);
+ tester.ExpectTotalCount(histogram, 2);
+
+ UmaHistogramPercentage(histogram, 100);
+ tester.ExpectBucketCount(histogram, 100, 1);
+ tester.ExpectTotalCount(histogram, 3);
// Test overflows.
- UmaHistogramPercentage(histogram, 110);
+ UmaHistogramPercentage(histogram, 101);
tester.ExpectBucketCount(histogram, 101, 1);
- tester.ExpectTotalCount(histogram, 2);
+ tester.ExpectTotalCount(histogram, 4);
+
+ UmaHistogramPercentage(histogram, 500);
+ tester.ExpectBucketCount(histogram, 101, 2);
+ tester.ExpectTotalCount(histogram, 5);
}
TEST(HistogramFunctionsTest, Counts) {
diff --git a/chromium/base/metrics/sparse_histogram_unittest.cc b/chromium/base/metrics/sparse_histogram_unittest.cc
index 4bada66dc50..1376e851291 100644
--- a/chromium/base/metrics/sparse_histogram_unittest.cc
+++ b/chromium/base/metrics/sparse_histogram_unittest.cc
@@ -400,10 +400,10 @@ TEST_P(SparseHistogramTest, HistogramNameHash) {
TEST_P(SparseHistogramTest, CheckGetCountAndBucketData) {
std::unique_ptr<SparseHistogram> histogram(NewSparseHistogram("Sparse"));
// Add samples in reverse order and make sure the output is in correct order.
- histogram->AddCount(/*sample=*/200, /*value=*/15);
- histogram->AddCount(/*sample=*/100, /*value=*/5);
+ histogram->AddCount(/*sample=*/200, /*count=*/15);
+ histogram->AddCount(/*sample=*/100, /*count=*/5);
// Add samples to the same bucket and make sure they'll be aggregated.
- histogram->AddCount(/*sample=*/100, /*value=*/5);
+ histogram->AddCount(/*sample=*/100, /*count=*/5);
base::Histogram::Count total_count;
int64_t sum;
@@ -438,8 +438,8 @@ TEST_P(SparseHistogramTest, CheckGetCountAndBucketData) {
TEST_P(SparseHistogramTest, WriteAscii) {
HistogramBase* histogram =
SparseHistogram::FactoryGet("AsciiOut", HistogramBase::kNoFlags);
- histogram->AddCount(/*sample=*/4, /*value=*/5);
- histogram->AddCount(/*sample=*/10, /*value=*/15);
+ histogram->AddCount(/*sample=*/4, /*count=*/5);
+ histogram->AddCount(/*sample=*/10, /*count=*/15);
std::string output;
histogram->WriteAscii(&output);
@@ -455,8 +455,8 @@ TEST_P(SparseHistogramTest, WriteAscii) {
TEST_P(SparseHistogramTest, ToGraphDict) {
HistogramBase* histogram =
SparseHistogram::FactoryGet("HTMLOut", HistogramBase::kNoFlags);
- histogram->AddCount(/*sample=*/4, /*value=*/5);
- histogram->AddCount(/*sample=*/10, /*value=*/15);
+ histogram->AddCount(/*sample=*/4, /*count=*/5);
+ histogram->AddCount(/*sample=*/10, /*count=*/15);
base::DictionaryValue output = histogram->ToGraphDict();
std::string* header = output.FindStringKey("header");
diff --git a/chromium/base/metrics/statistics_recorder.cc b/chromium/base/metrics/statistics_recorder.cc
index 58a442d7a90..b8cacab8995 100644
--- a/chromium/base/metrics/statistics_recorder.cc
+++ b/chromium/base/metrics/statistics_recorder.cc
@@ -16,6 +16,7 @@
#include "base/metrics/metrics_hashes.h"
#include "base/metrics/persistent_histogram_allocator.h"
#include "base/metrics/record_histogram_checker.h"
+#include "base/ranges/algorithm.h"
#include "base/stl_util.h"
#include "base/strings/stringprintf.h"
#include "base/values.h"
@@ -366,7 +367,7 @@ StatisticsRecorder::Histograms StatisticsRecorder::GetHistograms() {
// static
StatisticsRecorder::Histograms StatisticsRecorder::Sort(Histograms histograms) {
- std::sort(histograms.begin(), histograms.end(), &HistogramNameLesser);
+ ranges::sort(histograms, &HistogramNameLesser);
return histograms;
}
@@ -376,12 +377,12 @@ StatisticsRecorder::Histograms StatisticsRecorder::WithName(
const std::string& query) {
// Need a C-string query for comparisons against C-string histogram name.
const char* const query_string = query.c_str();
- histograms.erase(std::remove_if(histograms.begin(), histograms.end(),
- [query_string](const HistogramBase* const h) {
- return !strstr(h->histogram_name(),
- query_string);
- }),
- histograms.end());
+ histograms.erase(
+ ranges::remove_if(histograms,
+ [query_string](const HistogramBase* const h) {
+ return !strstr(h->histogram_name(), query_string);
+ }),
+ histograms.end());
return histograms;
}
@@ -389,10 +390,11 @@ StatisticsRecorder::Histograms StatisticsRecorder::WithName(
StatisticsRecorder::Histograms StatisticsRecorder::NonPersistent(
Histograms histograms) {
histograms.erase(
- std::remove_if(histograms.begin(), histograms.end(),
- [](const HistogramBase* const h) {
- return (h->flags() & HistogramBase::kIsPersistent) != 0;
- }),
+ ranges::remove_if(histograms,
+ [](const HistogramBase* const h) {
+ return (h->flags() & HistogramBase::kIsPersistent) !=
+ 0;
+ }),
histograms.end());
return histograms;
}
diff --git a/chromium/base/metrics/statistics_recorder.h b/chromium/base/metrics/statistics_recorder.h
index ecace07ed4a..8e275488f92 100644
--- a/chromium/base/metrics/statistics_recorder.h
+++ b/chromium/base/metrics/statistics_recorder.h
@@ -39,7 +39,7 @@ class HistogramSnapshotManager;
//
// All the public methods are static and act on a global recorder. This global
// recorder is internally synchronized and all the static methods are thread
-// safe.
+// safe. This is intended to only be run/used in the browser process.
//
// StatisticsRecorder doesn't have any public constructor. For testing purpose,
// you can create a temporary recorder using the factory method
diff --git a/chromium/base/metrics/ukm_source_id.cc b/chromium/base/metrics/ukm_source_id.cc
deleted file mode 100644
index 0b2a8baf296..00000000000
--- a/chromium/base/metrics/ukm_source_id.cc
+++ /dev/null
@@ -1,65 +0,0 @@
-// Copyright 2018 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.
-
-#include "base/metrics/ukm_source_id.h"
-
-#include <cmath>
-
-#include "base/atomic_sequence_num.h"
-#include "base/check_op.h"
-#include "base/rand_util.h"
-
-namespace base {
-
-namespace {
-
-const int64_t kLowBitsMask = (INT64_C(1) << 32) - 1;
-
-int64_t GetNumTypeBits() {
- return std::ceil(
- std::log2(static_cast<int64_t>(UkmSourceId::Type::kMaxValue) + 1));
-}
-
-} // namespace
-
-// static
-UkmSourceId UkmSourceId::New() {
- // Generate some bits which are unique to this process, so we can generate
- // IDs independently in different processes. IDs generated by this method may
- // collide, but it should be sufficiently rare enough to not impact data
- // quality.
- const static int64_t process_id_bits =
- static_cast<int64_t>(RandUint64()) & ~kLowBitsMask;
- // Generate some bits which are unique within the process, using a counter.
- static AtomicSequenceNumber seq;
- UkmSourceId local_id =
- FromOtherId(seq.GetNext() + 1, UkmSourceId::Type::DEFAULT);
- // Combine the local and process bits to generate a unique ID.
- return UkmSourceId((local_id.value_ & kLowBitsMask) | process_id_bits);
-}
-
-// static
-UkmSourceId UkmSourceId::FromOtherId(int64_t other_id, UkmSourceId::Type type) {
- // Note on syntax: std::ceil and std::log2 are not constexpr functions thus
- // these variables cannot be initialized statically in the global scope above.
- // Function static initialization here is thread safe; so they are initialized
- // at most once.
- static const int64_t kNumTypeBits = GetNumTypeBits();
- static const int64_t kTypeMask = (INT64_C(1) << kNumTypeBits) - 1;
-
- const int64_t type_bits = static_cast<int64_t>(type);
- DCHECK_EQ(type_bits, type_bits & kTypeMask);
- // Stores the type of the source ID in its lower bits, and shift the rest of
- // the ID to make room. This could cause the original ID to overflow, but
- // that should be rare enough that it won't matter for UKM's purposes.
- return UkmSourceId((other_id << kNumTypeBits) | type_bits);
-}
-
-UkmSourceId::Type UkmSourceId::GetType() const {
- static const int64_t kNumTypeBits = GetNumTypeBits();
- static const int64_t kTypeMask = (INT64_C(1) << kNumTypeBits) - 1;
- return static_cast<UkmSourceId::Type>(value_ & kTypeMask);
-}
-
-} // namespace base
diff --git a/chromium/base/metrics/ukm_source_id.h b/chromium/base/metrics/ukm_source_id.h
deleted file mode 100644
index 93fc390ba93..00000000000
--- a/chromium/base/metrics/ukm_source_id.h
+++ /dev/null
@@ -1,111 +0,0 @@
-// Copyright 2018 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 BASE_METRICS_UKM_SOURCE_ID_H_
-#define BASE_METRICS_UKM_SOURCE_ID_H_
-
-#include <stdint.h>
-
-#include "base/base_export.h"
-
-namespace base {
-
-// An ID used to identify a Source to UKM, for recording information about it.
-// These objects are copyable, assignable, and occupy 64-bits per instance.
-// Prefer passing them by value. When a new type is added, please also update
-// the enum type in third_party/metrics_proto/ukm/source.proto and the
-// converting function ToProtobufSourceType.
-class BASE_EXPORT UkmSourceId {
- public:
- enum class Type : int64_t {
- // Source ids of this type are created via ukm::AssignNewSourceId, to denote
- // 'custom' source other than the types below. Source of this type has
- // additional restrictions with logging, as determined by
- // IsWhitelistedSourceId.
- DEFAULT = 0,
- // Sources created by navigation. They will be kept in memory as long as
- // the associated tab is still alive and the number of sources are within
- // the max threshold.
- NAVIGATION_ID = 1,
- // Source ID used by AppLaunchEventLogger::Log. A new source of this type
- // and associated events are expected to be recorded within the same report
- // interval; it will not be kept in memory between different reports.
- APP_ID = 2,
- // Source ID for background events that don't have an open tab but the
- // associated URL is still present in the browser's history. A new source of
- // this type and associated events are expected to be recorded within the
- // same report interval; it will not be kept in memory between different
- // reports.
- HISTORY_ID = 3,
- // Source ID used by WebApkUkmRecorder. A new source of this type and
- // associated events are expected to be recorded within the same report
- // interval; it will not be kept in memory between different reports.
- WEBAPK_ID = 4,
- // Source ID for service worker based payment handlers. A new source of this
- // type and associated events are expected to be recorded within the same
- // report interval; it will not be kept in memory between different reports.
- PAYMENT_APP_ID = 5,
- // Source ID for desktop web apps, based on the start_url in the web app
- // manifest. A new source of this type and associated events are expected to
- // be recorded within the same report interval; it will not be kept in
- // memory between different reports.
- DESKTOP_WEB_APP_ID = 6,
- // Source ID for web workers, namely SharedWorkers and ServiceWorkers. Web
- // workers may inherit a source ID from the spawner context (in the case of
- // dedicated workers), or may have their own source IDs (in the case of
- // shared workers and service workers). Shared workers and service workers
- // can be connected to multiple clients (e.g. documents or other workers).
- WORKER_ID = 7,
- kMaxValue = WORKER_ID,
- };
-
- // Default constructor has the invalid value.
- constexpr UkmSourceId() : value_(0) {}
-
- constexpr UkmSourceId& operator=(UkmSourceId other) {
- value_ = other.value_;
- return *this;
- }
-
- // Allow identity comparisons.
- constexpr bool operator==(UkmSourceId other) const {
- return value_ == other.value_;
- }
- constexpr bool operator!=(UkmSourceId other) const {
- return value_ != other.value_;
- }
-
- // Allow coercive comparisons to simplify test migration.
- // TODO(crbug/873866): Remove these once callers are migrated.
- constexpr bool operator==(int64_t other) const { return value_ == other; }
- constexpr bool operator!=(int64_t other) const { return value_ == other; }
-
- // Extract the Type of the SourceId.
- Type GetType() const;
-
- // Return the ID as an int64.
- constexpr int64_t ToInt64() const { return value_; }
-
- // Convert an int64 ID value to an ID.
- static constexpr UkmSourceId FromInt64(int64_t internal_value) {
- return UkmSourceId(internal_value);
- }
-
- // Get a new UKM-Type SourceId, which is unique within the scope of a
- // browser session.
- static UkmSourceId New();
-
- // Utility for converting other unique ids to source ids.
- static UkmSourceId FromOtherId(int64_t value, Type type);
-
- private:
- constexpr explicit UkmSourceId(int64_t value) : value_(value) {}
- int64_t value_;
-};
-
-constexpr UkmSourceId kInvalidUkmSourceId = UkmSourceId();
-
-} // namespace base
-
-#endif // BASE_METRICS_UKM_SOURCE_ID_H_