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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: Source/core/html/track/TrackBaseList.cpp
diff --git a/Source/core/html/track/TrackBaseList.cpp b/Source/core/html/track/TrackBaseList.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..9281d7e03b700cdf923d2829f1ebafca29751f97
--- /dev/null
+++ b/Source/core/html/track/TrackBaseList.cpp
@@ -0,0 +1,127 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "config.h"
+#include "core/html/track/TrackBaseList.h"
+
+#include "core/events/GenericEventQueue.h"
+#include "core/html/track/TrackBase.h"
+#include "core/html/track/TrackEvent.h"
+#include "platform/Logging.h"
+
+namespace WebCore {
+
+TrackBaseList::TrackBaseList(HTMLMediaElement* mediaElement)
+ : ActiveDOMObject(mediaElement->executionContext())
+ , m_shutdown(false)
+ , m_asyncEventQueue(GenericEventQueue::create(this))
+{
+ ASSERT(mediaElement);
+}
+
+TrackBaseList::~TrackBaseList()
+{
+ ASSERT(m_shutdown);
+ ASSERT(m_tracks.isEmpty());
+}
+
+void TrackBaseList::shutdown()
+{
+ m_shutdown = true;
+ removeAll();
+ m_asyncEventQueue->close();
+}
+
+TrackBase* TrackBaseList::getByIndex(unsigned index) const
+{
+ if (index >= m_tracks.size())
+ return 0;
philipj_slow 2014/03/13 10:00:04 This seems unreachable in the current code, ASSERT
+
+ 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
+}
+
+TrackBase* TrackBaseList::getById(const AtomicString& id) const
+{
+ for (unsigned i = 0; i < m_tracks.size(); ++i) {
+ if (m_tracks[i]->id() == id)
+ return m_tracks[i].get();
+ }
+
+ return 0;
+}
+
+unsigned TrackBaseList::getIndex(const AtomicString& id) const
philipj_slow 2014/03/13 10:00:04 This is only used by VideoTrackList::trackSelected
+{
+ for (unsigned i = 0; i < m_tracks.size(); ++i) {
+ if (m_tracks[i]->id() == id)
+ return i;
+ }
+
+ ASSERT_NOT_REACHED();
+ return 0;
+}
+
+ExecutionContext* TrackBaseList::executionContext() const
+{
+ return ActiveDOMObject::executionContext();
+}
+
+bool TrackBaseList::hasPendingActivity() const
+{
+ return !m_shutdown || m_asyncEventQueue->hasPendingEvents() || ActiveDOMObject::hasPendingActivity();
+}
+
+void TrackBaseList::stop()
+{
+ shutdown();
+}
+
+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.
+{
+ m_tracks.append(track);
+
+ scheduleTrackEvent(EventTypeNames::addtrack, track);
+}
+
+void TrackBaseList::remove(const String& id)
+{
+ for (unsigned i = 0; i < m_tracks.size(); ++i) {
+ if (m_tracks[i]->id() == id) {
+ m_tracks[i]->setMediaElement(0);
+ scheduleTrackEvent(EventTypeNames::removetrack, m_tracks[i]);
+ m_tracks.remove(i);
+ return;
+ }
+ }
+}
+
+void TrackBaseList::removeAll()
+{
+ for (unsigned i = 0; i < m_tracks.size(); ++i)
+ m_tracks[i]->setMediaElement(0);
+
+ m_tracks.clear();
+}
+
+void TrackBaseList::scheduleChangeEvent()
+{
+ WTF_LOG(Media, "TrackBaseList::scheduleChangeEvent() : %p", this);
+ EventInit initializer;
+ initializer.bubbles = false;
+ initializer.cancelable = false;
+ m_asyncEventQueue->enqueueEvent(Event::create(EventTypeNames::change, initializer));
+}
+
+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
+{
+ WTF_LOG(Media, "TrackBaseList::scheduleTrackEvent(%s) : %p", eventName.string().ascii().data(), this);
+ TrackEventInit initializer;
+ initializer.track = track;
+ initializer.bubbles = false;
+ initializer.cancelable = false;
+
+ m_asyncEventQueue->enqueueEvent(TrackEvent::create(eventName, initializer));
+}
+
+}

Powered by Google App Engine
This is Rietveld 408576698