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 "chrome/browser/speech/speech_input_extension_manager.h" | 5 #include "chrome/browser/speech/speech_input_extension_manager.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 default: | 506 default: |
507 NOTREACHED(); | 507 NOTREACHED(); |
508 } | 508 } |
509 | 509 |
510 extension_id_in_use_ = extension_id; | 510 extension_id_in_use_ = extension_id; |
511 VLOG(1) << "State changed to starting"; | 511 VLOG(1) << "State changed to starting"; |
512 state_ = kStarting; | 512 state_ = kStarting; |
513 | 513 |
514 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 514 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
515 base::Bind(&SpeechInputExtensionManager::StartOnIOThread, this, | 515 base::Bind(&SpeechInputExtensionManager::StartOnIOThread, this, |
516 profile_->GetRequestContext(), &profile_->GetResourceContext(), | 516 profile_->GetRequestContext(), profile_->GetResourceContext(), |
517 language, grammar, filter_profanities)); | 517 language, grammar, filter_profanities)); |
518 return true; | 518 return true; |
519 } | 519 } |
520 | 520 |
521 void SpeechInputExtensionManager::StartOnIOThread( | 521 void SpeechInputExtensionManager::StartOnIOThread( |
522 net::URLRequestContextGetter* context_getter, | 522 net::URLRequestContextGetter* context_getter, |
523 const content::ResourceContext* resource_context, | 523 content::ResourceContext* resource_context, |
524 const std::string& language, | 524 const std::string& language, |
525 const std::string& grammar, | 525 const std::string& grammar, |
526 bool filter_profanities) { | 526 bool filter_profanities) { |
527 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 527 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
528 VLOG(1) << "Requesting start (IO thread)"; | 528 VLOG(1) << "Requesting start (IO thread)"; |
529 | 529 |
530 // Everything put inside the lock to ensure the validity of context_getter, | 530 // Everything put inside the lock to ensure the validity of context_getter, |
531 // guaranteed while not in the shutdown state. Any ongoing or recognition | 531 // guaranteed while not in the shutdown state. Any ongoing or recognition |
532 // request will be requested to be aborted when entering the shutdown state. | 532 // request will be requested to be aborted when entering the shutdown state. |
533 base::AutoLock auto_lock(state_lock_); | 533 base::AutoLock auto_lock(state_lock_); |
(...skipping 14 matching lines...) Expand all Loading... |
548 base::Bind(&SpeechInputExtensionManager::DispatchError, this, | 548 base::Bind(&SpeechInputExtensionManager::DispatchError, this, |
549 std::string(kErrorRecordingDeviceInUse), false)); | 549 std::string(kErrorRecordingDeviceInUse), false)); |
550 return; | 550 return; |
551 } | 551 } |
552 | 552 |
553 GetSpeechInputExtensionInterface()->StartRecording(this, context_getter, | 553 GetSpeechInputExtensionInterface()->StartRecording(this, context_getter, |
554 resource_context, kSpeechCallerId, language, grammar, filter_profanities); | 554 resource_context, kSpeechCallerId, language, grammar, filter_profanities); |
555 } | 555 } |
556 | 556 |
557 bool SpeechInputExtensionManager::HasAudioInputDevices( | 557 bool SpeechInputExtensionManager::HasAudioInputDevices( |
558 const content::ResourceContext* resource_context) { | 558 content::ResourceContext* resource_context) { |
559 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 559 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
560 DCHECK(resource_context); | 560 DCHECK(resource_context); |
561 return resource_context->audio_manager()->HasAudioInputDevices(); | 561 return resource_context->GetAudioManager()->HasAudioInputDevices(); |
562 } | 562 } |
563 | 563 |
564 bool SpeechInputExtensionManager::IsRecordingInProcess( | 564 bool SpeechInputExtensionManager::IsRecordingInProcess( |
565 const content::ResourceContext* resource_context) { | 565 content::ResourceContext* resource_context) { |
566 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 566 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
567 DCHECK(resource_context); | 567 DCHECK(resource_context); |
568 return resource_context->audio_manager()->IsRecordingInProcess(); | 568 return resource_context->GetAudioManager()->IsRecordingInProcess(); |
569 } | 569 } |
570 | 570 |
571 void SpeechInputExtensionManager::IsRecording( | 571 void SpeechInputExtensionManager::IsRecording( |
572 const IsRecordingCallback& callback) { | 572 const IsRecordingCallback& callback) { |
573 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 573 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
574 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 574 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
575 base::Bind(&SpeechInputExtensionManager::IsRecordingOnIOThread, | 575 base::Bind(&SpeechInputExtensionManager::IsRecordingOnIOThread, |
576 this, callback, &profile_->GetResourceContext())); | 576 this, callback, profile_->GetResourceContext())); |
577 } | 577 } |
578 | 578 |
579 void SpeechInputExtensionManager::IsRecordingOnIOThread( | 579 void SpeechInputExtensionManager::IsRecordingOnIOThread( |
580 const IsRecordingCallback& callback, | 580 const IsRecordingCallback& callback, |
581 const content::ResourceContext* resource_context) { | 581 content::ResourceContext* resource_context) { |
582 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 582 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
583 DCHECK(resource_context); | 583 DCHECK(resource_context); |
584 | 584 |
585 bool result = GetSpeechInputExtensionInterface()->IsRecordingInProcess( | 585 bool result = GetSpeechInputExtensionInterface()->IsRecordingInProcess( |
586 resource_context); | 586 resource_context); |
587 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 587 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
588 base::Bind(&SpeechInputExtensionManager::IsRecordingOnUIThread, | 588 base::Bind(&SpeechInputExtensionManager::IsRecordingOnUIThread, |
589 this, callback, result)); | 589 this, callback, result)); |
590 } | 590 } |
591 | 591 |
592 void SpeechInputExtensionManager::IsRecordingOnUIThread( | 592 void SpeechInputExtensionManager::IsRecordingOnUIThread( |
593 const IsRecordingCallback& callback, | 593 const IsRecordingCallback& callback, |
594 bool result) { | 594 bool result) { |
595 BrowserThread::CurrentlyOn(BrowserThread::UI); | 595 BrowserThread::CurrentlyOn(BrowserThread::UI); |
596 callback.Run(result); | 596 callback.Run(result); |
597 } | 597 } |
598 | 598 |
599 void SpeechInputExtensionManager::StartRecording( | 599 void SpeechInputExtensionManager::StartRecording( |
600 speech_input::SpeechRecognizerDelegate* delegate, | 600 speech_input::SpeechRecognizerDelegate* delegate, |
601 net::URLRequestContextGetter* context_getter, | 601 net::URLRequestContextGetter* context_getter, |
602 const content::ResourceContext* resource_context, | 602 content::ResourceContext* resource_context, |
603 int caller_id, | 603 int caller_id, |
604 const std::string& language, | 604 const std::string& language, |
605 const std::string& grammar, | 605 const std::string& grammar, |
606 bool filter_profanities) { | 606 bool filter_profanities) { |
607 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 607 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
608 DCHECK(resource_context); | 608 DCHECK(resource_context); |
609 DCHECK(!recognizer_); | 609 DCHECK(!recognizer_); |
610 recognizer_ = new SpeechRecognizer(delegate, caller_id, language, grammar, | 610 recognizer_ = new SpeechRecognizer(delegate, caller_id, language, grammar, |
611 context_getter, resource_context->audio_manager(), | 611 context_getter, resource_context->GetAudioManager(), |
612 filter_profanities, "", ""); | 612 filter_profanities, "", ""); |
613 recognizer_->StartRecording(); | 613 recognizer_->StartRecording(); |
614 } | 614 } |
615 | 615 |
616 bool SpeechInputExtensionManager::HasValidRecognizer() { | 616 bool SpeechInputExtensionManager::HasValidRecognizer() { |
617 // Conditional expression used to avoid a performance warning on windows. | 617 // Conditional expression used to avoid a performance warning on windows. |
618 return recognizer_ ? true : false; | 618 return recognizer_ ? true : false; |
619 } | 619 } |
620 | 620 |
621 bool SpeechInputExtensionManager::Stop(const std::string& extension_id, | 621 bool SpeechInputExtensionManager::Stop(const std::string& extension_id, |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
715 base::Bind(&SpeechInputExtensionManager::SetInputVolumeOnUIThread, | 715 base::Bind(&SpeechInputExtensionManager::SetInputVolumeOnUIThread, |
716 this, volume)); | 716 this, volume)); |
717 } | 717 } |
718 | 718 |
719 void SpeechInputExtensionManager::SetInputVolumeOnUIThread( | 719 void SpeechInputExtensionManager::SetInputVolumeOnUIThread( |
720 float volume) { | 720 float volume) { |
721 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 721 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
722 DCHECK(notification_.get()); | 722 DCHECK(notification_.get()); |
723 notification_->SetVUMeterVolume(volume); | 723 notification_->SetVUMeterVolume(volume); |
724 } | 724 } |
OLD | NEW |