diff options
Diffstat (limited to 'chromium/media/base/media_log_type_enforcement.h')
-rw-r--r-- | chromium/media/base/media_log_type_enforcement.h | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/chromium/media/base/media_log_type_enforcement.h b/chromium/media/base/media_log_type_enforcement.h new file mode 100644 index 00000000000..8404e00a23f --- /dev/null +++ b/chromium/media/base/media_log_type_enforcement.h @@ -0,0 +1,59 @@ +// Copyright 2019 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 MEDIA_BASE_MEDIA_LOG_TYPE_ENFORCEMENT_H_ +#define MEDIA_BASE_MEDIA_LOG_TYPE_ENFORCEMENT_H_ + +#include "media/base/media_serializers.h" + +namespace media { + +namespace internal { +enum class UnmatchableType {}; +} // namespace internal + +// Forward declare the enums. +enum class MediaLogProperty; +enum class MediaLogEvent; + +// Allow only specific types for an individual property. +template <MediaLogProperty PROP, typename T> +struct MediaLogPropertyTypeSupport {}; + +// Allow only specific types for an individual event. +// However unlike Property, T is not required, so we default it to some +// unmatchable type that will never be passed as an argument accidentally. +template <MediaLogEvent EVENT, typename T = internal::UnmatchableType> +struct MediaLogEventTypeSupport {}; + +// Lets us define the supported type in a single line in media_log_properties.h. +#define MEDIA_LOG_PROPERTY_SUPPORTS_TYPE(PROPERTY, TYPE) \ + template <> \ + struct MediaLogPropertyTypeSupport<MediaLogProperty::PROPERTY, TYPE> { \ + static base::Value Convert(const TYPE& type) { \ + return MediaSerialize<TYPE>(type); \ + } \ + } + +#define MEDIA_LOG_EVENT_NAMED_DATA(EVENT, TYPE, DISPLAY) \ + template <> \ + struct MediaLogEventTypeSupport<MediaLogEvent::EVENT, TYPE> { \ + static void AddExtraData(base::Value* params, const TYPE& t) { \ + DCHECK(params); \ + params->SetKey(DISPLAY, MediaSerialize<TYPE>(t)); \ + } \ + static std::string TypeName() { return #EVENT; } \ + } + +// Specifically do not create the Convert or DisplayName methods +#define MEDIA_LOG_EVENT_TYPELESS(EVENT) \ + template <> \ + struct MediaLogEventTypeSupport<MediaLogEvent::EVENT> { \ + static std::string TypeName() { return #EVENT; } \ + static void AddExtraData(base::Value* params) {} \ + } + +} // namespace media + +#endif // MEDIA_BASE_MEDIA_LOG_TYPE_ENFORCEMENT_H_ |