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

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

Issue 2453623003: Decouple MediaSession messages from WebContents (full patch) (Closed)
Patch Set: nit Created 4 years, 1 month 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/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_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(WebContentsImpl *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 MediaSession::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(int32_t pp_instance) {
45 players_played_sound_map_[pp_instance] = false; 45 players_played_sound_map_[pp_instance] = false;
46 } 46 }
47 47
48 void PepperPlaybackObserver::PepperInstanceDeleted(int32_t pp_instance) { 48 void PepperPlaybackObserver::PepperInstanceDeleted(int32_t pp_instance) {
49 UMA_HISTOGRAM_BOOLEAN("Media.Pepper.PlayedSound", 49 UMA_HISTOGRAM_BOOLEAN("Media.Pepper.PlayedSound",
50 players_played_sound_map_[pp_instance]); 50 players_played_sound_map_[pp_instance]);
51 players_played_sound_map_.erase(pp_instance); 51 players_played_sound_map_.erase(pp_instance);
52 52
53 PepperStopsPlayback(pp_instance); 53 PepperStopsPlayback(pp_instance);
54 } 54 }
55 55
56 void PepperPlaybackObserver::PepperStartsPlayback(int32_t pp_instance) { 56 void PepperPlaybackObserver::PepperStartsPlayback(int32_t pp_instance) {
57 players_played_sound_map_[pp_instance] = true; 57 players_played_sound_map_[pp_instance] = true;
58 58
59 if (players_map_.count(pp_instance)) 59 if (players_map_.count(pp_instance))
60 return; 60 return;
61 61
62 players_map_[pp_instance].reset(new PepperPlayerDelegate( 62 players_map_[pp_instance].reset(new PepperPlayerDelegate(
63 contents_, pp_instance)); 63 contents_, pp_instance));
64 64
65 MediaSession::Get(contents_)->AddPlayer( 65 MediaSessionImpl::Get(contents_)->AddPlayer(
66 players_map_[pp_instance].get(), PepperPlayerDelegate::kPlayerId, 66 players_map_[pp_instance].get(), PepperPlayerDelegate::kPlayerId,
67 ShouldDuckFlash() ? media::MediaContentType::Pepper 67 ShouldDuckFlash() ? media::MediaContentType::Pepper
68 : media::MediaContentType::Persistent); 68 : media::MediaContentType::Persistent);
69 } 69 }
70 70
71 void PepperPlaybackObserver::PepperStopsPlayback(int32_t pp_instance) { 71 void PepperPlaybackObserver::PepperStopsPlayback(int32_t pp_instance) {
72 if (!players_map_.count(pp_instance)) 72 if (!players_map_.count(pp_instance))
73 return; 73 return;
74 74
75 MediaSession::Get(contents_)->RemovePlayer( 75 MediaSessionImpl::Get(contents_)->RemovePlayer(
76 players_map_[pp_instance].get(), PepperPlayerDelegate::kPlayerId); 76 players_map_[pp_instance].get(), PepperPlayerDelegate::kPlayerId);
77 77
78 players_map_.erase(pp_instance); 78 players_map_.erase(pp_instance);
79 } 79 }
80 80
81 } // namespace content 81 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698