| 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/feature_list.h" |
| 8 #include "base/metrics/histogram_macros.h" | 8 #include "base/metrics/histogram_macros.h" |
| 9 #include "content/browser/media/session/media_session.h" | 9 #include "content/browser/media/session/media_session.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 { |
| 19 |
| 20 bool ShouldDuckFlash() { |
| 21 return base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 22 switches::kEnableDefaultMediaSession) == |
| 23 switches::kEnableDefaultMediaSessionDuckFlash; |
| 24 } |
| 25 |
| 26 } // anonymous namespace |
| 27 |
| 18 PepperPlaybackObserver::PepperPlaybackObserver(WebContentsImpl *contents) | 28 PepperPlaybackObserver::PepperPlaybackObserver(WebContentsImpl *contents) |
| 19 : contents_(contents) {} | 29 : contents_(contents) {} |
| 20 | 30 |
| 21 PepperPlaybackObserver::~PepperPlaybackObserver() { | 31 PepperPlaybackObserver::~PepperPlaybackObserver() { |
| 22 // 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 |
| 23 // call this. MediaSession may decide to send further IPC messages | 33 // call this. MediaSession may decide to send further IPC messages |
| 24 // through PepperPlayerDelegates, which might be declined if the | 34 // through PepperPlayerDelegates, which might be declined if the |
| 25 // RenderViewHost has been destroyed. | 35 // RenderViewHost has been destroyed. |
| 26 for (PlayersMap::iterator iter = players_map_.begin(); | 36 for (PlayersMap::iterator iter = players_map_.begin(); |
| 27 iter != players_map_.end();) { | 37 iter != players_map_.end();) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 39 UMA_HISTOGRAM_BOOLEAN("Media.Pepper.PlayedSound", | 49 UMA_HISTOGRAM_BOOLEAN("Media.Pepper.PlayedSound", |
| 40 players_played_sound_map_[pp_instance]); | 50 players_played_sound_map_[pp_instance]); |
| 41 players_played_sound_map_.erase(pp_instance); | 51 players_played_sound_map_.erase(pp_instance); |
| 42 | 52 |
| 43 PepperStopsPlayback(pp_instance); | 53 PepperStopsPlayback(pp_instance); |
| 44 } | 54 } |
| 45 | 55 |
| 46 void PepperPlaybackObserver::PepperStartsPlayback(int32_t pp_instance) { | 56 void PepperPlaybackObserver::PepperStartsPlayback(int32_t pp_instance) { |
| 47 players_played_sound_map_[pp_instance] = true; | 57 players_played_sound_map_[pp_instance] = true; |
| 48 | 58 |
| 49 if (base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | |
| 50 switches::kEnableDefaultMediaSession) != | |
| 51 switches::kEnableDefaultMediaSessionWithFlash) { | |
| 52 return; | |
| 53 } | |
| 54 | |
| 55 if (players_map_.count(pp_instance)) | 59 if (players_map_.count(pp_instance)) |
| 56 return; | 60 return; |
| 57 | 61 |
| 58 players_map_[pp_instance].reset(new PepperPlayerDelegate( | 62 players_map_[pp_instance].reset(new PepperPlayerDelegate( |
| 59 contents_, pp_instance)); | 63 contents_, pp_instance)); |
| 64 |
| 60 MediaSession::Get(contents_)->AddPlayer( | 65 MediaSession::Get(contents_)->AddPlayer( |
| 61 players_map_[pp_instance].get(), | 66 players_map_[pp_instance].get(), PepperPlayerDelegate::kPlayerId, |
| 62 PepperPlayerDelegate::kPlayerId, | 67 ShouldDuckFlash() ? media::MediaContentType::Pepper |
| 63 media::MediaContentType::Pepper); | 68 : media::MediaContentType::Persistent); |
| 64 } | 69 } |
| 65 | 70 |
| 66 void PepperPlaybackObserver::PepperStopsPlayback(int32_t pp_instance) { | 71 void PepperPlaybackObserver::PepperStopsPlayback(int32_t pp_instance) { |
| 67 if (!players_map_.count(pp_instance)) | 72 if (!players_map_.count(pp_instance)) |
| 68 return; | 73 return; |
| 69 | 74 |
| 70 MediaSession::Get(contents_)->RemovePlayer( | 75 MediaSession::Get(contents_)->RemovePlayer( |
| 71 players_map_[pp_instance].get(), PepperPlayerDelegate::kPlayerId); | 76 players_map_[pp_instance].get(), PepperPlayerDelegate::kPlayerId); |
| 72 | 77 |
| 73 players_map_.erase(pp_instance); | 78 players_map_.erase(pp_instance); |
| 74 } | 79 } |
| 75 | 80 |
| 76 } // namespace content | 81 } // namespace content |
| OLD | NEW |