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 #ifndef CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_DISPATCHER_HOST_H_ 6 #define CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_DISPATCHER_HOST_H_ 7 8 #include "base/memory/scoped_ptr.h" 9 #include "content/common/content_export.h" 10 #include "content/public/browser/browser_message_filter.h" 11 #include "content/public/browser/speech_recognition_event_listener.h" 12 #include "net/url_request/url_request_context_getter.h" 13 14 struct SpeechRecognitionHostMsg_StartRequest_Params; 15 16 namespace content { 17 18 class SpeechRecognitionManager; 19 struct SpeechRecognitionResult; 20 21 // SpeechRecognitionDispatcherHost is a delegate for Speech API messages used by 22 // RenderMessageFilter. Basically it acts as a proxy, relaying the events coming 23 // from the SpeechRecognitionManager to IPC messages (and vice versa). 24 // It's the complement of SpeechRecognitionDispatcher (owned by RenderView). 25 class CONTENT_EXPORT SpeechRecognitionDispatcherHost 26 : public BrowserMessageFilter, 27 public SpeechRecognitionEventListener { 28 public: 29 SpeechRecognitionDispatcherHost( 30 int render_process_id, 31 net::URLRequestContextGetter* context_getter); 32 33 // SpeechRecognitionEventListener methods. 34 virtual void OnRecognitionStart(int session_id) OVERRIDE; 35 virtual void OnAudioStart(int session_id) OVERRIDE; 36 virtual void OnEnvironmentEstimationComplete(int session_id) OVERRIDE; 37 virtual void OnSoundStart(int session_id) OVERRIDE; 38 virtual void OnSoundEnd(int session_id) OVERRIDE; 39 virtual void OnAudioEnd(int session_id) OVERRIDE; 40 virtual void OnRecognitionEnd(int session_id) OVERRIDE; 41 virtual void OnRecognitionResults( 42 int session_id, 43 const SpeechRecognitionResults& results) OVERRIDE; 44 virtual void OnRecognitionError( 45 int session_id, 46 const SpeechRecognitionError& error) OVERRIDE; 47 virtual void OnAudioLevelsChange(int session_id, 48 float volume, 49 float noise_volume) OVERRIDE; 50 51 // BrowserMessageFilter implementation. 52 virtual bool OnMessageReceived(const IPC::Message& message, 53 bool* message_was_ok) OVERRIDE; 54 virtual void OverrideThreadForMessage( 55 const IPC::Message& message, 56 BrowserThread::ID* thread) OVERRIDE; 57 58 private: 59 virtual ~SpeechRecognitionDispatcherHost(); 60 61 void OnStartRequest( 62 const SpeechRecognitionHostMsg_StartRequest_Params& params); 63 void OnStartRequestOnIO( 64 const SpeechRecognitionHostMsg_StartRequest_Params& params, 65 bool filter_profanities); 66 void OnAbortRequest(int render_view_id, int request_id); 67 void OnStopCaptureRequest(int render_view_id, int request_id); 68 69 int render_process_id_; 70 scoped_refptr<net::URLRequestContextGetter> context_getter_; 71 72 DISALLOW_COPY_AND_ASSIGN(SpeechRecognitionDispatcherHost); 73 }; 74 75 } // namespace content 76 77 #endif // CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_DISPATCHER_HOST_H_ 78