Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(96)

Side by Side Diff: content/browser/media/session/pepper_playback_observer.cc

Issue 2551093002: Route Pepper MediaSession messages to frames (Closed)
Patch Set: fixed Android build Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 (auto it = players_played_sound_map_.begin();
37 iter != players_map_.end();) { 37 it != players_played_sound_map_.end();) {
38 MediaSessionImpl::Get(contents_)->RemovePlayer( 38 const PlayerId& id = (it++)->first;
39 iter->second.get(), PepperPlayerDelegate::kPlayerId); 39 PepperInstanceDeleted(id.first, id.second);
40 iter = players_map_.erase(iter);
41 } 40 }
42 } 41 }
43 42
44 void PepperPlaybackObserver::PepperInstanceCreated(int32_t pp_instance) { 43 void PepperPlaybackObserver::RenderFrameDeleted(
45 players_played_sound_map_[pp_instance] = false; 44 RenderFrameHost* render_frame_host) {
45 std::vector<PlayerId> players_to_remove;
46 for (auto it = players_played_sound_map_.begin();
47 it != players_played_sound_map_.end();) {
48 const PlayerId& id = (it++)->first;
49 if (id.first == render_frame_host)
50 PepperInstanceDeleted(id.first, id.second);
51 }
46 } 52 }
47 53
48 void PepperPlaybackObserver::PepperInstanceDeleted(int32_t pp_instance) { 54 void PepperPlaybackObserver::PepperInstanceCreated(
49 UMA_HISTOGRAM_BOOLEAN("Media.Pepper.PlayedSound", 55 RenderFrameHost* render_frame_host, int32_t pp_instance) {
50 players_played_sound_map_[pp_instance]); 56 PlayerId id(render_frame_host, pp_instance);
51 players_played_sound_map_.erase(pp_instance); 57 players_played_sound_map_[id] = false;
52
53 PepperStopsPlayback(pp_instance);
54 } 58 }
55 59
56 void PepperPlaybackObserver::PepperStartsPlayback(int32_t pp_instance) { 60 void PepperPlaybackObserver::PepperInstanceDeleted(
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 auto iter = players_played_sound_map_.find(id);
65 if (iter == players_played_sound_map_.end())
60 return; 66 return;
61 67
62 players_map_[pp_instance].reset(new PepperPlayerDelegate( 68 UMA_HISTOGRAM_BOOLEAN("Media.Pepper.PlayedSound", iter->second);
63 contents_, pp_instance)); 69 players_played_sound_map_.erase(iter);
70
71 PepperStopsPlayback(render_frame_host, pp_instance);
72 }
73
74 void PepperPlaybackObserver::PepperStartsPlayback(
75 RenderFrameHost* render_frame_host, int32_t pp_instance) {
76 PlayerId id(render_frame_host, pp_instance);
77
78 players_played_sound_map_[id] = true;
79
80 if (players_map_.count(id))
81 return;
82
83 players_map_[id].reset(new PepperPlayerDelegate(
84 render_frame_host, pp_instance));
64 85
65 MediaSessionImpl::Get(contents_)->AddPlayer( 86 MediaSessionImpl::Get(contents_)->AddPlayer(
66 players_map_[pp_instance].get(), PepperPlayerDelegate::kPlayerId, 87 players_map_[id].get(), PepperPlayerDelegate::kPlayerId,
67 ShouldDuckFlash() ? media::MediaContentType::Pepper 88 ShouldDuckFlash() ? media::MediaContentType::Pepper
68 : media::MediaContentType::OneShot); 89 : media::MediaContentType::OneShot);
69 } 90 }
70 91
71 void PepperPlaybackObserver::PepperStopsPlayback(int32_t pp_instance) { 92 void PepperPlaybackObserver::PepperStopsPlayback(
72 if (!players_map_.count(pp_instance)) 93 RenderFrameHost* render_frame_host, int32_t pp_instance) {
94 PlayerId id(render_frame_host, pp_instance);
95
96 if (!players_map_.count(id))
73 return; 97 return;
74 98
75 MediaSessionImpl::Get(contents_)->RemovePlayer( 99 MediaSessionImpl::Get(contents_)->RemovePlayer(
76 players_map_[pp_instance].get(), PepperPlayerDelegate::kPlayerId); 100 players_map_[id].get(), PepperPlayerDelegate::kPlayerId);
77 101
78 players_map_.erase(pp_instance); 102 players_map_.erase(id);
79 } 103 }
80 104
81 } // namespace content 105 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/media/session/pepper_playback_observer.h ('k') | content/browser/media/session/pepper_player_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698