- add sources.
[platform/framework/web/crosswalk.git] / src / media / audio / test_audio_input_controller_factory.cc
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
8 namespace media {
9
10 TestAudioInputController::TestAudioInputController(
11     TestAudioInputControllerFactory* factory,
12     AudioManager* audio_manager,
13     const AudioParameters& audio_parameters,
14     EventHandler* event_handler,
15     SyncWriter* sync_writer,
16     UserInputMonitor* user_input_monitor)
17     : AudioInputController(event_handler, sync_writer, user_input_monitor),
18       audio_parameters_(audio_parameters),
19       factory_(factory),
20       event_handler_(event_handler) {
21   message_loop_ = audio_manager->GetMessageLoop();
22 }
23
24 TestAudioInputController::~TestAudioInputController() {
25   // Inform the factory so that it allows creating new instances in future.
26   factory_->OnTestAudioInputControllerDestroyed(this);
27 }
28
29 void TestAudioInputController::Record() {
30   if (factory_->delegate_)
31     factory_->delegate_->TestAudioControllerOpened(this);
32 }
33
34 void TestAudioInputController::Close(const base::Closure& closed_task) {
35   message_loop_->PostTask(FROM_HERE, closed_task);
36   if (factory_->delegate_)
37     factory_->delegate_->TestAudioControllerClosed(this);
38 }
39
40 TestAudioInputControllerFactory::TestAudioInputControllerFactory()
41     : controller_(NULL),
42       delegate_(NULL) {
43 }
44
45 TestAudioInputControllerFactory::~TestAudioInputControllerFactory() {
46   DCHECK(!controller_);
47 }
48
49 AudioInputController* TestAudioInputControllerFactory::Create(
50     AudioManager* audio_manager,
51     AudioInputController::EventHandler* event_handler,
52     AudioParameters params,
53     UserInputMonitor* user_input_monitor) {
54   DCHECK(!controller_);  // Only one test instance managed at a time.
55   controller_ = new TestAudioInputController(
56       this, audio_manager, params, event_handler, NULL, user_input_monitor);
57   return controller_;
58 }
59
60 void TestAudioInputControllerFactory::OnTestAudioInputControllerDestroyed(
61     TestAudioInputController* controller) {
62   DCHECK_EQ(controller_, controller);
63   controller_ = NULL;
64 }
65
66 }  // namespace media