| Index: content/browser/media/audio_debug_controller.cc
|
| diff --git a/content/browser/media/audio_debug_controller.cc b/content/browser/media/audio_debug_controller.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..a2bbf427b5edde794e5c7ee136adc572f884ad51
|
| --- /dev/null
|
| +++ b/content/browser/media/audio_debug_controller.cc
|
| @@ -0,0 +1,90 @@
|
| +// Copyright 2015 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/browser/media/audio_debug_controller.h"
|
| +
|
| +#include <utility>
|
| +
|
| +#include "base/bind.h"
|
| +#include "base/logging.h"
|
| +#include "base/memory/singleton.h"
|
| +#include "base/stl_util.h"
|
| +#include "content/browser/media/audio_debug_recording_impl.h"
|
| +
|
| +namespace content {
|
| +
|
| +// static
|
| +AudioDebugController* AudioDebugController::GetInstance() {
|
| + return base::Singleton<AudioDebugController>::get();
|
| +}
|
| +
|
| +// static
|
| +void AudioDebugController::CreateService(
|
| + int render_host_id,
|
| + const scoped_refptr<AudioInputRendererHost>& audio_input_renderer_host,
|
| + mojo::InterfaceRequest<AudioDebugRecording> request) {
|
| + GetInstance()->CreateServiceInternal(
|
| + render_host_id, audio_input_renderer_host, std::move(request));
|
| +}
|
| +
|
| +AudioDebugController::AudioDebugController() {}
|
| +
|
| +AudioDebugController::~AudioDebugController() {
|
| + DCHECK(thread_checker_.CalledOnValidThread());
|
| + STLDeleteContainerPointers(registered_impls_.begin(),
|
| + registered_impls_.end());
|
| +}
|
| +
|
| +void AudioDebugController::EnableAudioDebugRecording(
|
| + const base::FilePath& file) {
|
| + DCHECK(thread_checker_.CalledOnValidThread());
|
| + for (auto impl : registered_impls_)
|
| + impl->EnableAudioDebugRecording(file);
|
| +}
|
| +
|
| +void AudioDebugController::DisableAudioDebugRecording() {
|
| + DCHECK(thread_checker_.CalledOnValidThread());
|
| + for (auto impl : registered_impls_)
|
| + impl->DisableAudioDebugRecording();
|
| +}
|
| +
|
| +void AudioDebugController::EnableAudioDebugRecordingForHost(
|
| + int render_host_id, const base::FilePath& file) {
|
| + DCHECK(thread_checker_.CalledOnValidThread());
|
| + for (auto impl : registered_impls_) {
|
| + if (impl->render_host_id() == render_host_id)
|
| + impl->EnableAudioDebugRecording(file);
|
| + }
|
| +}
|
| +
|
| +void AudioDebugController::DisableAudioDebugRecordingForHost(
|
| + int render_host_id) {
|
| + DCHECK(thread_checker_.CalledOnValidThread());
|
| + for (auto impl : registered_impls_) {
|
| + if (impl->render_host_id() == render_host_id)
|
| + impl->DisableAudioDebugRecording();
|
| + }
|
| +}
|
| +
|
| +void AudioDebugController::CreateServiceInternal(
|
| + int render_host_id,
|
| + const scoped_refptr<AudioInputRendererHost>& audio_input_renderer_host,
|
| + mojo::InterfaceRequest<AudioDebugRecording> request) {
|
| + DCHECK(thread_checker_.CalledOnValidThread());
|
| + AudioDebugRecordingImpl* impl = new AudioDebugRecordingImpl(
|
| + render_host_id, audio_input_renderer_host,
|
| + base::Bind(&AudioDebugController::OnDisconnect, base::Unretained(this)),
|
| + std::move(request));
|
| + bool inserted = registered_impls_.insert(impl).second;
|
| + DCHECK(inserted);
|
| +}
|
| +
|
| +void AudioDebugController::OnDisconnect(AudioDebugRecordingImpl* impl) {
|
| + DCHECK(thread_checker_.CalledOnValidThread());
|
| + size_t num_removed = registered_impls_.erase(impl);
|
| + DCHECK_EQ(num_removed, 1U);
|
| + delete impl;
|
| +}
|
| +
|
| +} // namespace content
|
|
|