Chromium Code Reviews| 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..44f83bf9a5b2cd46abca2c835ea33907907f9a6b |
| --- /dev/null |
| +++ b/content/renderer/pepper/pepper_audio_controller.cc |
| @@ -0,0 +1,72 @@ |
| +// 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)) return; |
|
mlamouri (slow - plz ping)
2016/06/23 13:04:13
style: I think that's okay in Java but not in C++,
Zhiqiang Zhang (Slow)
2016/06/23 14:50:29
Done.
|
| + |
| + 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; |
|
mlamouri (slow - plz ping)
2016/06/23 13:04:13
ditto
Zhiqiang Zhang (Slow)
2016/06/23 14:50:29
Done.
|
| + |
| + ppb_audios_.erase(audio); |
| + |
| + if (ppb_audios_.empty()) |
| + NotifyPlaybackStopsOnEmpty(); |
| +} |
| + |
| +void PepperAudioController::SetVolume(double volume) { |
| + if (!instance_) return; |
|
mlamouri (slow - plz ping)
2016/06/23 13:04:13
ditto
Zhiqiang Zhang (Slow)
2016/06/23 14:50:29
Done.
|
| + |
| + 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 |