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 | |
mlamouri (slow - plz ping)
2016/07/06 14:17:05
style: remove empty line.
| |
39 UMA_HISTOGRAM_BOOLEAN("Media.Pepper.PlayedSound", | |
40 players_played_sound_map_[pp_instance]); | |
41 players_played_sound_map_.erase(pp_instance); | |
42 | |
36 PepperStopsPlayback(pp_instance); | 43 PepperStopsPlayback(pp_instance); |
37 } | 44 } |
38 | 45 |
39 void PepperPlaybackObserver::PepperStartsPlayback(int32_t pp_instance) { | 46 void PepperPlaybackObserver::PepperStartsPlayback(int32_t pp_instance) { |
47 players_played_sound_map_[pp_instance] = true; | |
48 | |
40 if (!base::FeatureList::IsEnabled(media::kFlashJoinsMediaSession)) | 49 if (!base::FeatureList::IsEnabled(media::kFlashJoinsMediaSession)) |
41 return; | 50 return; |
42 | 51 |
43 if (players_map_.count(pp_instance)) | 52 if (players_map_.count(pp_instance)) |
44 return; | 53 return; |
45 | 54 |
46 players_map_[pp_instance].reset(new PepperPlayerDelegate( | 55 players_map_[pp_instance].reset(new PepperPlayerDelegate( |
47 contents_, pp_instance)); | 56 contents_, pp_instance)); |
48 MediaSession::Get(contents_)->AddPlayer( | 57 MediaSession::Get(contents_)->AddPlayer( |
49 players_map_[pp_instance].get(), | 58 players_map_[pp_instance].get(), |
50 PepperPlayerDelegate::kPlayerId, | 59 PepperPlayerDelegate::kPlayerId, |
51 MediaSession::Type::Content); | 60 MediaSession::Type::Content); |
52 } | 61 } |
53 | 62 |
54 void PepperPlaybackObserver::PepperStopsPlayback(int32_t pp_instance) { | 63 void PepperPlaybackObserver::PepperStopsPlayback(int32_t pp_instance) { |
55 if (!players_map_.count(pp_instance)) | 64 if (!players_map_.count(pp_instance)) |
56 return; | 65 return; |
57 | 66 |
58 MediaSession::Get(contents_)->RemovePlayer( | 67 MediaSession::Get(contents_)->RemovePlayer( |
59 players_map_[pp_instance].get(), PepperPlayerDelegate::kPlayerId); | 68 players_map_[pp_instance].get(), PepperPlayerDelegate::kPlayerId); |
60 | 69 |
61 players_map_.erase(pp_instance); | 70 players_map_.erase(pp_instance); |
62 } | 71 } |
63 | 72 |
64 } // namespace content | 73 } // namespace content |
OLD | NEW |