Commit 5eb53a45 authored by Abigail Klein's avatar Abigail Klein Committed by Commit Bot

[Live Caption] Manage SODA installation and progress updates for

ChromeOS and non-ChromeOS installations.

Introduce a new SODAInstaller which is responsible for installing
SODA (Speech On-Device API). It has a separate implementations in
ChromeOS and non-ChromeOS. The SODAInstallerImpl on ChromeOS installs
SODA with the DlcserviceClient. The SODAInstallerImpl on non-ChromeOS
installs SODA with the ComponentUpdaterService. Each sends installation
progress updates to its observers.

The SODAInstaller has a single instance, because SODA is only downloaded
once for the entire device.

The CaptionController initiates the SODA download by calling the
InstallSODA method of the SODAInstaller. It initiates language downloads
by calling InstallLanguage.

The CaptionsHandler is a SODAInstallerObserver. It sends SODA download
updates to the captions subpage WebUI in settings. Since the
SODAInstallerObserver is a common interface between the ChromeOS
and non-ChromeOS implementations, there now only needs to be one
CaptionsHandler.

More SODAInstallerObservers will be introduced in upcoming CLs.

For more information, see this design doc: https://docs.google.com/document/d/1e9ie7WequR4UafYq72-wpXwFj0-lLWMvjXZP5jXXpwU/edit#

