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

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

Issue 2060933002: Let Flash join and be controlled by media session (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@pepper_to_contents
Patch Set: addressed dcheng and mlamouri's comments Created 4 years, 5 months 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
(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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698