Chromium Code Reviews| 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/media/media_stream_manager.h" | |
| 9 #include "content/browser/speech/google_one_shot_remote_engine.h" | 10 #include "content/browser/speech/google_one_shot_remote_engine.h" |
| 10 #include "content/browser/speech/google_streaming_remote_engine.h" | 11 #include "content/browser/speech/google_streaming_remote_engine.h" |
| 11 #include "content/browser/speech/speech_recognition_engine.h" | 12 #include "content/browser/speech/speech_recognition_engine.h" |
| 12 #include "content/browser/speech/speech_recognizer.h" | 13 #include "content/browser/speech/speech_recognizer.h" |
| 13 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 14 #include "content/public/browser/content_browser_client.h" | 15 #include "content/public/browser/content_browser_client.h" |
| 15 #include "content/public/browser/resource_context.h" | 16 #include "content/public/browser/resource_context.h" |
| 16 #include "content/public/browser/speech_recognition_event_listener.h" | 17 #include "content/public/browser/speech_recognition_event_listener.h" |
| 17 #include "content/public/browser/speech_recognition_manager_delegate.h" | 18 #include "content/public/browser/speech_recognition_manager_delegate.h" |
| 18 #include "content/public/browser/speech_recognition_session_config.h" | 19 #include "content/public/browser/speech_recognition_session_config.h" |
| 19 #include "content/public/browser/speech_recognition_session_context.h" | 20 #include "content/public/browser/speech_recognition_session_context.h" |
| 21 #include "content/public/common/speech_recognition_error.h" | |
| 20 #include "content/public/common/speech_recognition_result.h" | 22 #include "content/public/common/speech_recognition_result.h" |
| 21 #include "media/audio/audio_manager.h" | 23 #include "media/audio/audio_manager.h" |
| 22 | 24 |
| 23 using base::Callback; | 25 using base::Callback; |
| 24 using content::BrowserMainLoop; | 26 using content::BrowserMainLoop; |
| 25 using content::BrowserThread; | 27 using content::BrowserThread; |
| 26 using content::SpeechRecognitionError; | |
| 27 using content::SpeechRecognitionEventListener; | 28 using content::SpeechRecognitionEventListener; |
| 28 using content::SpeechRecognitionManager; | 29 using content::SpeechRecognitionManager; |
| 29 using content::SpeechRecognitionResult; | 30 using content::SpeechRecognitionResult; |
| 30 using content::SpeechRecognitionSessionContext; | 31 using content::SpeechRecognitionSessionContext; |
| 31 using content::SpeechRecognitionSessionConfig; | 32 using content::SpeechRecognitionSessionConfig; |
| 32 | 33 |
| 33 namespace content { | 34 namespace content { |
| 34 SpeechRecognitionManager* SpeechRecognitionManager::GetInstance() { | 35 SpeechRecognitionManager* SpeechRecognitionManager::GetInstance() { |
| 35 return speech::SpeechRecognitionManagerImpl::GetInstance(); | 36 return speech::SpeechRecognitionManagerImpl::GetInstance(); |
| 36 } | 37 } |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 48 } | 49 } |
| 49 } // namespace | 50 } // namespace |
| 50 | 51 |
| 51 namespace speech { | 52 namespace speech { |
| 52 | 53 |
| 53 SpeechRecognitionManagerImpl* SpeechRecognitionManagerImpl::GetInstance() { | 54 SpeechRecognitionManagerImpl* SpeechRecognitionManagerImpl::GetInstance() { |
| 54 return g_speech_recognition_manager_impl; | 55 return g_speech_recognition_manager_impl; |
| 55 } | 56 } |
| 56 | 57 |
| 57 SpeechRecognitionManagerImpl::SpeechRecognitionManagerImpl() | 58 SpeechRecognitionManagerImpl::SpeechRecognitionManagerImpl() |
| 58 : session_id_capturing_audio_(kSessionIDInvalid), | 59 : primary_session_id_(kSessionIDInvalid), |
| 59 last_session_id_(kSessionIDInvalid), | 60 last_session_id_(kSessionIDInvalid), |
| 60 is_dispatching_event_(false), | 61 is_dispatching_event_(false), |
| 61 delegate_(content::GetContentClient()->browser()-> | 62 delegate_(content::GetContentClient()->browser()-> |
| 62 GetSpeechRecognitionManagerDelegate()), | 63 GetSpeechRecognitionManagerDelegate()), |
| 63 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { | 64 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
| 64 DCHECK(!g_speech_recognition_manager_impl); | 65 DCHECK(!g_speech_recognition_manager_impl); |
| 65 g_speech_recognition_manager_impl = this; | 66 g_speech_recognition_manager_impl = this; |
| 66 } | 67 } |
| 67 | 68 |
| 68 SpeechRecognitionManagerImpl::~SpeechRecognitionManagerImpl() { | 69 SpeechRecognitionManagerImpl::~SpeechRecognitionManagerImpl() { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 117 google_remote_engine); | 118 google_remote_engine); |
| 118 return session_id; | 119 return session_id; |
| 119 } | 120 } |
| 120 | 121 |
| 121 void SpeechRecognitionManagerImpl::StartSession(int session_id) { | 122 void SpeechRecognitionManagerImpl::StartSession(int session_id) { |
| 122 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 123 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 123 if (!SessionExists(session_id)) | 124 if (!SessionExists(session_id)) |
| 124 return; | 125 return; |
| 125 | 126 |
| 126 // If there is another active session, abort that. | 127 // If there is another active session, abort that. |
| 127 if (session_id_capturing_audio_ != kSessionIDInvalid && | 128 if (primary_session_id_ != kSessionIDInvalid && |
| 128 session_id_capturing_audio_ != session_id) { | 129 primary_session_id_ != session_id) { |
| 129 AbortSession(session_id_capturing_audio_); | 130 AbortSession(primary_session_id_); |
| 130 } | 131 } |
| 131 | 132 |
| 132 if (delegate_.get()) | 133 primary_session_id_ = session_id; |
| 134 | |
| 135 if (delegate_.get()) { | |
| 136 sessions_[session_id].is_waiting_for_permission = true; | |
| 133 delegate_->CheckRecognitionIsAllowed( | 137 delegate_->CheckRecognitionIsAllowed( |
| 134 session_id, | 138 session_id, |
| 135 base::Bind(&SpeechRecognitionManagerImpl::RecognitionAllowedCallback, | 139 base::Bind(&SpeechRecognitionManagerImpl::RecognitionAllowedCallback, |
| 136 weak_factory_.GetWeakPtr())); | 140 weak_factory_.GetWeakPtr(), |
| 141 session_id)); | |
| 142 } | |
| 137 } | 143 } |
| 138 | 144 |
| 139 void SpeechRecognitionManagerImpl::RecognitionAllowedCallback(int session_id, | 145 void SpeechRecognitionManagerImpl::RecognitionAllowedCallback(int session_id, |
| 146 bool ask_user, | |
| 140 bool is_allowed) { | 147 bool is_allowed) { |
| 141 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 148 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 142 DCHECK(SessionExists(session_id)); | 149 DCHECK(SessionExists(session_id)); |
|
Satish
2012/09/12 06:15:09
this is not new code, but is it possible that in t
hans
2012/09/12 09:46:58
Done.
| |
| 150 | |
| 151 if (ask_user) { | |
| 152 media_stream::MediaStreamManager* media_stream_manager = | |
| 153 BrowserMainLoop::GetMediaStreamManager(); | |
| 154 | |
| 155 const SpeechRecognitionSessionContext& context = | |
| 156 GetSessionContext(session_id); | |
| 157 | |
| 158 permission_request_.reset(new PermissionRequest( | |
| 159 media_stream_manager, | |
| 160 base::Bind(&SpeechRecognitionManagerImpl::RecognitionAllowedCallback, | |
| 161 weak_factory_.GetWeakPtr(), | |
| 162 session_id, | |
| 163 false))); | |
| 164 | |
| 165 permission_request_->Start(context.render_process_id, | |
| 166 context.render_view_id, | |
| 167 GURL(context.context_name)); | |
| 168 | |
| 169 return; | |
| 170 } | |
| 171 | |
| 172 sessions_[session_id].is_waiting_for_permission = false; | |
| 173 | |
| 143 if (is_allowed) { | 174 if (is_allowed) { |
| 144 MessageLoop::current()->PostTask(FROM_HERE, | 175 MessageLoop::current()->PostTask(FROM_HERE, |
| 145 base::Bind(&SpeechRecognitionManagerImpl::DispatchEvent, | 176 base::Bind(&SpeechRecognitionManagerImpl::DispatchEvent, |
| 146 weak_factory_.GetWeakPtr(), session_id, EVENT_START)); | 177 weak_factory_.GetWeakPtr(), session_id, EVENT_START)); |
| 147 } else { | 178 } else { |
| 148 sessions_.erase(session_id); | 179 OnRecognitionError(session_id, content::SpeechRecognitionError( |
| 180 content::SPEECH_RECOGNITION_ERROR_NOT_ALLOWED)); | |
| 181 MessageLoop::current()->PostTask(FROM_HERE, | |
| 182 base::Bind(&SpeechRecognitionManagerImpl::DispatchEvent, | |
| 183 weak_factory_.GetWeakPtr(), session_id, EVENT_ABORT)); | |
| 149 } | 184 } |
| 150 } | 185 } |
| 151 | 186 |
| 152 void SpeechRecognitionManagerImpl::AbortSession(int session_id) { | 187 void SpeechRecognitionManagerImpl::AbortSession(int session_id) { |
| 153 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 188 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 154 if (!SessionExists(session_id)) | 189 if (!SessionExists(session_id)) |
| 155 return; | 190 return; |
| 156 | 191 |
| 192 if (GetSession(session_id).is_waiting_for_permission) { | |
| 193 DCHECK(permission_request_.get()); | |
| 194 permission_request_->Abort(); | |
| 195 } | |
| 196 | |
| 157 MessageLoop::current()->PostTask(FROM_HERE, | 197 MessageLoop::current()->PostTask(FROM_HERE, |
| 158 base::Bind(&SpeechRecognitionManagerImpl::DispatchEvent, | 198 base::Bind(&SpeechRecognitionManagerImpl::DispatchEvent, |
| 159 weak_factory_.GetWeakPtr(), session_id, EVENT_ABORT)); | 199 weak_factory_.GetWeakPtr(), session_id, EVENT_ABORT)); |
| 160 } | 200 } |
| 161 | 201 |
| 162 void SpeechRecognitionManagerImpl::StopAudioCaptureForSession(int session_id) { | 202 void SpeechRecognitionManagerImpl::StopAudioCaptureForSession(int session_id) { |
| 163 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 203 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 164 if (!SessionExists(session_id)) | 204 if (!SessionExists(session_id)) |
| 165 return; | 205 return; |
| 166 | 206 |
| 207 if (GetSession(session_id).is_waiting_for_permission) { | |
| 208 DCHECK(permission_request_.get()); | |
| 209 permission_request_->Abort(); | |
| 210 } | |
| 211 | |
| 167 MessageLoop::current()->PostTask(FROM_HERE, | 212 MessageLoop::current()->PostTask(FROM_HERE, |
| 168 base::Bind(&SpeechRecognitionManagerImpl::DispatchEvent, | 213 base::Bind(&SpeechRecognitionManagerImpl::DispatchEvent, |
| 169 weak_factory_.GetWeakPtr(), session_id, EVENT_STOP_CAPTURE)); | 214 weak_factory_.GetWeakPtr(), session_id, EVENT_STOP_CAPTURE)); |
| 170 } | 215 } |
| 171 | 216 |
| 172 // Here begins the SpeechRecognitionEventListener interface implementation, | 217 // Here begins the SpeechRecognitionEventListener interface implementation, |
| 173 // which will simply relay the events to the proper listener registered for the | 218 // which will simply relay the events to the proper listener registered for the |
| 174 // particular session (most likely InputTagSpeechDispatcherHost) and to the | 219 // particular session (most likely InputTagSpeechDispatcherHost) and to the |
| 175 // catch-all listener provided by the delegate (if any). | 220 // catch-all listener provided by the delegate (if any). |
| 176 | 221 |
| 177 void SpeechRecognitionManagerImpl::OnRecognitionStart(int session_id) { | 222 void SpeechRecognitionManagerImpl::OnRecognitionStart(int session_id) { |
| 178 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 223 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 179 if (!SessionExists(session_id)) | 224 if (!SessionExists(session_id)) |
| 180 return; | 225 return; |
| 181 | 226 |
| 182 DCHECK_EQ(session_id_capturing_audio_, session_id); | 227 DCHECK_EQ(primary_session_id_, session_id); |
| 183 if (SpeechRecognitionEventListener* delegate_listener = GetDelegateListener()) | 228 if (SpeechRecognitionEventListener* delegate_listener = GetDelegateListener()) |
| 184 delegate_listener->OnRecognitionStart(session_id); | 229 delegate_listener->OnRecognitionStart(session_id); |
| 185 if (SpeechRecognitionEventListener* listener = GetListener(session_id)) | 230 if (SpeechRecognitionEventListener* listener = GetListener(session_id)) |
| 186 listener->OnRecognitionStart(session_id); | 231 listener->OnRecognitionStart(session_id); |
| 187 } | 232 } |
| 188 | 233 |
| 189 void SpeechRecognitionManagerImpl::OnAudioStart(int session_id) { | 234 void SpeechRecognitionManagerImpl::OnAudioStart(int session_id) { |
| 190 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 235 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 191 if (!SessionExists(session_id)) | 236 if (!SessionExists(session_id)) |
| 192 return; | 237 return; |
| 193 | 238 |
| 194 DCHECK_EQ(session_id_capturing_audio_, session_id); | 239 DCHECK_EQ(primary_session_id_, session_id); |
| 195 if (SpeechRecognitionEventListener* delegate_listener = GetDelegateListener()) | 240 if (SpeechRecognitionEventListener* delegate_listener = GetDelegateListener()) |
| 196 delegate_listener->OnAudioStart(session_id); | 241 delegate_listener->OnAudioStart(session_id); |
| 197 if (SpeechRecognitionEventListener* listener = GetListener(session_id)) | 242 if (SpeechRecognitionEventListener* listener = GetListener(session_id)) |
| 198 listener->OnAudioStart(session_id); | 243 listener->OnAudioStart(session_id); |
| 199 } | 244 } |
| 200 | 245 |
| 201 void SpeechRecognitionManagerImpl::OnEnvironmentEstimationComplete( | 246 void SpeechRecognitionManagerImpl::OnEnvironmentEstimationComplete( |
| 202 int session_id) { | 247 int session_id) { |
| 203 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 248 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 204 if (!SessionExists(session_id)) | 249 if (!SessionExists(session_id)) |
| 205 return; | 250 return; |
| 206 | 251 |
| 207 DCHECK_EQ(session_id_capturing_audio_, session_id); | 252 DCHECK_EQ(primary_session_id_, session_id); |
| 208 if (SpeechRecognitionEventListener* delegate_listener = GetDelegateListener()) | 253 if (SpeechRecognitionEventListener* delegate_listener = GetDelegateListener()) |
| 209 delegate_listener->OnEnvironmentEstimationComplete(session_id); | 254 delegate_listener->OnEnvironmentEstimationComplete(session_id); |
| 210 if (SpeechRecognitionEventListener* listener = GetListener(session_id)) | 255 if (SpeechRecognitionEventListener* listener = GetListener(session_id)) |
| 211 listener->OnEnvironmentEstimationComplete(session_id); | 256 listener->OnEnvironmentEstimationComplete(session_id); |
| 212 } | 257 } |
| 213 | 258 |
| 214 void SpeechRecognitionManagerImpl::OnSoundStart(int session_id) { | 259 void SpeechRecognitionManagerImpl::OnSoundStart(int session_id) { |
| 215 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 260 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 216 if (!SessionExists(session_id)) | 261 if (!SessionExists(session_id)) |
| 217 return; | 262 return; |
| 218 | 263 |
| 219 DCHECK_EQ(session_id_capturing_audio_, session_id); | 264 DCHECK_EQ(primary_session_id_, session_id); |
| 220 if (SpeechRecognitionEventListener* delegate_listener = GetDelegateListener()) | 265 if (SpeechRecognitionEventListener* delegate_listener = GetDelegateListener()) |
| 221 delegate_listener->OnSoundStart(session_id); | 266 delegate_listener->OnSoundStart(session_id); |
| 222 if (SpeechRecognitionEventListener* listener = GetListener(session_id)) | 267 if (SpeechRecognitionEventListener* listener = GetListener(session_id)) |
| 223 listener->OnSoundStart(session_id); | 268 listener->OnSoundStart(session_id); |
| 224 } | 269 } |
| 225 | 270 |
| 226 void SpeechRecognitionManagerImpl::OnSoundEnd(int session_id) { | 271 void SpeechRecognitionManagerImpl::OnSoundEnd(int session_id) { |
| 227 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 272 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 228 if (!SessionExists(session_id)) | 273 if (!SessionExists(session_id)) |
| 229 return; | 274 return; |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 389 // completed the transition from CAPTURING_AUDIO to WAITING_FOR_RESULT, thus | 434 // completed the transition from CAPTURING_AUDIO to WAITING_FOR_RESULT, thus |
| 390 // we perceive the AUDIO_ENDED event in WAITING_FOR_RESULT). | 435 // we perceive the AUDIO_ENDED event in WAITING_FOR_RESULT). |
| 391 // This makes the code below a bit tricky but avoids a lot of code for | 436 // This makes the code below a bit tricky but avoids a lot of code for |
| 392 // tracking and reconstructing asynchronously the state of the recognizer. | 437 // tracking and reconstructing asynchronously the state of the recognizer. |
| 393 switch (session_state) { | 438 switch (session_state) { |
| 394 case SESSION_STATE_IDLE: | 439 case SESSION_STATE_IDLE: |
| 395 switch (event) { | 440 switch (event) { |
| 396 case EVENT_START: | 441 case EVENT_START: |
| 397 return SessionStart(session); | 442 return SessionStart(session); |
| 398 case EVENT_ABORT: | 443 case EVENT_ABORT: |
| 444 return SessionAbort(session); | |
| 399 case EVENT_RECOGNITION_ENDED: | 445 case EVENT_RECOGNITION_ENDED: |
| 400 return SessionDelete(session); | 446 return SessionDelete(session); |
| 401 case EVENT_STOP_CAPTURE: | 447 case EVENT_STOP_CAPTURE: |
| 448 return SessionStopAudioCapture(session); | |
| 402 case EVENT_AUDIO_ENDED: | 449 case EVENT_AUDIO_ENDED: |
| 403 return; | 450 return; |
| 404 } | 451 } |
| 405 break; | 452 break; |
| 406 case SESSION_STATE_CAPTURING_AUDIO: | 453 case SESSION_STATE_CAPTURING_AUDIO: |
| 407 switch (event) { | 454 switch (event) { |
| 408 case EVENT_STOP_CAPTURE: | 455 case EVENT_STOP_CAPTURE: |
| 409 return SessionStopAudioCapture(session); | 456 return SessionStopAudioCapture(session); |
| 410 case EVENT_ABORT: | 457 case EVENT_ABORT: |
| 411 return SessionAbort(session); | 458 return SessionAbort(session); |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 441 if (session.recognizer->IsCapturingAudio()) | 488 if (session.recognizer->IsCapturingAudio()) |
| 442 return SESSION_STATE_CAPTURING_AUDIO; | 489 return SESSION_STATE_CAPTURING_AUDIO; |
| 443 return SESSION_STATE_WAITING_FOR_RESULT; | 490 return SESSION_STATE_WAITING_FOR_RESULT; |
| 444 } | 491 } |
| 445 | 492 |
| 446 // ----------- Contract for all the FSM evolution functions below ------------- | 493 // ----------- Contract for all the FSM evolution functions below ------------- |
| 447 // - Are guaranteed to be executed in the IO thread; | 494 // - Are guaranteed to be executed in the IO thread; |
| 448 // - Are guaranteed to be not reentrant (themselves and each other); | 495 // - Are guaranteed to be not reentrant (themselves and each other); |
| 449 | 496 |
| 450 void SpeechRecognitionManagerImpl::SessionStart(const Session& session) { | 497 void SpeechRecognitionManagerImpl::SessionStart(const Session& session) { |
| 451 session_id_capturing_audio_ = session.id; | 498 DCHECK_EQ(primary_session_id_, session.id); |
| 452 session.recognizer->StartRecognition(); | 499 session.recognizer->StartRecognition(); |
| 453 } | 500 } |
| 454 | 501 |
| 455 void SpeechRecognitionManagerImpl::SessionAbort(const Session& session) { | 502 void SpeechRecognitionManagerImpl::SessionAbort(const Session& session) { |
| 456 if (session_id_capturing_audio_ == session.id) | 503 if (primary_session_id_ == session.id) |
| 457 session_id_capturing_audio_ = kSessionIDInvalid; | 504 primary_session_id_ = kSessionIDInvalid; |
| 458 DCHECK(session.recognizer.get() && session.recognizer->IsActive()); | 505 DCHECK(session.recognizer.get()); |
| 459 session.recognizer->AbortRecognition(); | 506 session.recognizer->AbortRecognition(); |
| 460 } | 507 } |
| 461 | 508 |
| 462 void SpeechRecognitionManagerImpl::SessionStopAudioCapture( | 509 void SpeechRecognitionManagerImpl::SessionStopAudioCapture( |
| 463 const Session& session) { | 510 const Session& session) { |
| 464 DCHECK(session.recognizer.get() && session.recognizer->IsCapturingAudio()); | 511 DCHECK(session.recognizer.get()); |
|
Satish
2012/09/12 06:15:09
why was the second condition removed?
hans
2012/09/12 09:46:58
Because it's possible to stop or abort a session w
| |
| 465 session.recognizer->StopAudioCapture(); | 512 session.recognizer->StopAudioCapture(); |
| 466 } | 513 } |
| 467 | 514 |
| 468 void SpeechRecognitionManagerImpl::ResetCapturingSessionId( | 515 void SpeechRecognitionManagerImpl::ResetCapturingSessionId( |
| 469 const Session& session) { | 516 const Session& session) { |
| 470 DCHECK_EQ(session_id_capturing_audio_, session.id); | 517 DCHECK_EQ(primary_session_id_, session.id); |
| 471 session_id_capturing_audio_ = kSessionIDInvalid; | 518 primary_session_id_ = kSessionIDInvalid; |
| 472 } | 519 } |
| 473 | 520 |
| 474 void SpeechRecognitionManagerImpl::SessionDelete(const Session& session) { | 521 void SpeechRecognitionManagerImpl::SessionDelete(const Session& session) { |
| 475 DCHECK(session.recognizer == NULL || !session.recognizer->IsActive()); | 522 DCHECK(session.recognizer == NULL || !session.recognizer->IsActive()); |
| 476 if (session_id_capturing_audio_ == session.id) | 523 if (primary_session_id_ == session.id) |
| 477 session_id_capturing_audio_ = kSessionIDInvalid; | 524 primary_session_id_ = kSessionIDInvalid; |
| 478 sessions_.erase(session.id); | 525 sessions_.erase(session.id); |
| 479 } | 526 } |
| 480 | 527 |
| 481 void SpeechRecognitionManagerImpl::NotFeasible(const Session& session, | 528 void SpeechRecognitionManagerImpl::NotFeasible(const Session& session, |
| 482 FSMEvent event) { | 529 FSMEvent event) { |
| 483 NOTREACHED() << "Unfeasible event " << event | 530 NOTREACHED() << "Unfeasible event " << event |
| 484 << " in state " << GetSessionState(session.id) | 531 << " in state " << GetSessionState(session.id) |
| 485 << " for session " << session.id; | 532 << " for session " << session.id; |
| 486 } | 533 } |
| 487 | 534 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 535 | 582 |
| 536 void SpeechRecognitionManagerImpl::ShowAudioInputSettings() { | 583 void SpeechRecognitionManagerImpl::ShowAudioInputSettings() { |
| 537 // Since AudioManager::ShowAudioInputSettings can potentially launch external | 584 // Since AudioManager::ShowAudioInputSettings can potentially launch external |
| 538 // processes, do that in the FILE thread to not block the calling threads. | 585 // processes, do that in the FILE thread to not block the calling threads. |
| 539 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 586 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 540 base::Bind(&ShowAudioInputSettingsOnFileThread)); | 587 base::Bind(&ShowAudioInputSettingsOnFileThread)); |
| 541 } | 588 } |
| 542 | 589 |
| 543 SpeechRecognitionManagerImpl::Session::Session() | 590 SpeechRecognitionManagerImpl::Session::Session() |
| 544 : id(kSessionIDInvalid), | 591 : id(kSessionIDInvalid), |
| 545 listener_is_active(true) { | 592 listener_is_active(true), |
| 593 is_waiting_for_permission(false) { | |
| 546 } | 594 } |
| 547 | 595 |
| 548 SpeechRecognitionManagerImpl::Session::~Session() { | 596 SpeechRecognitionManagerImpl::Session::~Session() { |
| 549 } | 597 } |
| 550 | 598 |
| 599 SpeechRecognitionManagerImpl::PermissionRequest::PermissionRequest( | |
| 600 media_stream::MediaStreamManager* media_stream_manager, | |
| 601 const base::Callback<void(bool is_allowed)>& callback) | |
| 602 : media_stream_manager_(media_stream_manager), | |
|
Satish
2012/09/12 06:15:09
indent to right by 2 spaces
hans
2012/09/12 09:46:58
This line got moved, and I think I got it right in
| |
| 603 callback_(callback) { | |
| 604 } | |
| 605 | |
| 606 SpeechRecognitionManagerImpl::PermissionRequest::~PermissionRequest() { | |
| 607 } | |
| 608 | |
| 609 void SpeechRecognitionManagerImpl::PermissionRequest::Start( | |
| 610 int render_process_id, int render_view_id, const GURL& origin) { | |
| 611 media_stream_manager_->GenerateStream( | |
|
Satish
2012/09/12 06:15:09
these method names don't seem to make sense when c
hans
2012/09/12 09:46:58
MediaStream does not have a convenient way of just
Satish
2012/09/12 13:51:38
xians/tommyw, any thoughts on this? Can the infoba
| |
| 612 this, | |
| 613 render_process_id, | |
| 614 render_view_id, | |
| 615 media_stream::StreamOptions(/*audio=*/true, /*video=*/false), | |
| 616 origin, | |
| 617 &label_); | |
| 618 } | |
| 619 | |
| 620 void SpeechRecognitionManagerImpl::PermissionRequest::Abort() { | |
| 621 media_stream_manager_->CancelGenerateStream(label_); | |
|
Satish
2012/09/12 06:15:09
ditto
| |
| 622 } | |
| 623 | |
| 624 void SpeechRecognitionManagerImpl::PermissionRequest::StreamGenerated( | |
| 625 const std::string& label, | |
| 626 const media_stream::StreamDeviceInfoArray& audio_devices, | |
| 627 const media_stream::StreamDeviceInfoArray& video_devices) { | |
| 628 | |
|
Satish
2012/09/12 06:15:09
remove empty line
hans
2012/09/12 09:46:58
Done.
| |
| 629 // TODO(hans): One day it would be nice to actually use the generated stream, | |
| 630 // but right now we only use it to request permission, and then we dump it. | |
| 631 BrowserThread::PostTask( | |
| 632 BrowserThread::IO, | |
| 633 FROM_HERE, | |
| 634 base::Bind(&media_stream::MediaStreamManager::StopGeneratedStream, | |
| 635 base::Unretained(media_stream_manager_), | |
| 636 label)); | |
| 637 callback_.Run(true); | |
| 638 } | |
| 639 | |
| 640 void SpeechRecognitionManagerImpl::PermissionRequest::StreamGenerationFailed( | |
| 641 const std::string& label) { | |
| 642 callback_.Run(false); | |
| 643 } | |
| 644 | |
| 551 } // namespace speech | 645 } // namespace speech |
| OLD | NEW |