Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Side by Side Diff: content/browser/speech/speech_recognition_manager_impl.cc

Issue 1005683003: favor DCHECK_CURRENTLY_ON for better logs in content/browser/[q-z]* (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 21 matching lines...) Expand all
32 32
33 namespace content { 33 namespace content {
34 34
35 SpeechRecognitionManager* SpeechRecognitionManager::manager_for_tests_; 35 SpeechRecognitionManager* SpeechRecognitionManager::manager_for_tests_;
36 36
37 namespace { 37 namespace {
38 38
39 SpeechRecognitionManagerImpl* g_speech_recognition_manager_impl; 39 SpeechRecognitionManagerImpl* g_speech_recognition_manager_impl;
40 40
41 void ShowAudioInputSettingsOnFileThread(media::AudioManager* audio_manager) { 41 void ShowAudioInputSettingsOnFileThread(media::AudioManager* audio_manager) {
42 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 42 DCHECK_CURRENTLY_ON(BrowserThread::FILE);
43 audio_manager->ShowAudioInputSettings(); 43 audio_manager->ShowAudioInputSettings();
44 } 44 }
45 45
46 } // namespace 46 } // namespace
47 47
48 SpeechRecognitionManager* SpeechRecognitionManager::GetInstance() { 48 SpeechRecognitionManager* SpeechRecognitionManager::GetInstance() {
49 if (manager_for_tests_) 49 if (manager_for_tests_)
50 return manager_for_tests_; 50 return manager_for_tests_;
51 return SpeechRecognitionManagerImpl::GetInstance(); 51 return SpeechRecognitionManagerImpl::GetInstance();
52 } 52 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 // MediaStreamUIProxy must be deleted on the IO thread. 84 // MediaStreamUIProxy must be deleted on the IO thread.
85 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, 85 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE,
86 it->second->ui.release()); 86 it->second->ui.release());
87 delete it->second; 87 delete it->second;
88 } 88 }
89 sessions_.clear(); 89 sessions_.clear();
90 } 90 }
91 91
92 int SpeechRecognitionManagerImpl::CreateSession( 92 int SpeechRecognitionManagerImpl::CreateSession(
93 const SpeechRecognitionSessionConfig& config) { 93 const SpeechRecognitionSessionConfig& config) {
94 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 94 DCHECK_CURRENTLY_ON(BrowserThread::IO);
95 95
96 const int session_id = GetNextSessionID(); 96 const int session_id = GetNextSessionID();
97 DCHECK(!SessionExists(session_id)); 97 DCHECK(!SessionExists(session_id));
98 // Set-up the new session. 98 // Set-up the new session.
99 Session* session = new Session(); 99 Session* session = new Session();
100 sessions_[session_id] = session; 100 sessions_[session_id] = session;
101 session->id = session_id; 101 session->id = session_id;
102 session->config = config; 102 session->config = config;
103 session->context = config.initial_context; 103 session->context = config.initial_context;
104 104
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 config.continuous, 153 config.continuous,
154 config.interim_results, 154 config.interim_results,
155 google_remote_engine); 155 google_remote_engine);
156 #else 156 #else
157 session->recognizer = new SpeechRecognizerImplAndroid(this, session_id); 157 session->recognizer = new SpeechRecognizerImplAndroid(this, session_id);
158 #endif 158 #endif
159 return session_id; 159 return session_id;
160 } 160 }
161 161
162 void SpeechRecognitionManagerImpl::StartSession(int session_id) { 162 void SpeechRecognitionManagerImpl::StartSession(int session_id) {
163 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 163 DCHECK_CURRENTLY_ON(BrowserThread::IO);
164 if (!SessionExists(session_id)) 164 if (!SessionExists(session_id))
165 return; 165 return;
166 166
167 // If there is another active session, abort that. 167 // If there is another active session, abort that.
168 if (primary_session_id_ != kSessionIDInvalid && 168 if (primary_session_id_ != kSessionIDInvalid &&
169 primary_session_id_ != session_id) { 169 primary_session_id_ != session_id) {
170 AbortSession(primary_session_id_); 170 AbortSession(primary_session_id_);
171 } 171 }
172 172
173 primary_session_id_ = session_id; 173 primary_session_id_ = session_id;
174 174
175 if (delegate_) { 175 if (delegate_) {
176 delegate_->CheckRecognitionIsAllowed( 176 delegate_->CheckRecognitionIsAllowed(
177 session_id, 177 session_id,
178 base::Bind(&SpeechRecognitionManagerImpl::RecognitionAllowedCallback, 178 base::Bind(&SpeechRecognitionManagerImpl::RecognitionAllowedCallback,
179 weak_factory_.GetWeakPtr(), 179 weak_factory_.GetWeakPtr(),
180 session_id)); 180 session_id));
181 } 181 }
182 } 182 }
183 183
184 void SpeechRecognitionManagerImpl::RecognitionAllowedCallback(int session_id, 184 void SpeechRecognitionManagerImpl::RecognitionAllowedCallback(int session_id,
185 bool ask_user, 185 bool ask_user,
186 bool is_allowed) { 186 bool is_allowed) {
187 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 187 DCHECK_CURRENTLY_ON(BrowserThread::IO);
188 if (!SessionExists(session_id)) 188 if (!SessionExists(session_id))
189 return; 189 return;
190 190
191 SessionsTable::iterator iter = sessions_.find(session_id); 191 SessionsTable::iterator iter = sessions_.find(session_id);
192 DCHECK(iter != sessions_.end()); 192 DCHECK(iter != sessions_.end());
193 Session* session = iter->second; 193 Session* session = iter->second;
194 194
195 if (session->abort_requested) 195 if (session->abort_requested)
196 return; 196 return;
197 197
(...skipping 27 matching lines...) Expand all
225 weak_factory_.GetWeakPtr(), 225 weak_factory_.GetWeakPtr(),
226 session_id, 226 session_id,
227 EVENT_ABORT)); 227 EVENT_ABORT));
228 } 228 }
229 } 229 }
230 230
231 void SpeechRecognitionManagerImpl::MediaRequestPermissionCallback( 231 void SpeechRecognitionManagerImpl::MediaRequestPermissionCallback(
232 int session_id, 232 int session_id,
233 const MediaStreamDevices& devices, 233 const MediaStreamDevices& devices,
234 scoped_ptr<MediaStreamUIProxy> stream_ui) { 234 scoped_ptr<MediaStreamUIProxy> stream_ui) {
235 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 235 DCHECK_CURRENTLY_ON(BrowserThread::IO);
236 236
237 SessionsTable::iterator iter = sessions_.find(session_id); 237 SessionsTable::iterator iter = sessions_.find(session_id);
238 if (iter == sessions_.end()) 238 if (iter == sessions_.end())
239 return; 239 return;
240 240
241 bool is_allowed = !devices.empty(); 241 bool is_allowed = !devices.empty();
242 if (is_allowed) { 242 if (is_allowed) {
243 // Copy the approved devices array to the context for UI indication. 243 // Copy the approved devices array to the context for UI indication.
244 iter->second->context.devices = devices; 244 iter->second->context.devices = devices;
245 245
246 // Save the UI object. 246 // Save the UI object.
247 iter->second->ui = stream_ui.Pass(); 247 iter->second->ui = stream_ui.Pass();
248 } 248 }
249 249
250 // Clear the label to indicate the request has been done. 250 // Clear the label to indicate the request has been done.
251 iter->second->context.label.clear(); 251 iter->second->context.label.clear();
252 252
253 // Notify the recognition about the request result. 253 // Notify the recognition about the request result.
254 RecognitionAllowedCallback(iter->first, false, is_allowed); 254 RecognitionAllowedCallback(iter->first, false, is_allowed);
255 } 255 }
256 256
257 void SpeechRecognitionManagerImpl::AbortSession(int session_id) { 257 void SpeechRecognitionManagerImpl::AbortSession(int session_id) {
258 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 258 DCHECK_CURRENTLY_ON(BrowserThread::IO);
259 if (!SessionExists(session_id)) 259 if (!SessionExists(session_id))
260 return; 260 return;
261 261
262 SessionsTable::iterator iter = sessions_.find(session_id); 262 SessionsTable::iterator iter = sessions_.find(session_id);
263 iter->second->ui.reset(); 263 iter->second->ui.reset();
264 264
265 if (iter->second->abort_requested) 265 if (iter->second->abort_requested)
266 return; 266 return;
267 267
268 iter->second->abort_requested = true; 268 iter->second->abort_requested = true;
269 269
270 base::MessageLoop::current()->PostTask( 270 base::MessageLoop::current()->PostTask(
271 FROM_HERE, 271 FROM_HERE,
272 base::Bind(&SpeechRecognitionManagerImpl::DispatchEvent, 272 base::Bind(&SpeechRecognitionManagerImpl::DispatchEvent,
273 weak_factory_.GetWeakPtr(), 273 weak_factory_.GetWeakPtr(),
274 session_id, 274 session_id,
275 EVENT_ABORT)); 275 EVENT_ABORT));
276 } 276 }
277 277
278 void SpeechRecognitionManagerImpl::StopAudioCaptureForSession(int session_id) { 278 void SpeechRecognitionManagerImpl::StopAudioCaptureForSession(int session_id) {
279 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 279 DCHECK_CURRENTLY_ON(BrowserThread::IO);
280 if (!SessionExists(session_id)) 280 if (!SessionExists(session_id))
281 return; 281 return;
282 282
283 SessionsTable::iterator iter = sessions_.find(session_id); 283 SessionsTable::iterator iter = sessions_.find(session_id);
284 iter->second->ui.reset(); 284 iter->second->ui.reset();
285 285
286 base::MessageLoop::current()->PostTask( 286 base::MessageLoop::current()->PostTask(
287 FROM_HERE, 287 FROM_HERE,
288 base::Bind(&SpeechRecognitionManagerImpl::DispatchEvent, 288 base::Bind(&SpeechRecognitionManagerImpl::DispatchEvent,
289 weak_factory_.GetWeakPtr(), 289 weak_factory_.GetWeakPtr(),
290 session_id, 290 session_id,
291 EVENT_STOP_CAPTURE)); 291 EVENT_STOP_CAPTURE));
292 } 292 }
293 293
294 // Here begins the SpeechRecognitionEventListener interface implementation, 294 // Here begins the SpeechRecognitionEventListener interface implementation,
295 // which will simply relay the events to the proper listener registered for the 295 // which will simply relay the events to the proper listener registered for the
296 // particular session and to the catch-all listener provided by the delegate 296 // particular session and to the catch-all listener provided by the delegate
297 // (if any). 297 // (if any).
298 298
299 void SpeechRecognitionManagerImpl::OnRecognitionStart(int session_id) { 299 void SpeechRecognitionManagerImpl::OnRecognitionStart(int session_id) {
300 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 300 DCHECK_CURRENTLY_ON(BrowserThread::IO);
301 if (!SessionExists(session_id)) 301 if (!SessionExists(session_id))
302 return; 302 return;
303 303
304 SessionsTable::iterator iter = sessions_.find(session_id); 304 SessionsTable::iterator iter = sessions_.find(session_id);
305 if (iter->second->ui) { 305 if (iter->second->ui) {
306 // Notify the UI that the devices are being used. 306 // Notify the UI that the devices are being used.
307 iter->second->ui->OnStarted(base::Closure(), 307 iter->second->ui->OnStarted(base::Closure(),
308 MediaStreamUIProxy::WindowIdCallback()); 308 MediaStreamUIProxy::WindowIdCallback());
309 } 309 }
310 310
311 DCHECK_EQ(primary_session_id_, session_id); 311 DCHECK_EQ(primary_session_id_, session_id);
312 if (SpeechRecognitionEventListener* delegate_listener = GetDelegateListener()) 312 if (SpeechRecognitionEventListener* delegate_listener = GetDelegateListener())
313 delegate_listener->OnRecognitionStart(session_id); 313 delegate_listener->OnRecognitionStart(session_id);
314 if (SpeechRecognitionEventListener* listener = GetListener(session_id)) 314 if (SpeechRecognitionEventListener* listener = GetListener(session_id))
315 listener->OnRecognitionStart(session_id); 315 listener->OnRecognitionStart(session_id);
316 } 316 }
317 317
318 void SpeechRecognitionManagerImpl::OnAudioStart(int session_id) { 318 void SpeechRecognitionManagerImpl::OnAudioStart(int session_id) {
319 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 319 DCHECK_CURRENTLY_ON(BrowserThread::IO);
320 if (!SessionExists(session_id)) 320 if (!SessionExists(session_id))
321 return; 321 return;
322 322
323 DCHECK_EQ(primary_session_id_, session_id); 323 DCHECK_EQ(primary_session_id_, session_id);
324 if (SpeechRecognitionEventListener* delegate_listener = GetDelegateListener()) 324 if (SpeechRecognitionEventListener* delegate_listener = GetDelegateListener())
325 delegate_listener->OnAudioStart(session_id); 325 delegate_listener->OnAudioStart(session_id);
326 if (SpeechRecognitionEventListener* listener = GetListener(session_id)) 326 if (SpeechRecognitionEventListener* listener = GetListener(session_id))
327 listener->OnAudioStart(session_id); 327 listener->OnAudioStart(session_id);
328 } 328 }
329 329
330 void SpeechRecognitionManagerImpl::OnEnvironmentEstimationComplete( 330 void SpeechRecognitionManagerImpl::OnEnvironmentEstimationComplete(
331 int session_id) { 331 int session_id) {
332 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 332 DCHECK_CURRENTLY_ON(BrowserThread::IO);
333 if (!SessionExists(session_id)) 333 if (!SessionExists(session_id))
334 return; 334 return;
335 335
336 DCHECK_EQ(primary_session_id_, session_id); 336 DCHECK_EQ(primary_session_id_, session_id);
337 if (SpeechRecognitionEventListener* delegate_listener = GetDelegateListener()) 337 if (SpeechRecognitionEventListener* delegate_listener = GetDelegateListener())
338 delegate_listener->OnEnvironmentEstimationComplete(session_id); 338 delegate_listener->OnEnvironmentEstimationComplete(session_id);
339 if (SpeechRecognitionEventListener* listener = GetListener(session_id)) 339 if (SpeechRecognitionEventListener* listener = GetListener(session_id))
340 listener->OnEnvironmentEstimationComplete(session_id); 340 listener->OnEnvironmentEstimationComplete(session_id);
341 } 341 }
342 342
343 void SpeechRecognitionManagerImpl::OnSoundStart(int session_id) { 343 void SpeechRecognitionManagerImpl::OnSoundStart(int session_id) {
344 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 344 DCHECK_CURRENTLY_ON(BrowserThread::IO);
345 if (!SessionExists(session_id)) 345 if (!SessionExists(session_id))
346 return; 346 return;
347 347
348 DCHECK_EQ(primary_session_id_, session_id); 348 DCHECK_EQ(primary_session_id_, session_id);
349 if (SpeechRecognitionEventListener* delegate_listener = GetDelegateListener()) 349 if (SpeechRecognitionEventListener* delegate_listener = GetDelegateListener())
350 delegate_listener->OnSoundStart(session_id); 350 delegate_listener->OnSoundStart(session_id);
351 if (SpeechRecognitionEventListener* listener = GetListener(session_id)) 351 if (SpeechRecognitionEventListener* listener = GetListener(session_id))
352 listener->OnSoundStart(session_id); 352 listener->OnSoundStart(session_id);
353 } 353 }
354 354
355 void SpeechRecognitionManagerImpl::OnSoundEnd(int session_id) { 355 void SpeechRecognitionManagerImpl::OnSoundEnd(int session_id) {
356 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 356 DCHECK_CURRENTLY_ON(BrowserThread::IO);
357 if (!SessionExists(session_id)) 357 if (!SessionExists(session_id))
358 return; 358 return;
359 359
360 if (SpeechRecognitionEventListener* delegate_listener = GetDelegateListener()) 360 if (SpeechRecognitionEventListener* delegate_listener = GetDelegateListener())
361 delegate_listener->OnSoundEnd(session_id); 361 delegate_listener->OnSoundEnd(session_id);
362 if (SpeechRecognitionEventListener* listener = GetListener(session_id)) 362 if (SpeechRecognitionEventListener* listener = GetListener(session_id))
363 listener->OnSoundEnd(session_id); 363 listener->OnSoundEnd(session_id);
364 } 364 }
365 365
366 void SpeechRecognitionManagerImpl::OnAudioEnd(int session_id) { 366 void SpeechRecognitionManagerImpl::OnAudioEnd(int session_id) {
367 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 367 DCHECK_CURRENTLY_ON(BrowserThread::IO);
368 if (!SessionExists(session_id)) 368 if (!SessionExists(session_id))
369 return; 369 return;
370 370
371 if (SpeechRecognitionEventListener* delegate_listener = GetDelegateListener()) 371 if (SpeechRecognitionEventListener* delegate_listener = GetDelegateListener())
372 delegate_listener->OnAudioEnd(session_id); 372 delegate_listener->OnAudioEnd(session_id);
373 if (SpeechRecognitionEventListener* listener = GetListener(session_id)) 373 if (SpeechRecognitionEventListener* listener = GetListener(session_id))
374 listener->OnAudioEnd(session_id); 374 listener->OnAudioEnd(session_id);
375 base::MessageLoop::current()->PostTask( 375 base::MessageLoop::current()->PostTask(
376 FROM_HERE, 376 FROM_HERE,
377 base::Bind(&SpeechRecognitionManagerImpl::DispatchEvent, 377 base::Bind(&SpeechRecognitionManagerImpl::DispatchEvent,
378 weak_factory_.GetWeakPtr(), 378 weak_factory_.GetWeakPtr(),
379 session_id, 379 session_id,
380 EVENT_AUDIO_ENDED)); 380 EVENT_AUDIO_ENDED));
381 } 381 }
382 382
383 void SpeechRecognitionManagerImpl::OnRecognitionResults( 383 void SpeechRecognitionManagerImpl::OnRecognitionResults(
384 int session_id, const SpeechRecognitionResults& results) { 384 int session_id, const SpeechRecognitionResults& results) {
385 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 385 DCHECK_CURRENTLY_ON(BrowserThread::IO);
386 if (!SessionExists(session_id)) 386 if (!SessionExists(session_id))
387 return; 387 return;
388 388
389 if (SpeechRecognitionEventListener* delegate_listener = GetDelegateListener()) 389 if (SpeechRecognitionEventListener* delegate_listener = GetDelegateListener())
390 delegate_listener->OnRecognitionResults(session_id, results); 390 delegate_listener->OnRecognitionResults(session_id, results);
391 if (SpeechRecognitionEventListener* listener = GetListener(session_id)) 391 if (SpeechRecognitionEventListener* listener = GetListener(session_id))
392 listener->OnRecognitionResults(session_id, results); 392 listener->OnRecognitionResults(session_id, results);
393 } 393 }
394 394
395 void SpeechRecognitionManagerImpl::OnRecognitionError( 395 void SpeechRecognitionManagerImpl::OnRecognitionError(
396 int session_id, const SpeechRecognitionError& error) { 396 int session_id, const SpeechRecognitionError& error) {
397 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 397 DCHECK_CURRENTLY_ON(BrowserThread::IO);
398 if (!SessionExists(session_id)) 398 if (!SessionExists(session_id))
399 return; 399 return;
400 400
401 if (SpeechRecognitionEventListener* delegate_listener = GetDelegateListener()) 401 if (SpeechRecognitionEventListener* delegate_listener = GetDelegateListener())
402 delegate_listener->OnRecognitionError(session_id, error); 402 delegate_listener->OnRecognitionError(session_id, error);
403 if (SpeechRecognitionEventListener* listener = GetListener(session_id)) 403 if (SpeechRecognitionEventListener* listener = GetListener(session_id))
404 listener->OnRecognitionError(session_id, error); 404 listener->OnRecognitionError(session_id, error);
405 } 405 }
406 406
407 void SpeechRecognitionManagerImpl::OnAudioLevelsChange( 407 void SpeechRecognitionManagerImpl::OnAudioLevelsChange(
408 int session_id, float volume, float noise_volume) { 408 int session_id, float volume, float noise_volume) {
409 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 409 DCHECK_CURRENTLY_ON(BrowserThread::IO);
410 if (!SessionExists(session_id)) 410 if (!SessionExists(session_id))
411 return; 411 return;
412 412
413 if (SpeechRecognitionEventListener* delegate_listener = GetDelegateListener()) 413 if (SpeechRecognitionEventListener* delegate_listener = GetDelegateListener())
414 delegate_listener->OnAudioLevelsChange(session_id, volume, noise_volume); 414 delegate_listener->OnAudioLevelsChange(session_id, volume, noise_volume);
415 if (SpeechRecognitionEventListener* listener = GetListener(session_id)) 415 if (SpeechRecognitionEventListener* listener = GetListener(session_id))
416 listener->OnAudioLevelsChange(session_id, volume, noise_volume); 416 listener->OnAudioLevelsChange(session_id, volume, noise_volume);
417 } 417 }
418 418
419 void SpeechRecognitionManagerImpl::OnRecognitionEnd(int session_id) { 419 void SpeechRecognitionManagerImpl::OnRecognitionEnd(int session_id) {
420 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 420 DCHECK_CURRENTLY_ON(BrowserThread::IO);
421 if (!SessionExists(session_id)) 421 if (!SessionExists(session_id))
422 return; 422 return;
423 423
424 if (SpeechRecognitionEventListener* delegate_listener = GetDelegateListener()) 424 if (SpeechRecognitionEventListener* delegate_listener = GetDelegateListener())
425 delegate_listener->OnRecognitionEnd(session_id); 425 delegate_listener->OnRecognitionEnd(session_id);
426 if (SpeechRecognitionEventListener* listener = GetListener(session_id)) 426 if (SpeechRecognitionEventListener* listener = GetListener(session_id))
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_view_id, int request_id) const {
438 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 438 DCHECK_CURRENTLY_ON(BrowserThread::IO);
439 SessionsTable::const_iterator iter; 439 SessionsTable::const_iterator iter;
440 for (iter = sessions_.begin(); iter != sessions_.end(); ++iter) { 440 for (iter = sessions_.begin(); iter != sessions_.end(); ++iter) {
441 const int session_id = iter->first; 441 const int session_id = iter->first;
442 const SpeechRecognitionSessionContext& context = iter->second->context; 442 const SpeechRecognitionSessionContext& context = iter->second->context;
443 if (context.render_process_id == render_process_id && 443 if (context.render_process_id == render_process_id &&
444 context.render_view_id == render_view_id && 444 context.render_view_id == render_view_id &&
445 context.request_id == request_id) { 445 context.request_id == request_id) {
446 return session_id; 446 return session_id;
447 } 447 }
448 } 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::AbortAllSessionsForRenderProcess(
458 int render_process_id) { 458 int render_process_id) {
459 // This method gracefully destroys sessions for the listener. However, since 459 // This method gracefully destroys sessions for the listener. However, since
460 // the listener itself is likely to be destroyed after this call, we avoid 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. 461 // dispatching further events to it, marking the |listener_is_active| flag.
462 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 462 DCHECK_CURRENTLY_ON(BrowserThread::IO);
463 for (SessionsTable::iterator it = sessions_.begin(); it != sessions_.end(); 463 for (SessionsTable::iterator it = sessions_.begin(); it != sessions_.end();
464 ++it) { 464 ++it) {
465 Session* session = it->second; 465 Session* session = it->second;
466 if (session->context.render_process_id == render_process_id) { 466 if (session->context.render_process_id == render_process_id) {
467 AbortSession(session->id); 467 AbortSession(session->id);
468 session->listener_is_active = false; 468 session->listener_is_active = false;
469 } 469 }
470 } 470 }
471 } 471 }
472 472
473 void SpeechRecognitionManagerImpl::AbortAllSessionsForRenderView( 473 void SpeechRecognitionManagerImpl::AbortAllSessionsForRenderView(
474 int render_process_id, 474 int render_process_id,
475 int render_view_id) { 475 int render_view_id) {
476 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 476 DCHECK_CURRENTLY_ON(BrowserThread::IO);
477 for (SessionsTable::iterator it = sessions_.begin(); it != sessions_.end(); 477 for (SessionsTable::iterator it = sessions_.begin(); it != sessions_.end();
478 ++it) { 478 ++it) {
479 Session* session = it->second; 479 Session* session = it->second;
480 if (session->context.render_process_id == render_process_id && 480 if (session->context.render_process_id == render_process_id &&
481 session->context.render_view_id == render_view_id) { 481 session->context.render_view_id == render_view_id) {
482 AbortSession(session->id); 482 AbortSession(session->id);
483 } 483 }
484 } 484 }
485 } 485 }
486 486
487 // ----------------------- Core FSM implementation --------------------------- 487 // ----------------------- Core FSM implementation ---------------------------
488 void SpeechRecognitionManagerImpl::DispatchEvent(int session_id, 488 void SpeechRecognitionManagerImpl::DispatchEvent(int session_id,
489 FSMEvent event) { 489 FSMEvent event) {
490 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 490 DCHECK_CURRENTLY_ON(BrowserThread::IO);
491 491
492 // There are some corner cases in which the session might be deleted (due to 492 // There are some corner cases in which the session might be deleted (due to
493 // an EndRecognition event) between a request (e.g. Abort) and its dispatch. 493 // an EndRecognition event) between a request (e.g. Abort) and its dispatch.
494 if (!SessionExists(session_id)) 494 if (!SessionExists(session_id))
495 return; 495 return;
496 496
497 Session* session = GetSession(session_id); 497 Session* session = GetSession(session_id);
498 FSMState session_state = GetSessionState(session_id); 498 FSMState session_state = GetSessionState(session_id);
499 DCHECK_LE(session_state, SESSION_STATE_MAX_VALUE); 499 DCHECK_LE(session_state, SESSION_STATE_MAX_VALUE);
500 DCHECK_LE(event, EVENT_MAX_VALUE); 500 DCHECK_LE(event, EVENT_MAX_VALUE);
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 last_session_id_ = 1; 644 last_session_id_ = 1;
645 return last_session_id_; 645 return last_session_id_;
646 } 646 }
647 647
648 bool SpeechRecognitionManagerImpl::SessionExists(int session_id) const { 648 bool SpeechRecognitionManagerImpl::SessionExists(int session_id) const {
649 return sessions_.find(session_id) != sessions_.end(); 649 return sessions_.find(session_id) != sessions_.end();
650 } 650 }
651 651
652 SpeechRecognitionManagerImpl::Session* 652 SpeechRecognitionManagerImpl::Session*
653 SpeechRecognitionManagerImpl::GetSession(int session_id) const { 653 SpeechRecognitionManagerImpl::GetSession(int session_id) const {
654 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 654 DCHECK_CURRENTLY_ON(BrowserThread::IO);
655 SessionsTable::const_iterator iter = sessions_.find(session_id); 655 SessionsTable::const_iterator iter = sessions_.find(session_id);
656 DCHECK(iter != sessions_.end()); 656 DCHECK(iter != sessions_.end());
657 return iter->second; 657 return iter->second;
658 } 658 }
659 659
660 SpeechRecognitionEventListener* SpeechRecognitionManagerImpl::GetListener( 660 SpeechRecognitionEventListener* SpeechRecognitionManagerImpl::GetListener(
661 int session_id) const { 661 int session_id) const {
662 Session* session = GetSession(session_id); 662 Session* session = GetSession(session_id);
663 if (session->listener_is_active && session->config.event_listener) 663 if (session->listener_is_active && session->config.event_listener)
664 return session->config.event_listener.get(); 664 return session->config.event_listener.get();
(...skipping 29 matching lines...) Expand all
694 SpeechRecognitionManagerImpl::Session::Session() 694 SpeechRecognitionManagerImpl::Session::Session()
695 : id(kSessionIDInvalid), 695 : id(kSessionIDInvalid),
696 abort_requested(false), 696 abort_requested(false),
697 listener_is_active(true) { 697 listener_is_active(true) {
698 } 698 }
699 699
700 SpeechRecognitionManagerImpl::Session::~Session() { 700 SpeechRecognitionManagerImpl::Session::~Session() {
701 } 701 }
702 702
703 } // namespace content 703 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/shared_worker/shared_worker_service_impl.cc ('k') | content/browser/speech/speech_recognizer_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698