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

Side by Side Diff: third_party/WebKit/Source/platform/mediastream/MediaStreamSource.cpp

Issue 1885053002: Safely iterate over MediaStreamSource observers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add test Created 4 years, 8 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
« no previous file with comments | « third_party/WebKit/LayoutTests/fast/mediastream/MediaStreamTrack-observer-iterate-no-crash-expected.txt ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 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 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 , m_readonly(readonly) 46 , m_readonly(readonly)
47 , m_readyState(readyState) 47 , m_readyState(readyState)
48 , m_requiresConsumer(requiresConsumer) 48 , m_requiresConsumer(requiresConsumer)
49 { 49 {
50 } 50 }
51 51
52 void MediaStreamSource::setReadyState(ReadyState readyState) 52 void MediaStreamSource::setReadyState(ReadyState readyState)
53 { 53 {
54 if (m_readyState != ReadyStateEnded && m_readyState != readyState) { 54 if (m_readyState != ReadyStateEnded && m_readyState != readyState) {
55 m_readyState = readyState; 55 m_readyState = readyState;
56 for (auto i = m_observers.begin(); i != m_observers.end(); ++i) 56
57 (*i)->sourceChangedState(); 57 // Observers may dispatch events which create and add new Observers;
58 // take a snapshot so as to safely iterate.
59 HeapVector<Member<Observer>> observers;
60 copyToVector(m_observers, observers);
61 for (auto observer : observers)
62 observer->sourceChangedState();
58 } 63 }
59 } 64 }
60 65
61 void MediaStreamSource::addObserver(MediaStreamSource::Observer* observer) 66 void MediaStreamSource::addObserver(MediaStreamSource::Observer* observer)
62 { 67 {
63 m_observers.add(observer); 68 m_observers.add(observer);
64 } 69 }
65 70
66 void MediaStreamSource::addAudioConsumer(AudioDestinationConsumer* consumer) 71 void MediaStreamSource::addAudioConsumer(AudioDestinationConsumer* consumer)
67 { 72 {
(...skipping 29 matching lines...) Expand all
97 (*it)->consumeAudio(bus, numberOfFrames); 102 (*it)->consumeAudio(bus, numberOfFrames);
98 } 103 }
99 104
100 DEFINE_TRACE(MediaStreamSource) 105 DEFINE_TRACE(MediaStreamSource)
101 { 106 {
102 visitor->trace(m_observers); 107 visitor->trace(m_observers);
103 visitor->trace(m_audioConsumers); 108 visitor->trace(m_audioConsumers);
104 } 109 }
105 110
106 } // namespace blink 111 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/fast/mediastream/MediaStreamTrack-observer-iterate-no-crash-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698