Commit 552d105d authored by evliu's avatar evliu Committed by Commit Bot

Clean up SODA files on browser start-up

This CL adds logic to delete the SODA binary and accompanying SODA files
on browser start-up if the Live Caption feature is disabled at the time
of start up. This is an alternative to the more complicated proposal
at go/component-updater-delayed-deletion. Optimization of this behavior
will be determined by user metrics once the feature lands.

Bug: 1097948
Change-Id: I858ec034f1b1c89a80611db3f51049d500877a85
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2258576Reviewed-by: default avatarJoshua Pawlicki <waffles@chromium.org>
Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Commit-Queue: Evan Liu <evliu@google.com>
Cr-Commit-Position: refs/heads/master@{#781905}
parent 380601a1
...@@ -98,7 +98,8 @@ void CaptionController::UpdateSpeechRecognitionServiceEnabled() { ...@@ -98,7 +98,8 @@ void CaptionController::UpdateSpeechRecognitionServiceEnabled() {
base::BindOnce(&component_updater::SODAComponentInstallerPolicy:: base::BindOnce(&component_updater::SODAComponentInstallerPolicy::
UpdateSODAComponentOnDemand)); UpdateSODAComponentOnDemand));
} else { } else {
// TODO(evliu): Unregister SODA component. // Do nothing. The SODA component will be uninstalled and removed from the
// device on the next start up.
} }
} }
......
...@@ -178,9 +178,8 @@ void RegisterComponentsForUpdate(bool is_off_the_record_profile, ...@@ -178,9 +178,8 @@ void RegisterComponentsForUpdate(bool is_off_the_record_profile,
#endif // BUILDFLAG(GOOGLE_CHROME_BRANDING) && defined(OS_ANDROID) #endif // BUILDFLAG(GOOGLE_CHROME_BRANDING) && defined(OS_ANDROID)
#if !defined(OS_ANDROID) #if !defined(OS_ANDROID)
if (profile_prefs->GetBoolean(prefs::kLiveCaptionEnabled)) component_updater::RegisterSODAComponent(cus, profile_prefs,
component_updater::RegisterSODAComponent(cus, profile_prefs, base::OnceClosure());
base::OnceClosure());
#endif #endif
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
......
...@@ -133,12 +133,38 @@ void RegisterSODAComponent(ComponentUpdateService* cus, ...@@ -133,12 +133,38 @@ void RegisterSODAComponent(ComponentUpdateService* cus,
auto installer = base::MakeRefCounted<ComponentInstaller>( auto installer = base::MakeRefCounted<ComponentInstaller>(
std::make_unique<SODAComponentInstallerPolicy>(base::BindRepeating( std::make_unique<SODAComponentInstallerPolicy>(base::BindRepeating(
[](PrefService* prefs, const base::FilePath& install_dir) { [](ComponentUpdateService* cus, PrefService* prefs,
content::GetUIThreadTaskRunner({base::TaskPriority::BEST_EFFORT}) const base::FilePath& install_dir) {
->PostTask(FROM_HERE, base::BindOnce(&UpdateSODAInstallDirPref, if (prefs->GetBoolean(prefs::kLiveCaptionEnabled)) {
prefs, install_dir)); content::GetUIThreadTaskRunner({base::TaskPriority::BEST_EFFORT})
->PostTask(FROM_HERE,
base::BindOnce(&UpdateSODAInstallDirPref, prefs,
install_dir));
}
}, },
prefs))); cus, prefs)));
installer->Register(cus, std::move(callback));
if (prefs->GetBoolean(prefs::kLiveCaptionEnabled)) {
installer->Register(cus, std::move(callback));
} else {
// Register and uninstall the SODA component to delete the previously
// installed SODA files.
if (!prefs->GetFilePath(prefs::kSODAPath).empty()) {
installer->Register(
cus,
base::BindOnce(
[](ComponentUpdateService* cus, PrefService* prefs) {
if (component_updater::UninstallSODAComponent(cus, prefs)) {
prefs->SetFilePath(prefs::kSODAPath, base::FilePath());
}
},
cus, prefs));
}
}
}
bool UninstallSODAComponent(ComponentUpdateService* cus, PrefService* prefs) {
return cus->UnregisterComponent(
SODAComponentInstallerPolicy::GetExtensionId());
} }
} // namespace component_updater } // namespace component_updater
...@@ -61,6 +61,8 @@ void RegisterSODAComponent(ComponentUpdateService* cus, ...@@ -61,6 +61,8 @@ void RegisterSODAComponent(ComponentUpdateService* cus,
PrefService* prefs, PrefService* prefs,
base::OnceClosure callback); base::OnceClosure callback);
bool UninstallSODAComponent(ComponentUpdateService* cus, PrefService* prefs);
} // namespace component_updater } // namespace component_updater
#endif // CHROME_BROWSER_COMPONENT_UPDATER_SODA_COMPONENT_INSTALLER_H_ #endif // CHROME_BROWSER_COMPONENT_UPDATER_SODA_COMPONENT_INSTALLER_H_
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