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

Side by Side Diff: third_party/WebKit/Source/modules/webaudio/BaseAudioContext.h

Issue 2404743002: Web Audio: record autoplay status when an AudioContext is destroyed. (Closed)
Patch Set: move recording Created 4 years, 2 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 #include "wtf/build_config.h" 47 #include "wtf/build_config.h"
48 48
49 namespace blink { 49 namespace blink {
50 50
51 class AnalyserNode; 51 class AnalyserNode;
52 class AudioBuffer; 52 class AudioBuffer;
53 class AudioBufferCallback; 53 class AudioBufferCallback;
54 class AudioBufferSourceNode; 54 class AudioBufferSourceNode;
55 class AudioListener; 55 class AudioListener;
56 class AudioSummingJunction; 56 class AudioSummingJunction;
57 class BaseAudioContextTest;
57 class BiquadFilterNode; 58 class BiquadFilterNode;
58 class ChannelMergerNode; 59 class ChannelMergerNode;
59 class ChannelSplitterNode; 60 class ChannelSplitterNode;
60 class ConstantSourceNode; 61 class ConstantSourceNode;
61 class ConvolverNode; 62 class ConvolverNode;
62 class DelayNode; 63 class DelayNode;
63 class Dictionary; 64 class Dictionary;
64 class Document; 65 class Document;
65 class DynamicsCompressorNode; 66 class DynamicsCompressorNode;
66 class ExceptionState; 67 class ExceptionState;
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 // - it has been stopped by its execution context. 293 // - it has been stopped by its execution context.
293 virtual bool isContextClosed() const { return m_isCleared; } 294 virtual bool isContextClosed() const { return m_isCleared; }
294 295
295 // Get the security origin for this audio context. 296 // Get the security origin for this audio context.
296 SecurityOrigin* getSecurityOrigin() const; 297 SecurityOrigin* getSecurityOrigin() const;
297 298
298 // Get the PeriodicWave for the specified oscillator type. The table is 299 // Get the PeriodicWave for the specified oscillator type. The table is
299 // initialized internally if necessary. 300 // initialized internally if necessary.
300 PeriodicWave* periodicWave(int type); 301 PeriodicWave* periodicWave(int type);
301 302
303 // For metrics purpose, records when start() is called on a
304 // AudioScheduledSourceHandler or a AudioBufferSourceHandler without a user
305 // gesture while the AudioContext requires a user gesture.
306 void maybeRecordStartAttempt();
307
302 protected: 308 protected:
303 explicit BaseAudioContext(Document*); 309 explicit BaseAudioContext(Document*);
304 BaseAudioContext(Document*, 310 BaseAudioContext(Document*,
305 unsigned numberOfChannels, 311 unsigned numberOfChannels,
306 size_t numberOfFrames, 312 size_t numberOfFrames,
307 float sampleRate); 313 float sampleRate);
308 314
309 void initialize(); 315 void initialize();
310 void uninitialize(); 316 void uninitialize();
311 317
(...skipping 23 matching lines...) Expand all
335 void rejectPendingDecodeAudioDataResolvers(); 341 void rejectPendingDecodeAudioDataResolvers();
336 342
337 // If any, unlock user gesture requirements if a user gesture is being 343 // If any, unlock user gesture requirements if a user gesture is being
338 // processed. 344 // processed.
339 void maybeUnlockUserGesture(); 345 void maybeUnlockUserGesture();
340 346
341 // Returns whether the AudioContext is allowed to start rendering. 347 // Returns whether the AudioContext is allowed to start rendering.
342 bool isAllowedToStart() const; 348 bool isAllowedToStart() const;
343 349
344 private: 350 private:
351 friend class BaseAudioContextTest;
352
353 // Do not change the order of this enum, it is used for metrics.
354 enum AutoplayStatus {
355 // The AudioContext failed to activate because of user gesture requirements.
356 AutoplayStatusFailed = 0,
357 // Same as AutoplayStatusFailed but start() on a node was called with a user
358 // gesture.
359 AutoplayStatusFailedWithStart = 1,
360 // The AudioContext had user gesture requirements and was able to activate
361 // with a user gesture.
362 AutoplayStatusSucceeded = 2,
363
364 // Keep at the end.
365 AutoplayStatusCount
366 };
367
345 bool m_isCleared; 368 bool m_isCleared;
346 void clear(); 369 void clear();
347 370
348 // When the context goes away, there might still be some sources which 371 // When the context goes away, there might still be some sources which
349 // haven't finished playing. Make sure to release them here. 372 // haven't finished playing. Make sure to release them here.
350 void releaseActiveSourceNodes(); 373 void releaseActiveSourceNodes();
351 374
352 void removeFinishedSourceNodes(); 375 void removeFinishedSourceNodes();
353 376
354 // Listener for the PannerNodes 377 // Listener for the PannerNodes
(...skipping 21 matching lines...) Expand all
376 // FIXME(dominicc): Move these to AudioContext because only 399 // FIXME(dominicc): Move these to AudioContext because only
377 // it creates these Promises. 400 // it creates these Promises.
378 // Handle Promises for resume() and suspend() 401 // Handle Promises for resume() and suspend()
379 void resolvePromisesForResume(); 402 void resolvePromisesForResume();
380 void resolvePromisesForResumeOnMainThread(); 403 void resolvePromisesForResumeOnMainThread();
381 404
382 // When the context is going away, reject any pending script promise 405 // When the context is going away, reject any pending script promise
383 // resolvers. 406 // resolvers.
384 virtual void rejectPendingResolvers(); 407 virtual void rejectPendingResolvers();
385 408
409 // Record the current autoplay status and clear it.
410 void recordAutoplayStatus();
411
386 // True if we're in the process of resolving promises for resume(). Resolving 412 // True if we're in the process of resolving promises for resume(). Resolving
387 // can take some time and the audio context process loop is very fast, so we 413 // can take some time and the audio context process loop is very fast, so we
388 // don't want to call resolve an excessive number of times. 414 // don't want to call resolve an excessive number of times.
389 bool m_isResolvingResumePromises; 415 bool m_isResolvingResumePromises;
390 416
391 // Whether a user gesture is required to start this AudioContext. 417 // Whether a user gesture is required to start this AudioContext.
392 bool m_userGestureRequired; 418 bool m_userGestureRequired;
393 419
394 unsigned m_connectionCount; 420 unsigned m_connectionCount;
395 421
(...skipping 19 matching lines...) Expand all
415 // sample rate. so they can be shared with all OscillatorNodes in the context. 441 // sample rate. so they can be shared with all OscillatorNodes in the context.
416 // To conserve memory, these are lazily initialized on first use. 442 // To conserve memory, these are lazily initialized on first use.
417 Member<PeriodicWave> m_periodicWaveSine; 443 Member<PeriodicWave> m_periodicWaveSine;
418 Member<PeriodicWave> m_periodicWaveSquare; 444 Member<PeriodicWave> m_periodicWaveSquare;
419 Member<PeriodicWave> m_periodicWaveSawtooth; 445 Member<PeriodicWave> m_periodicWaveSawtooth;
420 Member<PeriodicWave> m_periodicWaveTriangle; 446 Member<PeriodicWave> m_periodicWaveTriangle;
421 447
422 // This is considering 32 is large enough for multiple channels audio. 448 // This is considering 32 is large enough for multiple channels audio.
423 // It is somewhat arbitrary and could be increased if necessary. 449 // It is somewhat arbitrary and could be increased if necessary.
424 enum { MaxNumberOfChannels = 32 }; 450 enum { MaxNumberOfChannels = 32 };
451
452 Optional<AutoplayStatus> m_autoplayStatus;
425 }; 453 };
426 454
427 } // namespace blink 455 } // namespace blink
428 456
429 #endif // BaseAudioContext_h 457 #endif // BaseAudioContext_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698