Chromium Code Reviews| 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/browser/web_contents/web_contents_impl.h" | |
|
whywhat
2016/12/06 01:37:31
nit: Is this header necessary? Seems like the only
Zhiqiang Zhang (Slow)
2016/12/06 12:05:56
Actually we only need to store WebContents* in Pep
| |
| 11 #include "content/common/frame_messages.h" | 12 #include "content/common/frame_messages.h" |
| 12 #include "ipc/ipc_message_macros.h" | 13 #include "ipc/ipc_message_macros.h" |
| 13 #include "media/base/media_content_type.h" | 14 #include "media/base/media_content_type.h" |
| 14 #include "media/base/media_switches.h" | 15 #include "media/base/media_switches.h" |
| 15 | 16 |
| 16 namespace content { | 17 namespace content { |
| 17 | 18 |
| 18 namespace { | 19 namespace { |
| 19 | 20 |
| 20 bool ShouldDuckFlash() { | 21 bool ShouldDuckFlash() { |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 34 // through PepperPlayerDelegates, which might be declined if the | 35 // through PepperPlayerDelegates, which might be declined if the |
| 35 // RenderViewHost has been destroyed. | 36 // RenderViewHost has been destroyed. |
| 36 for (PlayersMap::iterator iter = players_map_.begin(); | 37 for (PlayersMap::iterator iter = players_map_.begin(); |
| 37 iter != players_map_.end();) { | 38 iter != players_map_.end();) { |
| 38 MediaSessionImpl::Get(contents_)->RemovePlayer( | 39 MediaSessionImpl::Get(contents_)->RemovePlayer( |
| 39 iter->second.get(), PepperPlayerDelegate::kPlayerId); | 40 iter->second.get(), PepperPlayerDelegate::kPlayerId); |
| 40 iter = players_map_.erase(iter); | 41 iter = players_map_.erase(iter); |
| 41 } | 42 } |
| 42 } | 43 } |
| 43 | 44 |
| 44 void PepperPlaybackObserver::PepperInstanceCreated(int32_t pp_instance) { | 45 void PepperPlaybackObserver::PepperInstanceCreated( |
| 45 players_played_sound_map_[pp_instance] = false; | 46 RenderFrameHost* render_frame_host, int32_t pp_instance) { |
| 47 PlayerId id(render_frame_host, pp_instance); | |
| 48 players_played_sound_map_[id] = false; | |
| 46 } | 49 } |
| 47 | 50 |
| 48 void PepperPlaybackObserver::PepperInstanceDeleted(int32_t pp_instance) { | 51 void PepperPlaybackObserver::PepperInstanceDeleted( |
| 52 RenderFrameHost* render_frame_host, int32_t pp_instance) { | |
| 53 PlayerId id(render_frame_host, pp_instance); | |
| 49 UMA_HISTOGRAM_BOOLEAN("Media.Pepper.PlayedSound", | 54 UMA_HISTOGRAM_BOOLEAN("Media.Pepper.PlayedSound", |
| 50 players_played_sound_map_[pp_instance]); | 55 players_played_sound_map_[id]); |
| 51 players_played_sound_map_.erase(pp_instance); | 56 players_played_sound_map_.erase(id); |
| 52 | 57 |
| 53 PepperStopsPlayback(pp_instance); | 58 PepperStopsPlayback(render_frame_host, pp_instance); |
| 54 } | 59 } |
| 55 | 60 |
| 56 void PepperPlaybackObserver::PepperStartsPlayback(int32_t pp_instance) { | 61 void PepperPlaybackObserver::PepperStartsPlayback( |
| 57 players_played_sound_map_[pp_instance] = true; | 62 RenderFrameHost* render_frame_host, int32_t pp_instance) { |
| 63 PlayerId id(render_frame_host, pp_instance); | |
| 58 | 64 |
| 59 if (players_map_.count(pp_instance)) | 65 players_played_sound_map_[id] = true; |
| 66 | |
| 67 if (players_map_.count(id)) | |
| 60 return; | 68 return; |
| 61 | 69 |
| 62 players_map_[pp_instance].reset(new PepperPlayerDelegate( | 70 players_map_[id].reset(new PepperPlayerDelegate( |
| 63 contents_, pp_instance)); | 71 render_frame_host, pp_instance)); |
| 64 | 72 |
| 65 MediaSessionImpl::Get(contents_)->AddPlayer( | 73 MediaSessionImpl::Get(contents_)->AddPlayer( |
| 66 players_map_[pp_instance].get(), PepperPlayerDelegate::kPlayerId, | 74 players_map_[id].get(), PepperPlayerDelegate::kPlayerId, |
| 67 ShouldDuckFlash() ? media::MediaContentType::Pepper | 75 ShouldDuckFlash() ? media::MediaContentType::Pepper |
| 68 : media::MediaContentType::OneShot); | 76 : media::MediaContentType::OneShot); |
| 69 } | 77 } |
| 70 | 78 |
| 71 void PepperPlaybackObserver::PepperStopsPlayback(int32_t pp_instance) { | 79 void PepperPlaybackObserver::PepperStopsPlayback( |
| 72 if (!players_map_.count(pp_instance)) | 80 RenderFrameHost* render_frame_host, int32_t pp_instance) { |
| 81 PlayerId id(render_frame_host, pp_instance); | |
| 82 | |
| 83 if (!players_map_.count(id)) | |
| 73 return; | 84 return; |
| 74 | 85 |
| 75 MediaSessionImpl::Get(contents_)->RemovePlayer( | 86 MediaSessionImpl::Get(contents_)->RemovePlayer( |
| 76 players_map_[pp_instance].get(), PepperPlayerDelegate::kPlayerId); | 87 players_map_[id].get(), PepperPlayerDelegate::kPlayerId); |
| 77 | 88 |
| 78 players_map_.erase(pp_instance); | 89 players_map_.erase(id); |
| 79 } | 90 } |
| 80 | 91 |
| 81 } // namespace content | 92 } // namespace content |
| OLD | NEW |