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

Unified 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 Jochen's comments Created 4 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/media/session/pepper_playback_observer.cc
diff --git a/content/browser/media/session/pepper_playback_observer.cc b/content/browser/media/session/pepper_playback_observer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..994416056ac5f923f57231109ee624498c9ff3fe
--- /dev/null
+++ b/content/browser/media/session/pepper_playback_observer.cc
@@ -0,0 +1,60 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/browser/media/session/pepper_playback_observer.h"
+
+#include "base/feature_list.h"
+#include "content/browser/media/session/media_session.h"
+#include "content/browser/media/session/pepper_player_delegate.h"
+#include "content/common/frame_messages.h"
+#include "ipc/ipc_message_macros.h"
+#include "media/base/media_switches.h"
+
+namespace content {
+
+PepperPlaybackObserver::PepperPlaybackObserver(WebContents *contents)
+ : contents_(contents) {}
+
+PepperPlaybackObserver::~PepperPlaybackObserver() {
+ // At this point WebContents is being destructed, so it's safe to
+ // call this. MediaSession may decide to send further IPC messages
+ // through PepperPlayerDelegates, which might be declined if the
+ // RenderViewHost has been destroyed.
+ for (PlayersMap::iterator iter(&players_map_);
+ !iter.IsAtEnd(); iter.Advance())
+ PepperStopsPlayback(iter.GetCurrentKey());
mlamouri (slow - plz ping) 2016/06/30 11:01:18 style: can you wrap this into { }
Zhiqiang Zhang (Slow) 2016/06/30 12:46:54 Done.
+ contents_ = nullptr;
+}
+
+void PepperPlaybackObserver::PepperInstanceCreated(int32_t pp_instance) {
+}
+
+void PepperPlaybackObserver::PepperInstanceDeleted(int32_t pp_instance) {
+ PepperStopsPlayback(pp_instance);
+}
+
+void PepperPlaybackObserver::PepperStartsPlayback(int32_t pp_instance) {
+ if (!base::FeatureList::IsEnabled(media::kFlashJoinsMediaSession))
+ return;
+
+ if (players_map_.Lookup(pp_instance))
+ return;
+
+ players_map_.AddWithID(new PepperPlayerDelegate(
dcheng 2016/06/30 07:02:39 Would an ordinary std::map work here? It doesn't s
Zhiqiang Zhang (Slow) 2016/06/30 12:46:54 Actually it was suggested by jochen. IDMap allows
dcheng 2016/07/01 05:57:59 I just don't see much of a point to using IDMap he
Zhiqiang Zhang (Slow) 2016/07/01 11:01:06 OK, I agree with you. changed to std::map. But one
+ static_cast<WebContentsImpl*>(contents_), pp_instance), pp_instance);
+ MediaSession::Get(contents_)->AddPlayer(
+ players_map_.Lookup(pp_instance), 0, MediaSession::Type::Content);
dcheng 2016/06/30 07:02:39 Perhaps make 0 a constant so it's clear this is th
Zhiqiang Zhang (Slow) 2016/06/30 12:46:54 Done.
+}
+
+void PepperPlaybackObserver::PepperStopsPlayback(int32_t pp_instance) {
+ if (!players_map_.Lookup(pp_instance))
+ return;
+
+ MediaSession::Get(contents_)->RemovePlayer(
+ players_map_.Lookup(pp_instance), 0);
+
+ players_map_.Remove(pp_instance);
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698