| 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_BROWSER_MEDIA_SESSION_PEPPER_PLAYBACK_OBSERVER_H_ | 5 #ifndef CONTENT_BROWSER_MEDIA_SESSION_PEPPER_PLAYBACK_OBSERVER_H_ |
| 6 #define CONTENT_BROWSER_MEDIA_SESSION_PEPPER_PLAYBACK_OBSERVER_H_ | 6 #define CONTENT_BROWSER_MEDIA_SESSION_PEPPER_PLAYBACK_OBSERVER_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <utility> |
| 11 | 12 |
| 12 #include "base/macros.h" | 13 #include "base/macros.h" |
| 13 | 14 |
| 14 namespace content { | 15 namespace content { |
| 15 | 16 |
| 16 class PepperPlayerDelegate; | 17 class PepperPlayerDelegate; |
| 17 class WebContentsImpl; | 18 class RenderFrameHost; |
| 19 class WebContents; |
| 18 | 20 |
| 19 // Class observing Pepper playback changes from WebContents, and update | 21 // Class observing Pepper playback changes from WebContents, and update |
| 20 // MediaSession accordingly. Can only be a member of WebContentsImpl and must be | 22 // MediaSession accordingly. Can only be a member of WebContents and must be |
| 21 // destroyed in ~WebContentsImpl(). | 23 // destroyed in ~WebContents(). |
| 22 class PepperPlaybackObserver { | 24 class PepperPlaybackObserver { |
| 23 public: | 25 public: |
| 24 explicit PepperPlaybackObserver(WebContentsImpl* contents); | 26 explicit PepperPlaybackObserver(WebContents* contents); |
| 25 virtual ~PepperPlaybackObserver(); | 27 virtual ~PepperPlaybackObserver(); |
| 26 | 28 |
| 27 void PepperInstanceCreated(int32_t pp_instance); | 29 void PepperInstanceCreated(RenderFrameHost* render_frame_host, |
| 28 void PepperInstanceDeleted(int32_t pp_instance); | 30 int32_t pp_instance); |
| 31 void PepperInstanceDeleted(RenderFrameHost* render_frame_host, |
| 32 int32_t pp_instance); |
| 29 // This method is called when a Pepper instance starts making sound. | 33 // This method is called when a Pepper instance starts making sound. |
| 30 void PepperStartsPlayback(int32_t pp_instance); | 34 void PepperStartsPlayback(RenderFrameHost* render_frame_host, |
| 35 int32_t pp_instance); |
| 31 // This method is called when a Pepper instance stops making sound. | 36 // This method is called when a Pepper instance stops making sound. |
| 32 void PepperStopsPlayback(int32_t pp_instance); | 37 void PepperStopsPlayback(RenderFrameHost* render_frame_host, |
| 38 int32_t pp_instance); |
| 33 | 39 |
| 34 private: | 40 private: |
| 41 using PlayerId = std::pair<RenderFrameHost*, int32_t>; |
| 42 |
| 35 // Owning PepperPlayerDelegates. | 43 // Owning PepperPlayerDelegates. |
| 36 using PlayersMap = | 44 using PlayersMap = |
| 37 std::map<int32_t, std::unique_ptr<PepperPlayerDelegate>>; | 45 std::map<PlayerId, std::unique_ptr<PepperPlayerDelegate>>; |
| 38 PlayersMap players_map_; | 46 PlayersMap players_map_; |
| 39 | 47 |
| 40 // Map for whether Pepper players have ever played sound. | 48 // Map for whether Pepper players have ever played sound. |
| 41 // Used for recording UMA. | 49 // Used for recording UMA. |
| 42 using PlayersPlayedSoundMap = | 50 using PlayersPlayedSoundMap = |
| 43 std::map<int32_t, bool>; | 51 std::map<PlayerId, bool>; |
| 44 PlayersPlayedSoundMap players_played_sound_map_; | 52 PlayersPlayedSoundMap players_played_sound_map_; |
| 45 | 53 |
| 46 // Weak reference to WebContents. | 54 // Weak reference to WebContents. |
| 47 WebContentsImpl* contents_; | 55 WebContents* contents_; |
| 48 | 56 |
| 49 DISALLOW_COPY_AND_ASSIGN(PepperPlaybackObserver); | 57 DISALLOW_COPY_AND_ASSIGN(PepperPlaybackObserver); |
| 50 }; | 58 }; |
| 51 | 59 |
| 52 } // namespace content | 60 } // namespace content |
| 53 | 61 |
| 54 #endif // CONTENT_BROWSER_MEDIA_SESSION_PEPPER_PLAYBACK_OBSERVER_H_ | 62 #endif // CONTENT_BROWSER_MEDIA_SESSION_PEPPER_PLAYBACK_OBSERVER_H_ |
| OLD | NEW |