| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/media/media_stream_manager.h" | 9 #include "content/browser/renderer_host/media/media_stream_manager.h" |
| 10 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" | 10 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 } | 177 } |
| 178 } | 178 } |
| 179 | 179 |
| 180 void SpeechRecognitionManagerImpl::RecognitionAllowedCallback(int session_id, | 180 void SpeechRecognitionManagerImpl::RecognitionAllowedCallback(int session_id, |
| 181 bool ask_user, | 181 bool ask_user, |
| 182 bool is_allowed) { | 182 bool is_allowed) { |
| 183 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 183 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 184 if (!SessionExists(session_id)) | 184 if (!SessionExists(session_id)) |
| 185 return; | 185 return; |
| 186 | 186 |
| 187 SessionsTable::iterator iter = sessions_.find(session_id); |
| 188 DCHECK(iter != sessions_.end()); |
| 189 Session* session = iter->second; |
| 190 |
| 191 if (session->abort_requested) |
| 192 return; |
| 193 |
| 187 if (ask_user) { | 194 if (ask_user) { |
| 188 SessionsTable::iterator iter = sessions_.find(session_id); | 195 SpeechRecognitionSessionContext& context = session->context; |
| 189 DCHECK(iter != sessions_.end()); | |
| 190 SpeechRecognitionSessionContext& context = iter->second->context; | |
| 191 context.label = media_stream_manager_->MakeMediaAccessRequest( | 196 context.label = media_stream_manager_->MakeMediaAccessRequest( |
| 192 context.render_process_id, | 197 context.render_process_id, |
| 193 context.render_view_id, | 198 context.render_view_id, |
| 194 context.request_id, | 199 context.request_id, |
| 195 StreamOptions(MEDIA_DEVICE_AUDIO_CAPTURE, MEDIA_NO_SERVICE), | 200 StreamOptions(MEDIA_DEVICE_AUDIO_CAPTURE, MEDIA_NO_SERVICE), |
| 196 GURL(context.context_name), | 201 GURL(context.context_name), |
| 197 base::Bind( | 202 base::Bind( |
| 198 &SpeechRecognitionManagerImpl::MediaRequestPermissionCallback, | 203 &SpeechRecognitionManagerImpl::MediaRequestPermissionCallback, |
| 199 weak_factory_.GetWeakPtr(), session_id)); | 204 weak_factory_.GetWeakPtr(), session_id)); |
| 200 return; | 205 return; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 } | 251 } |
| 247 | 252 |
| 248 void SpeechRecognitionManagerImpl::AbortSession(int session_id) { | 253 void SpeechRecognitionManagerImpl::AbortSession(int session_id) { |
| 249 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 254 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 250 if (!SessionExists(session_id)) | 255 if (!SessionExists(session_id)) |
| 251 return; | 256 return; |
| 252 | 257 |
| 253 SessionsTable::iterator iter = sessions_.find(session_id); | 258 SessionsTable::iterator iter = sessions_.find(session_id); |
| 254 iter->second->ui.reset(); | 259 iter->second->ui.reset(); |
| 255 | 260 |
| 261 if (iter->second->abort_requested) |
| 262 return; |
| 263 |
| 264 iter->second->abort_requested = true; |
| 265 |
| 256 base::MessageLoop::current()->PostTask( | 266 base::MessageLoop::current()->PostTask( |
| 257 FROM_HERE, | 267 FROM_HERE, |
| 258 base::Bind(&SpeechRecognitionManagerImpl::DispatchEvent, | 268 base::Bind(&SpeechRecognitionManagerImpl::DispatchEvent, |
| 259 weak_factory_.GetWeakPtr(), | 269 weak_factory_.GetWeakPtr(), |
| 260 session_id, | 270 session_id, |
| 261 EVENT_ABORT)); | 271 EVENT_ABORT)); |
| 262 } | 272 } |
| 263 | 273 |
| 264 void SpeechRecognitionManagerImpl::StopAudioCaptureForSession(int session_id) { | 274 void SpeechRecognitionManagerImpl::StopAudioCaptureForSession(int session_id) { |
| 265 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 275 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| (...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 669 void SpeechRecognitionManagerImpl::ShowAudioInputSettings() { | 679 void SpeechRecognitionManagerImpl::ShowAudioInputSettings() { |
| 670 // Since AudioManager::ShowAudioInputSettings can potentially launch external | 680 // Since AudioManager::ShowAudioInputSettings can potentially launch external |
| 671 // processes, do that in the FILE thread to not block the calling threads. | 681 // processes, do that in the FILE thread to not block the calling threads. |
| 672 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 682 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 673 base::Bind(&ShowAudioInputSettingsOnFileThread, | 683 base::Bind(&ShowAudioInputSettingsOnFileThread, |
| 674 audio_manager_)); | 684 audio_manager_)); |
| 675 } | 685 } |
| 676 | 686 |
| 677 SpeechRecognitionManagerImpl::Session::Session() | 687 SpeechRecognitionManagerImpl::Session::Session() |
| 678 : id(kSessionIDInvalid), | 688 : id(kSessionIDInvalid), |
| 689 abort_requested(false), |
| 679 listener_is_active(true) { | 690 listener_is_active(true) { |
| 680 } | 691 } |
| 681 | 692 |
| 682 SpeechRecognitionManagerImpl::Session::~Session() { | 693 SpeechRecognitionManagerImpl::Session::~Session() { |
| 683 } | 694 } |
| 684 | 695 |
| 685 } // namespace content | 696 } // namespace content |
| OLD | NEW |