| 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 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 } | 443 } |
| 444 } | 444 } |
| 445 return kSessionIDInvalid; | 445 return kSessionIDInvalid; |
| 446 } | 446 } |
| 447 | 447 |
| 448 SpeechRecognitionSessionContext | 448 SpeechRecognitionSessionContext |
| 449 SpeechRecognitionManagerImpl::GetSessionContext(int session_id) const { | 449 SpeechRecognitionManagerImpl::GetSessionContext(int session_id) const { |
| 450 return GetSession(session_id)->context; | 450 return GetSession(session_id)->context; |
| 451 } | 451 } |
| 452 | 452 |
| 453 void SpeechRecognitionManagerImpl::AbortAllSessionsForListener( | 453 void SpeechRecognitionManagerImpl::AbortAllSessionsForRenderProcess( |
| 454 SpeechRecognitionEventListener* listener) { | 454 int render_process_id) { |
| 455 // This method gracefully destroys sessions for the listener. However, since | 455 // This method gracefully destroys sessions for the listener. However, since |
| 456 // the listener itself is likely to be destroyed after this call, we avoid | 456 // the listener itself is likely to be destroyed after this call, we avoid |
| 457 // dispatching further events to it, marking the |listener_is_active| flag. | 457 // dispatching further events to it, marking the |listener_is_active| flag. |
| 458 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 458 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 459 for (SessionsTable::iterator it = sessions_.begin(); it != sessions_.end(); | 459 for (SessionsTable::iterator it = sessions_.begin(); it != sessions_.end(); |
| 460 ++it) { | 460 ++it) { |
| 461 Session* session = it->second; | 461 Session* session = it->second; |
| 462 if (session->config.event_listener == listener) { | 462 if (session->context.render_process_id == render_process_id) { |
| 463 AbortSession(session->id); | 463 AbortSession(session->id); |
| 464 session->listener_is_active = false; | 464 session->listener_is_active = false; |
| 465 } | 465 } |
| 466 } | 466 } |
| 467 } | 467 } |
| 468 | 468 |
| 469 void SpeechRecognitionManagerImpl::AbortAllSessionsForRenderView( | 469 void SpeechRecognitionManagerImpl::AbortAllSessionsForRenderView( |
| 470 int render_process_id, | 470 int render_process_id, |
| 471 int render_view_id) { | 471 int render_view_id) { |
| 472 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 472 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 649 SpeechRecognitionManagerImpl::GetSession(int session_id) const { | 649 SpeechRecognitionManagerImpl::GetSession(int session_id) const { |
| 650 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 650 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 651 SessionsTable::const_iterator iter = sessions_.find(session_id); | 651 SessionsTable::const_iterator iter = sessions_.find(session_id); |
| 652 DCHECK(iter != sessions_.end()); | 652 DCHECK(iter != sessions_.end()); |
| 653 return iter->second; | 653 return iter->second; |
| 654 } | 654 } |
| 655 | 655 |
| 656 SpeechRecognitionEventListener* SpeechRecognitionManagerImpl::GetListener( | 656 SpeechRecognitionEventListener* SpeechRecognitionManagerImpl::GetListener( |
| 657 int session_id) const { | 657 int session_id) const { |
| 658 Session* session = GetSession(session_id); | 658 Session* session = GetSession(session_id); |
| 659 return session->listener_is_active ? session->config.event_listener : NULL; | 659 if (session->listener_is_active && session->config.event_listener) |
| 660 return session->config.event_listener.get(); |
| 661 return NULL; |
| 660 } | 662 } |
| 661 | 663 |
| 662 SpeechRecognitionEventListener* | 664 SpeechRecognitionEventListener* |
| 663 SpeechRecognitionManagerImpl::GetDelegateListener() const { | 665 SpeechRecognitionManagerImpl::GetDelegateListener() const { |
| 664 return delegate_.get() ? delegate_->GetEventListener() : NULL; | 666 return delegate_.get() ? delegate_->GetEventListener() : NULL; |
| 665 } | 667 } |
| 666 | 668 |
| 667 const SpeechRecognitionSessionConfig& | 669 const SpeechRecognitionSessionConfig& |
| 668 SpeechRecognitionManagerImpl::GetSessionConfig(int session_id) const { | 670 SpeechRecognitionManagerImpl::GetSessionConfig(int session_id) const { |
| 669 return GetSession(session_id)->config; | 671 return GetSession(session_id)->config; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 688 SpeechRecognitionManagerImpl::Session::Session() | 690 SpeechRecognitionManagerImpl::Session::Session() |
| 689 : id(kSessionIDInvalid), | 691 : id(kSessionIDInvalid), |
| 690 abort_requested(false), | 692 abort_requested(false), |
| 691 listener_is_active(true) { | 693 listener_is_active(true) { |
| 692 } | 694 } |
| 693 | 695 |
| 694 SpeechRecognitionManagerImpl::Session::~Session() { | 696 SpeechRecognitionManagerImpl::Session::~Session() { |
| 695 } | 697 } |
| 696 | 698 |
| 697 } // namespace content | 699 } // namespace content |
| OLD | NEW |