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

Side by Side Diff: third_party/WebKit/Source/modules/mediasession/MediaMetadata.cpp

Issue 2584703002: Media Session API: make MediaMetadata mutable. (Closed)
Patch Set: review comments and tests Created 4 years 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
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 11
11 namespace blink { 12 namespace blink {
12 13
13 // static 14 // static
14 MediaMetadata* MediaMetadata::create(ExecutionContext* context, 15 MediaMetadata* MediaMetadata::create(ExecutionContext* context,
15 const MediaMetadataInit& metadata) { 16 const MediaMetadataInit& metadata) {
16 return new MediaMetadata(context, metadata); 17 return new MediaMetadata(context, metadata);
17 } 18 }
18 19
19 MediaMetadata::MediaMetadata(ExecutionContext* context, 20 MediaMetadata::MediaMetadata(ExecutionContext* context,
20 const MediaMetadataInit& metadata) { 21 const MediaMetadataInit& metadata)
22 : m_notifySessionTimer(this, &MediaMetadata::notifySessionTimerFired) {
21 m_title = metadata.title(); 23 m_title = metadata.title();
22 m_artist = metadata.artist(); 24 m_artist = metadata.artist();
23 m_album = metadata.album(); 25 m_album = metadata.album();
24 for (const auto& image : metadata.artwork()) 26 for (const auto& image : metadata.artwork())
25 m_artwork.append(MediaImage::create(context, image)); 27 m_artwork.append(MediaImage::create(context, image));
26 } 28 }
27 29
28 String MediaMetadata::title() const { 30 String MediaMetadata::title() const {
29 return m_title; 31 return m_title;
30 } 32 }
31 33
32 String MediaMetadata::artist() const { 34 String MediaMetadata::artist() const {
33 return m_artist; 35 return m_artist;
34 } 36 }
35 37
36 String MediaMetadata::album() const { 38 String MediaMetadata::album() const {
37 return m_album; 39 return m_album;
38 } 40 }
39 41
40 const HeapVector<Member<MediaImage>>& MediaMetadata::artwork() const { 42 const HeapVector<Member<MediaImage>>& MediaMetadata::artwork() const {
41 return m_artwork; 43 return m_artwork;
42 } 44 }
43 45
46 void MediaMetadata::setTitle(const String& title) {
47 m_title = title;
48 notifySessionAsync();
49 }
50
51 void MediaMetadata::setArtist(const String& artist) {
52 m_artist = artist;
53 notifySessionAsync();
54 }
55
56 void MediaMetadata::setAlbum(const String& album) {
57 m_album = album;
58 notifySessionAsync();
59 }
60
61 void MediaMetadata::setArtwork(const HeapVector<Member<MediaImage>>& artwork) {
62 m_artwork = artwork;
63 notifySessionAsync();
64 }
65
66 void MediaMetadata::setSession(MediaSession* session) {
67 m_session = session;
68 }
69
70 void MediaMetadata::notifySessionAsync() {
71 if (!m_session || m_notifySessionTimer.isActive())
72 return;
73 m_notifySessionTimer.startOneShot(0, BLINK_FROM_HERE);
74 }
75
76 void MediaMetadata::notifySessionTimerFired(TimerBase*) {
77 if (!m_session)
78 return;
79 m_session->onMetadataChanged();
80 }
81
44 DEFINE_TRACE(MediaMetadata) { 82 DEFINE_TRACE(MediaMetadata) {
45 visitor->trace(m_artwork); 83 visitor->trace(m_artwork);
84 visitor->trace(m_session);
46 } 85 }
47 86
48 } // namespace blink 87 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698