Separate Simple Backend creation from initialization.
[chromium-blink-merge.git] / media / audio / test_audio_input_controller_factory.cc
blob64bfb9f060d6f00daca07a29e38cc0e7a1a6aae3
1 // Copyright (c) 2012 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.
5 #include "media/audio/test_audio_input_controller_factory.h"
6 #include "media/audio/audio_io.h"
8 namespace media {
10 TestAudioInputController::TestAudioInputController(
11 TestAudioInputControllerFactory* factory,
12 AudioManager* audio_manager,
13 const AudioParameters& audio_parameters,
14 EventHandler* event_handler,
15 SyncWriter* sync_writer)
16 : AudioInputController(event_handler, sync_writer),
17 audio_parameters_(audio_parameters),
18 factory_(factory),
19 event_handler_(event_handler) {
20 message_loop_ = audio_manager->GetMessageLoop();
23 TestAudioInputController::~TestAudioInputController() {
24 // Inform the factory so that it allows creating new instances in future.
25 factory_->OnTestAudioInputControllerDestroyed(this);
28 void TestAudioInputController::Record() {
29 if (factory_->delegate_)
30 factory_->delegate_->TestAudioControllerOpened(this);
33 void TestAudioInputController::Close(const base::Closure& closed_task) {
34 message_loop_->PostTask(FROM_HERE, closed_task);
35 if (factory_->delegate_)
36 factory_->delegate_->TestAudioControllerClosed(this);
39 TestAudioInputControllerFactory::TestAudioInputControllerFactory()
40 : controller_(NULL),
41 delegate_(NULL) {
44 TestAudioInputControllerFactory::~TestAudioInputControllerFactory() {
45 DCHECK(!controller_);
48 AudioInputController* TestAudioInputControllerFactory::Create(
49 AudioManager* audio_manager,
50 AudioInputController::EventHandler* event_handler,
51 AudioParameters params) {
52 DCHECK(!controller_); // Only one test instance managed at a time.
53 controller_ = new TestAudioInputController(this, audio_manager, params,
54 event_handler, NULL);
55 return controller_;
58 void TestAudioInputControllerFactory::SetDelegateForTests(
59 TestAudioInputControllerDelegate* delegate) {
60 delegate_ = delegate;
63 void TestAudioInputControllerFactory::OnTestAudioInputControllerDestroyed(
64 TestAudioInputController* controller) {
65 DCHECK_EQ(controller_, controller);
66 controller_ = NULL;
69 } // namespace media