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 "content/browser/media/session/media_session.h" | 9 #include "content/browser/media/session/media_session.h" |
9 #include "content/browser/media/session/pepper_player_delegate.h" | 10 #include "content/browser/media/session/pepper_player_delegate.h" |
10 #include "content/common/frame_messages.h" | 11 #include "content/common/frame_messages.h" |
11 #include "ipc/ipc_message_macros.h" | 12 #include "ipc/ipc_message_macros.h" |
12 #include "media/base/media_switches.h" | 13 #include "media/base/media_switches.h" |
13 | 14 |
14 namespace content { | 15 namespace content { |
15 | 16 |
16 PepperPlaybackObserver::PepperPlaybackObserver(WebContentsImpl *contents) | 17 PepperPlaybackObserver::PepperPlaybackObserver(WebContentsImpl *contents) |
17 : contents_(contents) {} | 18 : contents_(contents) {} |
18 | 19 |
19 PepperPlaybackObserver::~PepperPlaybackObserver() { | 20 PepperPlaybackObserver::~PepperPlaybackObserver() { |
20 // At this point WebContents is being destructed, so it's safe to | 21 // At this point WebContents is being destructed, so it's safe to |
21 // call this. MediaSession may decide to send further IPC messages | 22 // call this. MediaSession may decide to send further IPC messages |
22 // through PepperPlayerDelegates, which might be declined if the | 23 // through PepperPlayerDelegates, which might be declined if the |
23 // RenderViewHost has been destroyed. | 24 // RenderViewHost has been destroyed. |
24 for (PlayersMap::iterator iter = players_map_.begin(); | 25 for (PlayersMap::iterator iter = players_map_.begin(); |
25 iter != players_map_.end();) { | 26 iter != players_map_.end();) { |
26 MediaSession::Get(contents_)->RemovePlayer( | 27 MediaSession::Get(contents_)->RemovePlayer( |
27 iter->second.get(), PepperPlayerDelegate::kPlayerId); | 28 iter->second.get(), PepperPlayerDelegate::kPlayerId); |
28 iter = players_map_.erase(iter); | 29 iter = players_map_.erase(iter); |
29 } | 30 } |
30 } | 31 } |
31 | 32 |
32 void PepperPlaybackObserver::PepperInstanceCreated(int32_t pp_instance) { | 33 void PepperPlaybackObserver::PepperInstanceCreated(int32_t pp_instance) { |
| 34 players_played_sound_map_[pp_instance] = false; |
33 } | 35 } |
34 | 36 |
35 void PepperPlaybackObserver::PepperInstanceDeleted(int32_t pp_instance) { | 37 void PepperPlaybackObserver::PepperInstanceDeleted(int32_t pp_instance) { |
| 38 UMA_HISTOGRAM_BOOLEAN("Media.Pepper.PlayedSound", |
| 39 players_played_sound_map_[pp_instance]); |
| 40 players_played_sound_map_.erase(pp_instance); |
| 41 |
36 PepperStopsPlayback(pp_instance); | 42 PepperStopsPlayback(pp_instance); |
37 } | 43 } |
38 | 44 |
39 void PepperPlaybackObserver::PepperStartsPlayback(int32_t pp_instance) { | 45 void PepperPlaybackObserver::PepperStartsPlayback(int32_t pp_instance) { |
| 46 players_played_sound_map_[pp_instance] = true; |
| 47 |
40 if (!base::FeatureList::IsEnabled(media::kFlashJoinsMediaSession)) | 48 if (!base::FeatureList::IsEnabled(media::kFlashJoinsMediaSession)) |
41 return; | 49 return; |
42 | 50 |
43 if (players_map_.count(pp_instance)) | 51 if (players_map_.count(pp_instance)) |
44 return; | 52 return; |
45 | 53 |
46 players_map_[pp_instance].reset(new PepperPlayerDelegate( | 54 players_map_[pp_instance].reset(new PepperPlayerDelegate( |
47 contents_, pp_instance)); | 55 contents_, pp_instance)); |
48 MediaSession::Get(contents_)->AddPlayer( | 56 MediaSession::Get(contents_)->AddPlayer( |
49 players_map_[pp_instance].get(), | 57 players_map_[pp_instance].get(), |
50 PepperPlayerDelegate::kPlayerId, | 58 PepperPlayerDelegate::kPlayerId, |
51 MediaSession::Type::Content); | 59 MediaSession::Type::Content); |
52 } | 60 } |
53 | 61 |
54 void PepperPlaybackObserver::PepperStopsPlayback(int32_t pp_instance) { | 62 void PepperPlaybackObserver::PepperStopsPlayback(int32_t pp_instance) { |
55 if (!players_map_.count(pp_instance)) | 63 if (!players_map_.count(pp_instance)) |
56 return; | 64 return; |
57 | 65 |
58 MediaSession::Get(contents_)->RemovePlayer( | 66 MediaSession::Get(contents_)->RemovePlayer( |
59 players_map_[pp_instance].get(), PepperPlayerDelegate::kPlayerId); | 67 players_map_[pp_instance].get(), PepperPlayerDelegate::kPlayerId); |
60 | 68 |
61 players_map_.erase(pp_instance); | 69 players_map_.erase(pp_instance); |
62 } | 70 } |
63 | 71 |
64 } // namespace content | 72 } // namespace content |
OLD | NEW |