Chromium Code Reviews| OLD | NEW |
|---|---|
| (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/renderer/pepper/pepper_audio_controller.h" | |
| 6 | |
| 7 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" | |
| 8 #include "content/renderer/pepper/ppb_audio_impl.h" | |
| 9 #include "content/renderer/render_frame_impl.h" | |
| 10 | |
| 11 namespace content { | |
| 12 | |
| 13 PepperAudioController::PepperAudioController( | |
| 14 PepperPluginInstanceImpl* instance) | |
| 15 : instance_(instance) { | |
| 16 DCHECK(instance_); | |
| 17 } | |
| 18 | |
| 19 PepperAudioController::~PepperAudioController() { | |
| 20 if (instance_) | |
| 21 OnPepperInstanceDeleted(); | |
| 22 } | |
| 23 | |
| 24 void PepperAudioController::AddInstance(PPB_Audio_Impl* audio) { | |
| 25 if (!instance_) return; | |
| 26 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.
| |
| 27 | |
| 28 if (ppb_audios_.empty()) { | |
| 29 RenderFrameImpl* render_frame = instance_->render_frame(); | |
| 30 if (render_frame) | |
| 31 render_frame->PepperStartsPlayback(instance_); | |
| 32 } | |
| 33 | |
| 34 ppb_audios_.insert(audio); | |
| 35 } | |
| 36 | |
| 37 void PepperAudioController::RemoveInstance(PPB_Audio_Impl* audio) { | |
| 38 if (!instance_) return; | |
| 39 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.
| |
| 40 | |
| 41 ppb_audios_.erase(audio); | |
| 42 | |
| 43 if (ppb_audios_.empty()) | |
| 44 NotifyPlaybackStopsOnEmpty(); | |
| 45 } | |
| 46 | |
| 47 void PepperAudioController::SetVolume(double volume) { | |
| 48 if (!instance_) return; | |
|
mlamouri (slow - plz ping)
2016/06/23 13:04:13
ditto
Zhiqiang Zhang (Slow)
2016/06/23 14:50:29
Done.
| |
| 49 | |
| 50 for (auto* ppb_audio : ppb_audios_) | |
| 51 ppb_audio->SetVolume(volume); | |
| 52 } | |
| 53 | |
| 54 void PepperAudioController::OnPepperInstanceDeleted() { | |
| 55 DCHECK(instance_); | |
| 56 | |
| 57 if (!ppb_audios_.empty()) | |
| 58 NotifyPlaybackStopsOnEmpty(); | |
| 59 | |
| 60 ppb_audios_.clear(); | |
| 61 instance_ = nullptr; | |
| 62 } | |
| 63 | |
| 64 void PepperAudioController::NotifyPlaybackStopsOnEmpty() { | |
| 65 DCHECK(instance_); | |
| 66 | |
| 67 RenderFrameImpl* render_frame = instance_->render_frame(); | |
| 68 if (render_frame) | |
| 69 render_frame->PepperStopsPlayback(instance_); | |
| 70 } | |
| 71 | |
| 72 } // namespace content | |
| OLD | NEW |