| 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_recognition_manager_impl.h" | 5 #include "content/browser/speech/speech_recognition_manager_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "content/browser/browser_main_loop.h" | 8 #include "content/browser/browser_main_loop.h" |
| 9 #include "content/browser/renderer_host/render_view_host_impl.h" | 9 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 10 #include "content/browser/speech/input_tag_speech_dispatcher_host.h" | 10 #include "content/browser/speech/input_tag_speech_dispatcher_host.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 | 26 |
| 27 SpeechRecognitionManager* SpeechRecognitionManager::GetInstance() { | 27 SpeechRecognitionManager* SpeechRecognitionManager::GetInstance() { |
| 28 return speech::SpeechRecognitionManagerImpl::GetInstance(); | 28 return speech::SpeechRecognitionManagerImpl::GetInstance(); |
| 29 } | 29 } |
| 30 | 30 |
| 31 namespace speech { | 31 namespace speech { |
| 32 | 32 |
| 33 struct SpeechRecognitionManagerImpl::SpeechRecognitionParams { | 33 struct SpeechRecognitionManagerImpl::SpeechRecognitionParams { |
| 34 SpeechRecognitionParams( | 34 SpeechRecognitionParams( |
| 35 InputTagSpeechDispatcherHost* delegate, | 35 InputTagSpeechDispatcherHost* delegate, |
| 36 int caller_id, | 36 int session_id, |
| 37 int render_process_id, | 37 int render_process_id, |
| 38 int render_view_id, | 38 int render_view_id, |
| 39 const gfx::Rect& element_rect, | 39 const gfx::Rect& element_rect, |
| 40 const std::string& language, | 40 const std::string& language, |
| 41 const std::string& grammar, | 41 const std::string& grammar, |
| 42 const std::string& origin_url, | 42 const std::string& origin_url, |
| 43 net::URLRequestContextGetter* context_getter, | 43 net::URLRequestContextGetter* context_getter, |
| 44 content::SpeechRecognitionPreferences* recognition_prefs) | 44 content::SpeechRecognitionPreferences* recognition_prefs) |
| 45 : delegate(delegate), | 45 : delegate(delegate), |
| 46 caller_id(caller_id), | 46 session_id(session_id), |
| 47 render_process_id(render_process_id), | 47 render_process_id(render_process_id), |
| 48 render_view_id(render_view_id), | 48 render_view_id(render_view_id), |
| 49 element_rect(element_rect), | 49 element_rect(element_rect), |
| 50 language(language), | 50 language(language), |
| 51 grammar(grammar), | 51 grammar(grammar), |
| 52 origin_url(origin_url), | 52 origin_url(origin_url), |
| 53 context_getter(context_getter), | 53 context_getter(context_getter), |
| 54 recognition_prefs(recognition_prefs) { | 54 recognition_prefs(recognition_prefs) { |
| 55 } | 55 } |
| 56 | 56 |
| 57 InputTagSpeechDispatcherHost* delegate; | 57 InputTagSpeechDispatcherHost* delegate; |
| 58 int caller_id; | 58 int session_id; |
| 59 int render_process_id; | 59 int render_process_id; |
| 60 int render_view_id; | 60 int render_view_id; |
| 61 gfx::Rect element_rect; | 61 gfx::Rect element_rect; |
| 62 std::string language; | 62 std::string language; |
| 63 std::string grammar; | 63 std::string grammar; |
| 64 std::string origin_url; | 64 std::string origin_url; |
| 65 net::URLRequestContextGetter* context_getter; | 65 net::URLRequestContextGetter* context_getter; |
| 66 content::SpeechRecognitionPreferences* recognition_prefs; | 66 content::SpeechRecognitionPreferences* recognition_prefs; |
| 67 }; | 67 }; |
| 68 | 68 |
| 69 SpeechRecognitionManagerImpl* SpeechRecognitionManagerImpl::GetInstance() { | 69 SpeechRecognitionManagerImpl* SpeechRecognitionManagerImpl::GetInstance() { |
| 70 return Singleton<SpeechRecognitionManagerImpl>::get(); | 70 return Singleton<SpeechRecognitionManagerImpl>::get(); |
| 71 } | 71 } |
| 72 | 72 |
| 73 SpeechRecognitionManagerImpl::SpeechRecognitionManagerImpl() | 73 SpeechRecognitionManagerImpl::SpeechRecognitionManagerImpl() |
| 74 : can_report_metrics_(false), | 74 : can_report_metrics_(false), |
| 75 recording_caller_id_(0) { | 75 recording_session_id_(0) { |
| 76 delegate_.reset(content::GetContentClient()->browser()-> | 76 delegate_.reset(content::GetContentClient()->browser()-> |
| 77 GetSpeechRecognitionManagerDelegate()); | 77 GetSpeechRecognitionManagerDelegate()); |
| 78 } | 78 } |
| 79 | 79 |
| 80 SpeechRecognitionManagerImpl::~SpeechRecognitionManagerImpl() { | 80 SpeechRecognitionManagerImpl::~SpeechRecognitionManagerImpl() { |
| 81 while (requests_.begin() != requests_.end()) | 81 while (requests_.begin() != requests_.end()) |
| 82 CancelRecognition(requests_.begin()->first); | 82 CancelRecognition(requests_.begin()->first); |
| 83 } | 83 } |
| 84 | 84 |
| 85 bool SpeechRecognitionManagerImpl::HasAudioInputDevices() { | 85 bool SpeechRecognitionManagerImpl::HasAudioInputDevices() { |
| 86 return BrowserMainLoop::GetAudioManager()->HasAudioInputDevices(); | 86 return BrowserMainLoop::GetAudioManager()->HasAudioInputDevices(); |
| 87 } | 87 } |
| 88 | 88 |
| 89 bool SpeechRecognitionManagerImpl::IsCapturingAudio() { | 89 bool SpeechRecognitionManagerImpl::IsCapturingAudio() { |
| 90 return BrowserMainLoop::GetAudioManager()->IsRecordingInProcess(); | 90 return BrowserMainLoop::GetAudioManager()->IsRecordingInProcess(); |
| 91 } | 91 } |
| 92 | 92 |
| 93 string16 SpeechRecognitionManagerImpl::GetAudioInputDeviceModel() { | 93 string16 SpeechRecognitionManagerImpl::GetAudioInputDeviceModel() { |
| 94 return BrowserMainLoop::GetAudioManager()->GetAudioInputDeviceModel(); | 94 return BrowserMainLoop::GetAudioManager()->GetAudioInputDeviceModel(); |
| 95 } | 95 } |
| 96 | 96 |
| 97 bool SpeechRecognitionManagerImpl::HasPendingRequest(int caller_id) const { | 97 bool SpeechRecognitionManagerImpl::HasPendingRequest(int session_id) const { |
| 98 return requests_.find(caller_id) != requests_.end(); | 98 return requests_.find(session_id) != requests_.end(); |
| 99 } | 99 } |
| 100 | 100 |
| 101 InputTagSpeechDispatcherHost* SpeechRecognitionManagerImpl::GetDelegate( | 101 InputTagSpeechDispatcherHost* SpeechRecognitionManagerImpl::GetDelegate( |
| 102 int caller_id) const { | 102 int session_id) const { |
| 103 return requests_.find(caller_id)->second.delegate; | 103 return requests_.find(session_id)->second.delegate; |
| 104 } | 104 } |
| 105 | 105 |
| 106 void SpeechRecognitionManagerImpl::ShowAudioInputSettings() { | 106 void SpeechRecognitionManagerImpl::ShowAudioInputSettings() { |
| 107 // Since AudioManager::ShowAudioInputSettings can potentially launch external | 107 // Since AudioManager::ShowAudioInputSettings can potentially launch external |
| 108 // processes, do that in the FILE thread to not block the calling threads. | 108 // processes, do that in the FILE thread to not block the calling threads. |
| 109 if (!BrowserThread::CurrentlyOn(BrowserThread::FILE)) { | 109 if (!BrowserThread::CurrentlyOn(BrowserThread::FILE)) { |
| 110 BrowserThread::PostTask( | 110 BrowserThread::PostTask( |
| 111 BrowserThread::FILE, FROM_HERE, | 111 BrowserThread::FILE, FROM_HERE, |
| 112 base::Bind(&SpeechRecognitionManagerImpl::ShowAudioInputSettings, | 112 base::Bind(&SpeechRecognitionManagerImpl::ShowAudioInputSettings, |
| 113 base::Unretained(this))); | 113 base::Unretained(this))); |
| 114 return; | 114 return; |
| 115 } | 115 } |
| 116 | 116 |
| 117 media::AudioManager* audio_manager = BrowserMainLoop::GetAudioManager(); | 117 media::AudioManager* audio_manager = BrowserMainLoop::GetAudioManager(); |
| 118 DCHECK(audio_manager->CanShowAudioInputSettings()); | 118 DCHECK(audio_manager->CanShowAudioInputSettings()); |
| 119 if (audio_manager->CanShowAudioInputSettings()) | 119 if (audio_manager->CanShowAudioInputSettings()) |
| 120 audio_manager->ShowAudioInputSettings(); | 120 audio_manager->ShowAudioInputSettings(); |
| 121 } | 121 } |
| 122 | 122 |
| 123 void SpeechRecognitionManagerImpl::StartRecognition( | 123 void SpeechRecognitionManagerImpl::StartRecognition( |
| 124 InputTagSpeechDispatcherHost* delegate, | 124 InputTagSpeechDispatcherHost* delegate, |
| 125 int caller_id, | 125 int session_id, |
| 126 int render_process_id, | 126 int render_process_id, |
| 127 int render_view_id, | 127 int render_view_id, |
| 128 const gfx::Rect& element_rect, | 128 const gfx::Rect& element_rect, |
| 129 const std::string& language, | 129 const std::string& language, |
| 130 const std::string& grammar, | 130 const std::string& grammar, |
| 131 const std::string& origin_url, | 131 const std::string& origin_url, |
| 132 net::URLRequestContextGetter* context_getter, | 132 net::URLRequestContextGetter* context_getter, |
| 133 content::SpeechRecognitionPreferences* recognition_prefs) { | 133 content::SpeechRecognitionPreferences* recognition_prefs) { |
| 134 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 134 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 135 BrowserThread::PostTask( | 135 BrowserThread::PostTask( |
| 136 BrowserThread::UI, FROM_HERE, | 136 BrowserThread::UI, FROM_HERE, |
| 137 base::Bind( | 137 base::Bind( |
| 138 &SpeechRecognitionManagerImpl::CheckRenderViewTypeAndStartRecognition, | 138 &SpeechRecognitionManagerImpl::CheckRenderViewTypeAndStartRecognition, |
| 139 base::Unretained(this), | 139 base::Unretained(this), |
| 140 SpeechRecognitionParams( | 140 SpeechRecognitionParams( |
| 141 delegate, caller_id, render_process_id, render_view_id, | 141 delegate, session_id, render_process_id, render_view_id, |
| 142 element_rect, language, grammar, origin_url, context_getter, | 142 element_rect, language, grammar, origin_url, context_getter, |
| 143 recognition_prefs))); | 143 recognition_prefs))); |
| 144 } | 144 } |
| 145 | 145 |
| 146 void SpeechRecognitionManagerImpl::CheckRenderViewTypeAndStartRecognition( | 146 void SpeechRecognitionManagerImpl::CheckRenderViewTypeAndStartRecognition( |
| 147 const SpeechRecognitionParams& params) { | 147 const SpeechRecognitionParams& params) { |
| 148 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 148 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 149 | 149 |
| 150 RenderViewHostImpl* render_view_host = RenderViewHostImpl::FromID( | 150 RenderViewHostImpl* render_view_host = RenderViewHostImpl::FromID( |
| 151 params.render_process_id, params.render_view_id); | 151 params.render_process_id, params.render_view_id); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 163 BrowserThread::PostTask( | 163 BrowserThread::PostTask( |
| 164 BrowserThread::IO, FROM_HERE, | 164 BrowserThread::IO, FROM_HERE, |
| 165 base::Bind(&SpeechRecognitionManagerImpl::ProceedStartingRecognition, | 165 base::Bind(&SpeechRecognitionManagerImpl::ProceedStartingRecognition, |
| 166 base::Unretained(this), params)); | 166 base::Unretained(this), params)); |
| 167 } | 167 } |
| 168 } | 168 } |
| 169 | 169 |
| 170 void SpeechRecognitionManagerImpl::ProceedStartingRecognition( | 170 void SpeechRecognitionManagerImpl::ProceedStartingRecognition( |
| 171 const SpeechRecognitionParams& params) { | 171 const SpeechRecognitionParams& params) { |
| 172 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 172 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 173 DCHECK(!HasPendingRequest(params.caller_id)); | 173 DCHECK(!HasPendingRequest(params.session_id)); |
| 174 | 174 |
| 175 if (delegate_.get()) { | 175 if (delegate_.get()) { |
| 176 delegate_->ShowRecognitionRequested( | 176 delegate_->ShowRecognitionRequested( |
| 177 params.caller_id, params.render_process_id, params.render_view_id, | 177 params.session_id, params.render_process_id, params.render_view_id, |
| 178 params.element_rect); | 178 params.element_rect); |
| 179 delegate_->GetRequestInfo(&can_report_metrics_, &request_info_); | 179 delegate_->GetRequestInfo(&can_report_metrics_, &request_info_); |
| 180 } | 180 } |
| 181 | 181 |
| 182 Request* request = &requests_[params.caller_id]; | 182 Request* request = &requests_[params.session_id]; |
| 183 request->delegate = params.delegate; | 183 request->delegate = params.delegate; |
| 184 request->recognizer = content::SpeechRecognizer::Create( | 184 request->recognizer = content::SpeechRecognizer::Create( |
| 185 this, params.caller_id, params.language, params.grammar, | 185 this, params.session_id, params.language, params.grammar, |
| 186 params.context_getter, params.recognition_prefs->FilterProfanities(), | 186 params.context_getter, params.recognition_prefs->FilterProfanities(), |
| 187 request_info_, can_report_metrics_ ? params.origin_url : ""); | 187 request_info_, can_report_metrics_ ? params.origin_url : ""); |
| 188 request->is_active = false; | 188 request->is_active = false; |
| 189 | 189 |
| 190 StartRecognitionForRequest(params.caller_id); | 190 StartRecognitionForRequest(params.session_id); |
| 191 } | 191 } |
| 192 | 192 |
| 193 void SpeechRecognitionManagerImpl::StartRecognitionForRequest(int caller_id) { | 193 void SpeechRecognitionManagerImpl::StartRecognitionForRequest(int session_id) { |
| 194 SpeechRecognizerMap::iterator request = requests_.find(caller_id); | 194 SpeechRecognizerMap::iterator request = requests_.find(session_id); |
| 195 if (request == requests_.end()) { | 195 if (request == requests_.end()) { |
| 196 NOTREACHED(); | 196 NOTREACHED(); |
| 197 return; | 197 return; |
| 198 } | 198 } |
| 199 | 199 |
| 200 // We should not currently be recording for the caller. | 200 // We should not currently be recording for the session. |
| 201 CHECK(recording_caller_id_ != caller_id); | 201 CHECK(recording_session_id_ != session_id); |
| 202 | 202 |
| 203 // If we are currently recording audio for another caller, abort that cleanly. | 203 // If we are currently recording audio for another session, abort it cleanly. |
| 204 if (recording_caller_id_) | 204 if (recording_session_id_) |
| 205 CancelRecognitionAndInformDelegate(recording_caller_id_); | 205 CancelRecognitionAndInformDelegate(recording_session_id_); |
| 206 recording_caller_id_ = caller_id; | 206 recording_session_id_ = session_id; |
| 207 requests_[caller_id].is_active = true; | 207 requests_[session_id].is_active = true; |
| 208 requests_[caller_id].recognizer->StartRecognition(); | 208 requests_[session_id].recognizer->StartRecognition(); |
| 209 if (delegate_.get()) | 209 if (delegate_.get()) |
| 210 delegate_->ShowWarmUp(caller_id); | 210 delegate_->ShowWarmUp(session_id); |
| 211 } | 211 } |
| 212 | 212 |
| 213 void SpeechRecognitionManagerImpl::CancelRecognitionForRequest(int caller_id) { | 213 void SpeechRecognitionManagerImpl::CancelRecognitionForRequest(int session_id) { |
| 214 // Ignore if the caller id was not in our active recognizers list because the | 214 // Ignore if the session id was not in our active recognizers list because the |
| 215 // user might have clicked more than once, or recognition could have been | 215 // user might have clicked more than once, or recognition could have been |
| 216 // ended due to other reasons before the user click was processed. | 216 // ended due to other reasons before the user click was processed. |
| 217 if (!HasPendingRequest(caller_id)) | 217 if (!HasPendingRequest(session_id)) |
| 218 return; | 218 return; |
| 219 | 219 |
| 220 CancelRecognitionAndInformDelegate(caller_id); | 220 CancelRecognitionAndInformDelegate(session_id); |
| 221 } | 221 } |
| 222 | 222 |
| 223 void SpeechRecognitionManagerImpl::FocusLostForRequest(int caller_id) { | 223 void SpeechRecognitionManagerImpl::FocusLostForRequest(int session_id) { |
| 224 // See above comment. | 224 // See above comment. |
| 225 if (!HasPendingRequest(caller_id)) | 225 if (!HasPendingRequest(session_id)) |
| 226 return; | 226 return; |
| 227 | 227 |
| 228 // If this is an ongoing recording or if we were displaying an error message | 228 // If this is an ongoing recording or if we were displaying an error message |
| 229 // to the user, abort it since user has switched focus. Otherwise | 229 // to the user, abort it since user has switched focus. Otherwise |
| 230 // recognition has started and keep that going so user can start speaking to | 230 // recognition has started and keep that going so user can start speaking to |
| 231 // another element while this gets the results in parallel. | 231 // another element while this gets the results in parallel. |
| 232 if (recording_caller_id_ == caller_id || !requests_[caller_id].is_active) | 232 if (recording_session_id_ == session_id || !requests_[session_id].is_active) |
| 233 CancelRecognitionAndInformDelegate(caller_id); | 233 CancelRecognitionAndInformDelegate(session_id); |
| 234 } | 234 } |
| 235 | 235 |
| 236 void SpeechRecognitionManagerImpl::CancelRecognition(int caller_id) { | 236 void SpeechRecognitionManagerImpl::CancelRecognition(int session_id) { |
| 237 DCHECK(HasPendingRequest(caller_id)); | 237 DCHECK(HasPendingRequest(session_id)); |
| 238 if (requests_[caller_id].is_active) | 238 if (requests_[session_id].is_active) |
| 239 requests_[caller_id].recognizer->AbortRecognition(); | 239 requests_[session_id].recognizer->AbortRecognition(); |
| 240 requests_.erase(caller_id); | 240 requests_.erase(session_id); |
| 241 if (recording_caller_id_ == caller_id) | 241 if (recording_session_id_ == session_id) |
| 242 recording_caller_id_ = 0; | 242 recording_session_id_ = 0; |
| 243 if (delegate_.get()) | 243 if (delegate_.get()) |
| 244 delegate_->DoClose(caller_id); | 244 delegate_->DoClose(session_id); |
| 245 } | 245 } |
| 246 | 246 |
| 247 void SpeechRecognitionManagerImpl::CancelAllRequestsWithDelegate( | 247 void SpeechRecognitionManagerImpl::CancelAllRequestsWithDelegate( |
| 248 InputTagSpeechDispatcherHost* delegate) { | 248 InputTagSpeechDispatcherHost* delegate) { |
| 249 SpeechRecognizerMap::iterator it = requests_.begin(); | 249 SpeechRecognizerMap::iterator it = requests_.begin(); |
| 250 while (it != requests_.end()) { | 250 while (it != requests_.end()) { |
| 251 if (it->second.delegate == delegate) { | 251 if (it->second.delegate == delegate) { |
| 252 CancelRecognition(it->first); | 252 CancelRecognition(it->first); |
| 253 // This map will have very few elements so it is simpler to restart. | 253 // This map will have very few elements so it is simpler to restart. |
| 254 it = requests_.begin(); | 254 it = requests_.begin(); |
| 255 } else { | 255 } else { |
| 256 ++it; | 256 ++it; |
| 257 } | 257 } |
| 258 } | 258 } |
| 259 } | 259 } |
| 260 | 260 |
| 261 void SpeechRecognitionManagerImpl::StopRecording(int caller_id) { | 261 void SpeechRecognitionManagerImpl::StopRecording(int session_id) { |
| 262 // No pending requests on extension popups. | 262 // No pending requests on extension popups. |
| 263 if (!HasPendingRequest(caller_id)) | 263 if (!HasPendingRequest(session_id)) |
| 264 return; | 264 return; |
| 265 | 265 |
| 266 requests_[caller_id].recognizer->StopAudioCapture(); | 266 requests_[session_id].recognizer->StopAudioCapture(); |
| 267 } | 267 } |
| 268 | 268 |
| 269 // -------- SpeechRecognitionEventListener interface implementation. --------- | 269 // -------- SpeechRecognitionEventListener interface implementation. --------- |
| 270 | 270 |
| 271 void SpeechRecognitionManagerImpl::OnRecognitionResult( | 271 void SpeechRecognitionManagerImpl::OnRecognitionResult( |
| 272 int caller_id, const content::SpeechRecognitionResult& result) { | 272 int session_id, const content::SpeechRecognitionResult& result) { |
| 273 DCHECK(HasPendingRequest(caller_id)); | 273 DCHECK(HasPendingRequest(session_id)); |
| 274 GetDelegate(caller_id)->SetRecognitionResult(caller_id, result); | 274 GetDelegate(session_id)->SetRecognitionResult(session_id, result); |
| 275 } | 275 } |
| 276 | 276 |
| 277 void SpeechRecognitionManagerImpl::OnAudioEnd(int caller_id) { | 277 void SpeechRecognitionManagerImpl::OnAudioEnd(int session_id) { |
| 278 if (recording_caller_id_ != caller_id) | 278 if (recording_session_id_ != session_id) |
| 279 return; | 279 return; |
| 280 DCHECK_EQ(recording_caller_id_, caller_id); | 280 DCHECK_EQ(recording_session_id_, session_id); |
| 281 DCHECK(HasPendingRequest(caller_id)); | 281 DCHECK(HasPendingRequest(session_id)); |
| 282 if (!requests_[caller_id].is_active) | 282 if (!requests_[session_id].is_active) |
| 283 return; | 283 return; |
| 284 recording_caller_id_ = 0; | 284 recording_session_id_ = 0; |
| 285 GetDelegate(caller_id)->DidCompleteRecording(caller_id); | 285 GetDelegate(session_id)->DidCompleteRecording(session_id); |
| 286 if (delegate_.get()) | 286 if (delegate_.get()) |
| 287 delegate_->ShowRecognizing(caller_id); | 287 delegate_->ShowRecognizing(session_id); |
| 288 } | 288 } |
| 289 | 289 |
| 290 void SpeechRecognitionManagerImpl::OnRecognitionEnd(int caller_id) { | 290 void SpeechRecognitionManagerImpl::OnRecognitionEnd(int session_id) { |
| 291 if (!HasPendingRequest(caller_id) || !requests_[caller_id].is_active) | 291 if (!HasPendingRequest(session_id) || !requests_[session_id].is_active) |
| 292 return; | 292 return; |
| 293 GetDelegate(caller_id)->DidCompleteRecognition(caller_id); | 293 GetDelegate(session_id)->DidCompleteRecognition(session_id); |
| 294 requests_.erase(caller_id); | 294 requests_.erase(session_id); |
| 295 if (delegate_.get()) | 295 if (delegate_.get()) |
| 296 delegate_->DoClose(caller_id); | 296 delegate_->DoClose(session_id); |
| 297 } | 297 } |
| 298 | 298 |
| 299 void SpeechRecognitionManagerImpl::OnSoundStart(int caller_id) { | 299 void SpeechRecognitionManagerImpl::OnSoundStart(int session_id) { |
| 300 } | 300 } |
| 301 | 301 |
| 302 void SpeechRecognitionManagerImpl::OnSoundEnd(int caller_id) { | 302 void SpeechRecognitionManagerImpl::OnSoundEnd(int session_id) { |
| 303 } | 303 } |
| 304 | 304 |
| 305 void SpeechRecognitionManagerImpl::OnRecognitionError( | 305 void SpeechRecognitionManagerImpl::OnRecognitionError( |
| 306 int caller_id, const content::SpeechRecognitionError& error) { | 306 int session_id, const content::SpeechRecognitionError& error) { |
| 307 DCHECK(HasPendingRequest(caller_id)); | 307 DCHECK(HasPendingRequest(session_id)); |
| 308 if (caller_id == recording_caller_id_) | 308 if (session_id == recording_session_id_) |
| 309 recording_caller_id_ = 0; | 309 recording_session_id_ = 0; |
| 310 requests_[caller_id].is_active = false; | 310 requests_[session_id].is_active = false; |
| 311 if (delegate_.get()) { | 311 if (delegate_.get()) { |
| 312 if (error.code == content::SPEECH_RECOGNITION_ERROR_AUDIO && | 312 if (error.code == content::SPEECH_RECOGNITION_ERROR_AUDIO && |
| 313 error.details == content::SPEECH_AUDIO_ERROR_DETAILS_NO_MIC) { | 313 error.details == content::SPEECH_AUDIO_ERROR_DETAILS_NO_MIC) { |
| 314 delegate_->ShowMicError(caller_id, | 314 delegate_->ShowMicError(session_id, |
| 315 SpeechRecognitionManagerDelegate::MIC_ERROR_NO_DEVICE_AVAILABLE); | 315 SpeechRecognitionManagerDelegate::MIC_ERROR_NO_DEVICE_AVAILABLE); |
| 316 } else if (error.code == content::SPEECH_RECOGNITION_ERROR_AUDIO && | 316 } else if (error.code == content::SPEECH_RECOGNITION_ERROR_AUDIO && |
| 317 error.details == content::SPEECH_AUDIO_ERROR_DETAILS_IN_USE) { | 317 error.details == content::SPEECH_AUDIO_ERROR_DETAILS_IN_USE) { |
| 318 delegate_->ShowMicError( | 318 delegate_->ShowMicError(session_id, |
| 319 caller_id, SpeechRecognitionManagerDelegate::MIC_ERROR_DEVICE_IN_USE); | 319 SpeechRecognitionManagerDelegate::MIC_ERROR_DEVICE_IN_USE); |
| 320 } else { | 320 } else { |
| 321 delegate_->ShowRecognizerError(caller_id, error.code); | 321 delegate_->ShowRecognizerError(session_id, error.code); |
| 322 } | 322 } |
| 323 } | 323 } |
| 324 } | 324 } |
| 325 | 325 |
| 326 void SpeechRecognitionManagerImpl::OnAudioStart(int caller_id) { | 326 void SpeechRecognitionManagerImpl::OnAudioStart(int session_id) { |
| 327 DCHECK(HasPendingRequest(caller_id)); | 327 DCHECK(HasPendingRequest(session_id)); |
| 328 DCHECK_EQ(recording_caller_id_, caller_id); | 328 DCHECK_EQ(recording_session_id_, session_id); |
| 329 if (delegate_.get()) | 329 if (delegate_.get()) |
| 330 delegate_->ShowRecording(caller_id); | 330 delegate_->ShowRecording(session_id); |
| 331 } | 331 } |
| 332 | 332 |
| 333 void SpeechRecognitionManagerImpl::OnRecognitionStart(int caller_id) { | 333 void SpeechRecognitionManagerImpl::OnRecognitionStart(int session_id) { |
| 334 } | 334 } |
| 335 | 335 |
| 336 void SpeechRecognitionManagerImpl::OnEnvironmentEstimationComplete( | 336 void SpeechRecognitionManagerImpl::OnEnvironmentEstimationComplete( |
| 337 int caller_id) { | 337 int session_id) { |
| 338 DCHECK(HasPendingRequest(caller_id)); | 338 DCHECK(HasPendingRequest(session_id)); |
| 339 DCHECK_EQ(recording_caller_id_, caller_id); | 339 DCHECK_EQ(recording_session_id_, session_id); |
| 340 } | 340 } |
| 341 | 341 |
| 342 void SpeechRecognitionManagerImpl::OnAudioLevelsChange( | 342 void SpeechRecognitionManagerImpl::OnAudioLevelsChange( |
| 343 int caller_id, float volume, float noise_volume) { | 343 int session_id, float volume, float noise_volume) { |
| 344 DCHECK(HasPendingRequest(caller_id)); | 344 DCHECK(HasPendingRequest(session_id)); |
| 345 DCHECK_EQ(recording_caller_id_, caller_id); | 345 DCHECK_EQ(recording_session_id_, session_id); |
| 346 if (delegate_.get()) | 346 if (delegate_.get()) |
| 347 delegate_->ShowInputVolume(caller_id, volume, noise_volume); | 347 delegate_->ShowInputVolume(session_id, volume, noise_volume); |
| 348 } | 348 } |
| 349 | 349 |
| 350 void SpeechRecognitionManagerImpl::CancelRecognitionAndInformDelegate( | 350 void SpeechRecognitionManagerImpl::CancelRecognitionAndInformDelegate( |
| 351 int caller_id) { | 351 int session_id) { |
| 352 InputTagSpeechDispatcherHost* cur_delegate = GetDelegate(caller_id); | 352 InputTagSpeechDispatcherHost* cur_delegate = GetDelegate(session_id); |
| 353 CancelRecognition(caller_id); | 353 CancelRecognition(session_id); |
| 354 cur_delegate->DidCompleteRecording(caller_id); | 354 cur_delegate->DidCompleteRecording(session_id); |
| 355 cur_delegate->DidCompleteRecognition(caller_id); | 355 cur_delegate->DidCompleteRecognition(session_id); |
| 356 } | 356 } |
| 357 | 357 |
| 358 SpeechRecognitionManagerImpl::Request::Request() | 358 SpeechRecognitionManagerImpl::Request::Request() |
| 359 : is_active(false) { | 359 : is_active(false) { |
| 360 } | 360 } |
| 361 | 361 |
| 362 SpeechRecognitionManagerImpl::Request::~Request() { | 362 SpeechRecognitionManagerImpl::Request::~Request() { |
| 363 } | 363 } |
| 364 | 364 |
| 365 } // namespace speech | 365 } // namespace speech |
| OLD | NEW |