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

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: Created 6 years, 10 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* owner)
16 : m_owner(owner)
17 , m_asyncEventQueue(GenericEventQueue::create(this))
18 {
19 ASSERT(owner);
20 }
21
22 TrackBaseList::~TrackBaseList()
23 {
24 ASSERT(!m_owner);
25
26 m_asyncEventQueue->close();
27 }
28
29 TrackBase* TrackBaseList::getByIndex(unsigned index) const
30 {
31 if (index >= m_tracks.size())
32 return 0;
33
34 return m_tracks[index].get();
35 }
36
37 TrackBase* TrackBaseList::getById(const AtomicString& id) const
38 {
39 for (unsigned i = 0; i < m_tracks.size(); ++i) {
40 if (m_tracks[i]->id() == id)
41 return m_tracks[i].get();
42 }
43
44 return 0;
45 }
46
47 unsigned TrackBaseList::getIndex(TrackBase* track) const
48 {
49 for (unsigned i = 0; i < m_tracks.size(); ++i) {
50 if (m_tracks[i] == track)
51 return i;
52 }
53
54 ASSERT_NOT_REACHED();
55 return 0;
56 }
57
58 void TrackBaseList::add(TrackBase* track)
59 {
60 m_tracks.append(track);
61
62 scheduleTrackEvent(EventTypeNames::addtrack, track);
63 }
64
65 void TrackBaseList::remove(const String& id)
66 {
67 for (unsigned i = 0; i < m_tracks.size(); ++i) {
68 if (m_tracks[i]->id() == id) {
69 scheduleTrackEvent(EventTypeNames::removetrack, m_tracks[i]);
70 m_tracks.remove(i);
71 return;
72 }
73 }
74 }
75
76 void TrackBaseList::removeAll()
77 {
78 m_tracks.clear();
79 }
80
81 void TrackBaseList::scheduleChangeEvent()
82 {
83 WTF_LOG(Media, "TrackBaseList::scheduleChangeEvent() : %p", this);
84 EventInit initializer;
85 initializer.bubbles = false;
86 initializer.cancelable = false;
87 m_asyncEventQueue->enqueueEvent(Event::create(EventTypeNames::change, initia lizer));
88 }
89
90 void TrackBaseList::scheduleTrackEvent(const AtomicString& eventName, PassRefPtr <TrackBase> track)
91 {
92 WTF_LOG(Media, "TrackBaseList::scheduleTrackEvent(%s) : %p", eventName.strin g().ascii().data(), this);
93 TrackEventInit initializer;
94 initializer.track = track;
95 initializer.bubbles = false;
96 initializer.cancelable = false;
97
98 m_asyncEventQueue->enqueueEvent(TrackEvent::create(eventName, initializer));
99 }
100
101 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698