diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-21 17:12:36 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-21 17:12:36 +0000 |
commit | aa44546e0270e7cff9d934d9d5dc236df2030e99 (patch) | |
tree | 0426863811e17a9385c6b43edf6a84bf76290678 /content/browser/speech | |
parent | 9a61fe162777f3e586d59a06165aee869466cb1b (diff) | |
download | chromium_src-aa44546e0270e7cff9d934d9d5dc236df2030e99.zip chromium_src-aa44546e0270e7cff9d934d9d5dc236df2030e99.tar.gz chromium_src-aa44546e0270e7cff9d934d9d5dc236df2030e99.tar.bz2 |
Minor cleanup to remove the static thread-safe methods on BrowserMainLoop. Initially I thought this would be one getter so it seemed fine, but now it has 3 and more are on the way. Switch to one static getter for this class, and then getters for the member variables. I used dependency injection to allow access to these objects from other threads, which also cleaned up tests a bit.
R=scherkus@chromium.org
Review URL: https://codereview.chromium.org/17508005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@207871 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/speech')
-rw-r--r-- | content/browser/speech/speech_recognition_manager_impl.cc | 36 | ||||
-rw-r--r-- | content/browser/speech/speech_recognition_manager_impl.h | 10 |
2 files changed, 29 insertions, 17 deletions
diff --git a/content/browser/speech/speech_recognition_manager_impl.cc b/content/browser/speech/speech_recognition_manager_impl.cc index 82aa13a..19dff5c 100644 --- a/content/browser/speech/speech_recognition_manager_impl.cc +++ b/content/browser/speech/speech_recognition_manager_impl.cc @@ -37,9 +37,9 @@ namespace { SpeechRecognitionManagerImpl* g_speech_recognition_manager_impl; -void ShowAudioInputSettingsOnFileThread() { +void ShowAudioInputSettingsOnFileThread(media::AudioManager* audio_manager) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); - BrowserMainLoop::GetAudioManager()->ShowAudioInputSettings(); + audio_manager->ShowAudioInputSettings(); } } // namespace @@ -59,8 +59,12 @@ SpeechRecognitionManagerImpl* SpeechRecognitionManagerImpl::GetInstance() { return g_speech_recognition_manager_impl; } -SpeechRecognitionManagerImpl::SpeechRecognitionManagerImpl() - : primary_session_id_(kSessionIDInvalid), +SpeechRecognitionManagerImpl::SpeechRecognitionManagerImpl( + media::AudioManager* audio_manager, + MediaStreamManager* media_stream_manager) + : audio_manager_(audio_manager), + media_stream_manager_(media_stream_manager), + primary_session_id_(kSessionIDInvalid), last_session_id_(kSessionIDInvalid), is_dispatching_event_(false), delegate_(GetContentClient()->browser()-> @@ -183,15 +187,14 @@ void SpeechRecognitionManagerImpl::RecognitionAllowedCallback(int session_id, SessionsTable::iterator iter = sessions_.find(session_id); DCHECK(iter != sessions_.end()); SpeechRecognitionSessionContext& context = iter->second->context; - context.label = - BrowserMainLoop::GetMediaStreamManager()->MakeMediaAccessRequest( - context.render_process_id, - context.render_view_id, - StreamOptions(MEDIA_DEVICE_AUDIO_CAPTURE, MEDIA_NO_SERVICE), - GURL(context.context_name), - base::Bind( - &SpeechRecognitionManagerImpl::MediaRequestPermissionCallback, - weak_factory_.GetWeakPtr(), session_id)); + context.label = media_stream_manager_->MakeMediaAccessRequest( + context.render_process_id, + context.render_view_id, + StreamOptions(MEDIA_DEVICE_AUDIO_CAPTURE, MEDIA_NO_SERVICE), + GURL(context.context_name), + base::Bind( + &SpeechRecognitionManagerImpl::MediaRequestPermissionCallback, + weak_factory_.GetWeakPtr(), session_id)); return; } @@ -642,18 +645,19 @@ SpeechRecognitionManagerImpl::GetSessionConfig(int session_id) const { } bool SpeechRecognitionManagerImpl::HasAudioInputDevices() { - return BrowserMainLoop::GetAudioManager()->HasAudioInputDevices(); + return audio_manager_->HasAudioInputDevices(); } string16 SpeechRecognitionManagerImpl::GetAudioInputDeviceModel() { - return BrowserMainLoop::GetAudioManager()->GetAudioInputDeviceModel(); + return audio_manager_->GetAudioInputDeviceModel(); } void SpeechRecognitionManagerImpl::ShowAudioInputSettings() { // Since AudioManager::ShowAudioInputSettings can potentially launch external // processes, do that in the FILE thread to not block the calling threads. BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, - base::Bind(&ShowAudioInputSettingsOnFileThread)); + base::Bind(&ShowAudioInputSettingsOnFileThread, + audio_manager_)); } SpeechRecognitionManagerImpl::Session::Session() diff --git a/content/browser/speech/speech_recognition_manager_impl.h b/content/browser/speech/speech_recognition_manager_impl.h index d7cc3c1..bf86ac1 100644 --- a/content/browser/speech/speech_recognition_manager_impl.h +++ b/content/browser/speech/speech_recognition_manager_impl.h @@ -19,8 +19,13 @@ #include "content/public/browser/speech_recognition_session_context.h" #include "content/public/common/speech_recognition_error.h" +namespace media { +class AudioManager; +} + namespace content { class BrowserMainLoop; +class MediaStreamManager; class MediaStreamUIProxy; class SpeechRecognitionManagerDelegate; class SpeechRecognizer; @@ -93,7 +98,8 @@ class CONTENT_EXPORT SpeechRecognitionManagerImpl : friend class BrowserMainLoop; // Needed for dtor. friend struct base::DefaultDeleter<SpeechRecognitionManagerImpl>; - SpeechRecognitionManagerImpl(); + SpeechRecognitionManagerImpl(media::AudioManager* audio_manager, + MediaStreamManager* media_stream_manager); virtual ~SpeechRecognitionManagerImpl(); private: @@ -165,6 +171,8 @@ class CONTENT_EXPORT SpeechRecognitionManagerImpl : SpeechRecognitionEventListener* GetDelegateListener() const; int GetNextSessionID(); + media::AudioManager* audio_manager_; + MediaStreamManager* media_stream_manager_; typedef std::map<int, Session*> SessionsTable; SessionsTable sessions_; int primary_session_id_; |