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_INPUT_TAG_SPEECH_DISPATCHER_HOST_H_ | 5 #ifndef CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_DISPATCHER_HOST_H_ |
6 #define CONTENT_BROWSER_SPEECH_INPUT_TAG_SPEECH_DISPATCHER_HOST_H_ | 6 #define CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_DISPATCHER_HOST_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/compiler_specific.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/memory/ref_counted.h" | |
11 #include "content/common/content_export.h" | 10 #include "content/common/content_export.h" |
12 #include "content/public/browser/browser_message_filter.h" | 11 #include "content/public/browser/browser_message_filter.h" |
13 #include "content/public/browser/speech_recognition_event_listener.h" | 12 #include "content/public/browser/speech_recognition_event_listener.h" |
14 #include "net/url_request/url_request_context_getter.h" | 13 #include "net/url_request/url_request_context_getter.h" |
15 | 14 |
16 struct InputTagSpeechHostMsg_StartRecognition_Params; | 15 struct SpeechRecognitionHostMsg_StartRequest_Params; |
17 | 16 |
18 namespace content { | 17 namespace content { |
19 class SpeechRecognitionManager; | 18 class SpeechRecognitionManager; |
20 class SpeechRecognitionPreferences; | 19 class SpeechRecognitionPreferences; |
21 struct SpeechRecognitionResult; | 20 struct SpeechRecognitionResult; |
22 } | 21 } |
23 | 22 |
24 namespace speech { | 23 namespace speech { |
25 | 24 |
26 // InputTagSpeechDispatcherHost is a delegate for Speech API messages used by | 25 // SpeechRecognitionDispatcherHost is a delegate for Speech API messages used by |
27 // RenderMessageFilter. Basically it acts as a proxy, relaying the events coming | 26 // RenderMessageFilter. Basically it acts as a proxy, relaying the events coming |
28 // from the SpeechRecognitionManager to IPC messages (and vice versa). | 27 // from the SpeechRecognitionManager to IPC messages (and vice versa). |
29 // It's the complement of SpeechRecognitionDispatcher (owned by RenderView). | 28 // It's the complement of SpeechRecognitionDispatcher (owned by RenderView). |
30 class CONTENT_EXPORT InputTagSpeechDispatcherHost | 29 class CONTENT_EXPORT SpeechRecognitionDispatcherHost |
31 : public content::BrowserMessageFilter, | 30 : public content::BrowserMessageFilter, |
32 public content::SpeechRecognitionEventListener { | 31 public content::SpeechRecognitionEventListener { |
33 public: | 32 public: |
34 InputTagSpeechDispatcherHost( | 33 SpeechRecognitionDispatcherHost( |
35 int render_process_id, | 34 int render_process_id, |
36 net::URLRequestContextGetter* url_request_context_getter, | 35 net::URLRequestContextGetter* context_getter, |
37 content::SpeechRecognitionPreferences* recognition_preferences); | 36 content::SpeechRecognitionPreferences* recognition_preferences); |
38 | 37 |
39 // SpeechRecognitionEventListener methods. | 38 // SpeechRecognitionEventListener methods. |
40 virtual void OnRecognitionStart(int session_id) OVERRIDE; | 39 virtual void OnRecognitionStart(int session_id) OVERRIDE; |
41 virtual void OnAudioStart(int session_id) OVERRIDE; | 40 virtual void OnAudioStart(int session_id) OVERRIDE; |
42 virtual void OnEnvironmentEstimationComplete(int session_id) OVERRIDE; | 41 virtual void OnEnvironmentEstimationComplete(int session_id) OVERRIDE; |
43 virtual void OnSoundStart(int session_id) OVERRIDE; | 42 virtual void OnSoundStart(int session_id) OVERRIDE; |
44 virtual void OnSoundEnd(int session_id) OVERRIDE; | 43 virtual void OnSoundEnd(int session_id) OVERRIDE; |
45 virtual void OnAudioEnd(int session_id) OVERRIDE; | 44 virtual void OnAudioEnd(int session_id) OVERRIDE; |
46 virtual void OnRecognitionEnd(int session_id) OVERRIDE; | 45 virtual void OnRecognitionEnd(int session_id) OVERRIDE; |
47 virtual void OnRecognitionResult( | 46 virtual void OnRecognitionResult( |
48 int session_id, const content::SpeechRecognitionResult& result) OVERRIDE; | 47 int session_id, const content::SpeechRecognitionResult& result) OVERRIDE; |
49 virtual void OnRecognitionError( | 48 virtual void OnRecognitionError( |
50 int session_id, const content::SpeechRecognitionError& error) OVERRIDE; | 49 int session_id, const content::SpeechRecognitionError& error) OVERRIDE; |
51 virtual void OnAudioLevelsChange( | 50 virtual void OnAudioLevelsChange( |
52 int session_id, float volume, float noise_volume) OVERRIDE; | 51 int session_id, float volume, float noise_volume) OVERRIDE; |
53 | 52 |
54 // content::BrowserMessageFilter implementation. | 53 // content::BrowserMessageFilter implementation. |
55 virtual bool OnMessageReceived(const IPC::Message& message, | 54 virtual bool OnMessageReceived(const IPC::Message& message, |
56 bool* message_was_ok) OVERRIDE; | 55 bool* message_was_ok) OVERRIDE; |
57 | 56 |
58 // Singleton manager setter useful for tests. | 57 // Singleton manager setter useful for tests. |
59 static void SetManagerForTests(content::SpeechRecognitionManager* manager); | 58 static void SetManagerForTests(content::SpeechRecognitionManager* manager); |
60 | 59 |
61 private: | 60 private: |
62 virtual ~InputTagSpeechDispatcherHost(); | 61 virtual ~SpeechRecognitionDispatcherHost(); |
63 | 62 |
64 void OnStartRecognition( | 63 void OnStartRequest( |
65 const InputTagSpeechHostMsg_StartRecognition_Params ¶ms); | 64 const SpeechRecognitionHostMsg_StartRequest_Params& params); |
66 void OnCancelRecognition(int render_view_id, int request_id); | 65 void OnAbortRequest(int render_view_id, int request_id); |
67 void OnStopRecording(int render_view_id, int request_id); | 66 void OnStopCaptureRequest(int render_view_id, int request_id); |
68 | 67 |
69 // Returns the speech recognition manager to forward events to, creating one | 68 // Returns the speech recognition manager to forward requests to. |
70 // if needed. | |
71 content::SpeechRecognitionManager* manager(); | 69 content::SpeechRecognitionManager* manager(); |
72 | 70 |
73 int render_process_id_; | 71 int render_process_id_; |
74 bool may_have_pending_requests_; // Set if we received any speech IPC request | 72 scoped_refptr<net::URLRequestContextGetter> context_getter_; |
75 | |
76 scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_; | |
77 scoped_refptr<content::SpeechRecognitionPreferences> recognition_preferences_; | 73 scoped_refptr<content::SpeechRecognitionPreferences> recognition_preferences_; |
78 | 74 |
79 static content::SpeechRecognitionManager* manager_for_tests_; | 75 static content::SpeechRecognitionManager* manager_for_tests_; |
80 | 76 |
81 DISALLOW_COPY_AND_ASSIGN(InputTagSpeechDispatcherHost); | 77 DISALLOW_COPY_AND_ASSIGN(SpeechRecognitionDispatcherHost); |
82 }; | 78 }; |
83 | 79 |
84 } // namespace speech | 80 } // namespace speech |
85 | 81 |
86 #endif // CONTENT_BROWSER_SPEECH_INPUT_TAG_SPEECH_DISPATCHER_HOST_H_ | 82 #endif // CONTENT_BROWSER_SPEECH_SPEECH_RECOGNITION_DISPATCHER_HOST_H_ |
OLD | NEW |