Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "modules/mediasession/MediaMetadata.h" | 5 #include "modules/mediasession/MediaMetadata.h" |
| 6 | 6 |
| 7 #include "core/dom/ExecutionContext.h" | 7 #include "core/dom/ExecutionContext.h" |
| 8 #include "modules/mediasession/MediaImage.h" | 8 #include "modules/mediasession/MediaImage.h" |
| 9 #include "modules/mediasession/MediaMetadataInit.h" | 9 #include "modules/mediasession/MediaMetadataInit.h" |
| 10 #include "modules/mediasession/MediaSession.h" | 10 #include "modules/mediasession/MediaSession.h" |
| 11 | 11 |
| 12 namespace blink { | 12 namespace blink { |
| 13 | 13 |
| 14 // static | 14 // static |
| 15 MediaMetadata* MediaMetadata::create(ExecutionContext* context, | 15 MediaMetadata* MediaMetadata::create(ExecutionContext* context, |
| 16 const MediaMetadataInit& metadata) { | 16 const MediaMetadataInit& metadata) { |
| 17 return new MediaMetadata(context, metadata); | 17 return new MediaMetadata(context, metadata); |
| 18 } | 18 } |
| 19 | 19 |
| 20 MediaMetadata::MediaMetadata(ExecutionContext* context, | 20 MediaMetadata::MediaMetadata(ExecutionContext* context, |
| 21 const MediaMetadataInit& metadata) | 21 const MediaMetadataInit& metadata) |
| 22 : m_notifySessionTimer(this, &MediaMetadata::notifySessionTimerFired) { | 22 : m_notifySessionTimer(this, &MediaMetadata::notifySessionTimerFired) { |
| 23 m_title = metadata.title(); | 23 m_title = metadata.title(); |
| 24 m_artist = metadata.artist(); | 24 m_artist = metadata.artist(); |
| 25 m_album = metadata.album(); | 25 m_album = metadata.album(); |
| 26 for (const auto& image : metadata.artwork()) | 26 m_artwork = metadata.artwork(); |
|
Zhiqiang Zhang (Slow)
2017/01/04 16:05:24
Create copies of MediaImages and freeze them if we
mlamouri (slow - plz ping)
2017/01/05 15:40:20
Done.
| |
| 27 m_artwork.append(MediaImage::create(context, image)); | |
| 28 } | 27 } |
| 29 | 28 |
| 30 String MediaMetadata::title() const { | 29 String MediaMetadata::title() const { |
| 31 return m_title; | 30 return m_title; |
| 32 } | 31 } |
| 33 | 32 |
| 34 String MediaMetadata::artist() const { | 33 String MediaMetadata::artist() const { |
| 35 return m_artist; | 34 return m_artist; |
| 36 } | 35 } |
| 37 | 36 |
| 38 String MediaMetadata::album() const { | 37 String MediaMetadata::album() const { |
| 39 return m_album; | 38 return m_album; |
| 40 } | 39 } |
| 41 | 40 |
| 42 const HeapVector<Member<MediaImage>>& MediaMetadata::artwork() const { | 41 const HeapVector<MediaImage>& MediaMetadata::artwork() const { |
| 43 return m_artwork; | 42 return m_artwork; |
| 44 } | 43 } |
| 45 | 44 |
| 46 void MediaMetadata::setTitle(const String& title) { | 45 void MediaMetadata::setTitle(const String& title) { |
| 47 m_title = title; | 46 m_title = title; |
| 48 notifySessionAsync(); | 47 notifySessionAsync(); |
| 49 } | 48 } |
| 50 | 49 |
| 51 void MediaMetadata::setArtist(const String& artist) { | 50 void MediaMetadata::setArtist(const String& artist) { |
| 52 m_artist = artist; | 51 m_artist = artist; |
| 53 notifySessionAsync(); | 52 notifySessionAsync(); |
| 54 } | 53 } |
| 55 | 54 |
| 56 void MediaMetadata::setAlbum(const String& album) { | 55 void MediaMetadata::setAlbum(const String& album) { |
| 57 m_album = album; | 56 m_album = album; |
| 58 notifySessionAsync(); | 57 notifySessionAsync(); |
| 59 } | 58 } |
| 60 | 59 |
| 61 void MediaMetadata::setArtwork(const HeapVector<Member<MediaImage>>& artwork) { | 60 void MediaMetadata::setArtwork(const HeapVector<MediaImage>& artwork) { |
| 62 m_artwork = artwork; | 61 m_artwork = artwork; |
| 63 notifySessionAsync(); | 62 notifySessionAsync(); |
| 64 } | 63 } |
| 65 | 64 |
| 66 void MediaMetadata::setSession(MediaSession* session) { | 65 void MediaMetadata::setSession(MediaSession* session) { |
| 67 m_session = session; | 66 m_session = session; |
| 68 } | 67 } |
| 69 | 68 |
| 70 void MediaMetadata::notifySessionAsync() { | 69 void MediaMetadata::notifySessionAsync() { |
| 71 if (!m_session || m_notifySessionTimer.isActive()) | 70 if (!m_session || m_notifySessionTimer.isActive()) |
| 72 return; | 71 return; |
| 73 m_notifySessionTimer.startOneShot(0, BLINK_FROM_HERE); | 72 m_notifySessionTimer.startOneShot(0, BLINK_FROM_HERE); |
| 74 } | 73 } |
| 75 | 74 |
| 76 void MediaMetadata::notifySessionTimerFired(TimerBase*) { | 75 void MediaMetadata::notifySessionTimerFired(TimerBase*) { |
| 77 if (!m_session) | 76 if (!m_session) |
| 78 return; | 77 return; |
| 79 m_session->onMetadataChanged(); | 78 m_session->onMetadataChanged(); |
| 80 } | 79 } |
| 81 | 80 |
| 82 DEFINE_TRACE(MediaMetadata) { | 81 DEFINE_TRACE(MediaMetadata) { |
| 83 visitor->trace(m_artwork); | 82 visitor->trace(m_artwork); |
| 84 visitor->trace(m_session); | 83 visitor->trace(m_session); |
| 85 } | 84 } |
| 86 | 85 |
| 87 } // namespace blink | 86 } // namespace blink |
| OLD | NEW |