| 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_) |
| 26 return; |
| 27 if (ppb_audios_.count(audio)) |
| 28 return; |
| 29 |
| 30 if (ppb_audios_.empty()) { |
| 31 RenderFrameImpl* render_frame = instance_->render_frame(); |
| 32 if (render_frame) |
| 33 render_frame->PepperStartsPlayback(instance_); |
| 34 } |
| 35 |
| 36 ppb_audios_.insert(audio); |
| 37 } |
| 38 |
| 39 void PepperAudioController::RemoveInstance(PPB_Audio_Impl* audio) { |
| 40 if (!instance_) |
| 41 return; |
| 42 if (!ppb_audios_.count(audio)) |
| 43 return; |
| 44 |
| 45 ppb_audios_.erase(audio); |
| 46 |
| 47 if (ppb_audios_.empty()) |
| 48 NotifyPlaybackStopsOnEmpty(); |
| 49 } |
| 50 |
| 51 void PepperAudioController::SetVolume(double volume) { |
| 52 if (!instance_) |
| 53 return; |
| 54 |
| 55 for (auto* ppb_audio : ppb_audios_) |
| 56 ppb_audio->SetVolume(volume); |
| 57 } |
| 58 |
| 59 void PepperAudioController::OnPepperInstanceDeleted() { |
| 60 DCHECK(instance_); |
| 61 |
| 62 if (!ppb_audios_.empty()) |
| 63 NotifyPlaybackStopsOnEmpty(); |
| 64 |
| 65 ppb_audios_.clear(); |
| 66 instance_ = nullptr; |
| 67 } |
| 68 |
| 69 void PepperAudioController::NotifyPlaybackStopsOnEmpty() { |
| 70 DCHECK(instance_); |
| 71 |
| 72 RenderFrameImpl* render_frame = instance_->render_frame(); |
| 73 if (render_frame) |
| 74 render_frame->PepperStopsPlayback(instance_); |
| 75 } |
| 76 |
| 77 } // namespace content |
| OLD | NEW |