Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(113)

Side by Side Diff: third_party/WebKit/Source/modules/webaudio/AbstractAudioContext.cpp

Issue 2031393003: WebAudio: record whether user gesture was available and provided. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review comments Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010, Google Inc. All rights reserved. 2 * Copyright (C) 2010, Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 14 matching lines...) Expand all
25 #include "modules/webaudio/AbstractAudioContext.h" 25 #include "modules/webaudio/AbstractAudioContext.h"
26 #include "bindings/core/v8/Dictionary.h" 26 #include "bindings/core/v8/Dictionary.h"
27 #include "bindings/core/v8/ExceptionMessages.h" 27 #include "bindings/core/v8/ExceptionMessages.h"
28 #include "bindings/core/v8/ExceptionState.h" 28 #include "bindings/core/v8/ExceptionState.h"
29 #include "bindings/core/v8/ScriptPromiseResolver.h" 29 #include "bindings/core/v8/ScriptPromiseResolver.h"
30 #include "bindings/core/v8/ScriptState.h" 30 #include "bindings/core/v8/ScriptState.h"
31 #include "core/dom/DOMException.h" 31 #include "core/dom/DOMException.h"
32 #include "core/dom/Document.h" 32 #include "core/dom/Document.h"
33 #include "core/dom/ExceptionCode.h" 33 #include "core/dom/ExceptionCode.h"
34 #include "core/dom/ExecutionContextTask.h" 34 #include "core/dom/ExecutionContextTask.h"
35 #include "core/frame/Settings.h"
35 #include "core/html/HTMLMediaElement.h" 36 #include "core/html/HTMLMediaElement.h"
36 #include "modules/mediastream/MediaStream.h" 37 #include "modules/mediastream/MediaStream.h"
37 #include "modules/webaudio/AnalyserNode.h" 38 #include "modules/webaudio/AnalyserNode.h"
38 #include "modules/webaudio/AudioBuffer.h" 39 #include "modules/webaudio/AudioBuffer.h"
39 #include "modules/webaudio/AudioBufferCallback.h" 40 #include "modules/webaudio/AudioBufferCallback.h"
40 #include "modules/webaudio/AudioBufferSourceNode.h" 41 #include "modules/webaudio/AudioBufferSourceNode.h"
41 #include "modules/webaudio/AudioContext.h" 42 #include "modules/webaudio/AudioContext.h"
42 #include "modules/webaudio/AudioListener.h" 43 #include "modules/webaudio/AudioListener.h"
43 #include "modules/webaudio/AudioNodeInput.h" 44 #include "modules/webaudio/AudioNodeInput.h"
44 #include "modules/webaudio/AudioNodeOutput.h" 45 #include "modules/webaudio/AudioNodeOutput.h"
(...skipping 12 matching lines...) Expand all
57 #include "modules/webaudio/OfflineAudioCompletionEvent.h" 58 #include "modules/webaudio/OfflineAudioCompletionEvent.h"
58 #include "modules/webaudio/OfflineAudioContext.h" 59 #include "modules/webaudio/OfflineAudioContext.h"
59 #include "modules/webaudio/OfflineAudioDestinationNode.h" 60 #include "modules/webaudio/OfflineAudioDestinationNode.h"
60 #include "modules/webaudio/OscillatorNode.h" 61 #include "modules/webaudio/OscillatorNode.h"
61 #include "modules/webaudio/PannerNode.h" 62 #include "modules/webaudio/PannerNode.h"
62 #include "modules/webaudio/PeriodicWave.h" 63 #include "modules/webaudio/PeriodicWave.h"
63 #include "modules/webaudio/PeriodicWaveConstraints.h" 64 #include "modules/webaudio/PeriodicWaveConstraints.h"
64 #include "modules/webaudio/ScriptProcessorNode.h" 65 #include "modules/webaudio/ScriptProcessorNode.h"
65 #include "modules/webaudio/StereoPannerNode.h" 66 #include "modules/webaudio/StereoPannerNode.h"
66 #include "modules/webaudio/WaveShaperNode.h" 67 #include "modules/webaudio/WaveShaperNode.h"
68 #include "platform/Histogram.h"
67 #include "platform/ThreadSafeFunctional.h" 69 #include "platform/ThreadSafeFunctional.h"
70 #include "platform/UserGestureIndicator.h"
68 #include "platform/audio/IIRFilter.h" 71 #include "platform/audio/IIRFilter.h"
69 #include "public/platform/Platform.h" 72 #include "public/platform/Platform.h"
70 #include "wtf/text/WTFString.h" 73 #include "wtf/text/WTFString.h"
71 74
72 namespace blink { 75 namespace blink {
73 76
77 namespace {
78
79 enum UserGestureRecord {
80 UserGestureRequiredAndAvailable = 0,
81 UserGestureRequiredAndNotAvailable,
82 UserGestureNotRequiredAndAvailable,
83 UserGestureNotRequiredAndNotAvailable,
84 UserGestureRecordMax
85 };
86
87 } // anonymous namespace
88
74 AbstractAudioContext* AbstractAudioContext::create(Document& document, Exception State& exceptionState) 89 AbstractAudioContext* AbstractAudioContext::create(Document& document, Exception State& exceptionState)
75 { 90 {
76 return AudioContext::create(document, exceptionState); 91 return AudioContext::create(document, exceptionState);
77 } 92 }
78 93
79 // FIXME(dominicc): Devolve these constructors to AudioContext 94 // FIXME(dominicc): Devolve these constructors to AudioContext
80 // and OfflineAudioContext respectively. 95 // and OfflineAudioContext respectively.
81 96
82 // Constructor for rendering to the audio hardware. 97 // Constructor for rendering to the audio hardware.
83 AbstractAudioContext::AbstractAudioContext(Document* document) 98 AbstractAudioContext::AbstractAudioContext(Document* document)
84 : ActiveScriptWrappable(this) 99 : ActiveScriptWrappable(this)
85 , ActiveDOMObject(document) 100 , ActiveDOMObject(document)
86 , m_destinationNode(nullptr) 101 , m_destinationNode(nullptr)
87 , m_isCleared(false) 102 , m_isCleared(false)
88 , m_isResolvingResumePromises(false) 103 , m_isResolvingResumePromises(false)
104 , m_userGestureRequired(false)
89 , m_connectionCount(0) 105 , m_connectionCount(0)
90 , m_deferredTaskHandler(DeferredTaskHandler::create()) 106 , m_deferredTaskHandler(DeferredTaskHandler::create())
91 , m_contextState(Suspended) 107 , m_contextState(Suspended)
92 , m_closedContextSampleRate(-1) 108 , m_closedContextSampleRate(-1)
93 , m_periodicWaveSine(nullptr) 109 , m_periodicWaveSine(nullptr)
94 , m_periodicWaveSquare(nullptr) 110 , m_periodicWaveSquare(nullptr)
95 , m_periodicWaveSawtooth(nullptr) 111 , m_periodicWaveSawtooth(nullptr)
96 , m_periodicWaveTriangle(nullptr) 112 , m_periodicWaveTriangle(nullptr)
97 { 113 {
114 // TODO(mlamouri): we might want to use other ways of checking for this but
115 // in order to record metrics, re-using the HTMLMediaElement setting is
116 // probably the simplest solution.
117 if (document->settings() && document->settings()->mediaPlaybackRequiresUserG esture())
118 m_userGestureRequired = true;
119
98 m_destinationNode = DefaultAudioDestinationNode::create(this); 120 m_destinationNode = DefaultAudioDestinationNode::create(this);
99 121
100 initialize(); 122 initialize();
101 } 123 }
102 124
103 // Constructor for offline (non-realtime) rendering. 125 // Constructor for offline (non-realtime) rendering.
104 AbstractAudioContext::AbstractAudioContext(Document* document, unsigned numberOf Channels, size_t numberOfFrames, float sampleRate) 126 AbstractAudioContext::AbstractAudioContext(Document* document, unsigned numberOf Channels, size_t numberOfFrames, float sampleRate)
105 : ActiveScriptWrappable(this) 127 : ActiveScriptWrappable(this)
106 , ActiveDOMObject(document) 128 , ActiveDOMObject(document)
107 , m_destinationNode(nullptr) 129 , m_destinationNode(nullptr)
108 , m_isCleared(false) 130 , m_isCleared(false)
109 , m_isResolvingResumePromises(false) 131 , m_isResolvingResumePromises(false)
132 , m_userGestureRequired(false)
110 , m_connectionCount(0) 133 , m_connectionCount(0)
111 , m_deferredTaskHandler(DeferredTaskHandler::create()) 134 , m_deferredTaskHandler(DeferredTaskHandler::create())
112 , m_contextState(Suspended) 135 , m_contextState(Suspended)
113 , m_closedContextSampleRate(-1) 136 , m_closedContextSampleRate(-1)
114 , m_periodicWaveSine(nullptr) 137 , m_periodicWaveSine(nullptr)
115 , m_periodicWaveSquare(nullptr) 138 , m_periodicWaveSquare(nullptr)
116 , m_periodicWaveSawtooth(nullptr) 139 , m_periodicWaveSawtooth(nullptr)
117 , m_periodicWaveTriangle(nullptr) 140 , m_periodicWaveTriangle(nullptr)
118 { 141 {
142 // TODO(mlamouri): we might want to use other ways of checking for this but
143 // in order to record metrics, re-using the HTMLMediaElement setting is
144 // probably the simplest solution.
145 if (document->settings() && document->settings()->mediaPlaybackRequiresUserG esture())
146 m_userGestureRequired = true;
Raymond Toy 2016/06/06 15:10:08 I don't think this is needed or wanted for an offl
mlamouri (slow - plz ping) 2016/06/06 15:14:45 My understanding is that Safari iOS doesn't make a
119 } 147 }
120 148
121 AbstractAudioContext::~AbstractAudioContext() 149 AbstractAudioContext::~AbstractAudioContext()
122 { 150 {
123 deferredTaskHandler().contextWillBeDestroyed(); 151 deferredTaskHandler().contextWillBeDestroyed();
124 // AudioNodes keep a reference to their context, so there should be no way t o be in the destructor if there are still AudioNodes around. 152 // AudioNodes keep a reference to their context, so there should be no way t o be in the destructor if there are still AudioNodes around.
125 ASSERT(!isDestinationInitialized()); 153 ASSERT(!isDestinationInitialized());
126 ASSERT(!m_activeSourceNodes.size()); 154 ASSERT(!m_activeSourceNodes.size());
127 ASSERT(!m_finishedSourceHandlers.size()); 155 ASSERT(!m_finishedSourceHandlers.size());
128 ASSERT(!m_isResolvingResumePromises); 156 ASSERT(!m_isResolvingResumePromises);
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 // Initialize the table if necessary 494 // Initialize the table if necessary
467 if (!m_periodicWaveTriangle) 495 if (!m_periodicWaveTriangle)
468 m_periodicWaveTriangle = PeriodicWave::createTriangle(sampleRate()); 496 m_periodicWaveTriangle = PeriodicWave::createTriangle(sampleRate());
469 return m_periodicWaveTriangle; 497 return m_periodicWaveTriangle;
470 default: 498 default:
471 ASSERT_NOT_REACHED(); 499 ASSERT_NOT_REACHED();
472 return nullptr; 500 return nullptr;
473 } 501 }
474 } 502 }
475 503
504 void AbstractAudioContext::recordUserGestureState()
505 {
506 DEFINE_STATIC_LOCAL(EnumerationHistogram, userGestureHistogram, ("WebAudio.U serGesture", UserGestureRecordMax));
507
508 if (!m_userGestureRequired) {
509 if (UserGestureIndicator::processingUserGesture())
510 userGestureHistogram.count(UserGestureNotRequiredAndAvailable);
511 else
512 userGestureHistogram.count(UserGestureNotRequiredAndNotAvailable);
513 return;
514 }
515 if (!UserGestureIndicator::processingUserGesture()) {
516 userGestureHistogram.count(UserGestureRequiredAndNotAvailable);
517 return;
518 }
519 userGestureHistogram.count(UserGestureRequiredAndAvailable);
520 m_userGestureRequired = false;
521 }
522
476 String AbstractAudioContext::state() const 523 String AbstractAudioContext::state() const
477 { 524 {
478 // These strings had better match the strings for AudioContextState in Audio Context.idl. 525 // These strings had better match the strings for AudioContextState in Audio Context.idl.
479 switch (m_contextState) { 526 switch (m_contextState) {
480 case Suspended: 527 case Suspended:
481 return "suspended"; 528 return "suspended";
482 case Running: 529 case Running:
483 return "running"; 530 return "running";
484 case Closed: 531 case Closed:
485 return "closed"; 532 return "closed";
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
710 { 757 {
711 return ActiveDOMObject::getExecutionContext(); 758 return ActiveDOMObject::getExecutionContext();
712 } 759 }
713 760
714 void AbstractAudioContext::startRendering() 761 void AbstractAudioContext::startRendering()
715 { 762 {
716 // This is called for both online and offline contexts. 763 // This is called for both online and offline contexts.
717 ASSERT(isMainThread()); 764 ASSERT(isMainThread());
718 ASSERT(m_destinationNode); 765 ASSERT(m_destinationNode);
719 766
767 recordUserGestureState();
768
720 if (m_contextState == Suspended) { 769 if (m_contextState == Suspended) {
721 destination()->audioDestinationHandler().startRendering(); 770 destination()->audioDestinationHandler().startRendering();
722 setContextState(Running); 771 setContextState(Running);
723 } 772 }
724 } 773 }
725 774
726 DEFINE_TRACE(AbstractAudioContext) 775 DEFINE_TRACE(AbstractAudioContext)
727 { 776 {
728 visitor->trace(m_destinationNode); 777 visitor->trace(m_destinationNode);
729 visitor->trace(m_listener); 778 visitor->trace(m_listener);
(...skipping 11 matching lines...) Expand all
741 790
742 SecurityOrigin* AbstractAudioContext::getSecurityOrigin() const 791 SecurityOrigin* AbstractAudioContext::getSecurityOrigin() const
743 { 792 {
744 if (getExecutionContext()) 793 if (getExecutionContext())
745 return getExecutionContext()->getSecurityOrigin(); 794 return getExecutionContext()->getSecurityOrigin();
746 795
747 return nullptr; 796 return nullptr;
748 } 797 }
749 798
750 } // namespace blink 799 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698