chromium/services/metrics/public/cpp/ukm_source_id.h

// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef SERVICES_METRICS_PUBLIC_CPP_UKM_SOURCE_ID_H_
#define SERVICES_METRICS_PUBLIC_CPP_UKM_SOURCE_ID_H_

#include <stdint.h>
#include <string>

#include "services/metrics/public/cpp/metrics_export.h"

namespace ukm {

SourceId;

const SourceId kInvalidSourceId =;

// An ID used to identify a Source to UKM, and contains the type information.
// 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
// conversion function ToProtobufSourceType.
// NOTES ON USAGE: if only the underlying int value is required to identify a
// Source and is used in Mojo interface, and no type conversion needs to be
// performed, use ukm::SourceId instead.
// TODO(crbug.com/40671096): migrate callers to use the public methods below
// then remove METRICS_EXPORT on this class.
class METRICS_EXPORT SourceIdObj {};

constexpr SourceIdObj kInvalidSourceIdObj =;

SourceIdType;

// Get a new source ID, which is unique for the duration of a browser session.
METRICS_EXPORT SourceId AssignNewSourceId();

// Utility for converting other unique ids to source ids.
METRICS_EXPORT SourceId ConvertToSourceId(int64_t other_id,
                                          SourceIdType id_type);

// Utility for getting source ID with NO_URL_ID type.
METRICS_EXPORT SourceId NoURLSourceId();

// Get the SourceIdType of the SourceId object.
METRICS_EXPORT SourceIdType GetSourceIdType(SourceId source_id);

// Get a string representation of the SourceIdType of the SourceId object.
METRICS_EXPORT std::string GetSourceIdTypeDebugString(SourceId source_id);
}  // namespace ukm

#endif  // SERVICES_METRICS_PUBLIC_CPP_UKM_SOURCE_ID_H_