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