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 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 listener->OnRecognitionEnd(session_id); | 427 listener->OnRecognitionEnd(session_id); |
428 base::MessageLoop::current()->PostTask( | 428 base::MessageLoop::current()->PostTask( |
429 FROM_HERE, | 429 FROM_HERE, |
430 base::Bind(&SpeechRecognitionManagerImpl::DispatchEvent, | 430 base::Bind(&SpeechRecognitionManagerImpl::DispatchEvent, |
431 weak_factory_.GetWeakPtr(), | 431 weak_factory_.GetWeakPtr(), |
432 session_id, | 432 session_id, |
433 EVENT_RECOGNITION_ENDED)); | 433 EVENT_RECOGNITION_ENDED)); |
434 } | 434 } |
435 | 435 |
436 int SpeechRecognitionManagerImpl::GetSession( | 436 int SpeechRecognitionManagerImpl::GetSession( |
437 int render_process_id, int render_view_id, int request_id) const { | 437 int render_process_id, int render_frame_id, int request_id) const { |
438 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 438 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
439 SessionsTable::const_iterator iter; | 439 |
440 for (iter = sessions_.begin(); iter != sessions_.end(); ++iter) { | 440 for (const auto& it : sessions_) { |
441 const int session_id = iter->first; | 441 Session* session = it.second; |
442 const SpeechRecognitionSessionContext& context = iter->second->context; | 442 if (session->context.render_process_id == render_process_id && |
443 if (context.render_process_id == render_process_id && | 443 session->context.render_frame_id == render_frame_id && |
444 context.render_view_id == render_view_id && | 444 session->context.request_id == request_id) { |
445 context.request_id == request_id) { | 445 return session->id; |
446 return session_id; | |
447 } | 446 } |
448 } | 447 } |
| 448 |
449 return kSessionIDInvalid; | 449 return kSessionIDInvalid; |
450 } | 450 } |
451 | 451 |
452 SpeechRecognitionSessionContext | 452 SpeechRecognitionSessionContext |
453 SpeechRecognitionManagerImpl::GetSessionContext(int session_id) const { | 453 SpeechRecognitionManagerImpl::GetSessionContext(int session_id) const { |
454 return GetSession(session_id)->context; | 454 return GetSession(session_id)->context; |
455 } | 455 } |
456 | 456 |
457 void SpeechRecognitionManagerImpl::AbortAllSessionsForRenderProcess( | 457 void SpeechRecognitionManagerImpl::AbortAllSessionsForRenderFrame( |
458 int render_process_id) { | 458 int render_process_id, int render_frame_id) { |
459 // This method gracefully destroys sessions for the listener. However, since | 459 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
460 // the listener itself is likely to be destroyed after this call, we avoid | |
461 // dispatching further events to it, marking the |listener_is_active| flag. | |
462 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
463 for (SessionsTable::iterator it = sessions_.begin(); it != sessions_.end(); | |
464 ++it) { | |
465 Session* session = it->second; | |
466 if (session->context.render_process_id == render_process_id) { | |
467 AbortSession(session->id); | |
468 session->listener_is_active = false; | |
469 } | |
470 } | |
471 } | |
472 | 460 |
473 void SpeechRecognitionManagerImpl::AbortAllSessionsForRenderView( | 461 for (const auto& it : sessions_) { |
474 int render_process_id, | 462 Session* session = it.second; |
475 int render_view_id) { | |
476 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
477 for (SessionsTable::iterator it = sessions_.begin(); it != sessions_.end(); | |
478 ++it) { | |
479 Session* session = it->second; | |
480 if (session->context.render_process_id == render_process_id && | 463 if (session->context.render_process_id == render_process_id && |
481 session->context.render_view_id == render_view_id) { | 464 session->context.render_frame_id == render_frame_id) { |
482 AbortSession(session->id); | 465 AbortSession(session->id); |
483 } | 466 } |
484 } | 467 } |
485 } | 468 } |
486 | 469 |
487 // ----------------------- Core FSM implementation --------------------------- | 470 // ----------------------- Core FSM implementation --------------------------- |
488 void SpeechRecognitionManagerImpl::DispatchEvent(int session_id, | 471 void SpeechRecognitionManagerImpl::DispatchEvent(int session_id, |
489 FSMEvent event) { | 472 FSMEvent event) { |
490 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 473 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
491 | 474 |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
694 SpeechRecognitionManagerImpl::Session::Session() | 677 SpeechRecognitionManagerImpl::Session::Session() |
695 : id(kSessionIDInvalid), | 678 : id(kSessionIDInvalid), |
696 abort_requested(false), | 679 abort_requested(false), |
697 listener_is_active(true) { | 680 listener_is_active(true) { |
698 } | 681 } |
699 | 682 |
700 SpeechRecognitionManagerImpl::Session::~Session() { | 683 SpeechRecognitionManagerImpl::Session::~Session() { |
701 } | 684 } |
702 | 685 |
703 } // namespace content | 686 } // namespace content |
OLD | NEW |