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

Unified Diff: content/renderer/pepper/pepper_audio_controller.cc

Issue 2065513004: Expose flash playback status and volume control to content renderer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@audio_focus_manager
Patch Set: addressing nits 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/renderer/pepper/pepper_audio_controller.cc
diff --git a/content/renderer/pepper/pepper_audio_controller.cc b/content/renderer/pepper/pepper_audio_controller.cc
new file mode 100644
index 0000000000000000000000000000000000000000..88d80f11bd02c441888e1403291875582f4b4e00
--- /dev/null
+++ b/content/renderer/pepper/pepper_audio_controller.cc
@@ -0,0 +1,77 @@
+// 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/renderer/pepper/pepper_audio_controller.h"
+
+#include "content/renderer/pepper/pepper_plugin_instance_impl.h"
+#include "content/renderer/pepper/ppb_audio_impl.h"
+#include "content/renderer/render_frame_impl.h"
+
+namespace content {
+
+PepperAudioController::PepperAudioController(
+ PepperPluginInstanceImpl* instance)
+ : instance_(instance) {
+ DCHECK(instance_);
+}
+
+PepperAudioController::~PepperAudioController() {
+ if (instance_)
+ OnPepperInstanceDeleted();
+}
+
+void PepperAudioController::AddInstance(PPB_Audio_Impl* audio) {
+ if (!instance_)
+ return;
+ if (ppb_audios_.count(audio))
dcheng 2016/06/23 19:35:36 Why do we have to verify this here and below? Why
+ return;
+
+ if (ppb_audios_.empty()) {
+ RenderFrameImpl* render_frame = instance_->render_frame();
+ if (render_frame)
+ render_frame->PepperStartsPlayback(instance_);
+ }
+
+ ppb_audios_.insert(audio);
+}
+
+void PepperAudioController::RemoveInstance(PPB_Audio_Impl* audio) {
+ if (!instance_)
+ return;
+ if (!ppb_audios_.count(audio))
+ return;
+
+ ppb_audios_.erase(audio);
+
+ if (ppb_audios_.empty())
+ NotifyPlaybackStopsOnEmpty();
+}
+
+void PepperAudioController::SetVolume(double volume) {
+ if (!instance_)
+ return;
+
+ for (auto* ppb_audio : ppb_audios_)
+ ppb_audio->SetVolume(volume);
+}
+
+void PepperAudioController::OnPepperInstanceDeleted() {
+ DCHECK(instance_);
+
+ if (!ppb_audios_.empty())
+ NotifyPlaybackStopsOnEmpty();
+
+ ppb_audios_.clear();
+ instance_ = nullptr;
+}
+
+void PepperAudioController::NotifyPlaybackStopsOnEmpty() {
+ DCHECK(instance_);
+
+ RenderFrameImpl* render_frame = instance_->render_frame();
+ if (render_frame)
+ render_frame->PepperStopsPlayback(instance_);
+}
+
+} // namespace content
« no previous file with comments | « content/renderer/pepper/pepper_audio_controller.h ('k') | content/renderer/pepper/pepper_platform_audio_output.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698