test_audio_input_controller_factory.cc revision 5821806d5e7f356e8fa4b058a389a808ea183019
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.
4
5#include "media/audio/test_audio_input_controller_factory.h"
6#include "media/audio/audio_io.h"
7
8namespace media {
9
10TestAudioInputController::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();
21}
22
23TestAudioInputController::~TestAudioInputController() {
24  // Inform the factory so that it allows creating new instances in future.
25  factory_->OnTestAudioInputControllerDestroyed(this);
26}
27
28void TestAudioInputController::Record() {
29  if (factory_->delegate_)
30    factory_->delegate_->TestAudioControllerOpened(this);
31}
32
33void TestAudioInputController::Close(const base::Closure& closed_task) {
34  message_loop_->PostTask(FROM_HERE, closed_task);
35  if (factory_->delegate_)
36    factory_->delegate_->TestAudioControllerClosed(this);
37}
38
39TestAudioInputControllerFactory::TestAudioInputControllerFactory()
40    : controller_(NULL),
41      delegate_(NULL) {
42}
43
44TestAudioInputControllerFactory::~TestAudioInputControllerFactory() {
45  DCHECK(!controller_);
46}
47
48AudioInputController* 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_;
56}
57
58void TestAudioInputControllerFactory::SetDelegateForTests(
59    TestAudioInputControllerDelegate* delegate) {
60  delegate_ = delegate;
61}
62
63void TestAudioInputControllerFactory::OnTestAudioInputControllerDestroyed(
64    TestAudioInputController* controller) {
65  DCHECK_EQ(controller_, controller);
66  controller_ = NULL;
67}
68
69}  // namespace media
70