| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #ifndef CONTENT_PUBLIC_BROWSER_MEDIA_SESSION_OBSERVER_H_ | 5 #ifndef CONTENT_PUBLIC_BROWSER_MEDIA_SESSION_OBSERVER_H_ |
| 6 #define CONTENT_PUBLIC_BROWSER_MEDIA_SESSION_OBSERVER_H_ | 6 #define CONTENT_PUBLIC_BROWSER_MEDIA_SESSION_OBSERVER_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/optional.h" | 11 #include "base/optional.h" |
| 12 #include "content/common/content_export.h" | 12 #include "content/common/content_export.h" |
| 13 #include "content/public/common/media_metadata.h" | 13 #include "content/public/common/media_metadata.h" |
| 14 | 14 |
| 15 namespace blink { | 15 namespace blink { |
| 16 namespace mojom { | 16 namespace mojom { |
| 17 enum class MediaSessionAction; | 17 enum class MediaSessionAction; |
| 18 } // namespace mojom | 18 } // namespace mojom |
| 19 } // namespace blink | 19 } // namespace blink |
| 20 | 20 |
| 21 namespace content { | 21 namespace content { |
| 22 | 22 |
| 23 class MediaSession; | 23 class MediaSession; |
| 24 class MediaSessionImpl; | |
| 25 | 24 |
| 26 // The observer for observing MediaSession events. | 25 // The observer for observing MediaSession events. |
| 27 class CONTENT_EXPORT MediaSessionObserver { | 26 class CONTENT_EXPORT MediaSessionObserver { |
| 28 public: | 27 public: |
| 29 // Gets the observed MediaSession. Will return null when the session is | 28 // Gets the observed MediaSession. Will return null when the session is |
| 30 // destroyed. | 29 // destroyed. |
| 31 MediaSession* media_session() const; | 30 MediaSession* media_session() const; |
| 32 | 31 |
| 33 // Called when the observed MediaSession is being destroyed. Give subclass a | 32 // Called when the observed MediaSession is being destroyed. Give subclass a |
| 34 // chance to clean up. media_session() will return nullptr after this method | 33 // chance to clean up. media_session() will return nullptr after this method |
| 35 // is called. | 34 // is called. |
| 36 virtual void MediaSessionDestroyed() {} | 35 virtual void MediaSessionDestroyed() {} |
| 37 | 36 |
| 38 // Called when the observed MediaSession has changed its state. | 37 // Called when the observed MediaSession has changed its state. |
| 39 virtual void MediaSessionStateChanged(bool is_controllable, | 38 virtual void MediaSessionStateChanged(bool is_controllable, |
| 40 bool is_suspended) {} | 39 bool is_suspended) {} |
| 41 | 40 |
| 42 // Called when the observed MediaSession has changed metadata. | 41 // Called when the observed MediaSession has changed metadata. |
| 43 virtual void MediaSessionMetadataChanged( | 42 virtual void MediaSessionMetadataChanged( |
| 44 const base::Optional<MediaMetadata>& metadata) {} | 43 const base::Optional<MediaMetadata>& metadata) {} |
| 45 | 44 |
| 46 // Called when the media session action list has changed. | 45 // Called when the media session action list has changed. |
| 47 virtual void MediaSessionActionsChanged( | 46 virtual void MediaSessionActionsChanged( |
| 48 const std::set<blink::mojom::MediaSessionAction>& action) {} | 47 const std::set<blink::mojom::MediaSessionAction>& action) {} |
| 49 | 48 |
| 50 protected: | 49 protected: |
| 51 // Create a MediaSessionObserver and start observing a session. | 50 // Create a MediaSessionObserver and start observing a session. |
| 52 MediaSessionObserver(MediaSession* media_session); | 51 explicit MediaSessionObserver(MediaSession* media_session); |
| 53 // Destruct a MediaSessionObserver and remove it from the session if it's | 52 // Destruct a MediaSessionObserver and remove it from the session if it's |
| 54 // still observing. | 53 // still observing. |
| 55 virtual ~MediaSessionObserver(); | 54 virtual ~MediaSessionObserver(); |
| 56 | 55 |
| 57 private: | 56 private: |
| 58 friend class MediaSessionImpl; | 57 friend class MediaSessionImpl; |
| 59 | 58 |
| 60 void StopObserving(); | 59 void StopObserving(); |
| 61 | 60 |
| 62 // Weak pointer to MediaSession | 61 // Weak pointer to MediaSession |
| 63 MediaSessionImpl* media_session_; | 62 MediaSession* media_session_; |
| 64 | 63 |
| 65 DISALLOW_COPY_AND_ASSIGN(MediaSessionObserver); | 64 DISALLOW_COPY_AND_ASSIGN(MediaSessionObserver); |
| 66 }; | 65 }; |
| 67 | 66 |
| 68 } // namespace content | 67 } // namespace content |
| 69 | 68 |
| 70 #endif // CONTENT_PUBLIC_BROWSER_MEDIA_SESSION_OBSERVER_H_ | 69 #endif // CONTENT_PUBLIC_BROWSER_MEDIA_SESSION_OBSERVER_H_ |
| OLD | NEW |