| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2015 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/browser/media/audio_debug_controller.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/logging.h" |
| 9 #include "base/memory/singleton.h" |
| 10 #include "base/stl_util.h" |
| 11 #include "content/browser/media/audio_debug_recording_impl.h" |
| 12 |
| 13 namespace content { |
| 14 |
| 15 // static |
| 16 AudioDebugController* AudioDebugController::GetInstance() { |
| 17 return base::Singleton<AudioDebugController>::get(); |
| 18 } |
| 19 |
| 20 // static |
| 21 void AudioDebugController::CreateService( |
| 22 int render_host_id, |
| 23 const scoped_refptr<AudioInputRendererHost>& audio_input_renderer_host, |
| 24 mojo::InterfaceRequest<AudioDebugRecording> request) { |
| 25 GetInstance()->CreateServiceInternal( |
| 26 render_host_id, audio_input_renderer_host, request.Pass()); |
| 27 } |
| 28 |
| 29 AudioDebugController::AudioDebugController() {} |
| 30 |
| 31 AudioDebugController::~AudioDebugController() { |
| 32 STLDeleteContainerPointers(registered_impls_.begin(), |
| 33 registered_impls_.end()); |
| 34 } |
| 35 |
| 36 void AudioDebugController::EnableAudioDebugRecording( |
| 37 const base::FilePath& file) { |
| 38 for (auto impl : registered_impls_) |
| 39 impl->EnableAudioDebugRecording(file); |
| 40 } |
| 41 |
| 42 void AudioDebugController::DisableAudioDebugRecording() { |
| 43 for (auto impl : registered_impls_) |
| 44 impl->DisableAudioDebugRecording(); |
| 45 } |
| 46 |
| 47 void AudioDebugController::CreateServiceInternal( |
| 48 int render_host_id, |
| 49 const scoped_refptr<AudioInputRendererHost>& audio_input_renderer_host, |
| 50 mojo::InterfaceRequest<AudioDebugRecording> request) { |
| 51 AudioDebugRecordingImpl* impl = new AudioDebugRecordingImpl( |
| 52 render_host_id, audio_input_renderer_host, |
| 53 base::Bind(&AudioDebugController::OnDisconnect, base::Unretained(this)), |
| 54 request.Pass()); |
| 55 bool inserted = registered_impls_.insert(impl).second; |
| 56 DCHECK(inserted); |
| 57 } |
| 58 |
| 59 void AudioDebugController::OnDisconnect(AudioDebugRecordingImpl* impl) { |
| 60 size_t num_removed = registered_impls_.erase(impl); |
| 61 DCHECK_EQ(num_removed, 1U); |
| 62 delete impl; |
| 63 } |
| 64 |
| 65 } // namespace content |
| OLD | NEW |