summaryrefslogtreecommitdiffstats
path: root/content/browser/speech/speech_input_browsertest.cc
diff options
context:
space:
mode:
authortommi@chromium.org <tommi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-12 21:50:00 +0000
committertommi@chromium.org <tommi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-12 21:50:00 +0000
commit2e77cb39b4b2760c6aa15fb194355cc429f9cb8a (patch)
tree5e90a41a0c15409cee0fca52719187b2025a6dc9 /content/browser/speech/speech_input_browsertest.cc
parent25db386820026afcaf815b8e9290817146be111e (diff)
downloadchromium_src-2e77cb39b4b2760c6aa15fb194355cc429f9cb8a.zip
chromium_src-2e77cb39b4b2760c6aa15fb194355cc429f9cb8a.tar.gz
chromium_src-2e77cb39b4b2760c6aa15fb194355cc429f9cb8a.tar.bz2
Remove the AudioManager singleton.
Unit tests now instantiate their own AudioManager and can choose to use the default one or provide their own mock implementation without having to worry about conflicting with the singleton. The teardown sequence of the AudioManager and its thread has been cleaned up significantly and I don't think it has been completely tested before as the audio thread was terminated before all objects that belonged to the thread had a chance to do cleanup. The AudioManager unit tests do not use the actual audio thread, so this part seems to have been left out. In Chrome, the AudioManager instance is now owned by BrowserProcessImpl and always constructed on the UI thread. This instance is then shared in the same way that several other 'manager' type objects are shared to 'content' code, via content::ResourceContext. Audio specific classes do though receive a direct pointer to the AudioManager and are required to do proper reference counting if they need to hold onto the instance. I chose to use the ResourceContext rather than direct use of g_browser_process to avoid requiring another singleton when writing relatively simple tests that touch the AudioManager. I added a couple of safeguards to guard against future regressions: - Not more than one instance of the AudioManager should be created. - The AudioManager should not be addrefed by its own thread. This can basically become a circular reference and prevent deterministic shutdown. Reviewers: Of course you're free to review everything, but here's the breakdown in terms of the bare minimum from the standpoint of "Owners approval". I'm asking Henrik to be the main reviewer of the entire patch (sorry!). Henrik: Everything minus the below, but it would be great if you could take a look at the whole thing, specifically media/audio. Pawel: I'd like you to take a generic look at this approach. The key areas as far as the singleton itself goes are in media/audio/audio_manager[_base].* and chrome/browser/browser_process*.* Satish: content/browser/speech/* media/audio/audio_manager_base.* (new reference counting code) Andrew: content/browser/renderer_host/media/* content/renderer/media/webrtc_audio_device_unittest.cc (Owner) Avi: content/browser/renderer_host/render_process_host_impl.cc content/browser/resource_context.* William: chrome/browser/profiles/profile_io_data.cc chrome/browser/browser_process*.* Robert: This is basically a heads up. I hope that I didn't break the OpenBSD implementation, but unfortunately I have no way of knowing for sure. Shijing: Please take a look at AudioManagerLinux. I replaced the set of active streams with a simple counter. BUG=105249 TEST=content_unittests, media_unittests, browser_tests. Review URL: http://codereview.chromium.org/8818012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@114084 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/speech/speech_input_browsertest.cc')
-rw-r--r--content/browser/speech/speech_input_browsertest.cc51
1 files changed, 23 insertions, 28 deletions
diff --git a/content/browser/speech/speech_input_browsertest.cc b/content/browser/speech/speech_input_browsertest.cc
index 7dd1f9f..f0c6321 100644
--- a/content/browser/speech/speech_input_browsertest.cc
+++ b/content/browser/speech/speech_input_browsertest.cc
@@ -49,16 +49,13 @@ class FakeSpeechInputManager : public SpeechInputManager {
}
// SpeechInputManager methods.
- virtual void StartRecognition(Delegate* delegate,
- int caller_id,
- int render_process_id,
- int render_view_id,
- const gfx::Rect& element_rect,
- const std::string& language,
- const std::string& grammar,
- const std::string& origin_url,
- net::URLRequestContextGetter* context_getter,
- SpeechInputPreferences* speech_input_prefs) {
+ virtual void StartRecognition(Delegate* delegate, int caller_id,
+ int render_process_id, int render_view_id, const gfx::Rect& element_rect,
+ const std::string& language, const std::string& grammar,
+ const std::string& origin_url,
+ net::URLRequestContextGetter* context_getter,
+ SpeechInputPreferences* speech_input_prefs,
+ AudioManager* audio_manager) OVERRIDE {
VLOG(1) << "StartRecognition invoked.";
EXPECT_EQ(0, caller_id_);
EXPECT_EQ(NULL, delegate_);
@@ -77,18 +74,18 @@ class FakeSpeechInputManager : public SpeechInputManager {
base::Unretained(this)));
}
}
- virtual void CancelRecognition(int caller_id) {
+ virtual void CancelRecognition(int caller_id) OVERRIDE {
VLOG(1) << "CancelRecognition invoked.";
EXPECT_EQ(caller_id_, caller_id);
caller_id_ = 0;
delegate_ = NULL;
}
- virtual void StopRecording(int caller_id) {
+ virtual void StopRecording(int caller_id) OVERRIDE {
VLOG(1) << "StopRecording invoked.";
EXPECT_EQ(caller_id_, caller_id);
// Nothing to do here since we aren't really recording.
}
- virtual void CancelAllRequestsWithDelegate(Delegate* delegate) {
+ virtual void CancelAllRequestsWithDelegate(Delegate* delegate) OVERRIDE {
VLOG(1) << "CancelAllRequestsWithDelegate invoked.";
// delegate_ is set to NULL if a fake result was received (see below), so
// check that delegate_ matches the incoming parameter only when there is
@@ -98,23 +95,21 @@ class FakeSpeechInputManager : public SpeechInputManager {
}
protected:
- virtual void GetRequestInfo(bool* can_report_metrics,
- std::string* request_info) {}
- virtual void ShowRecognitionRequested(int caller_id,
- int render_process_id,
- int render_view_id,
- const gfx::Rect& element_rect) {}
- virtual void ShowWarmUp(int caller_id) {}
- virtual void ShowRecognizing(int caller_id) {}
- virtual void ShowRecording(int caller_id) {}
- virtual void ShowInputVolume(int caller_id,
- float volume,
- float noise_volume) {}
+ virtual void GetRequestInfo(AudioManager* audio_manager,
+ bool* can_report_metrics,
+ std::string* request_info) OVERRIDE {}
+ virtual void ShowRecognitionRequested(int caller_id, int render_process_id,
+ int render_view_id, const gfx::Rect& element_rect) OVERRIDE {}
+ virtual void ShowWarmUp(int caller_id) OVERRIDE {}
+ virtual void ShowRecognizing(int caller_id) OVERRIDE {}
+ virtual void ShowRecording(int caller_id) OVERRIDE {}
+ virtual void ShowInputVolume(int caller_id, float volume,
+ float noise_volume) OVERRIDE {}
virtual void ShowMicError(int caller_id,
- SpeechInputManager::MicError error) {}
+ SpeechInputManager::MicError error) OVERRIDE {}
virtual void ShowRecognizerError(int caller_id,
- content::SpeechInputError error) {}
- virtual void DoClose(int caller_id) {}
+ content::SpeechInputError error) OVERRIDE {}
+ virtual void DoClose(int caller_id) OVERRIDE {}
private:
void SetFakeRecognitionResult() {