Commit 115d1274 authored by Daniel Cheng's avatar Daniel Cheng Committed by Commit Bot

Follow updated UMA best practices in blink::HTMLMediaElement.

- Use updated kMaxValue convention for representing the histogram
  boundary. While it doesn't matter much here, not having a sentinel
  value is generally preferred (especially if the enum is used in switch
  statements).
- Default to using the function instead of the macro. The macro is more
  performant, but the UMA recording paths here aren't on the critical
  path
- Switch away from blink::EnumerationHistogram

Bug: 742517, 1047547
Change-Id: Ibdcbb312dc1157d6284bdb0de8c9a3b2a591de62
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2032417Reviewed-by: default avatarDave Tapuska <dtapuska@chromium.org>
Commit-Queue: Daniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#737888}
parent 7ff76b73
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include "base/debug/crash_logging.h" #include "base/debug/crash_logging.h"
#include "base/feature_list.h" #include "base/feature_list.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/metrics/histogram_functions.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "media/base/logging_override_if_enabled.h" #include "media/base/logging_override_if_enabled.h"
#include "media/base/media_switches.h" #include "media/base/media_switches.h"
...@@ -101,7 +102,6 @@ ...@@ -101,7 +102,6 @@
#include "third_party/blink/renderer/platform/bindings/microtask.h" #include "third_party/blink/renderer/platform/bindings/microtask.h"
#include "third_party/blink/renderer/platform/graphics/graphics_layer.h" #include "third_party/blink/renderer/platform/graphics/graphics_layer.h"
#include "third_party/blink/renderer/platform/heap/heap.h" #include "third_party/blink/renderer/platform/heap/heap.h"
#include "third_party/blink/renderer/platform/instrumentation/histogram.h"
#include "third_party/blink/renderer/platform/instrumentation/use_counter.h" #include "third_party/blink/renderer/platform/instrumentation/use_counter.h"
#include "third_party/blink/renderer/platform/mediastream/media_stream_descriptor.h" #include "third_party/blink/renderer/platform/mediastream/media_stream_descriptor.h"
#include "third_party/blink/renderer/platform/network/mime/content_type.h" #include "third_party/blink/renderer/platform/network/mime/content_type.h"
...@@ -134,25 +134,25 @@ using DocumentElementSetMap = ...@@ -134,25 +134,25 @@ using DocumentElementSetMap =
namespace { namespace {
// This enum is used to record histograms. Do not reorder. // This enum is used to record histograms. Do not reorder.
enum MediaControlsShow { enum class MediaControlsShow {
kMediaControlsShowAttribute = 0, kAttribute = 0,
kMediaControlsShowFullscreen, kFullscreen,
kMediaControlsShowNoScript, kNoScript,
kMediaControlsShowNotShown, kNotShown,
kMediaControlsShowDisabledSettings, kDisabledSettings,
kMediaControlsShowMax kMaxValue = kDisabledSettings,
}; };
// These values are used for the Media.MediaElement.ContentTypeResult histogram. // These values are used for the Media.MediaElement.ContentTypeResult histogram.
// Do not reorder. // Do not reorder.
enum ContentTypeParseableResult { enum class ContentTypeParseableResult {
kIsSupportedParseable = 0, kIsSupportedParseable = 0,
kMayBeSupportedParseable, kMayBeSupportedParseable,
kIsNotSupportedParseable, kIsNotSupportedParseable,
kIsSupportedNotParseable, kIsSupportedNotParseable,
kMayBeSupportedNotParseable, kMayBeSupportedNotParseable,
kIsNotSupportedNotParseable, kIsNotSupportedNotParseable,
kContentTypeParseableMax kMaxValue = kIsNotSupportedNotParseable,
}; };
// This enum is used to record histograms. Do not reorder. // This enum is used to record histograms. Do not reorder.
...@@ -161,7 +161,7 @@ enum class PlayPromiseRejectReason { ...@@ -161,7 +161,7 @@ enum class PlayPromiseRejectReason {
kNoSupportedSources, kNoSupportedSources,
kInterruptedByPause, kInterruptedByPause,
kInterruptedByLoad, kInterruptedByLoad,
kCount, kMaxValue = kInterruptedByLoad,
}; };
static const base::TimeDelta kStalledNotificationInterval = static const base::TimeDelta kStalledNotificationInterval =
...@@ -173,26 +173,30 @@ const double kMaxRate = 16.0; ...@@ -173,26 +173,30 @@ const double kMaxRate = 16.0;
void ReportContentTypeResultToUMA(String content_type, void ReportContentTypeResultToUMA(String content_type,
MIMETypeRegistry::SupportsType result) { MIMETypeRegistry::SupportsType result) {
DEFINE_THREAD_SAFE_STATIC_LOCAL(
EnumerationHistogram, content_type_parseable_histogram,
("Media.MediaElement.ContentTypeParseable", kContentTypeParseableMax));
ParsedContentType parsed_content_type(content_type); ParsedContentType parsed_content_type(content_type);
ContentTypeParseableResult uma_result = kIsNotSupportedNotParseable; ContentTypeParseableResult uma_result =
ContentTypeParseableResult::kIsNotSupportedNotParseable;
switch (result) { switch (result) {
case MIMETypeRegistry::kIsSupported: case MIMETypeRegistry::kIsSupported:
uma_result = parsed_content_type.IsValid() ? kIsSupportedParseable uma_result = parsed_content_type.IsValid()
: kIsSupportedNotParseable; ? ContentTypeParseableResult::kIsSupportedParseable
: ContentTypeParseableResult::kIsSupportedNotParseable;
break; break;
case MIMETypeRegistry::kMayBeSupported: case MIMETypeRegistry::kMayBeSupported:
uma_result = parsed_content_type.IsValid() ? kMayBeSupportedParseable uma_result =
: kMayBeSupportedNotParseable; parsed_content_type.IsValid()
? ContentTypeParseableResult::kMayBeSupportedParseable
: ContentTypeParseableResult::kMayBeSupportedNotParseable;
break; break;
case MIMETypeRegistry::kIsNotSupported: case MIMETypeRegistry::kIsNotSupported:
uma_result = parsed_content_type.IsValid() ? kIsNotSupportedParseable uma_result =
: kIsNotSupportedNotParseable; parsed_content_type.IsValid()
? ContentTypeParseableResult::kIsNotSupportedParseable
: ContentTypeParseableResult::kIsNotSupportedNotParseable;
break; break;
} }
content_type_parseable_histogram.Count(uma_result); base::UmaHistogramEnumeration("Media.MediaElement.ContentTypeParseable",
uma_result);
} }
String UrlForLoggingMedia(const KURL& url) { String UrlForLoggingMedia(const KURL& url) {
...@@ -363,10 +367,16 @@ String PreloadTypeToString(WebMediaPlayer::Preload preload_type) { ...@@ -363,10 +367,16 @@ String PreloadTypeToString(WebMediaPlayer::Preload preload_type) {
} }
void RecordPlayPromiseRejected(PlayPromiseRejectReason reason) { void RecordPlayPromiseRejected(PlayPromiseRejectReason reason) {
DEFINE_STATIC_LOCAL(EnumerationHistogram, histogram, base::UmaHistogramEnumeration("Media.MediaElement.PlayPromiseReject", reason);
("Media.MediaElement.PlayPromiseReject", }
static_cast<int>(PlayPromiseRejectReason::kCount)));
histogram.Count(static_cast<int>(reason)); void RecordShowControlsUsage(const HTMLMediaElement* element,
MediaControlsShow value) {
if (element->IsHTMLVideoElement()) {
base::UmaHistogramEnumeration("Media.Controls.Show.Video", value);
return;
}
base::UmaHistogramEnumeration("Media.Controls.Show.Audio", value);
} }
bool IsValidPlaybackRate(double rate) { bool IsValidPlaybackRate(double rate) {
...@@ -2609,31 +2619,31 @@ bool HTMLMediaElement::ShouldShowControls( ...@@ -2609,31 +2619,31 @@ bool HTMLMediaElement::ShouldShowControls(
Settings* settings = GetDocument().GetSettings(); Settings* settings = GetDocument().GetSettings();
if (settings && !settings->GetMediaControlsEnabled()) { if (settings && !settings->GetMediaControlsEnabled()) {
if (record_metrics == RecordMetricsBehavior::kDoRecord) if (record_metrics == RecordMetricsBehavior::kDoRecord)
ShowControlsHistogram().Count(kMediaControlsShowDisabledSettings); RecordShowControlsUsage(this, MediaControlsShow::kDisabledSettings);
return false; return false;
} }
if (FastHasAttribute(html_names::kControlsAttr)) { if (FastHasAttribute(html_names::kControlsAttr)) {
if (record_metrics == RecordMetricsBehavior::kDoRecord) if (record_metrics == RecordMetricsBehavior::kDoRecord)
ShowControlsHistogram().Count(kMediaControlsShowAttribute); RecordShowControlsUsage(this, MediaControlsShow::kAttribute);
return true; return true;
} }
if (IsFullscreen()) { if (IsFullscreen()) {
if (record_metrics == RecordMetricsBehavior::kDoRecord) if (record_metrics == RecordMetricsBehavior::kDoRecord)
ShowControlsHistogram().Count(kMediaControlsShowFullscreen); RecordShowControlsUsage(this, MediaControlsShow::kFullscreen);
return true; return true;
} }
LocalFrame* frame = GetDocument().GetFrame(); LocalFrame* frame = GetDocument().GetFrame();
if (frame && !GetDocument().CanExecuteScripts(kNotAboutToExecuteScript)) { if (frame && !GetDocument().CanExecuteScripts(kNotAboutToExecuteScript)) {
if (record_metrics == RecordMetricsBehavior::kDoRecord) if (record_metrics == RecordMetricsBehavior::kDoRecord)
ShowControlsHistogram().Count(kMediaControlsShowNoScript); RecordShowControlsUsage(this, MediaControlsShow::kNoScript);
return true; return true;
} }
if (record_metrics == RecordMetricsBehavior::kDoRecord) if (record_metrics == RecordMetricsBehavior::kDoRecord)
ShowControlsHistogram().Count(kMediaControlsShowNotShown); RecordShowControlsUsage(this, MediaControlsShow::kNotShown);
return false; return false;
} }
...@@ -4150,18 +4160,6 @@ void HTMLMediaElement::RejectPlayPromisesInternal(DOMExceptionCode code, ...@@ -4150,18 +4160,6 @@ void HTMLMediaElement::RejectPlayPromisesInternal(DOMExceptionCode code,
play_promise_reject_list_.clear(); play_promise_reject_list_.clear();
} }
EnumerationHistogram& HTMLMediaElement::ShowControlsHistogram() const {
if (IsHTMLVideoElement()) {
DEFINE_STATIC_LOCAL(EnumerationHistogram, histogram,
("Media.Controls.Show.Video", kMediaControlsShowMax));
return histogram;
}
DEFINE_STATIC_LOCAL(EnumerationHistogram, histogram,
("Media.Controls.Show.Audio", kMediaControlsShowMax));
return histogram;
}
void HTMLMediaElement::OnRemovedFromDocumentTimerFired(TimerBase*) { void HTMLMediaElement::OnRemovedFromDocumentTimerFired(TimerBase*) {
if (InActiveDocument()) if (InActiveDocument())
return; return;
......
...@@ -61,7 +61,6 @@ class AudioTrackList; ...@@ -61,7 +61,6 @@ class AudioTrackList;
class AutoplayPolicy; class AutoplayPolicy;
class ContentType; class ContentType;
class CueTimeline; class CueTimeline;
class EnumerationHistogram;
class Event; class Event;
class EventQueue; class EventQueue;
class ExceptionState; class ExceptionState;
...@@ -557,8 +556,6 @@ class CORE_EXPORT HTMLMediaElement ...@@ -557,8 +556,6 @@ class CORE_EXPORT HTMLMediaElement
void RejectPlayPromises(DOMExceptionCode, const String&); void RejectPlayPromises(DOMExceptionCode, const String&);
void RejectPlayPromisesInternal(DOMExceptionCode, const String&); void RejectPlayPromisesInternal(DOMExceptionCode, const String&);
EnumerationHistogram& ShowControlsHistogram() const;
void OnRemovedFromDocumentTimerFired(TimerBase*); void OnRemovedFromDocumentTimerFired(TimerBase*);
Features GetFeatures() override; Features GetFeatures() override;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment