Commit f4b515c8 authored by Mounir Lamouri's avatar Mounir Lamouri Committed by Commit Bot

Web Audio: record UKM autoplay status for AudioContext.

Bug: 848537
Change-Id: I07e7195991ea350a9b5d17b48682a541ff2ef7a4
Reviewed-on: https://chromium-review.googlesource.com/1081871
Commit-Queue: Mounir Lamouri <mlamouri@chromium.org>
Reviewed-by: default avatarRaymond Toy <rtoy@chromium.org>
Reviewed-by: default avatarSteven Holte <holte@chromium.org>
Cr-Commit-Position: refs/heads/master@{#569275}
parent 9f0f325d
...@@ -68,7 +68,19 @@ class SourceUrlRecorderWebContentsObserver ...@@ -68,7 +68,19 @@ class SourceUrlRecorderWebContentsObserver
base::flat_map<int64_t, GURL> pending_navigations_; base::flat_map<int64_t, GURL> pending_navigations_;
// Holds pending DocumentCreated events. // Holds pending DocumentCreated events.
using PendingEvent = std::pair<int64_t, bool>; struct PendingEvent {
PendingEvent() = delete;
PendingEvent(int64_t source_id,
bool is_main_frame,
bool is_cross_origin_frame)
: source_id(source_id),
is_main_frame(is_main_frame),
is_cross_origin_frame(is_cross_origin_frame) {}
int64_t source_id;
bool is_main_frame;
bool is_cross_origin_frame;
};
std::vector<PendingEvent> pending_document_created_events_; std::vector<PendingEvent> pending_document_created_events_;
int64_t last_committed_source_id_; int64_t last_committed_source_id_;
...@@ -138,8 +150,17 @@ ukm::SourceId SourceUrlRecorderWebContentsObserver::GetLastCommittedSourceId() ...@@ -138,8 +150,17 @@ ukm::SourceId SourceUrlRecorderWebContentsObserver::GetLastCommittedSourceId()
void SourceUrlRecorderWebContentsObserver::SetDocumentSourceId( void SourceUrlRecorderWebContentsObserver::SetDocumentSourceId(
int64_t source_id) { int64_t source_id) {
content::RenderFrameHost* main_frame = web_contents()->GetMainFrame();
content::RenderFrameHost* current_frame = bindings_.GetCurrentTargetFrame();
bool is_main_frame = main_frame == current_frame;
bool is_cross_origin_frame =
is_main_frame ? false
: !main_frame->GetLastCommittedOrigin().IsSameOriginWith(
current_frame->GetLastCommittedOrigin());
pending_document_created_events_.emplace_back( pending_document_created_events_.emplace_back(
source_id, !bindings_.GetCurrentTargetFrame()->GetParent()); source_id, !bindings_.GetCurrentTargetFrame()->GetParent(),
is_cross_origin_frame);
MaybeFlushPendingEvents(); MaybeFlushPendingEvents();
} }
...@@ -154,9 +175,10 @@ void SourceUrlRecorderWebContentsObserver::MaybeFlushPendingEvents() { ...@@ -154,9 +175,10 @@ void SourceUrlRecorderWebContentsObserver::MaybeFlushPendingEvents() {
while (!pending_document_created_events_.empty()) { while (!pending_document_created_events_.empty()) {
auto record = pending_document_created_events_.back(); auto record = pending_document_created_events_.back();
ukm::builders::DocumentCreated(record.first) ukm::builders::DocumentCreated(record.source_id)
.SetNavigationSourceId(last_committed_source_id_) .SetNavigationSourceId(last_committed_source_id_)
.SetIsMainFrame(record.second) .SetIsMainFrame(record.is_main_frame)
.SetIsCrossOriginFrame(record.is_cross_origin_frame)
.Record(ukm_recorder); .Record(ukm_recorder);
pending_document_created_events_.pop_back(); pending_document_created_events_.pop_back();
......
include_rules = [ include_rules = [
"+services/metrics/public/cpp/ukm_builders.h",
"+services/metrics/public/cpp/ukm_recorder.h",
"-third_party/blink/renderer/modules", "-third_party/blink/renderer/modules",
"+third_party/blink/renderer/modules/event_modules.h", "+third_party/blink/renderer/modules/event_modules.h",
"+third_party/blink/renderer/modules/event_target_modules.h", "+third_party/blink/renderer/modules/event_target_modules.h",
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#include "third_party/blink/renderer/modules/webaudio/audio_context.h" #include "third_party/blink/renderer/modules/webaudio/audio_context.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "services/metrics/public/cpp/ukm_recorder.h"
#include "third_party/blink/public/platform/web_audio_latency_hint.h" #include "third_party/blink/public/platform/web_audio_latency_hint.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h" #include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h"
#include "third_party/blink/renderer/core/dom/dom_exception.h" #include "third_party/blink/renderer/core/dom/dom_exception.h"
...@@ -410,6 +412,15 @@ void AudioContext::RecordAutoplayMetrics() { ...@@ -410,6 +412,15 @@ void AudioContext::RecordAutoplayMetrics() {
if (!autoplay_status_.has_value()) if (!autoplay_status_.has_value())
return; return;
ukm::UkmRecorder* ukm_recorder = GetDocument()->UkmRecorder();
DCHECK(ukm_recorder);
ukm::builders::Media_Autoplay_AudioContext(GetDocument()->UkmSourceID())
.SetStatus(autoplay_status_.value())
.SetUnlockType(autoplay_unlock_type_
? static_cast<int>(autoplay_unlock_type_.value())
: -1)
.Record(ukm_recorder);
// Record autoplay_status_ value. // Record autoplay_status_ value.
DEFINE_STATIC_LOCAL( DEFINE_STATIC_LOCAL(
EnumerationHistogram, autoplay_histogram, EnumerationHistogram, autoplay_histogram,
......
...@@ -830,6 +830,12 @@ be describing additional metrics about the same event. ...@@ -830,6 +830,12 @@ be describing additional metrics about the same event.
navigation and whether the document was in the main frame. This can be used navigation and whether the document was in the main frame. This can be used
to link subframe UKM events to the parent document. to link subframe UKM events to the parent document.
</summary> </summary>
<metric name="IsCrossOriginFrame">
<summary>
Whether the document was in a cross origin iframe. This can either be 0 or
1.
</summary>
</metric>
<metric name="IsMainFrame"> <metric name="IsMainFrame">
<summary> <summary>
Whether the document was in the main frame. This is can either be 0 or 1. Whether the document was in the main frame. This is can either be 0 or 1.
...@@ -1231,6 +1237,27 @@ be describing additional metrics about the same event. ...@@ -1231,6 +1237,27 @@ be describing additional metrics about the same event.
</metric> </metric>
</event> </event>
<event name="Media.Autoplay.AudioContext">
<owner>mlamouri@chromium.org</owner>
<owner>media-dev@chromium.org</owner>
<summary>
Records the AudioContext autoplay information.
</summary>
<metric name="Status">
<summary>
Status of this AudioContext when the autoplay policy applies. It will
match the values from AudioContext::AutoplayStatus.
</summary>
</metric>
<metric name="UnlockType">
<summary>
How the AudioContext was unlocked if it was. It will match the values from
AudioContext::AutoplayUnlockType unless the AudioContext was never
unlocked in which case it will be equal to -1.
</summary>
</metric>
</event>
<event name="Media.Autoplay.Muted.UnmuteAction"> <event name="Media.Autoplay.Muted.UnmuteAction">
<owner>mlamouri@chromium.org</owner> <owner>mlamouri@chromium.org</owner>
<owner>media-dev@chromium.org</owner> <owner>media-dev@chromium.org</owner>
......
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