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 #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_manager.h" | 8 #include "content/browser/speech/speech_input_manager.h" |
9 #include "content/browser/speech/speech_recognizer.h" | 9 #include "content/browser/speech/speech_recognizer.h" |
10 #include "content/common/speech_input_messages.h" | 10 #include "content/common/speech_input_messages.h" |
11 #include "content/public/browser/content_browser_client.h" | 11 #include "content/public/browser/content_browser_client.h" |
12 #include "content/public/browser/resource_context.h" | |
13 #include "content/public/browser/speech_input_preferences.h" | 12 #include "content/public/browser/speech_input_preferences.h" |
14 | 13 |
15 using content::BrowserThread; | 14 using content::BrowserThread; |
16 | 15 |
17 namespace speech_input { | 16 namespace speech_input { |
18 | 17 |
19 //----------------------------- SpeechInputCallers ----------------------------- | 18 //----------------------------- SpeechInputCallers ----------------------------- |
20 | 19 |
21 // A singleton class to map the tuple | 20 // A singleton class to map the tuple |
22 // (render-process-id, render-view-id, requestid) to a single ID which is passed | 21 // (render-process-id, render-view-id, requestid) to a single ID which is passed |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 SpeechInputManager* SpeechInputDispatcherHost::manager_; | 110 SpeechInputManager* SpeechInputDispatcherHost::manager_; |
112 | 111 |
113 void SpeechInputDispatcherHost::set_manager(SpeechInputManager* manager) { | 112 void SpeechInputDispatcherHost::set_manager(SpeechInputManager* manager) { |
114 manager_ = manager; | 113 manager_ = manager; |
115 } | 114 } |
116 | 115 |
117 SpeechInputDispatcherHost::SpeechInputDispatcherHost( | 116 SpeechInputDispatcherHost::SpeechInputDispatcherHost( |
118 int render_process_id, | 117 int render_process_id, |
119 net::URLRequestContextGetter* context_getter, | 118 net::URLRequestContextGetter* context_getter, |
120 content::SpeechInputPreferences* speech_input_preferences, | 119 content::SpeechInputPreferences* speech_input_preferences, |
121 content::ResourceContext* resource_context) | 120 AudioManager* audio_manager) |
122 : render_process_id_(render_process_id), | 121 : render_process_id_(render_process_id), |
123 may_have_pending_requests_(false), | 122 may_have_pending_requests_(false), |
124 context_getter_(context_getter), | 123 context_getter_(context_getter), |
125 speech_input_preferences_(speech_input_preferences), | 124 speech_input_preferences_(speech_input_preferences), |
126 resource_context_(resource_context) { | 125 audio_manager_(audio_manager) { |
127 // This is initialized by Browser. Do not add any non-trivial | 126 // This is initialized by Browser. Do not add any non-trivial |
128 // initialization here, instead do it lazily when required (e.g. see the | 127 // initialization here, instead do it lazily when required (e.g. see the |
129 // method |manager()|) or add an Init() method. | 128 // method |manager()|) or add an Init() method. |
130 } | 129 } |
131 | 130 |
132 SpeechInputDispatcherHost::~SpeechInputDispatcherHost() { | 131 SpeechInputDispatcherHost::~SpeechInputDispatcherHost() { |
133 // If the renderer crashed for some reason or if we didn't receive a proper | 132 // If the renderer crashed for some reason or if we didn't receive a proper |
134 // Cancel/Stop call for an existing session, cancel such active sessions now. | 133 // Cancel/Stop call for an existing session, cancel such active sessions now. |
135 // We first check if this dispatcher received any speech IPC requst so that | 134 // We first check if this dispatcher received any speech IPC requst so that |
136 // we don't end up creating the speech input manager for web pages which don't | 135 // we don't end up creating the speech input manager for web pages which don't |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 const SpeechInputHostMsg_StartRecognition_Params ¶ms) { | 167 const SpeechInputHostMsg_StartRecognition_Params ¶ms) { |
169 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 168 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
170 int caller_id = g_speech_input_callers.Get().CreateId( | 169 int caller_id = g_speech_input_callers.Get().CreateId( |
171 render_process_id_, params.render_view_id, params.request_id); | 170 render_process_id_, params.render_view_id, params.request_id); |
172 manager()->StartRecognition(this, caller_id, | 171 manager()->StartRecognition(this, caller_id, |
173 render_process_id_, | 172 render_process_id_, |
174 params.render_view_id, params.element_rect, | 173 params.render_view_id, params.element_rect, |
175 params.language, params.grammar, | 174 params.language, params.grammar, |
176 params.origin_url, | 175 params.origin_url, |
177 context_getter_.get(), | 176 context_getter_.get(), |
178 speech_input_preferences_.get(), | 177 speech_input_preferences_.get()); |
179 resource_context_->GetAudioManager()); | |
180 } | 178 } |
181 | 179 |
182 void SpeechInputDispatcherHost::OnCancelRecognition(int render_view_id, | 180 void SpeechInputDispatcherHost::OnCancelRecognition(int render_view_id, |
183 int request_id) { | 181 int request_id) { |
184 int caller_id = g_speech_input_callers.Get().GetId( | 182 int caller_id = g_speech_input_callers.Get().GetId( |
185 render_process_id_, render_view_id, request_id); | 183 render_process_id_, render_view_id, request_id); |
186 if (caller_id) { | 184 if (caller_id) { |
187 manager()->CancelRecognition(caller_id); | 185 manager()->CancelRecognition(caller_id); |
188 // Request sequence ended so remove mapping. | 186 // Request sequence ended so remove mapping. |
189 g_speech_input_callers.Get().RemoveId(caller_id); | 187 g_speech_input_callers.Get().RemoveId(caller_id); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 g_speech_input_callers.Get().render_view_id(caller_id); | 227 g_speech_input_callers.Get().render_view_id(caller_id); |
230 int caller_request_id = g_speech_input_callers.Get().request_id(caller_id); | 228 int caller_request_id = g_speech_input_callers.Get().request_id(caller_id); |
231 Send(new SpeechInputMsg_RecognitionComplete(caller_render_view_id, | 229 Send(new SpeechInputMsg_RecognitionComplete(caller_render_view_id, |
232 caller_request_id)); | 230 caller_request_id)); |
233 // Request sequence ended, so remove mapping. | 231 // Request sequence ended, so remove mapping. |
234 g_speech_input_callers.Get().RemoveId(caller_id); | 232 g_speech_input_callers.Get().RemoveId(caller_id); |
235 VLOG(1) << "SpeechInputDispatcherHost::DidCompleteRecognition exit"; | 233 VLOG(1) << "SpeechInputDispatcherHost::DidCompleteRecognition exit"; |
236 } | 234 } |
237 | 235 |
238 } // namespace speech_input | 236 } // namespace speech_input |
OLD | NEW |