| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_DISPATCHER_HOST_H_ | 5 #ifndef CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_DISPATCHER_HOST_H_ |
| 6 #define CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_DISPATCHER_HOST_H_ | 6 #define CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_DISPATCHER_HOST_H_ |
| 7 | 7 |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/memory/weak_ptr.h" |
| 9 #include "content/common/content_export.h" | 10 #include "content/common/content_export.h" |
| 10 #include "content/public/browser/browser_message_filter.h" | 11 #include "content/public/browser/browser_message_filter.h" |
| 11 #include "content/public/browser/speech_recognition_event_listener.h" | 12 #include "content/public/browser/speech_recognition_event_listener.h" |
| 12 #include "net/url_request/url_request_context_getter.h" | 13 #include "net/url_request/url_request_context_getter.h" |
| 13 | 14 |
| 14 struct SpeechRecognitionHostMsg_StartRequest_Params; | 15 struct SpeechRecognitionHostMsg_StartRequest_Params; |
| 15 | 16 |
| 16 namespace content { | 17 namespace content { |
| 17 | 18 |
| 18 class SpeechRecognitionManager; | 19 class SpeechRecognitionManager; |
| 19 struct SpeechRecognitionResult; | 20 struct SpeechRecognitionResult; |
| 20 | 21 |
| 21 // SpeechRecognitionDispatcherHost is a delegate for Speech API messages used by | 22 // SpeechRecognitionDispatcherHost is a delegate for Speech API messages used by |
| 22 // RenderMessageFilter. Basically it acts as a proxy, relaying the events coming | 23 // RenderMessageFilter. Basically it acts as a proxy, relaying the events coming |
| 23 // from the SpeechRecognitionManager to IPC messages (and vice versa). | 24 // from the SpeechRecognitionManager to IPC messages (and vice versa). |
| 24 // It's the complement of SpeechRecognitionDispatcher (owned by RenderView). | 25 // It's the complement of SpeechRecognitionDispatcher (owned by RenderView). |
| 25 class CONTENT_EXPORT SpeechRecognitionDispatcherHost | 26 class CONTENT_EXPORT SpeechRecognitionDispatcherHost |
| 26 : public BrowserMessageFilter, | 27 : public BrowserMessageFilter, |
| 27 public SpeechRecognitionEventListener { | 28 public SpeechRecognitionEventListener { |
| 28 public: | 29 public: |
| 29 SpeechRecognitionDispatcherHost( | 30 SpeechRecognitionDispatcherHost( |
| 30 bool is_guest, | 31 bool is_guest, |
| 31 int render_process_id, | 32 int render_process_id, |
| 32 net::URLRequestContextGetter* context_getter); | 33 net::URLRequestContextGetter* context_getter); |
| 33 | 34 |
| 35 base::WeakPtr<SpeechRecognitionDispatcherHost> AsWeakPtr(); |
| 36 |
| 34 // SpeechRecognitionEventListener methods. | 37 // SpeechRecognitionEventListener methods. |
| 35 virtual void OnRecognitionStart(int session_id) OVERRIDE; | 38 virtual void OnRecognitionStart(int session_id) OVERRIDE; |
| 36 virtual void OnAudioStart(int session_id) OVERRIDE; | 39 virtual void OnAudioStart(int session_id) OVERRIDE; |
| 37 virtual void OnEnvironmentEstimationComplete(int session_id) OVERRIDE; | 40 virtual void OnEnvironmentEstimationComplete(int session_id) OVERRIDE; |
| 38 virtual void OnSoundStart(int session_id) OVERRIDE; | 41 virtual void OnSoundStart(int session_id) OVERRIDE; |
| 39 virtual void OnSoundEnd(int session_id) OVERRIDE; | 42 virtual void OnSoundEnd(int session_id) OVERRIDE; |
| 40 virtual void OnAudioEnd(int session_id) OVERRIDE; | 43 virtual void OnAudioEnd(int session_id) OVERRIDE; |
| 41 virtual void OnRecognitionEnd(int session_id) OVERRIDE; | 44 virtual void OnRecognitionEnd(int session_id) OVERRIDE; |
| 42 virtual void OnRecognitionResults( | 45 virtual void OnRecognitionResults( |
| 43 int session_id, | 46 int session_id, |
| 44 const SpeechRecognitionResults& results) OVERRIDE; | 47 const SpeechRecognitionResults& results) OVERRIDE; |
| 45 virtual void OnRecognitionError( | 48 virtual void OnRecognitionError( |
| 46 int session_id, | 49 int session_id, |
| 47 const SpeechRecognitionError& error) OVERRIDE; | 50 const SpeechRecognitionError& error) OVERRIDE; |
| 48 virtual void OnAudioLevelsChange(int session_id, | 51 virtual void OnAudioLevelsChange(int session_id, |
| 49 float volume, | 52 float volume, |
| 50 float noise_volume) OVERRIDE; | 53 float noise_volume) OVERRIDE; |
| 51 | 54 |
| 52 // BrowserMessageFilter implementation. | 55 // BrowserMessageFilter implementation. |
| 53 virtual bool OnMessageReceived(const IPC::Message& message, | 56 virtual bool OnMessageReceived(const IPC::Message& message, |
| 54 bool* message_was_ok) OVERRIDE; | 57 bool* message_was_ok) OVERRIDE; |
| 55 virtual void OverrideThreadForMessage( | 58 virtual void OverrideThreadForMessage( |
| 56 const IPC::Message& message, | 59 const IPC::Message& message, |
| 57 BrowserThread::ID* thread) OVERRIDE; | 60 BrowserThread::ID* thread) OVERRIDE; |
| 58 | 61 |
| 62 virtual void OnChannelClosing() OVERRIDE; |
| 63 |
| 59 private: | 64 private: |
| 60 virtual ~SpeechRecognitionDispatcherHost(); | 65 virtual ~SpeechRecognitionDispatcherHost(); |
| 61 | 66 |
| 62 void OnStartRequest( | 67 void OnStartRequest( |
| 63 const SpeechRecognitionHostMsg_StartRequest_Params& params); | 68 const SpeechRecognitionHostMsg_StartRequest_Params& params); |
| 64 void OnStartRequestOnIO( | 69 void OnStartRequestOnIO( |
| 65 int embedder_render_process_id, | 70 int embedder_render_process_id, |
| 66 int embedder_render_view_id, | 71 int embedder_render_view_id, |
| 67 const SpeechRecognitionHostMsg_StartRequest_Params& params, | 72 const SpeechRecognitionHostMsg_StartRequest_Params& params, |
| 68 bool filter_profanities); | 73 bool filter_profanities); |
| 69 void OnAbortRequest(int render_view_id, int request_id); | 74 void OnAbortRequest(int render_view_id, int request_id); |
| 70 void OnStopCaptureRequest(int render_view_id, int request_id); | 75 void OnStopCaptureRequest(int render_view_id, int request_id); |
| 71 | 76 |
| 72 bool is_guest_; | 77 bool is_guest_; |
| 73 int render_process_id_; | 78 int render_process_id_; |
| 74 scoped_refptr<net::URLRequestContextGetter> context_getter_; | 79 scoped_refptr<net::URLRequestContextGetter> context_getter_; |
| 75 | 80 |
| 81 // Used for posting asynchronous tasks (on the IO thread) without worrying |
| 82 // about this class being destroyed in the meanwhile (due to browser shutdown) |
| 83 // since tasks pending on a destroyed WeakPtr are automatically discarded. |
| 84 base::WeakPtrFactory<SpeechRecognitionDispatcherHost> weak_factory_; |
| 85 |
| 76 DISALLOW_COPY_AND_ASSIGN(SpeechRecognitionDispatcherHost); | 86 DISALLOW_COPY_AND_ASSIGN(SpeechRecognitionDispatcherHost); |
| 77 }; | 87 }; |
| 78 | 88 |
| 79 } // namespace content | 89 } // namespace content |
| 80 | 90 |
| 81 #endif // CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_DISPATCHER_HOST_H_ | 91 #endif // CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_DISPATCHER_HOST_H_ |
| OLD | NEW |