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(
registry->RegisterBooleanPref(
prefs::kLiveCaptionEnabled, false,
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.
registry->RegisterStringPref(prefs::kLiveCaptionLanguageCode, "en-US");
......
......@@ -141,9 +141,9 @@ class CaptionControllerTest : public InProcessBrowserTest {
IN_PROC_BROWSER_TEST_F(CaptionControllerTest, ProfilePrefsAreRegistered) {
EXPECT_FALSE(
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));
EXPECT_EQ(base::FilePath(), browser()->profile()->GetPrefs()->GetFilePath(
EXPECT_EQ(base::FilePath(), g_browser_process->local_state()->GetFilePath(
prefs::kSodaEnUsConfigPath));
}
......@@ -153,18 +153,18 @@ IN_PROC_BROWSER_TEST_F(CaptionControllerTest,
SetLiveCaptionEnabled(true);
EXPECT_TRUE(
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));
EXPECT_EQ(base::FilePath(), browser()->profile()->GetPrefs()->GetFilePath(
EXPECT_EQ(base::FilePath(), g_browser_process->local_state()->GetFilePath(
prefs::kSodaEnUsConfigPath));
// Ensure that live caption is also enabled in the incognito profile.
Profile* incognito_profile = browser()->profile()->GetPrimaryOTRProfile();
EXPECT_TRUE(
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));
EXPECT_EQ(base::FilePath(), browser()->profile()->GetPrefs()->GetFilePath(
EXPECT_EQ(base::FilePath(), g_browser_process->local_state()->GetFilePath(
prefs::kSodaEnUsConfigPath));
}
......
......@@ -74,7 +74,8 @@ void SODAInstallerImpl::InstallSODA(PrefService* prefs) {
void SODAInstallerImpl::InstallLanguage(PrefService* prefs) {
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(
g_browser_process->component_updater())) {
......
......@@ -185,7 +185,8 @@ void RegisterComponentsForUpdate(bool is_off_the_record_profile,
component_updater::RegisterSodaComponent(cus, profile_prefs,
g_browser_process->local_state(),
base::OnceClosure());
component_updater::RegisterSodaLanguageComponent(cus, profile_prefs);
component_updater::RegisterSodaLanguageComponent(
cus, profile_prefs, g_browser_process->local_state());
#endif
#if defined(OS_CHROMEOS)
......
......@@ -132,6 +132,9 @@ void UpdateSODAInstallDirPref(PrefService* prefs,
void RegisterPrefsForSodaComponent(PrefRegistrySimple* registry) {
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,
......@@ -146,15 +149,15 @@ void RegisterSodaComponent(ComponentUpdateService* cus,
global_prefs->SetTime(prefs::kSodaScheduledDeletionTime, base::Time());
auto installer = base::MakeRefCounted<ComponentInstaller>(
std::make_unique<SODAComponentInstallerPolicy>(base::BindRepeating(
[](ComponentUpdateService* cus, PrefService* profile_prefs,
[](ComponentUpdateService* cus, PrefService* global_prefs,
const base::FilePath& install_dir) {
content::GetUIThreadTaskRunner(
{base::TaskPriority::BEST_EFFORT})
->PostTask(FROM_HERE,
base::BindOnce(&UpdateSODAInstallDirPref,
profile_prefs, install_dir));
global_prefs, install_dir));
},
cus, profile_prefs)));
cus, global_prefs)));
installer->Register(cus, std::move(callback));
} else {
......@@ -170,11 +173,10 @@ void RegisterSodaComponent(ComponentUpdateService* cus,
}
void RegisterSodaLanguageComponent(ComponentUpdateService* cus,
PrefService* profile_prefs) {
PrefService* profile_prefs,
PrefService* global_prefs) {
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)) {
speech::LanguageCode language = speech::GetLanguageCode(
profile_prefs->GetString(prefs::kLiveCaptionLanguageCode));
......@@ -184,13 +186,13 @@ void RegisterSodaLanguageComponent(ComponentUpdateService* cus,
break;
case speech::LanguageCode::kEnUs:
RegisterSodaEnUsComponent(
cus, profile_prefs,
cus, global_prefs,
base::BindOnce(&SodaEnUsComponentInstallerPolicy::
UpdateSodaEnUsComponentOnDemand));
break;
case speech::LanguageCode::kJaJp:
RegisterSodaJaJpComponent(
cus, profile_prefs,
cus, global_prefs,
base::BindOnce(&SodaJaJpComponentInstallerPolicy::
UpdateSodaJaJpComponentOnDemand));
break;
......
......@@ -66,7 +66,8 @@ void RegisterSodaComponent(ComponentUpdateService* cus,
base::OnceClosure callback);
void RegisterSodaLanguageComponent(ComponentUpdateService* cus,
PrefService* profile_prefs);
PrefService* profile_prefs,
PrefService* global_prefs);
} // namespace component_updater
......
......@@ -135,15 +135,6 @@ void RegisterSodaEnUsComponent(ComponentUpdateService* cus,
PrefService* prefs,
base::OnceClosure callback) {
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>(
std::make_unique<SodaEnUsComponentInstallerPolicy>(base::BindRepeating(
[](ComponentUpdateService* cus, PrefService* prefs,
......@@ -156,7 +147,6 @@ void RegisterSodaEnUsComponent(ComponentUpdateService* cus,
cus, prefs)));
installer->Register(cus, std::move(callback));
}
}
} // namespace component_updater
......@@ -135,15 +135,6 @@ void RegisterSodaJaJpComponent(ComponentUpdateService* cus,
PrefService* prefs,
base::OnceClosure callback) {
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>(
std::make_unique<SodaJaJpComponentInstallerPolicy>(base::BindRepeating(
[](ComponentUpdateService* cus, PrefService* prefs,
......@@ -156,7 +147,6 @@ void RegisterSodaJaJpComponent(ComponentUpdateService* cus,
cus, prefs)));
installer->Register(cus, std::move(callback));
}
}
} // namespace component_updater
......@@ -4,6 +4,7 @@
#include "chrome/browser/speech/speech_recognition_service.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/service_sandbox_type.h"
#include "chrome/common/pref_names.h"
#include "chrome/grit/generated_resources.h"
......@@ -61,11 +62,13 @@ void SpeechRecognitionService::LaunchIfNotRunning() {
if (speech_recognition_service_.is_bound())
return;
PrefService* prefs = user_prefs::UserPrefs::Get(context_);
DCHECK(prefs);
PrefService* profile_prefs = user_prefs::UserPrefs::Get(context_);
PrefService* global_prefs = g_browser_process->local_state();
DCHECK(profile_prefs);
DCHECK(global_prefs);
auto binary_path = prefs->GetFilePath(prefs::kSodaBinaryPath);
auto config_path = SpeechRecognitionService::GetSodaConfigPath(prefs);
auto binary_path = global_prefs->GetFilePath(prefs::kSodaBinaryPath);
auto config_path = SpeechRecognitionService::GetSodaConfigPath(profile_prefs);
if (enable_soda_ && (binary_path.empty() || config_path.empty())) {
LOG(ERROR) << "Unable to find SODA files on the device.";
return;
......@@ -98,14 +101,15 @@ void SpeechRecognitionService::LaunchIfNotRunning() {
base::FilePath SpeechRecognitionService::GetSodaConfigPath(PrefService* prefs) {
speech::LanguageCode language = speech::GetLanguageCode(
prefs->GetString(prefs::kLiveCaptionLanguageCode));
PrefService* global_prefs = g_browser_process->local_state();
switch (language) {
case speech::LanguageCode::kNone:
NOTREACHED();
return base::FilePath();
case speech::LanguageCode::kEnUs:
return prefs->GetFilePath(prefs::kSodaEnUsConfigPath);
return global_prefs->GetFilePath(prefs::kSodaEnUsConfigPath);
case speech::LanguageCode::kJaJp:
return prefs->GetFilePath(prefs::kSodaJaJpConfigPath);
return global_prefs->GetFilePath(prefs::kSodaJaJpConfigPath);
}
return base::FilePath();
......
......@@ -5,6 +5,7 @@
#include "base/files/file_util.h"
#include "base/path_service.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_manager.h"
#include "chrome/browser/speech/speech_recognition_service.h"
......@@ -123,11 +124,11 @@ void SpeechRecognitionServiceTest::LaunchService() {
}
IN_PROC_BROWSER_TEST_F(SpeechRecognitionServiceTest, RecognizePhrase) {
ProfileManager::GetActiveUserProfile()->GetPrefs()->SetFilePath(
g_browser_process->local_state()->SetFilePath(
prefs::kSodaBinaryPath,
test_data_dir_.Append(base::FilePath(kSodaResourcesDir))
.Append(kSodaBinaryRelativePath));
ProfileManager::GetActiveUserProfile()->GetPrefs()->SetFilePath(
g_browser_process->local_state()->SetFilePath(
prefs::kSodaEnUsConfigPath,
test_data_dir_.Append(base::FilePath(kSodaResourcesDir))
.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