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

Side by Side Diff: Source/core/html/track/TrackBaseList.cpp

Issue 170233009: Initial implementation of AudioTrack, AudioTrackList, VideoTrack, and VideoTrackList. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@blink-master
Patch Set: Rebase Created 6 years, 9 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
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "config.h"
6 #include "core/html/track/TrackBaseList.h"
7
8 #include "core/events/GenericEventQueue.h"
9 #include "core/html/track/TrackBase.h"
10 #include "core/html/track/TrackEvent.h"
11 #include "platform/Logging.h"
12
13 namespace WebCore {
14
15 TrackBaseList::TrackBaseList(HTMLMediaElement* mediaElement)
16 : ActiveDOMObject(mediaElement->executionContext())
17 , m_shutdown(false)
18 , m_asyncEventQueue(GenericEventQueue::create(this))
19 {
20 ASSERT(mediaElement);
21 }
22
23 TrackBaseList::~TrackBaseList()
24 {
25 ASSERT(m_shutdown);
26 ASSERT(m_tracks.isEmpty());
27 }
28
29 void TrackBaseList::shutdown()
30 {
31 m_shutdown = true;
32 removeAll();
33 m_asyncEventQueue->close();
34 }
35
36 TrackBase* TrackBaseList::getByIndex(unsigned index) const
37 {
38 if (index >= m_tracks.size())
39 return 0;
philipj_slow 2014/03/13 10:00:04 This seems unreachable in the current code, ASSERT
40
41 return m_tracks[index].get();
philipj_slow 2014/03/13 10:00:04 Any reason to not return RefPtr<TrackBase> here an
acolwell GONE FROM CHROMIUM 2014/03/18 22:02:15 The RefPtr is not used to avoid an unnecessary ref
philipj_slow 2014/03/20 16:17:40 Thanks, that's something I should keep in mind as
42 }
43
44 TrackBase* TrackBaseList::getById(const AtomicString& id) const
45 {
46 for (unsigned i = 0; i < m_tracks.size(); ++i) {
47 if (m_tracks[i]->id() == id)
48 return m_tracks[i].get();
49 }
50
51 return 0;
52 }
53
54 unsigned TrackBaseList::getIndex(const AtomicString& id) const
philipj_slow 2014/03/13 10:00:04 This is only used by VideoTrackList::trackSelected
55 {
56 for (unsigned i = 0; i < m_tracks.size(); ++i) {
57 if (m_tracks[i]->id() == id)
58 return i;
59 }
60
61 ASSERT_NOT_REACHED();
62 return 0;
63 }
64
65 ExecutionContext* TrackBaseList::executionContext() const
66 {
67 return ActiveDOMObject::executionContext();
68 }
69
70 bool TrackBaseList::hasPendingActivity() const
71 {
72 return !m_shutdown || m_asyncEventQueue->hasPendingEvents() || ActiveDOMObje ct::hasPendingActivity();
73 }
74
75 void TrackBaseList::stop()
76 {
77 shutdown();
78 }
79
80 void TrackBaseList::add(TrackBase* track)
philipj_slow 2014/03/13 10:00:04 The callers have a RefPtr and call get(), use Pass
acolwell GONE FROM CHROMIUM 2014/03/18 22:02:15 Done.
81 {
82 m_tracks.append(track);
83
84 scheduleTrackEvent(EventTypeNames::addtrack, track);
85 }
86
87 void TrackBaseList::remove(const String& id)
88 {
89 for (unsigned i = 0; i < m_tracks.size(); ++i) {
90 if (m_tracks[i]->id() == id) {
91 m_tracks[i]->setMediaElement(0);
92 scheduleTrackEvent(EventTypeNames::removetrack, m_tracks[i]);
93 m_tracks.remove(i);
94 return;
95 }
96 }
97 }
98
99 void TrackBaseList::removeAll()
100 {
101 for (unsigned i = 0; i < m_tracks.size(); ++i)
102 m_tracks[i]->setMediaElement(0);
103
104 m_tracks.clear();
105 }
106
107 void TrackBaseList::scheduleChangeEvent()
108 {
109 WTF_LOG(Media, "TrackBaseList::scheduleChangeEvent() : %p", this);
110 EventInit initializer;
111 initializer.bubbles = false;
112 initializer.cancelable = false;
113 m_asyncEventQueue->enqueueEvent(Event::create(EventTypeNames::change, initia lizer));
114 }
115
116 void TrackBaseList::scheduleTrackEvent(const AtomicString& eventName, PassRefPtr <TrackBase> track)
philipj_slow 2014/03/13 10:00:04 Tests that verify that isTrusted is true for these
117 {
118 WTF_LOG(Media, "TrackBaseList::scheduleTrackEvent(%s) : %p", eventName.strin g().ascii().data(), this);
119 TrackEventInit initializer;
120 initializer.track = track;
121 initializer.bubbles = false;
122 initializer.cancelable = false;
123
124 m_asyncEventQueue->enqueueEvent(TrackEvent::create(eventName, initializer));
125 }
126
127 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698