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

Update SODA components to use local state prefs

This CL updates the SODA components to use the local state (AKA global
prefs) instead of profile prefs to keep track of the SODA file paths.

Bug: 1147587
Change-Id: Ic6039558eeee07f07aa3509b2f6fd9d48d4e9ee5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2530590Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Reviewed-by: default avatarJoshua Pawlicki <waffles@chromium.org>
Commit-Queue: Evan Liu <evliu@google.com>
Cr-Commit-Position: refs/heads/master@{#826912}
parent 2de7429d
...@@ -54,9 +54,6 @@ void CaptionController::RegisterProfilePrefs( ...@@ -54,9 +54,6 @@ void CaptionController::RegisterProfilePrefs(
registry->RegisterBooleanPref( registry->RegisterBooleanPref(
prefs::kLiveCaptionEnabled, false, prefs::kLiveCaptionEnabled, false,
user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
registry->RegisterFilePathPref(prefs::kSodaBinaryPath, base::FilePath());
registry->RegisterFilePathPref(prefs::kSodaEnUsConfigPath, base::FilePath());
registry->RegisterFilePathPref(prefs::kSodaJaJpConfigPath, base::FilePath());
// Initially default the language to en-US. // Initially default the language to en-US.
registry->RegisterStringPref(prefs::kLiveCaptionLanguageCode, "en-US"); registry->RegisterStringPref(prefs::kLiveCaptionLanguageCode, "en-US");
......
...@@ -141,9 +141,9 @@ class CaptionControllerTest : public InProcessBrowserTest { ...@@ -141,9 +141,9 @@ class CaptionControllerTest : public InProcessBrowserTest {
IN_PROC_BROWSER_TEST_F(CaptionControllerTest, ProfilePrefsAreRegistered) { IN_PROC_BROWSER_TEST_F(CaptionControllerTest, ProfilePrefsAreRegistered) {
EXPECT_FALSE( EXPECT_FALSE(
browser()->profile()->GetPrefs()->GetBoolean(prefs::kLiveCaptionEnabled)); browser()->profile()->GetPrefs()->GetBoolean(prefs::kLiveCaptionEnabled));
EXPECT_EQ(base::FilePath(), browser()->profile()->GetPrefs()->GetFilePath( EXPECT_EQ(base::FilePath(), g_browser_process->local_state()->GetFilePath(
prefs::kSodaBinaryPath)); prefs::kSodaBinaryPath));
EXPECT_EQ(base::FilePath(), browser()->profile()->GetPrefs()->GetFilePath( EXPECT_EQ(base::FilePath(), g_browser_process->local_state()->GetFilePath(
prefs::kSodaEnUsConfigPath)); prefs::kSodaEnUsConfigPath));
} }
...@@ -153,18 +153,18 @@ IN_PROC_BROWSER_TEST_F(CaptionControllerTest, ...@@ -153,18 +153,18 @@ IN_PROC_BROWSER_TEST_F(CaptionControllerTest,
SetLiveCaptionEnabled(true); SetLiveCaptionEnabled(true);
EXPECT_TRUE( EXPECT_TRUE(
browser()->profile()->GetPrefs()->GetBoolean(prefs::kLiveCaptionEnabled)); browser()->profile()->GetPrefs()->GetBoolean(prefs::kLiveCaptionEnabled));
EXPECT_EQ(base::FilePath(), browser()->profile()->GetPrefs()->GetFilePath( EXPECT_EQ(base::FilePath(), g_browser_process->local_state()->GetFilePath(
prefs::kSodaBinaryPath)); prefs::kSodaBinaryPath));
EXPECT_EQ(base::FilePath(), browser()->profile()->GetPrefs()->GetFilePath( EXPECT_EQ(base::FilePath(), g_browser_process->local_state()->GetFilePath(
prefs::kSodaEnUsConfigPath)); prefs::kSodaEnUsConfigPath));
// Ensure that live caption is also enabled in the incognito profile. // Ensure that live caption is also enabled in the incognito profile.
Profile* incognito_profile = browser()->profile()->GetPrimaryOTRProfile(); Profile* incognito_profile = browser()->profile()->GetPrimaryOTRProfile();
EXPECT_TRUE( EXPECT_TRUE(
incognito_profile->GetPrefs()->GetBoolean(prefs::kLiveCaptionEnabled)); incognito_profile->GetPrefs()->GetBoolean(prefs::kLiveCaptionEnabled));
EXPECT_EQ(base::FilePath(), browser()->profile()->GetPrefs()->GetFilePath( EXPECT_EQ(base::FilePath(), g_browser_process->local_state()->GetFilePath(
prefs::kSodaBinaryPath)); prefs::kSodaBinaryPath));
EXPECT_EQ(base::FilePath(), browser()->profile()->GetPrefs()->GetFilePath( EXPECT_EQ(base::FilePath(), g_browser_process->local_state()->GetFilePath(
prefs::kSodaEnUsConfigPath)); prefs::kSodaEnUsConfigPath));
} }
......
...@@ -74,7 +74,8 @@ void SODAInstallerImpl::InstallSODA(PrefService* prefs) { ...@@ -74,7 +74,8 @@ void SODAInstallerImpl::InstallSODA(PrefService* prefs) {
void SODAInstallerImpl::InstallLanguage(PrefService* prefs) { void SODAInstallerImpl::InstallLanguage(PrefService* prefs) {
component_updater::RegisterSodaLanguageComponent( component_updater::RegisterSodaLanguageComponent(
g_browser_process->component_updater(), prefs); g_browser_process->component_updater(), prefs,
g_browser_process->local_state());
if (!component_updater_observer_.IsObserving( if (!component_updater_observer_.IsObserving(
g_browser_process->component_updater())) { g_browser_process->component_updater())) {
......
...@@ -185,7 +185,8 @@ void RegisterComponentsForUpdate(bool is_off_the_record_profile, ...@@ -185,7 +185,8 @@ void RegisterComponentsForUpdate(bool is_off_the_record_profile,
component_updater::RegisterSodaComponent(cus, profile_prefs, component_updater::RegisterSodaComponent(cus, profile_prefs,
g_browser_process->local_state(), g_browser_process->local_state(),
base::OnceClosure()); base::OnceClosure());
component_updater::RegisterSodaLanguageComponent(cus, profile_prefs); component_updater::RegisterSodaLanguageComponent(
cus, profile_prefs, g_browser_process->local_state());
#endif #endif
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
......
...@@ -132,6 +132,9 @@ void UpdateSODAInstallDirPref(PrefService* prefs, ...@@ -132,6 +132,9 @@ void UpdateSODAInstallDirPref(PrefService* prefs,
void RegisterPrefsForSodaComponent(PrefRegistrySimple* registry) { void RegisterPrefsForSodaComponent(PrefRegistrySimple* registry) {
registry->RegisterTimePref(prefs::kSodaScheduledDeletionTime, base::Time()); registry->RegisterTimePref(prefs::kSodaScheduledDeletionTime, base::Time());
registry->RegisterFilePathPref(prefs::kSodaBinaryPath, base::FilePath());
registry->RegisterFilePathPref(prefs::kSodaEnUsConfigPath, base::FilePath());
registry->RegisterFilePathPref(prefs::kSodaJaJpConfigPath, base::FilePath());
} }
void RegisterSodaComponent(ComponentUpdateService* cus, void RegisterSodaComponent(ComponentUpdateService* cus,
...@@ -146,15 +149,15 @@ void RegisterSodaComponent(ComponentUpdateService* cus, ...@@ -146,15 +149,15 @@ void RegisterSodaComponent(ComponentUpdateService* cus,
global_prefs->SetTime(prefs::kSodaScheduledDeletionTime, base::Time()); global_prefs->SetTime(prefs::kSodaScheduledDeletionTime, base::Time());
auto installer = base::MakeRefCounted<ComponentInstaller>( auto installer = base::MakeRefCounted<ComponentInstaller>(
std::make_unique<SODAComponentInstallerPolicy>(base::BindRepeating( std::make_unique<SODAComponentInstallerPolicy>(base::BindRepeating(
[](ComponentUpdateService* cus, PrefService* profile_prefs, [](ComponentUpdateService* cus, PrefService* global_prefs,
const base::FilePath& install_dir) { const base::FilePath& install_dir) {
content::GetUIThreadTaskRunner( content::GetUIThreadTaskRunner(
{base::TaskPriority::BEST_EFFORT}) {base::TaskPriority::BEST_EFFORT})
->PostTask(FROM_HERE, ->PostTask(FROM_HERE,
base::BindOnce(&UpdateSODAInstallDirPref, base::BindOnce(&UpdateSODAInstallDirPref,
profile_prefs, install_dir)); global_prefs, install_dir));
}, },
cus, profile_prefs))); cus, global_prefs)));
installer->Register(cus, std::move(callback)); installer->Register(cus, std::move(callback));
} else { } else {
...@@ -170,11 +173,10 @@ void RegisterSodaComponent(ComponentUpdateService* cus, ...@@ -170,11 +173,10 @@ void RegisterSodaComponent(ComponentUpdateService* cus,
} }
void RegisterSodaLanguageComponent(ComponentUpdateService* cus, void RegisterSodaLanguageComponent(ComponentUpdateService* cus,
PrefService* profile_prefs) { PrefService* profile_prefs,
PrefService* global_prefs) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
// TODO(crbug.com/1143753): Clean up this component if the Live Caption
// feature hasn't been used for some time.
if (base::FeatureList::IsEnabled(media::kUseSodaForLiveCaption)) { if (base::FeatureList::IsEnabled(media::kUseSodaForLiveCaption)) {
speech::LanguageCode language = speech::GetLanguageCode( speech::LanguageCode language = speech::GetLanguageCode(
profile_prefs->GetString(prefs::kLiveCaptionLanguageCode)); profile_prefs->GetString(prefs::kLiveCaptionLanguageCode));
...@@ -184,13 +186,13 @@ void RegisterSodaLanguageComponent(ComponentUpdateService* cus, ...@@ -184,13 +186,13 @@ void RegisterSodaLanguageComponent(ComponentUpdateService* cus,
break; break;
case speech::LanguageCode::kEnUs: case speech::LanguageCode::kEnUs:
RegisterSodaEnUsComponent( RegisterSodaEnUsComponent(
cus, profile_prefs, cus, global_prefs,
base::BindOnce(&SodaEnUsComponentInstallerPolicy:: base::BindOnce(&SodaEnUsComponentInstallerPolicy::
UpdateSodaEnUsComponentOnDemand)); UpdateSodaEnUsComponentOnDemand));
break; break;
case speech::LanguageCode::kJaJp: case speech::LanguageCode::kJaJp:
RegisterSodaJaJpComponent( RegisterSodaJaJpComponent(
cus, profile_prefs, cus, global_prefs,
base::BindOnce(&SodaJaJpComponentInstallerPolicy:: base::BindOnce(&SodaJaJpComponentInstallerPolicy::
UpdateSodaJaJpComponentOnDemand)); UpdateSodaJaJpComponentOnDemand));
break; break;
......
...@@ -66,7 +66,8 @@ void RegisterSodaComponent(ComponentUpdateService* cus, ...@@ -66,7 +66,8 @@ void RegisterSodaComponent(ComponentUpdateService* cus,
base::OnceClosure callback); base::OnceClosure callback);
void RegisterSodaLanguageComponent(ComponentUpdateService* cus, void RegisterSodaLanguageComponent(ComponentUpdateService* cus,
PrefService* profile_prefs); PrefService* profile_prefs,
PrefService* global_prefs);
} // namespace component_updater } // namespace component_updater
......
...@@ -135,15 +135,6 @@ void RegisterSodaEnUsComponent(ComponentUpdateService* cus, ...@@ -135,15 +135,6 @@ void RegisterSodaEnUsComponent(ComponentUpdateService* cus,
PrefService* prefs, PrefService* prefs,
base::OnceClosure callback) { base::OnceClosure callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
// TODO(crbug.com/1143753): Clean up this component if the Live Caption
// feature hasn't been used for some time.
if (base::FeatureList::IsEnabled(media::kUseSodaForLiveCaption)) {
if (!prefs->GetBoolean(prefs::kLiveCaptionEnabled) ||
!base::FeatureList::IsEnabled(media::kLiveCaption)) {
return;
}
auto installer = base::MakeRefCounted<ComponentInstaller>( auto installer = base::MakeRefCounted<ComponentInstaller>(
std::make_unique<SodaEnUsComponentInstallerPolicy>(base::BindRepeating( std::make_unique<SodaEnUsComponentInstallerPolicy>(base::BindRepeating(
[](ComponentUpdateService* cus, PrefService* prefs, [](ComponentUpdateService* cus, PrefService* prefs,
...@@ -156,7 +147,6 @@ void RegisterSodaEnUsComponent(ComponentUpdateService* cus, ...@@ -156,7 +147,6 @@ void RegisterSodaEnUsComponent(ComponentUpdateService* cus,
cus, prefs))); cus, prefs)));
installer->Register(cus, std::move(callback)); installer->Register(cus, std::move(callback));
}
} }
} // namespace component_updater } // namespace component_updater
...@@ -135,15 +135,6 @@ void RegisterSodaJaJpComponent(ComponentUpdateService* cus, ...@@ -135,15 +135,6 @@ void RegisterSodaJaJpComponent(ComponentUpdateService* cus,
PrefService* prefs, PrefService* prefs,
base::OnceClosure callback) { base::OnceClosure callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
// TODO(crbug.com/1143753): Clean up this component if the Live Caption
// feature hasn't been used for some time.
if (base::FeatureList::IsEnabled(media::kUseSodaForLiveCaption)) {
if (!prefs->GetBoolean(prefs::kLiveCaptionEnabled) ||
!base::FeatureList::IsEnabled(media::kLiveCaption)) {
return;
}
auto installer = base::MakeRefCounted<ComponentInstaller>( auto installer = base::MakeRefCounted<ComponentInstaller>(
std::make_unique<SodaJaJpComponentInstallerPolicy>(base::BindRepeating( std::make_unique<SodaJaJpComponentInstallerPolicy>(base::BindRepeating(
[](ComponentUpdateService* cus, PrefService* prefs, [](ComponentUpdateService* cus, PrefService* prefs,
...@@ -156,7 +147,6 @@ void RegisterSodaJaJpComponent(ComponentUpdateService* cus, ...@@ -156,7 +147,6 @@ void RegisterSodaJaJpComponent(ComponentUpdateService* cus,
cus, prefs))); cus, prefs)));
installer->Register(cus, std::move(callback)); installer->Register(cus, std::move(callback));
}
} }
} // namespace component_updater } // namespace component_updater
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "chrome/browser/speech/speech_recognition_service.h" #include "chrome/browser/speech/speech_recognition_service.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/service_sandbox_type.h" #include "chrome/browser/service_sandbox_type.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
...@@ -61,11 +62,13 @@ void SpeechRecognitionService::LaunchIfNotRunning() { ...@@ -61,11 +62,13 @@ void SpeechRecognitionService::LaunchIfNotRunning() {
if (speech_recognition_service_.is_bound()) if (speech_recognition_service_.is_bound())
return; return;
PrefService* prefs = user_prefs::UserPrefs::Get(context_); PrefService* profile_prefs = user_prefs::UserPrefs::Get(context_);
DCHECK(prefs); PrefService* global_prefs = g_browser_process->local_state();
DCHECK(profile_prefs);
DCHECK(global_prefs);
auto binary_path = prefs->GetFilePath(prefs::kSodaBinaryPath); auto binary_path = global_prefs->GetFilePath(prefs::kSodaBinaryPath);
auto config_path = SpeechRecognitionService::GetSodaConfigPath(prefs); auto config_path = SpeechRecognitionService::GetSodaConfigPath(profile_prefs);
if (enable_soda_ && (binary_path.empty() || config_path.empty())) { if (enable_soda_ && (binary_path.empty() || config_path.empty())) {
LOG(ERROR) << "Unable to find SODA files on the device."; LOG(ERROR) << "Unable to find SODA files on the device.";
return; return;
...@@ -98,14 +101,15 @@ void SpeechRecognitionService::LaunchIfNotRunning() { ...@@ -98,14 +101,15 @@ void SpeechRecognitionService::LaunchIfNotRunning() {
base::FilePath SpeechRecognitionService::GetSodaConfigPath(PrefService* prefs) { base::FilePath SpeechRecognitionService::GetSodaConfigPath(PrefService* prefs) {
speech::LanguageCode language = speech::GetLanguageCode( speech::LanguageCode language = speech::GetLanguageCode(
prefs->GetString(prefs::kLiveCaptionLanguageCode)); prefs->GetString(prefs::kLiveCaptionLanguageCode));
PrefService* global_prefs = g_browser_process->local_state();
switch (language) { switch (language) {
case speech::LanguageCode::kNone: case speech::LanguageCode::kNone:
NOTREACHED(); NOTREACHED();
return base::FilePath(); return base::FilePath();
case speech::LanguageCode::kEnUs: case speech::LanguageCode::kEnUs:
return prefs->GetFilePath(prefs::kSodaEnUsConfigPath); return global_prefs->GetFilePath(prefs::kSodaEnUsConfigPath);
case speech::LanguageCode::kJaJp: case speech::LanguageCode::kJaJp:
return prefs->GetFilePath(prefs::kSodaJaJpConfigPath); return global_prefs->GetFilePath(prefs::kSodaJaJpConfigPath);
} }
return base::FilePath(); return base::FilePath();
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "base/files/file_util.h" #include "base/files/file_util.h"
#include "base/path_service.h" #include "base/path_service.h"
#include "base/test/scoped_feature_list.h" #include "base/test/scoped_feature_list.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/speech/speech_recognition_service.h" #include "chrome/browser/speech/speech_recognition_service.h"
...@@ -123,11 +124,11 @@ void SpeechRecognitionServiceTest::LaunchService() { ...@@ -123,11 +124,11 @@ void SpeechRecognitionServiceTest::LaunchService() {
} }
IN_PROC_BROWSER_TEST_F(SpeechRecognitionServiceTest, RecognizePhrase) { IN_PROC_BROWSER_TEST_F(SpeechRecognitionServiceTest, RecognizePhrase) {
ProfileManager::GetActiveUserProfile()->GetPrefs()->SetFilePath( g_browser_process->local_state()->SetFilePath(
prefs::kSodaBinaryPath, prefs::kSodaBinaryPath,
test_data_dir_.Append(base::FilePath(kSodaResourcesDir)) test_data_dir_.Append(base::FilePath(kSodaResourcesDir))
.Append(kSodaBinaryRelativePath)); .Append(kSodaBinaryRelativePath));
ProfileManager::GetActiveUserProfile()->GetPrefs()->SetFilePath( g_browser_process->local_state()->SetFilePath(
prefs::kSodaEnUsConfigPath, prefs::kSodaEnUsConfigPath,
test_data_dir_.Append(base::FilePath(kSodaResourcesDir)) test_data_dir_.Append(base::FilePath(kSodaResourcesDir))
.Append(kSodaLanguagePackRelativePath)); .Append(kSodaLanguagePackRelativePath));
......
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