| 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 #include "content/browser/media/session/pepper_playback_observer.h" | 5 #include "content/browser/media/session/pepper_playback_observer.h" |
| 6 | 6 |
| 7 #include "base/feature_list.h" | 7 #include "base/command_line.h" |
| 8 #include "base/metrics/histogram_macros.h" | 8 #include "base/metrics/histogram_macros.h" |
| 9 #include "content/browser/media/session/media_session_impl.h" | 9 #include "content/browser/media/session/media_session_impl.h" |
| 10 #include "content/browser/media/session/pepper_player_delegate.h" | 10 #include "content/browser/media/session/pepper_player_delegate.h" |
| 11 #include "content/common/frame_messages.h" | 11 #include "content/common/frame_messages.h" |
| 12 #include "ipc/ipc_message_macros.h" | 12 #include "ipc/ipc_message_macros.h" |
| 13 #include "media/base/media_content_type.h" | 13 #include "media/base/media_content_type.h" |
| 14 #include "media/base/media_switches.h" | 14 #include "media/base/media_switches.h" |
| 15 | 15 |
| 16 namespace content { | 16 namespace content { |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 bool ShouldDuckFlash() { | 20 bool ShouldDuckFlash() { |
| 21 return base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 21 return base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 22 switches::kEnableDefaultMediaSession) == | 22 switches::kEnableDefaultMediaSession) == |
| 23 switches::kEnableDefaultMediaSessionDuckFlash; | 23 switches::kEnableDefaultMediaSessionDuckFlash; |
| 24 } | 24 } |
| 25 | 25 |
| 26 } // anonymous namespace | 26 } // anonymous namespace |
| 27 | 27 |
| 28 PepperPlaybackObserver::PepperPlaybackObserver(WebContentsImpl *contents) | 28 PepperPlaybackObserver::PepperPlaybackObserver(WebContents *contents) |
| 29 : contents_(contents) {} | 29 : contents_(contents) {} |
| 30 | 30 |
| 31 PepperPlaybackObserver::~PepperPlaybackObserver() { | 31 PepperPlaybackObserver::~PepperPlaybackObserver() { |
| 32 // At this point WebContents is being destructed, so it's safe to | 32 // At this point WebContents is being destructed, so it's safe to |
| 33 // call this. MediaSession may decide to send further IPC messages | 33 // call this. MediaSession may decide to send further IPC messages |
| 34 // through PepperPlayerDelegates, which might be declined if the | 34 // through PepperPlayerDelegates, which might be declined if the |
| 35 // RenderViewHost has been destroyed. | 35 // RenderViewHost has been destroyed. |
| 36 for (PlayersMap::iterator iter = players_map_.begin(); | 36 for (PlayersMap::iterator iter = players_map_.begin(); |
| 37 iter != players_map_.end();) { | 37 iter != players_map_.end();) { |
| 38 MediaSessionImpl::Get(contents_)->RemovePlayer( | 38 MediaSessionImpl::Get(contents_)->RemovePlayer( |
| 39 iter->second.get(), PepperPlayerDelegate::kPlayerId); | 39 iter->second.get(), PepperPlayerDelegate::kPlayerId); |
| 40 iter = players_map_.erase(iter); | 40 iter = players_map_.erase(iter); |
| 41 } | 41 } |
| 42 } | 42 } |
| 43 | 43 |
| 44 void PepperPlaybackObserver::PepperInstanceCreated(int32_t pp_instance) { | 44 void PepperPlaybackObserver::PepperInstanceCreated( |
| 45 players_played_sound_map_[pp_instance] = false; | 45 RenderFrameHost* render_frame_host, int32_t pp_instance) { |
| 46 PlayerId id(render_frame_host, pp_instance); |
| 47 players_played_sound_map_[id] = false; |
| 46 } | 48 } |
| 47 | 49 |
| 48 void PepperPlaybackObserver::PepperInstanceDeleted(int32_t pp_instance) { | 50 void PepperPlaybackObserver::PepperInstanceDeleted( |
| 51 RenderFrameHost* render_frame_host, int32_t pp_instance) { |
| 52 PlayerId id(render_frame_host, pp_instance); |
| 49 UMA_HISTOGRAM_BOOLEAN("Media.Pepper.PlayedSound", | 53 UMA_HISTOGRAM_BOOLEAN("Media.Pepper.PlayedSound", |
| 50 players_played_sound_map_[pp_instance]); | 54 players_played_sound_map_[id]); |
| 51 players_played_sound_map_.erase(pp_instance); | 55 players_played_sound_map_.erase(id); |
| 52 | 56 |
| 53 PepperStopsPlayback(pp_instance); | 57 PepperStopsPlayback(render_frame_host, pp_instance); |
| 54 } | 58 } |
| 55 | 59 |
| 56 void PepperPlaybackObserver::PepperStartsPlayback(int32_t pp_instance) { | 60 void PepperPlaybackObserver::PepperStartsPlayback( |
| 57 players_played_sound_map_[pp_instance] = true; | 61 RenderFrameHost* render_frame_host, int32_t pp_instance) { |
| 62 PlayerId id(render_frame_host, pp_instance); |
| 58 | 63 |
| 59 if (players_map_.count(pp_instance)) | 64 players_played_sound_map_[id] = true; |
| 65 |
| 66 if (players_map_.count(id)) |
| 60 return; | 67 return; |
| 61 | 68 |
| 62 players_map_[pp_instance].reset(new PepperPlayerDelegate( | 69 players_map_[id].reset(new PepperPlayerDelegate( |
| 63 contents_, pp_instance)); | 70 render_frame_host, pp_instance)); |
| 64 | 71 |
| 65 MediaSessionImpl::Get(contents_)->AddPlayer( | 72 MediaSessionImpl::Get(contents_)->AddPlayer( |
| 66 players_map_[pp_instance].get(), PepperPlayerDelegate::kPlayerId, | 73 players_map_[id].get(), PepperPlayerDelegate::kPlayerId, |
| 67 ShouldDuckFlash() ? media::MediaContentType::Pepper | 74 ShouldDuckFlash() ? media::MediaContentType::Pepper |
| 68 : media::MediaContentType::OneShot); | 75 : media::MediaContentType::OneShot); |
| 69 } | 76 } |
| 70 | 77 |
| 71 void PepperPlaybackObserver::PepperStopsPlayback(int32_t pp_instance) { | 78 void PepperPlaybackObserver::PepperStopsPlayback( |
| 72 if (!players_map_.count(pp_instance)) | 79 RenderFrameHost* render_frame_host, int32_t pp_instance) { |
| 80 PlayerId id(render_frame_host, pp_instance); |
| 81 |
| 82 if (!players_map_.count(id)) |
| 73 return; | 83 return; |
| 74 | 84 |
| 75 MediaSessionImpl::Get(contents_)->RemovePlayer( | 85 MediaSessionImpl::Get(contents_)->RemovePlayer( |
| 76 players_map_[pp_instance].get(), PepperPlayerDelegate::kPlayerId); | 86 players_map_[id].get(), PepperPlayerDelegate::kPlayerId); |
| 77 | 87 |
| 78 players_map_.erase(pp_instance); | 88 players_map_.erase(id); |
| 79 } | 89 } |
| 80 | 90 |
| 81 } // namespace content | 91 } // namespace content |
| OLD | NEW |