Commit c8f0a829 authored by evliu's avatar evliu Committed by Commit Bot

Check SODA paths before launching service

This CL introduces a check to verify that the SODA binary and language
pack components are downloaded before launching the speech recognition
service. In the event where the files are not yet downloaded, a generic
error message will be shown to the user indicating that speech
recognition is not available.

Bug: 1121384
Change-Id: Iff628202884869a04ce54761137aca4d40497fc3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2373388Reviewed-by: default avatarAbigail Klein <abigailbklein@google.com>
Commit-Queue: Evan Liu <evliu@google.com>
Cr-Commit-Position: refs/heads/master@{#801310}
parent b5a259f0
...@@ -59,6 +59,17 @@ void SpeechRecognitionService::LaunchIfNotRunning() { ...@@ -59,6 +59,17 @@ void SpeechRecognitionService::LaunchIfNotRunning() {
if (speech_recognition_service_.is_bound()) if (speech_recognition_service_.is_bound())
return; return;
PrefService* prefs = user_prefs::UserPrefs::Get(context_);
DCHECK(prefs);
#if BUILDFLAG(ENABLE_SODA)
auto binary_path = prefs->GetFilePath(prefs::kSodaBinaryPath);
auto config_path = SpeechRecognitionService::GetSodaConfigPath(prefs);
if (binary_path.empty() || config_path.empty()) {
LOG(ERROR) << "Unable to find SODA files on the device.";
return;
}
#endif
content::ServiceProcessHost::Launch( content::ServiceProcessHost::Launch(
speech_recognition_service_.BindNewPipeAndPassReceiver(), speech_recognition_service_.BindNewPipeAndPassReceiver(),
content::ServiceProcessHost::Options() content::ServiceProcessHost::Options()
...@@ -74,12 +85,9 @@ void SpeechRecognitionService::LaunchIfNotRunning() { ...@@ -74,12 +85,9 @@ void SpeechRecognitionService::LaunchIfNotRunning() {
speech_recognition_service_.reset_on_idle_timeout(kIdleProcessTimeout); speech_recognition_service_.reset_on_idle_timeout(kIdleProcessTimeout);
speech_recognition_service_client_.reset(); speech_recognition_service_client_.reset();
#if BUILDFLAG(ENABLE_SODA)
PrefService* prefs = user_prefs::UserPrefs::Get(context_); speech_recognition_service_->SetSodaPath(binary_path, config_path);
DCHECK(prefs); #endif
speech_recognition_service_->SetSodaPath(
prefs->GetFilePath(prefs::kSodaBinaryPath),
prefs->GetFilePath(prefs::kSodaEnUsConfigPath));
speech_recognition_service_->BindSpeechRecognitionServiceClient( speech_recognition_service_->BindSpeechRecognitionServiceClient(
speech_recognition_service_client_.BindNewPipeAndPassRemote()); speech_recognition_service_client_.BindNewPipeAndPassRemote());
OnNetworkServiceDisconnect(); OnNetworkServiceDisconnect();
...@@ -89,12 +97,13 @@ base::FilePath SpeechRecognitionService::GetSodaConfigPath(PrefService* prefs) { ...@@ -89,12 +97,13 @@ base::FilePath SpeechRecognitionService::GetSodaConfigPath(PrefService* prefs) {
speech::LanguageCode language = speech::GetLanguageCode( speech::LanguageCode language = speech::GetLanguageCode(
prefs->GetString(prefs::kLiveCaptionLanguageCode)); prefs->GetString(prefs::kLiveCaptionLanguageCode));
switch (language) { switch (language) {
case speech::LanguageCode::kNone:
NOTREACHED();
return base::FilePath();
case speech::LanguageCode::kEnUs: case speech::LanguageCode::kEnUs:
return prefs->GetFilePath(prefs::kSodaEnUsConfigPath); return prefs->GetFilePath(prefs::kSodaEnUsConfigPath);
case speech::LanguageCode::kJaJp: case speech::LanguageCode::kJaJp:
return prefs->GetFilePath(prefs::kSodaJaJpConfigPath); return prefs->GetFilePath(prefs::kSodaJaJpConfigPath);
default:
NOTREACHED();
} }
return base::FilePath(); return base::FilePath();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment