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