Bug: 1055150, 1111002
Change-Id: Ia82285a1dc1440229d7912bb07ae522abde9900b
AX-Relnotes: N/A (feature not yet launched)
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2473744
Commit-Queue: Abigail Klein <abigailbklein@google.com>
Reviewed-by: default avatarSorin Jianu <sorin@chromium.org>
Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Reviewed-by: default avatardpapad <dpapad@chromium.org>
Reviewed-by: default avatarDominic Mazzoni <dmazzoni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#825222}
parent e9d0a99d
......@@ -3279,6 +3279,8 @@ static_library("browser") {
"accessibility/caption_host_impl.h",
"accessibility/invert_bubble_prefs.cc",
"accessibility/invert_bubble_prefs.h",
"accessibility/soda_installer.cc",
"accessibility/soda_installer.h",
"apps/app_service/app_icon_factory.cc",
"apps/app_service/app_icon_factory.h",
"apps/app_service/app_icon_source.cc",
......@@ -4060,6 +4062,11 @@ static_library("browser") {
"//chromeos/services/nearby/public/mojom",
"//components/arc:arc_base_utils",
]
} else {
sources += [
"accessibility/soda_installer_impl.cc",
"accessibility/soda_installer_impl.h",
]
}
if (enable_extensions) {
deps += [ "//extensions/browser" ]
......
......@@ -4,15 +4,15 @@
#include "chrome/browser/accessibility/caption_controller.h"
#include <string>
#include <memory>
#include "base/bind.h"
#include "base/command_line.h"
#include "base/feature_list.h"
#include "base/metrics/histogram_functions.h"
#include "chrome/browser/accessibility/caption_util.h"
#include "chrome/browser/accessibility/soda_installer.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/component_updater/soda_component_installer.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
......@@ -99,30 +99,13 @@ void CaptionController::OnLiveCaptionEnabledChanged() {
if (enabled == enabled_)
return;
enabled_ = enabled;
UpdateSpeechRecognitionServiceEnabled();
UpdateSpeechRecognitionLanguage();
UpdateUIEnabled();
}
void CaptionController::OnLiveCaptionLanguageChanged() {
UpdateSpeechRecognitionLanguage();
}
bool CaptionController::IsLiveCaptionEnabled() {
PrefService* profile_prefs = profile_->GetPrefs();
return profile_prefs->GetBoolean(prefs::kLiveCaptionEnabled);
}
void CaptionController::UpdateSpeechRecognitionServiceEnabled() {
if (enabled_) {
// Register SODA component and download speech model.
g_browser_process->local_state()->SetTime(prefs::kSodaScheduledDeletionTime,
base::Time());
// Register SODA component and download speech model.
component_updater::RegisterSodaComponent(
g_browser_process->component_updater(), profile_->GetPrefs(),
g_browser_process->local_state(),
base::BindOnce(&component_updater::SODAComponentInstallerPolicy::
UpdateSODAComponentOnDemand));
speech::SODAInstaller::GetInstance()->InstallSODA(profile_->GetPrefs());
speech::SODAInstaller::GetInstance()->InstallLanguage(profile_->GetPrefs());
} else {
// Schedule SODA to be deleted in 30 days if the feature is not enabled
// before then.
......@@ -130,14 +113,18 @@ void CaptionController::UpdateSpeechRecognitionServiceEnabled() {
prefs::kSodaScheduledDeletionTime,
base::Time::Now() + base::TimeDelta::FromDays(kSodaCleanUpDelayInDays));
}
UpdateUIEnabled();
}
void CaptionController::UpdateSpeechRecognitionLanguage() {
if (enabled_) {
component_updater::RegisterSodaLanguageComponent(
g_browser_process->component_updater(), profile_->GetPrefs());
}
} // namespace captions
void CaptionController::OnLiveCaptionLanguageChanged() {
if (enabled_)
speech::SODAInstaller::GetInstance()->InstallLanguage(profile_->GetPrefs());
}
bool CaptionController::IsLiveCaptionEnabled() {
PrefService* profile_prefs = profile_->GetPrefs();
return profile_prefs->GetBoolean(prefs::kLiveCaptionEnabled);
}
void CaptionController::UpdateUIEnabled() {
if (enabled_) {
......
......@@ -6,7 +6,6 @@
#define CHROME_BROWSER_ACCESSIBILITY_CAPTION_CONTROLLER_H_
#include <memory>
#include <string>
#include <unordered_map>
#include "chrome/browser/ui/browser_list_observer.h"
......@@ -89,8 +88,6 @@ class CaptionController : public BrowserListObserver, public KeyedService {
void OnLiveCaptionEnabledChanged();
void OnLiveCaptionLanguageChanged();
bool IsLiveCaptionEnabled();
void UpdateSpeechRecognitionServiceEnabled();
void UpdateSpeechRecognitionLanguage();
void UpdateUIEnabled();
void UpdateCaptionStyle();
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/accessibility/soda_installer.h"
namespace speech {
SODAInstaller::SODAInstaller() = default;
SODAInstaller::~SODAInstaller() = default;
void SODAInstaller::AddObserver(Observer* observer) {
observers_.AddObserver(observer);
}
void SODAInstaller::RemoveObserver(Observer* observer) {
observers_.RemoveObserver(observer);
}
void SODAInstaller::NotifyOnSODAInstalled() {
for (Observer& observer : observers_)
observer.OnSODAInstalled();
}
void SODAInstaller::NotifyOnSODAError() {
for (Observer& observer : observers_)
observer.OnSODAError();
}
void SODAInstaller::NotifyOnSODAProgress(int percent) {
for (Observer& observer : observers_)
observer.OnSODAProgress(percent);
}
} // namespace speech
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_ACCESSIBILITY_SODA_INSTALLER_H_
#define CHROME_BROWSER_ACCESSIBILITY_SODA_INSTALLER_H_
#include "base/observer_list.h"
class PrefService;
namespace speech {
// Installer of SODA (Speech On-Device API). This is a singleton because there
// is only one installation of SODA per device.
class SODAInstaller {
public:
// Observer of the SODA (Speech On-Device API) installation.
class Observer : public base::CheckedObserver {
public:
// Called when the SODA installation has completed.
virtual void OnSODAInstalled() = 0;
// Called if there is an error in the SODA installation.
virtual void OnSODAError() = 0;
// Called during the SODA installation. Progress is the download percentage
// out of 100.
virtual void OnSODAProgress(int progress) = 0;
};
SODAInstaller();
~SODAInstaller();
SODAInstaller(const SODAInstaller&) = delete;
SODAInstaller& operator=(const SODAInstaller&) = delete;
// Implemented in the platform-specific subclass to get the SODAInstaller
// instance.
static SODAInstaller* GetInstance();
// Installs the SODA binary. Called by CaptionController when the
// kLiveCaptionEnabled preference changes. PrefService is passed to share
// Live Captions preferences: whether it is enabled, which language to
// download, and what the download filepath should be.
virtual void InstallSODA(PrefService* prefs) = 0;
// Installs the user-selected SODA language model. Called by CaptionController
// when the kLiveCaptionEnabled or kLiveCaptionLanguageCode preferences
// change. PrefService is passed to share Live Captions preferences: whether
// it is enabled, which language to download, and what the download filepath
// should be.
virtual void InstallLanguage(PrefService* prefs) = 0;
// Adds an observer to the observer list.
void AddObserver(Observer* observer);
// Removes an observer from the observer list.
void RemoveObserver(Observer* observer);
// Notifies the observers that the SODA installation has completed.
void NotifyOnSODAInstalled();
// Notifies the observers that there is an error in the SODA installation.
void NotifyOnSODAError();
// Notifies the observers of the progress percentage as SODA is installed/
// Progress is the download percentage out of 100.
void NotifyOnSODAProgress(int progress);
protected:
base::ObserverList<Observer> observers_;
};
} // namespace speech
#endif // CHROME_BROWSER_ACCESSIBILITY_SODA_INSTALLER_H_
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/accessibility/soda_installer_impl.h"
#include <map>
#include <string>
#include "base/bind.h"
#include "base/check_op.h"
#include "base/no_destructor.h"
#include "base/numerics/ranges.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/component_updater/soda_component_installer.h"
#include "chrome/browser/component_updater/soda_en_us_component_installer.h"
#include "chrome/browser/component_updater/soda_ja_jp_component_installer.h"
#include "chrome/common/pref_names.h"
#include "components/prefs/pref_service.h"
#include "components/update_client/crx_update_item.h"
namespace {
int GetDownloadProgress(
const std::map<std::string, update_client::CrxUpdateItem>&
downloading_components) {
int total_bytes = 0;
int downloaded_bytes = 0;
for (auto component : downloading_components) {
if (component.second.downloaded_bytes >= 0 &&
component.second.total_bytes > 0) {
downloaded_bytes += component.second.downloaded_bytes;
total_bytes += component.second.total_bytes;
}
}
if (total_bytes == 0)
return -1;
DCHECK_LE(downloaded_bytes, total_bytes);
return 100 *
base::ClampToRange(double{downloaded_bytes} / total_bytes, 0.0, 1.0);
}
} // namespace
namespace speech {
// static
SODAInstaller* SODAInstaller::GetInstance() {
static base::NoDestructor<SODAInstallerImpl> instance;
return instance.get();
}
SODAInstallerImpl::SODAInstallerImpl() = default;
SODAInstallerImpl::~SODAInstallerImpl() {
component_updater_observer_.RemoveAll();
}
void SODAInstallerImpl::InstallSODA(PrefService* prefs) {
component_updater::RegisterSodaComponent(
g_browser_process->component_updater(), prefs,
g_browser_process->local_state(),
base::BindOnce(&component_updater::SODAComponentInstallerPolicy::
UpdateSODAComponentOnDemand));
if (!component_updater_observer_.IsObserving(
g_browser_process->component_updater())) {
component_updater_observer_.Add(g_browser_process->component_updater());
}
}
void SODAInstallerImpl::InstallLanguage(PrefService* prefs) {
component_updater::RegisterSodaLanguageComponent(
g_browser_process->component_updater(), prefs);
if (!component_updater_observer_.IsObserving(
g_browser_process->component_updater())) {
component_updater_observer_.Add(g_browser_process->component_updater());
}
}
void SODAInstallerImpl::OnEvent(Events event, const std::string& id) {
if (id != component_updater::SODAComponentInstallerPolicy::GetExtensionId() &&
id != component_updater::SodaEnUsComponentInstallerPolicy::
GetExtensionId() &&
id !=
component_updater::SodaJaJpComponentInstallerPolicy::GetExtensionId())
return;
switch (event) {
case Events::COMPONENT_UPDATE_FOUND:
case Events::COMPONENT_UPDATE_READY:
case Events::COMPONENT_WAIT:
case Events::COMPONENT_UPDATE_DOWNLOADING:
case Events::COMPONENT_UPDATE_UPDATING: {
update_client::CrxUpdateItem item;
g_browser_process->component_updater()->GetComponentDetails(id, &item);
downloading_components_[id] = item;
const int progress = GetDownloadProgress(downloading_components_);
// When GetDownloadProgress returns -1, do nothing. It returns -1 when the
// downloaded or total bytes is unknown.
if (progress != -1) {
NotifyOnSODAProgress(progress);
}
} break;
case Events::COMPONENT_UPDATED:
case Events::COMPONENT_NOT_UPDATED:
NotifyOnSODAInstalled();
break;
case Events::COMPONENT_UPDATE_ERROR:
NotifyOnSODAError();
break;
case Events::COMPONENT_CHECKING_FOR_UPDATES:
// Do nothing.
break;
}
}
} // namespace speech
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_ACCESSIBILITY_SODA_INSTALLER_IMPL_H_
#define CHROME_BROWSER_ACCESSIBILITY_SODA_INSTALLER_IMPL_H_
#include <map>
#include <string>
#include "base/scoped_observer.h"
#include "chrome/browser/accessibility/soda_installer.h"
#include "components/component_updater/component_updater_service.h"
class PrefService;
namespace update_client {
struct CrxUpdateItem;
}
namespace speech {
// Installer of SODA (Speech On-Device API) for the Live Caption feature on
// non-ChromeOS desktop versions of Chrome browser.
class SODAInstallerImpl : public SODAInstaller,
public component_updater::ServiceObserver {
public:
SODAInstallerImpl();
~SODAInstallerImpl() override;
SODAInstallerImpl(const SODAInstallerImpl&) = delete;
SODAInstallerImpl& operator=(const SODAInstallerImpl&) = delete;
// SODAInstaller:
void InstallSODA(PrefService* prefs) override;
void InstallLanguage(PrefService* prefs) override;
private:
// component_updater::ServiceObserver:
void OnEvent(Events event, const std::string& id) override;
std::map<std::string, update_client::CrxUpdateItem> downloading_components_;
ScopedObserver<component_updater::ComponentUpdateService,
component_updater::ComponentUpdateService::Observer>
component_updater_observer_{this};
};
} // namespace speech
#endif // CHROME_BROWSER_ACCESSIBILITY_SODA_INSTALLER_IMPL_H_
......@@ -424,6 +424,8 @@ source_set("chromeos") {
"accessibility/magnifier_type.h",
"accessibility/select_to_speak_event_handler_delegate.cc",
"accessibility/select_to_speak_event_handler_delegate.h",
"accessibility/soda_installer_impl_chromeos.cc",
"accessibility/soda_installer_impl_chromeos.h",
"account_manager/account_manager_edu_coexistence_controller.cc",
"account_manager/account_manager_edu_coexistence_controller.h",
"account_manager/account_manager_facade_factory_ash.cc",
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/chromeos/accessibility/soda_installer_impl_chromeos.h"
#include "base/bind.h"
#include "base/no_destructor.h"
#include "chromeos/dbus/dlcservice/dlcservice_client.h"
namespace {
// TODO(crbug.com/1111002): Replace this with the real SODA DLC id.
constexpr char kSODADlcName[] = "soda";
} // namespace
namespace speech {
SODAInstaller* SODAInstaller::GetInstance() {
static base::NoDestructor<SODAInstallerImplChromeOS> instance;
return instance.get();
}
SODAInstallerImplChromeOS::SODAInstallerImplChromeOS() = default;
SODAInstallerImplChromeOS::~SODAInstallerImplChromeOS() = default;
void SODAInstallerImplChromeOS::InstallSODA(PrefService* prefs) {
// Install SODA DLC.
chromeos::DlcserviceClient::Get()->Install(
kSODADlcName,
base::BindOnce(&SODAInstallerImplChromeOS::OnSODAInstalled,
base::Unretained(this)),
base::BindRepeating(&SODAInstallerImplChromeOS::OnSODAProgress,
base::Unretained(this)));
}
void SODAInstallerImplChromeOS::InstallLanguage(PrefService* prefs) {
// TODO(crbug.com/1111002): Install SODA language.
}
void SODAInstallerImplChromeOS::OnSODAInstalled(
const chromeos::DlcserviceClient::InstallResult& install_result) {
if (install_result.error == dlcservice::kErrorNone) {
NotifyOnSODAInstalled();
} else {
NotifyOnSODAError();
}
}
void SODAInstallerImplChromeOS::OnSODAProgress(double progress) {
NotifyOnSODAProgress(int{100 * progress});
}
} // namespace speech
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_CHROMEOS_ACCESSIBILITY_SODA_INSTALLER_IMPL_CHROMEOS_H_
#define CHROME_BROWSER_CHROMEOS_ACCESSIBILITY_SODA_INSTALLER_IMPL_CHROMEOS_H_
#include "chrome/browser/accessibility/soda_installer.h"
#include "chromeos/dbus/dlcservice/dlcservice_client.h"
class PrefService;
namespace speech {
// Installer of SODA (Speech On-Device API) for the Live Caption feature on
// ChromeOS.
class SODAInstallerImplChromeOS : public SODAInstaller {
public:
SODAInstallerImplChromeOS();
~SODAInstallerImplChromeOS();
SODAInstallerImplChromeOS(const SODAInstallerImplChromeOS&) = delete;
SODAInstallerImplChromeOS& operator=(const SODAInstallerImplChromeOS&) =
delete;
// SODAInstaller:
void InstallSODA(PrefService* prefs) override;
void InstallLanguage(PrefService* prefs) override;
private:
// This function is the InstallCallback for DlcserviceClient::Install().
void OnSODAInstalled(
const chromeos::DlcserviceClient::InstallResult& install_result);
// This function is the ProgressCallback for DlcserviceClient::Install().
void OnSODAProgress(double progress);
};
} // namespace speech
#endif // CHROME_BROWSER_CHROMEOS_ACCESSIBILITY_SODA_INSTALLER_IMPL_CHROMEOS_H_
......@@ -1402,6 +1402,8 @@ static_library("ui") {
"webui/settings/appearance_handler.h",
"webui/settings/browser_lifetime_handler.cc",
"webui/settings/browser_lifetime_handler.h",
"webui/settings/captions_handler.cc",
"webui/settings/captions_handler.h",
"webui/settings/custom_home_pages_table_model.cc",
"webui/settings/custom_home_pages_table_model.h",
"webui/settings/downloads_handler.cc",
......@@ -1562,13 +1564,6 @@ static_library("ui") {
deps += [ "//ui/base/ime/linux" ]
}
if (!is_chromeos) {
sources += [
"webui/settings/captions_handler.cc",
"webui/settings/captions_handler.h",
]
}
if (!toolkit_views) {
sources += [ "media_router/cloud_services_dialog.cc" ]
}
......@@ -2441,8 +2436,6 @@ static_library("ui") {
"webui/settings/chromeos/bluetooth_section.h",
"webui/settings/chromeos/calculator/size_calculator.cc",
"webui/settings/chromeos/calculator/size_calculator.h",
"webui/settings/chromeos/captions_handler.cc",
"webui/settings/chromeos/captions_handler.h",
"webui/settings/chromeos/change_picture_handler.cc",
"webui/settings/chromeos/change_picture_handler.h",
"webui/settings/chromeos/constants/constants_util.cc",
......
......@@ -5,20 +5,13 @@
#include "chrome/browser/ui/webui/settings/captions_handler.h"
#include "base/bind.h"
#include "base/check_op.h"
#include "base/numerics/ranges.h"
#include "base/values.h"
#include "build/build_config.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/component_updater/soda_component_installer.h"
#include "chrome/browser/component_updater/soda_en_us_component_installer.h"
#include "chrome/browser/component_updater/soda_ja_jp_component_installer.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/pref_names.h"
#include "chrome/grit/chromium_strings.h"
#include "chrome/grit/generated_resources.h"
#include "components/prefs/pref_service.h"
#include "components/update_client/crx_update_item.h"
#include "content/public/browser/web_ui.h"
#include "ui/base/l10n/l10n_util.h"
......@@ -26,31 +19,6 @@
#include "chrome/browser/accessibility/caption_settings_dialog.h"
#endif
namespace {
int GetDownloadProgress(std::map<std::string, update_client::CrxUpdateItem>
downloading_components) {
int total_bytes = 0;
int downloaded_bytes = 0;
for (auto component : downloading_components) {
if (component.second.downloaded_bytes >= 0 &&
component.second.total_bytes > 0) {
downloaded_bytes += component.second.downloaded_bytes;
total_bytes += component.second.total_bytes;
}
}
if (total_bytes == 0)
return -1;
DCHECK_LE(downloaded_bytes, total_bytes);
return 100 *
base::ClampToRange(double{downloaded_bytes} / total_bytes, 0.0, 1.0);
}
} // namespace
namespace settings {
CaptionsHandler::CaptionsHandler(PrefService* prefs) : prefs_(prefs) {}
......@@ -69,11 +37,11 @@ void CaptionsHandler::RegisterMessages() {
}
void CaptionsHandler::OnJavascriptAllowed() {
component_updater_observer_.Add(g_browser_process->component_updater());
speech::SODAInstaller::GetInstance()->AddObserver(this);
}
void CaptionsHandler::OnJavascriptDisallowed() {
component_updater_observer_.RemoveAll();
speech::SODAInstaller::GetInstance()->RemoveObserver(this);
}
void CaptionsHandler::HandleCaptionsSubpageReady(const base::ListValue* args) {
......@@ -87,52 +55,24 @@ void CaptionsHandler::HandleOpenSystemCaptionsDialog(
#endif
}
void CaptionsHandler::OnEvent(Events event, const std::string& id) {
if (id != component_updater::SODAComponentInstallerPolicy::GetExtensionId() &&
id != component_updater::SodaEnUsComponentInstallerPolicy::
GetExtensionId() &&
id !=
component_updater::SodaJaJpComponentInstallerPolicy::GetExtensionId())
return;
void CaptionsHandler::OnSODAInstalled() {
FireWebUIListener("enable-live-caption-subtitle-changed",
base::Value(l10n_util::GetStringUTF16(
IDS_SETTINGS_CAPTIONS_LIVE_CAPTION_DOWNLOAD_COMPLETE)));
}
void CaptionsHandler::OnSODAError() {
prefs_->SetBoolean(prefs::kLiveCaptionEnabled, false);
FireWebUIListener("enable-live-caption-subtitle-changed",
base::Value(l10n_util::GetStringUTF16(
IDS_SETTINGS_CAPTIONS_LIVE_CAPTION_DOWNLOAD_ERROR)));
}
switch (event) {
case Events::COMPONENT_UPDATE_FOUND:
case Events::COMPONENT_UPDATE_READY:
case Events::COMPONENT_WAIT:
case Events::COMPONENT_UPDATE_DOWNLOADING:
case Events::COMPONENT_UPDATE_UPDATING: {
update_client::CrxUpdateItem item;
g_browser_process->component_updater()->GetComponentDetails(id, &item);
downloading_components_[id] = item;
const int progress = GetDownloadProgress(downloading_components_);
// When GetDownloadProgress returns -1, do nothing. It returns -1 when the
// downloaded or total bytes is unknown.
if (progress != -1) {
FireWebUIListener(
"enable-live-caption-subtitle-changed",
base::Value(l10n_util::GetStringFUTF16Int(
IDS_SETTINGS_CAPTIONS_LIVE_CAPTION_DOWNLOAD_PROGRESS,
progress)));
}
} break;
case Events::COMPONENT_UPDATED:
case Events::COMPONENT_NOT_UPDATED:
FireWebUIListener(
"enable-live-caption-subtitle-changed",
base::Value(l10n_util::GetStringUTF16(
IDS_SETTINGS_CAPTIONS_LIVE_CAPTION_DOWNLOAD_COMPLETE)));
break;
case Events::COMPONENT_UPDATE_ERROR:
prefs_->SetBoolean(prefs::kLiveCaptionEnabled, false);
FireWebUIListener(
"enable-live-caption-subtitle-changed",
base::Value(l10n_util::GetStringUTF16(
IDS_SETTINGS_CAPTIONS_LIVE_CAPTION_DOWNLOAD_ERROR)));
break;
case Events::COMPONENT_CHECKING_FOR_UPDATES:
// Do nothing.
break;
}
void CaptionsHandler::OnSODAProgress(int progress) {
FireWebUIListener(
"enable-live-caption-subtitle-changed",
base::Value(l10n_util::GetStringFUTF16Int(
IDS_SETTINGS_CAPTIONS_LIVE_CAPTION_DOWNLOAD_PROGRESS, progress)));
}
} // namespace settings
......@@ -5,34 +5,23 @@
#ifndef CHROME_BROWSER_UI_WEBUI_SETTINGS_CAPTIONS_HANDLER_H_
#define CHROME_BROWSER_UI_WEBUI_SETTINGS_CAPTIONS_HANDLER_H_
#include <map>
#include <string>
#include "base/macros.h"
#include "base/scoped_observer.h"
#include "chrome/browser/accessibility/soda_installer.h"
#include "chrome/browser/ui/webui/settings/settings_page_ui_handler.h"
#include "components/component_updater/component_updater_service.h"
class PrefService;
namespace update_client {
struct CrxUpdateItem;
}
namespace settings {
// Settings handler for the captions settings page, chrome://settings/captions,
// and for caption settings on the main accessibility page,
// chrome://settings/accessibility, on non-ChromeOS desktop browsers.
class CaptionsHandler : public ::settings::SettingsPageUIHandler,
public component_updater::ServiceObserver {
// Settings handler for the captions settings subpage.
class CaptionsHandler : public SettingsPageUIHandler,
public speech::SODAInstaller::Observer {
public:
explicit CaptionsHandler(PrefService* prefs);
~CaptionsHandler() override;
CaptionsHandler(const CaptionsHandler&) = delete;
CaptionsHandler& operator=(const CaptionsHandler&) = delete;
// SettingsPageUIHandler overrides:
// SettingsPageUIHandler overrides.
void RegisterMessages() override;
void OnJavascriptAllowed() override;
void OnJavascriptDisallowed() override;
......@@ -41,14 +30,12 @@ class CaptionsHandler : public ::settings::SettingsPageUIHandler,
void HandleCaptionsSubpageReady(const base::ListValue* args);
void HandleOpenSystemCaptionsDialog(const base::ListValue* args);
// component_updater::ServiceObserver:
void OnEvent(Events event, const std::string& id) override;
// SODAInstaller::Observer overrides:
void OnSODAInstalled() override;
void OnSODAError() override;
void OnSODAProgress(int progress) override;
std::map<std::string, update_client::CrxUpdateItem> downloading_components_;
PrefService* prefs_;
ScopedObserver<component_updater::ComponentUpdateService,
component_updater::ComponentUpdateService::Observer>
component_updater_observer_{this};
};
} // namespace settings
......
......@@ -4,6 +4,11 @@
#include "chrome/browser/ui/webui/settings/chromeos/accessibility_section.h"
#include <memory>
#include <set>
#include <string>
#include <vector>
#include "ash/public/cpp/ash_features.h"
#include "ash/public/cpp/ash_pref_names.h"
#include "ash/public/cpp/tablet_mode.h"
......@@ -15,8 +20,8 @@
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/speech/extension_api/tts_engine_extension_observer_chromeos.h"
#include "chrome/browser/ui/webui/settings/accessibility_main_handler.h"
#include "chrome/browser/ui/webui/settings/captions_handler.h"
#include "chrome/browser/ui/webui/settings/chromeos/accessibility_handler.h"
#include "chrome/browser/ui/webui/settings/chromeos/captions_handler.h"
#include "chrome/browser/ui/webui/settings/chromeos/search/search_tag_registry.h"
#include "chrome/browser/ui/webui/settings/chromeos/switch_access_handler.h"
#include "chrome/browser/ui/webui/settings/chromeos/tts_handler.h"
......@@ -615,7 +620,8 @@ void AccessibilitySection::AddHandlers(content::WebUI* web_ui) {
web_ui->AddMessageHandler(std::make_unique<::settings::TtsHandler>());
web_ui->AddMessageHandler(
std::make_unique<::settings::FontHandler>(profile()));
web_ui->AddMessageHandler(std::make_unique<CaptionsHandler>());
web_ui->AddMessageHandler(
std::make_unique<::settings::CaptionsHandler>(profile()->GetPrefs()));
}
int AccessibilitySection::GetSectionNameMessageId() const {
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/webui/settings/chromeos/captions_handler.h"
#include "base/bind_helpers.h"
#include "content/public/browser/web_ui.h"
namespace chromeos {
namespace settings {
CaptionsHandler::CaptionsHandler() = default;
CaptionsHandler::~CaptionsHandler() = default;
void CaptionsHandler::RegisterMessages() {
// TODO(crbug.com/1111002): Show download progress of SODA component in the
// Live Caption subtitle.
web_ui()->RegisterMessageCallback("captionsSubpageReady", base::DoNothing());
}
} // namespace settings
} // namespace chromeos
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_WEBUI_SETTINGS_CHROMEOS_CAPTIONS_HANDLER_H_
#define CHROME_BROWSER_UI_WEBUI_SETTINGS_CHROMEOS_CAPTIONS_HANDLER_H_
#include "chrome/browser/ui/webui/settings/settings_page_ui_handler.h"
namespace chromeos {
namespace settings {
// Settings handler for the captions settings page on ChromeOS.
class CaptionsHandler : public ::settings::SettingsPageUIHandler {
public:
CaptionsHandler();
~CaptionsHandler() override;
CaptionsHandler(const CaptionsHandler&) = delete;
CaptionsHandler& operator=(const CaptionsHandler&) = delete;
// SettingsPageUIHandler overrides:
void RegisterMessages() override;
void OnJavascriptAllowed() override {}
void OnJavascriptDisallowed() override {}
};
} // namespace settings
} // namespace chromeos
#endif // CHROME_BROWSER_UI_WEBUI_SETTINGS_CHROMEOS_CAPTIONS_HANDLER_H_
......@@ -26,8 +26,8 @@ namespace policy {
class ComponentUpdaterPolicyTest;
}
namespace settings {
class CaptionsHandler;
namespace speech {
class SODAInstallerImpl;
}
namespace update_client {
......@@ -147,7 +147,7 @@ class ComponentUpdateService {
virtual bool GetComponentDetails(const std::string& id,
CrxUpdateItem* item) const = 0;
friend class settings::CaptionsHandler;
friend class speech::SODAInstallerImpl;
friend class ::ComponentsHandler;
FRIEND_TEST_ALL_PREFIXES(ComponentInstallerTest, RegisterComponent);
};
......
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