| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/browser/media/session/pepper_playback_observer.h" |
| 6 |
| 7 #include "base/feature_list.h" |
| 8 #include "content/browser/media/session/media_session.h" |
| 9 #include "content/browser/media/session/pepper_player_delegate.h" |
| 10 #include "content/common/frame_messages.h" |
| 11 #include "ipc/ipc_message_macros.h" |
| 12 #include "media/base/media_switches.h" |
| 13 |
| 14 namespace content { |
| 15 |
| 16 namespace { |
| 17 |
| 18 const int kPlayerId = 0; |
| 19 |
| 20 } |
| 21 |
| 22 PepperPlaybackObserver::PepperPlaybackObserver(WebContentsImpl *contents) |
| 23 : contents_(contents) {} |
| 24 |
| 25 PepperPlaybackObserver::~PepperPlaybackObserver() { |
| 26 // At this point WebContents is being destructed, so it's safe to |
| 27 // call this. MediaSession may decide to send further IPC messages |
| 28 // through PepperPlayerDelegates, which might be declined if the |
| 29 // RenderViewHost has been destroyed. |
| 30 for (PlayersMap::iterator iter(&players_map_); |
| 31 !iter.IsAtEnd(); iter.Advance()) { |
| 32 PepperStopsPlayback(iter.GetCurrentKey()); |
| 33 } |
| 34 } |
| 35 |
| 36 void PepperPlaybackObserver::PepperInstanceCreated(int32_t pp_instance) { |
| 37 } |
| 38 |
| 39 void PepperPlaybackObserver::PepperInstanceDeleted(int32_t pp_instance) { |
| 40 PepperStopsPlayback(pp_instance); |
| 41 } |
| 42 |
| 43 void PepperPlaybackObserver::PepperStartsPlayback(int32_t pp_instance) { |
| 44 if (!base::FeatureList::IsEnabled(media::kFlashJoinsMediaSession)) |
| 45 return; |
| 46 |
| 47 if (players_map_.Lookup(pp_instance)) |
| 48 return; |
| 49 |
| 50 players_map_.AddWithID(new PepperPlayerDelegate( |
| 51 contents_, pp_instance), pp_instance); |
| 52 MediaSession::Get(contents_)->AddPlayer( |
| 53 players_map_.Lookup(pp_instance), kPlayerId, MediaSession::Type::Content); |
| 54 } |
| 55 |
| 56 void PepperPlaybackObserver::PepperStopsPlayback(int32_t pp_instance) { |
| 57 if (!players_map_.Lookup(pp_instance)) |
| 58 return; |
| 59 |
| 60 MediaSession::Get(contents_)->RemovePlayer( |
| 61 players_map_.Lookup(pp_instance), kPlayerId); |
| 62 |
| 63 players_map_.Remove(pp_instance); |
| 64 } |
| 65 |
| 66 } // namespace content |
| OLD | NEW |