diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-09 21:10:29 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-09 21:10:29 +0000 |
commit | 9232738f3f237d64e15fe17f9830b516652f5c86 (patch) | |
tree | e8e64d72bdab3ff5a33c57c674f72105fcddf771 /content/browser/speech/speech_recognition_dispatcher_host.cc | |
parent | a081aebba3483e4605cff0e81b917b69b0f49fe3 (diff) | |
download | chromium_src-9232738f3f237d64e15fe17f9830b516652f5c86.zip chromium_src-9232738f3f237d64e15fe17f9830b516652f5c86.tar.gz chromium_src-9232738f3f237d64e15fe17f9830b516652f5c86.tar.bz2 |
Get rid of the SpeechRecognitionPreferences interface. It only had one method, and we can roll that into SpeechRecognitionDelegate instead to simplify things. This also allows us to get rid of ChromeSpeechRecognitionPreferences.
R=tommi@chromium.org
Review URL: https://codereview.chromium.org/18487007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@210616 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/speech/speech_recognition_dispatcher_host.cc')
-rw-r--r-- | content/browser/speech/speech_recognition_dispatcher_host.cc | 98 |
1 files changed, 51 insertions, 47 deletions
diff --git a/content/browser/speech/speech_recognition_dispatcher_host.cc b/content/browser/speech/speech_recognition_dispatcher_host.cc index 7f20ca4..e506675 100644 --- a/content/browser/speech/speech_recognition_dispatcher_host.cc +++ b/content/browser/speech/speech_recognition_dispatcher_host.cc @@ -7,42 +7,27 @@ #include "base/bind.h" #include "base/command_line.h" #include "base/lazy_instance.h" +#include "content/browser/speech/speech_recognition_manager_impl.h" #include "content/common/speech_recognition_messages.h" -#include "content/public/browser/speech_recognition_manager.h" -#include "content/public/browser/speech_recognition_preferences.h" +#include "content/public/browser/speech_recognition_manager_delegate.h" #include "content/public/browser/speech_recognition_session_config.h" #include "content/public/browser/speech_recognition_session_context.h" #include "content/public/common/content_switches.h" namespace content { -SpeechRecognitionManager* SpeechRecognitionDispatcherHost::manager_for_tests_; - -void SpeechRecognitionDispatcherHost::SetManagerForTests( - SpeechRecognitionManager* manager) { - manager_for_tests_ = manager; -} SpeechRecognitionDispatcherHost::SpeechRecognitionDispatcherHost( int render_process_id, - net::URLRequestContextGetter* context_getter, - SpeechRecognitionPreferences* recognition_preferences) + net::URLRequestContextGetter* context_getter) : render_process_id_(render_process_id), - context_getter_(context_getter), - recognition_preferences_(recognition_preferences) { + context_getter_(context_getter) { // Do not add any non-trivial initialization here, instead do it lazily when - // required (e.g. see the method |manager()|) or add an Init() method. + // required (e.g. see the method |SpeechRecognitionManager::GetInstance()|) or + // add an Init() method. } SpeechRecognitionDispatcherHost::~SpeechRecognitionDispatcherHost() { - if (SpeechRecognitionManager* sr_manager = manager()) - sr_manager->AbortAllSessionsForListener(this); -} - -SpeechRecognitionManager* SpeechRecognitionDispatcherHost::manager() { - if (manager_for_tests_) - return manager_for_tests_; - - return SpeechRecognitionManager::GetInstance(); + SpeechRecognitionManager::GetInstance()->AbortAllSessionsForListener(this); } bool SpeechRecognitionDispatcherHost::OnMessageReceived( @@ -61,9 +46,31 @@ bool SpeechRecognitionDispatcherHost::OnMessageReceived( return handled; } +void SpeechRecognitionDispatcherHost::OverrideThreadForMessage( + const IPC::Message& message, + BrowserThread::ID* thread) { + if (message.type() == SpeechRecognitionHostMsg_StartRequest::ID) + *thread = BrowserThread::UI; +} + void SpeechRecognitionDispatcherHost::OnStartRequest( const SpeechRecognitionHostMsg_StartRequest_Params& params) { - + bool filter_profanities = + SpeechRecognitionManagerImpl::GetInstance() && + SpeechRecognitionManagerImpl::GetInstance()->delegate() && + SpeechRecognitionManagerImpl::GetInstance()->delegate()-> + FilterProfanities(render_process_id_); + + BrowserThread::PostTask( + BrowserThread::IO, + FROM_HERE, + base::Bind(&SpeechRecognitionDispatcherHost::OnStartRequestOnIO, + this, params, filter_profanities)); +} + +void SpeechRecognitionDispatcherHost::OnStartRequestOnIO( + const SpeechRecognitionHostMsg_StartRequest_Params& params, + bool filter_profanities) { SpeechRecognitionSessionContext context; context.context_name = params.origin_url; context.render_process_id = render_process_id_; @@ -79,84 +86,81 @@ void SpeechRecognitionDispatcherHost::OnStartRequest( config.origin_url = params.origin_url; config.initial_context = context; config.url_request_context_getter = context_getter_.get(); - if (recognition_preferences_.get()) { - config.filter_profanities = recognition_preferences_->FilterProfanities(); - } else { - config.filter_profanities = false; - } + config.filter_profanities = filter_profanities; config.continuous = params.continuous; config.interim_results = params.interim_results; config.event_listener = this; - int session_id = manager()->CreateSession(config); + int session_id = SpeechRecognitionManager::GetInstance()->CreateSession( + config); DCHECK_NE(session_id, SpeechRecognitionManager::kSessionIDInvalid); - manager()->StartSession(session_id); + SpeechRecognitionManager::GetInstance()->StartSession(session_id); } void SpeechRecognitionDispatcherHost::OnAbortRequest(int render_view_id, int request_id) { - int session_id = manager()->GetSession(render_process_id_, - render_view_id, - request_id); + int session_id = SpeechRecognitionManager::GetInstance()->GetSession( + render_process_id_, render_view_id, request_id); // The renderer might provide an invalid |request_id| if the session was not // started as expected, e.g., due to unsatisfied security requirements. if (session_id != SpeechRecognitionManager::kSessionIDInvalid) - manager()->AbortSession(session_id); + SpeechRecognitionManager::GetInstance()->AbortSession(session_id); } void SpeechRecognitionDispatcherHost::OnStopCaptureRequest( int render_view_id, int request_id) { - int session_id = manager()->GetSession(render_process_id_, - render_view_id, - request_id); + int session_id = SpeechRecognitionManager::GetInstance()->GetSession( + render_process_id_, render_view_id, request_id); // The renderer might provide an invalid |request_id| if the session was not // started as expected, e.g., due to unsatisfied security requirements. - if (session_id != SpeechRecognitionManager::kSessionIDInvalid) - manager()->StopAudioCaptureForSession(session_id); + if (session_id != SpeechRecognitionManager::kSessionIDInvalid) { + SpeechRecognitionManager::GetInstance()->StopAudioCaptureForSession( + session_id); + } } // -------- SpeechRecognitionEventListener interface implementation ----------- void SpeechRecognitionDispatcherHost::OnRecognitionStart(int session_id) { const SpeechRecognitionSessionContext& context = - manager()->GetSessionContext(session_id); + SpeechRecognitionManager::GetInstance()->GetSessionContext(session_id); Send(new SpeechRecognitionMsg_Started(context.render_view_id, context.request_id)); } void SpeechRecognitionDispatcherHost::OnAudioStart(int session_id) { const SpeechRecognitionSessionContext& context = - manager()->GetSessionContext(session_id); + SpeechRecognitionManager::GetInstance()->GetSessionContext(session_id); Send(new SpeechRecognitionMsg_AudioStarted(context.render_view_id, context.request_id)); } void SpeechRecognitionDispatcherHost::OnSoundStart(int session_id) { const SpeechRecognitionSessionContext& context = - manager()->GetSessionContext(session_id); + SpeechRecognitionManager::GetInstance()->GetSessionContext(session_id); Send(new SpeechRecognitionMsg_SoundStarted(context.render_view_id, context.request_id)); } void SpeechRecognitionDispatcherHost::OnSoundEnd(int session_id) { const SpeechRecognitionSessionContext& context = - manager()->GetSessionContext(session_id); + SpeechRecognitionManager::GetInstance()->GetSessionContext(session_id); Send(new SpeechRecognitionMsg_SoundEnded(context.render_view_id, context.request_id)); } void SpeechRecognitionDispatcherHost::OnAudioEnd(int session_id) { const SpeechRecognitionSessionContext& context = - manager()->GetSessionContext(session_id); + SpeechRecognitionManager::GetInstance()->GetSessionContext(session_id); Send(new SpeechRecognitionMsg_AudioEnded(context.render_view_id, context.request_id)); } void SpeechRecognitionDispatcherHost::OnRecognitionEnd(int session_id) { const SpeechRecognitionSessionContext& context = - manager()->GetSessionContext(session_id); + SpeechRecognitionManager::GetInstance()->GetSessionContext(session_id); Send(new SpeechRecognitionMsg_Ended(context.render_view_id, context.request_id)); } @@ -165,7 +169,7 @@ void SpeechRecognitionDispatcherHost::OnRecognitionResults( int session_id, const SpeechRecognitionResults& results) { const SpeechRecognitionSessionContext& context = - manager()->GetSessionContext(session_id); + SpeechRecognitionManager::GetInstance()->GetSessionContext(session_id); Send(new SpeechRecognitionMsg_ResultRetrieved(context.render_view_id, context.request_id, results)); @@ -175,7 +179,7 @@ void SpeechRecognitionDispatcherHost::OnRecognitionError( int session_id, const SpeechRecognitionError& error) { const SpeechRecognitionSessionContext& context = - manager()->GetSessionContext(session_id); + SpeechRecognitionManager::GetInstance()->GetSessionContext(session_id); Send(new SpeechRecognitionMsg_ErrorOccurred(context.render_view_id, context.request_id, error)); |