Commit 225ff31e authored by Abigail Klein's avatar Abigail Klein Committed by Commit Bot

[Live Caption] Create the UI when feature is initialized.

When the caption controller feature is initialized, it should create
the UI of the live caption feature. Before this feature, the UI was only
created when the kLiveCaptionEnabled pref changed. Note that SODA should
only be registered when the pref changes.

Bug: 1055150
Change-Id: I5d78520854b1a5ad0d5388724aea236f527a7804
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2151893
Commit-Queue: Abigail Klein <abigailbklein@google.com>
Reviewed-by: default avatarKatie Dektar <katie@chromium.org>
Reviewed-by: default avatarEvan Liu <evliu@google.com>
Cr-Commit-Position: refs/heads/master@{#760097}
parent 698b9f04
...@@ -55,22 +55,41 @@ void CaptionController::Init() { ...@@ -55,22 +55,41 @@ void CaptionController::Init() {
prefs::kLiveCaptionEnabled, prefs::kLiveCaptionEnabled,
base::BindRepeating(&CaptionController::OnLiveCaptionEnabledChanged, base::BindRepeating(&CaptionController::OnLiveCaptionEnabledChanged,
base::Unretained(this))); base::Unretained(this)));
enabled_ = IsLiveCaptionEnabled();
if (enabled_)
UpdateUIEnabled();
} }
void CaptionController::OnLiveCaptionEnabledChanged() { void CaptionController::OnLiveCaptionEnabledChanged() {
PrefService* profile_prefs = profile_->GetPrefs(); bool enabled = IsLiveCaptionEnabled();
bool enabled = profile_prefs->GetBoolean(prefs::kLiveCaptionEnabled);
if (enabled == enabled_) if (enabled == enabled_)
return; return;
enabled_ = enabled; enabled_ = enabled;
UpdateSpeechRecognitionServiceEnabled();
UpdateUIEnabled();
}
bool CaptionController::IsLiveCaptionEnabled() {
PrefService* profile_prefs = profile_->GetPrefs();
return profile_prefs->GetBoolean(prefs::kLiveCaptionEnabled);
}
void CaptionController::UpdateSpeechRecognitionServiceEnabled() {
if (enabled_) { if (enabled_) {
// Register SODA component and download speech model. // Register SODA component and download speech model.
component_updater::RegisterSODAComponent( component_updater::RegisterSODAComponent(
g_browser_process->component_updater(), profile_prefs, g_browser_process->component_updater(), profile_->GetPrefs(),
base::BindOnce(&component_updater::SODAComponentInstallerPolicy:: base::BindOnce(&component_updater::SODAComponentInstallerPolicy::
UpdateSODAComponentOnDemand)); UpdateSODAComponentOnDemand));
} else {
// TODO(evliu): Unregister SODA component.
}
}
void CaptionController::UpdateUIEnabled() {
if (enabled_) {
// Create captions UI in each browser view. // Create captions UI in each browser view.
for (Browser* browser : *BrowserList::GetInstance()) { for (Browser* browser : *BrowserList::GetInstance()) {
OnBrowserAdded(browser); OnBrowserAdded(browser);
...@@ -79,8 +98,6 @@ void CaptionController::OnLiveCaptionEnabledChanged() { ...@@ -79,8 +98,6 @@ void CaptionController::OnLiveCaptionEnabledChanged() {
// Add observers to the BrowserList for new browser views being added. // Add observers to the BrowserList for new browser views being added.
BrowserList::GetInstance()->AddObserver(this); BrowserList::GetInstance()->AddObserver(this);
} else { } else {
// TODO(evliu): Unregister SODA component.
// Destroy caption bubble controllers. // Destroy caption bubble controllers.
caption_bubble_controllers_.clear(); caption_bubble_controllers_.clear();
......
...@@ -54,6 +54,9 @@ class CaptionController : public BrowserListObserver, public KeyedService { ...@@ -54,6 +54,9 @@ class CaptionController : public BrowserListObserver, public KeyedService {
void OnBrowserRemoved(Browser* browser) override; void OnBrowserRemoved(Browser* browser) override;
void OnLiveCaptionEnabledChanged(); void OnLiveCaptionEnabledChanged();
bool IsLiveCaptionEnabled();
void UpdateSpeechRecognitionServiceEnabled();
void UpdateUIEnabled();
// Owns us via the KeyedService mechanism. // Owns us via the KeyedService mechanism.
Profile* profile_; Profile* profile_;
......
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