cc: Added inline to Tile::IsReadyToDraw
[chromium-blink-merge.git] / media / audio / test_audio_input_controller_factory.h
blob4968c013d977e9c0480c572a49f15ad399de06af
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 #ifndef MEDIA_AUDIO_TEST_AUDIO_INPUT_CONTROLLER_FACTORY_H_
6 #define MEDIA_AUDIO_TEST_AUDIO_INPUT_CONTROLLER_FACTORY_H_
8 #include "base/bind.h"
9 #include "media/audio/audio_input_controller.h"
11 namespace media {
13 class UserInputMonitor;
14 class TestAudioInputControllerFactory;
16 // TestAudioInputController and TestAudioInputControllerFactory are used for
17 // testing consumers of AudioInputController. TestAudioInputControllerFactory
18 // is a AudioInputController::Factory that creates TestAudioInputControllers.
20 // TestAudioInputController::Record and Close are overriden to do nothing. It is
21 // expected that you'll grab the EventHandler from the TestAudioInputController
22 // and invoke the callback methods when appropriate. In this way it's easy to
23 // mock a AudioInputController.
25 // Typical usage:
26 // // Create and register factory.
27 // TestAudioInputControllerFactory factory;
28 // AudioInputController::set_factory_for_testing(&factory);
30 // // Do something that triggers creation of an AudioInputController.
31 // TestAudioInputController* controller = factory.last_controller();
32 // DCHECK(controller);
34 // // Notify event handler with whatever data you want.
35 // controller->event_handler()->OnCreated(...);
37 // // Do something that triggers AudioInputController::Record to be called.
38 // controller->event_handler()->OnData(...);
39 // controller->event_handler()->OnError(...);
41 // // Make sure consumer of AudioInputController does the right thing.
42 // ...
43 // // Reset factory.
44 // AudioInputController::set_factory_for_testing(NULL);
46 class TestAudioInputController : public AudioInputController {
47 public:
48 class Delegate {
49 public:
50 virtual void TestAudioControllerOpened(
51 TestAudioInputController* controller) = 0;
52 virtual void TestAudioControllerClosed(
53 TestAudioInputController* controller) = 0;
56 TestAudioInputController(TestAudioInputControllerFactory* factory,
57 AudioManager* audio_manager,
58 const AudioParameters& audio_parameters,
59 EventHandler* event_handler,
60 SyncWriter* sync_writer,
61 UserInputMonitor* user_input_monitor);
63 // Returns the event handler installed on the AudioInputController.
64 EventHandler* event_handler() const { return event_handler_; }
66 // Notifies the TestAudioControllerOpened() event to the delegate (if any).
67 virtual void Record() OVERRIDE;
69 // Ensure that the closure is run on the audio-manager thread.
70 virtual void Close(const base::Closure& closed_task) OVERRIDE;
72 protected:
73 virtual ~TestAudioInputController();
75 private:
76 AudioParameters audio_parameters_;
78 // These are not owned by us and expected to be valid for this object's
79 // lifetime.
80 TestAudioInputControllerFactory* factory_;
81 EventHandler* event_handler_;
83 DISALLOW_COPY_AND_ASSIGN(TestAudioInputController);
86 typedef TestAudioInputController::Delegate TestAudioInputControllerDelegate;
88 // Simple AudioInputController::Factory method that creates
89 // TestAudioInputControllers.
90 class TestAudioInputControllerFactory : public AudioInputController::Factory {
91 public:
92 TestAudioInputControllerFactory();
93 virtual ~TestAudioInputControllerFactory();
95 // AudioInputController::Factory methods.
96 virtual AudioInputController* Create(
97 AudioManager* audio_manager,
98 AudioInputController::EventHandler* event_handler,
99 AudioParameters params,
100 UserInputMonitor* user_input_monitor) OVERRIDE;
102 void SetDelegateForTests(TestAudioInputControllerDelegate* delegate);
104 TestAudioInputController* controller() const { return controller_; }
106 private:
107 friend class TestAudioInputController;
109 // Invoked by a TestAudioInputController when it gets destroyed.
110 void OnTestAudioInputControllerDestroyed(
111 TestAudioInputController* controller);
113 // The caller of Create owns this object.
114 TestAudioInputController* controller_;
116 // The delegate for tests for receiving audio controller events.
117 TestAudioInputControllerDelegate* delegate_;
119 DISALLOW_COPY_AND_ASSIGN(TestAudioInputControllerFactory);
122 } // namespace media
124 #endif // MEDIA_AUDIO_TEST_AUDIO_INPUT_CONTROLLER_FACTORY_H_