OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "content/browser/speech/speech_input_dispatcher_host.h" | 5 #include "content/browser/speech/speech_input_dispatcher_host.h" |
6 | 6 |
7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
8 #include "content/browser/speech/speech_input_preferences.h" | 8 #include "content/browser/speech/speech_input_preferences.h" |
9 #include "content/common/speech_input_messages.h" | 9 #include "content/common/speech_input_messages.h" |
10 #include "content/public/browser/content_browser_client.h" | 10 #include "content/public/browser/content_browser_client.h" |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 | 107 |
108 SpeechInputManager* SpeechInputDispatcherHost::manager_; | 108 SpeechInputManager* SpeechInputDispatcherHost::manager_; |
109 | 109 |
110 void SpeechInputDispatcherHost::set_manager(SpeechInputManager* manager) { | 110 void SpeechInputDispatcherHost::set_manager(SpeechInputManager* manager) { |
111 manager_ = manager; | 111 manager_ = manager; |
112 } | 112 } |
113 | 113 |
114 SpeechInputDispatcherHost::SpeechInputDispatcherHost( | 114 SpeechInputDispatcherHost::SpeechInputDispatcherHost( |
115 int render_process_id, | 115 int render_process_id, |
116 net::URLRequestContextGetter* context_getter, | 116 net::URLRequestContextGetter* context_getter, |
117 SpeechInputPreferences* speech_input_preferences) | 117 SpeechInputPreferences* speech_input_preferences, |
| 118 AudioManager* audio_manager) |
118 : render_process_id_(render_process_id), | 119 : render_process_id_(render_process_id), |
119 may_have_pending_requests_(false), | 120 may_have_pending_requests_(false), |
120 context_getter_(context_getter), | 121 context_getter_(context_getter), |
121 speech_input_preferences_(speech_input_preferences) { | 122 speech_input_preferences_(speech_input_preferences), |
| 123 audio_manager_(audio_manager) { |
122 // This is initialized by Browser. Do not add any non-trivial | 124 // This is initialized by Browser. Do not add any non-trivial |
123 // initialization here, instead do it lazily when required (e.g. see the | 125 // initialization here, instead do it lazily when required (e.g. see the |
124 // method |manager()|) or add an Init() method. | 126 // method |manager()|) or add an Init() method. |
125 } | 127 } |
126 | 128 |
127 SpeechInputDispatcherHost::~SpeechInputDispatcherHost() { | 129 SpeechInputDispatcherHost::~SpeechInputDispatcherHost() { |
128 // If the renderer crashed for some reason or if we didn't receive a proper | 130 // If the renderer crashed for some reason or if we didn't receive a proper |
129 // Cancel/Stop call for an existing session, cancel such active sessions now. | 131 // Cancel/Stop call for an existing session, cancel such active sessions now. |
130 // We first check if this dispatcher received any speech IPC requst so that | 132 // We first check if this dispatcher received any speech IPC requst so that |
131 // we don't end up creating the speech input manager for web pages which don't | 133 // we don't end up creating the speech input manager for web pages which don't |
(...skipping 21 matching lines...) Expand all Loading... |
153 IPC_MESSAGE_HANDLER(SpeechInputHostMsg_StopRecording, | 155 IPC_MESSAGE_HANDLER(SpeechInputHostMsg_StopRecording, |
154 OnStopRecording) | 156 OnStopRecording) |
155 IPC_MESSAGE_UNHANDLED(handled = false) | 157 IPC_MESSAGE_UNHANDLED(handled = false) |
156 IPC_END_MESSAGE_MAP() | 158 IPC_END_MESSAGE_MAP() |
157 if (handled) | 159 if (handled) |
158 may_have_pending_requests_ = true; | 160 may_have_pending_requests_ = true; |
159 return handled; | 161 return handled; |
160 } | 162 } |
161 | 163 |
162 void SpeechInputDispatcherHost::OnStartRecognition( | 164 void SpeechInputDispatcherHost::OnStartRecognition( |
163 const SpeechInputHostMsg_StartRecognition_Params ¶ms) { | 165 const SpeechInputHostMsg_StartRecognition_Params& params) { |
164 int caller_id = g_speech_input_callers.Get().CreateId( | 166 int caller_id = g_speech_input_callers.Get().CreateId( |
165 render_process_id_, params.render_view_id, params.request_id); | 167 render_process_id_, params.render_view_id, params.request_id); |
| 168 |
166 manager()->StartRecognition(this, caller_id, | 169 manager()->StartRecognition(this, caller_id, |
167 render_process_id_, | 170 render_process_id_, |
168 params.render_view_id, params.element_rect, | 171 params.render_view_id, params.element_rect, |
169 params.language, params.grammar, | 172 params.language, params.grammar, |
170 params.origin_url, | 173 params.origin_url, |
171 context_getter_.get(), | 174 context_getter_.get(), |
172 speech_input_preferences_.get()); | 175 speech_input_preferences_.get(), |
| 176 audio_manager_.get()); |
173 } | 177 } |
174 | 178 |
175 void SpeechInputDispatcherHost::OnCancelRecognition(int render_view_id, | 179 void SpeechInputDispatcherHost::OnCancelRecognition(int render_view_id, |
176 int request_id) { | 180 int request_id) { |
177 int caller_id = g_speech_input_callers.Get().GetId( | 181 int caller_id = g_speech_input_callers.Get().GetId( |
178 render_process_id_, render_view_id, request_id); | 182 render_process_id_, render_view_id, request_id); |
179 if (caller_id) { | 183 if (caller_id) { |
180 manager()->CancelRecognition(caller_id); | 184 manager()->CancelRecognition(caller_id); |
181 // Request sequence ended so remove mapping. | 185 // Request sequence ended so remove mapping. |
182 g_speech_input_callers.Get().RemoveId(caller_id); | 186 g_speech_input_callers.Get().RemoveId(caller_id); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 g_speech_input_callers.Get().render_view_id(caller_id); | 226 g_speech_input_callers.Get().render_view_id(caller_id); |
223 int caller_request_id = g_speech_input_callers.Get().request_id(caller_id); | 227 int caller_request_id = g_speech_input_callers.Get().request_id(caller_id); |
224 Send(new SpeechInputMsg_RecognitionComplete(caller_render_view_id, | 228 Send(new SpeechInputMsg_RecognitionComplete(caller_render_view_id, |
225 caller_request_id)); | 229 caller_request_id)); |
226 // Request sequence ended, so remove mapping. | 230 // Request sequence ended, so remove mapping. |
227 g_speech_input_callers.Get().RemoveId(caller_id); | 231 g_speech_input_callers.Get().RemoveId(caller_id); |
228 VLOG(1) << "SpeechInputDispatcherHost::DidCompleteRecognition exit"; | 232 VLOG(1) << "SpeechInputDispatcherHost::DidCompleteRecognition exit"; |
229 } | 233 } |
230 | 234 |
231 } // namespace speech_input | 235 } // namespace speech_input |
OLD | NEW |