| 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/speech/google_one_shot_remote_engine.h" | 9 #include "content/browser/speech/google_one_shot_remote_engine.h" |
| 10 #include "content/browser/speech/speech_recognition_engine.h" | 10 #include "content/browser/speech/speech_recognition_engine.h" |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 | 275 |
| 276 if (SpeechRecognitionEventListener* delegate_listener = GetDelegateListener()) | 276 if (SpeechRecognitionEventListener* delegate_listener = GetDelegateListener()) |
| 277 delegate_listener->OnRecognitionEnd(session_id); | 277 delegate_listener->OnRecognitionEnd(session_id); |
| 278 if (SpeechRecognitionEventListener* listener = GetListener(session_id)) | 278 if (SpeechRecognitionEventListener* listener = GetListener(session_id)) |
| 279 listener->OnRecognitionEnd(session_id); | 279 listener->OnRecognitionEnd(session_id); |
| 280 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 280 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 281 base::Bind(&SpeechRecognitionManagerImpl::DispatchEvent, | 281 base::Bind(&SpeechRecognitionManagerImpl::DispatchEvent, |
| 282 this->AsWeakPtr(), session_id, EVENT_RECOGNITION_ENDED)); | 282 this->AsWeakPtr(), session_id, EVENT_RECOGNITION_ENDED)); |
| 283 } | 283 } |
| 284 | 284 |
| 285 // TODO(primiano) After CL2: if we see that both InputTagDispatcherHost and | 285 int SpeechRecognitionManagerImpl::GetSession( |
| 286 // SpeechRecognitionDispatcherHost do the same lookup operations, implement the | 286 int render_process_id, int render_view_id, int request_id) const { |
| 287 // lookup method directly here. | |
| 288 int SpeechRecognitionManagerImpl::LookupSessionByContext( | |
| 289 Callback<bool(const SpeechRecognitionSessionContext&)> matcher) const { | |
| 290 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 287 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 291 SessionsTable::const_iterator iter; | 288 SessionsTable::const_iterator iter; |
| 292 // Note: the callback (matcher) must NEVER perform non-const calls on us. | |
| 293 for(iter = sessions_.begin(); iter != sessions_.end(); ++iter) { | 289 for(iter = sessions_.begin(); iter != sessions_.end(); ++iter) { |
| 294 const int session_id = iter->first; | 290 const int session_id = iter->first; |
| 295 const Session& session = iter->second; | 291 const SpeechRecognitionSessionContext& context = iter->second.context; |
| 296 bool matches = matcher.Run(session.context); | 292 if (context.render_process_id == render_process_id && |
| 297 if (matches) | 293 context.render_view_id == render_view_id && |
| 294 context.request_id == request_id) { |
| 298 return session_id; | 295 return session_id; |
| 296 } |
| 299 } | 297 } |
| 300 return kSessionIDInvalid; | 298 return kSessionIDInvalid; |
| 301 } | 299 } |
| 302 | 300 |
| 303 SpeechRecognitionSessionContext | 301 SpeechRecognitionSessionContext |
| 304 SpeechRecognitionManagerImpl::GetSessionContext(int session_id) const { | 302 SpeechRecognitionManagerImpl::GetSessionContext(int session_id) const { |
| 305 return GetSession(session_id).context; | 303 return GetSession(session_id).context; |
| 306 } | 304 } |
| 307 | 305 |
| 308 void SpeechRecognitionManagerImpl::AbortAllSessionsForListener( | 306 void SpeechRecognitionManagerImpl::AbortAllSessionsForListener( |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 | 520 |
| 523 SpeechRecognitionManagerImpl::Session::Session() | 521 SpeechRecognitionManagerImpl::Session::Session() |
| 524 : id(kSessionIDInvalid), | 522 : id(kSessionIDInvalid), |
| 525 listener_is_active(true) { | 523 listener_is_active(true) { |
| 526 } | 524 } |
| 527 | 525 |
| 528 SpeechRecognitionManagerImpl::Session::~Session() { | 526 SpeechRecognitionManagerImpl::Session::~Session() { |
| 529 } | 527 } |
| 530 | 528 |
| 531 } // namespace speech | 529 } // namespace speech |
| OLD | NEW |