Commit 96d45c70 authored by kcarattini's avatar kcarattini Committed by Commit bot

Add error indicators to always-on andno-dsp hotword checkboxes.

Also shows the indicator regardless of pref status.
(For always-on, the opt-in process requires that there
are no errors, so if something goes wrong it is better that the user know why.)

Screenshot in attached bug.

BUG=390086

Review URL: https://codereview.chromium.org/693393004

Cr-Commit-Position: refs/heads/master@{#302710}
parent c687507f
......@@ -168,6 +168,8 @@
i18n-content="learnMore"
i18n-values="href:hotwordLearnMoreURL">
</a>
<span id="hotword-always-on-search-setting-indicator"
pref="hotword.always_on_search_enabled" dialog-pref></span>
<div>
<span class="hotword-description"
i18n-content="hotwordAlwaysOnDesc">
......@@ -186,6 +188,8 @@
i18n-content="learnMore"
i18n-values="href:hotwordLearnMoreURL">
</a>
<span id="hotword-no-dsp-search-setting-indicator"
pref="hotword.search_enabled_2" dialog-pref></span>
<div>
<span class="hotword-description"
i18n-content="hotwordNoDSPDesc">
......
......@@ -224,8 +224,12 @@ cr.define('options', function() {
['Options_Homepage_ShowSettings']);
};
var hotwordIndicator = $('hotword-search-setting-indicator');
HotwordSearchSettingIndicator.decorate(hotwordIndicator);
HotwordSearchSettingIndicator.decorate(
$('hotword-search-setting-indicator'));
HotwordSearchSettingIndicator.decorate(
$('hotword-no-dsp-search-setting-indicator'));
HotwordSearchSettingIndicator.decorate(
$('hotword-always-on-search-setting-indicator'));
chrome.send('requestHotwordAvailable');
if ($('set-wallpaper')) {
......@@ -1127,34 +1131,56 @@ cr.define('options', function() {
/**
* Activates the Hotword section from the System settings page.
* @param {boolean} opt_enabled Current preference state for hotwording.
* @param {string} opt_error The error message to display.
* @param {string} sectionId The id of the section to display.
* @param {string} indicatorId The id of the indicator to display.
* @param {string=} opt_error The error message to display.
* @private
*/
showHotwordSection_: function(opt_enabled, opt_error) {
$('hotword-search').hidden = false;
$('hotword-search-setting-indicator').setError(opt_error);
if (opt_enabled && opt_error)
$('hotword-search-setting-indicator').updateBasedOnError();
showHotwordCheckboxAndIndicator_: function(sectionId, indicatorId,
opt_error) {
$(sectionId).hidden = false;
$(indicatorId).setError(opt_error);
if (opt_error)
$(indicatorId).updateBasedOnError();
},
/**
* Activates the Hotword section from the System settings page.
* @param {string=} opt_error The error message to display.
* @private
*/
showHotwordSection_: function(opt_error) {
this.showHotwordCheckboxAndIndicator_(
'hotword-search',
'hotword-search-setting-indicator',
opt_error);
},
/**
* Activates the Audio History and Always-On Hotword sections from the
* System settings page.
* @param {string=} opt_error The error message to display.
* @private
*/
showHotwordAlwaysOnSection_: function() {
$('hotword-always-on-search').hidden = false;
showHotwordAlwaysOnSection_: function(opt_error) {
this.showHotwordCheckboxAndIndicator_(
'hotword-always-on-search',
'hotword-always-on-search-setting-indicator',
opt_error);
$('audio-logging').hidden = false;
},
/**
* Activates the Hotword section on devices with no DSP
* from the System settings page.
* @param {string=} opt_error The error message to display.
* @private
*/
showHotwordNoDSPSection_: function() {
$('hotword-no-dsp-search').hidden = false;
showHotwordNoDspSection_: function(opt_error) {
this.showHotwordCheckboxAndIndicator_(
'hotword-no-dsp-search',
'hotword-no-dsp-search-setting-indicator',
opt_error);
},
/**
......@@ -2054,7 +2080,7 @@ cr.define('options', function() {
'showCreateProfileSuccess',
'showCreateProfileWarning',
'showHotwordAlwaysOnSection',
'showHotwordNoDSPSection',
'showHotwordNoDspSection',
'showHotwordSection',
'showMouseControls',
'showSupervisedUserImportError',
......
......@@ -4,7 +4,9 @@
/* Hotword extension-specific controlled setting indicator and bubble. */
#hotword-search-setting-indicator > div {
background: url('chrome://theme/IDR_WARNING') left top no-repeat;
#hotword-search-setting-indicator > div,
#hotword-always-on-search-setting-indicator > div,
#hotword-no-dsp-search-setting-indicator > div {
background: url(chrome://theme/IDR_WARNING) left top no-repeat;
background-size: 18px;
}
......@@ -1621,25 +1621,26 @@ void BrowserOptionsHandler::HandleRequestHotwordAvailable(
const base::ListValue* args) {
Profile* profile = Profile::FromWebUI(web_ui());
std::string group = base::FieldTrialList::FindFullName("VoiceTrigger");
base::FundamentalValue enabled(
profile->GetPrefs()->GetBoolean(prefs::kHotwordSearchEnabled));
if (group != "" && group != "Disabled" &&
HotwordServiceFactory::IsHotwordAllowed(profile)) {
// Update the current error value.
HotwordServiceFactory::IsServiceAvailable(profile);
int error = HotwordServiceFactory::GetCurrentError(profile);
std::string function_name;
if (CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableExperimentalHotwording)) {
if (HotwordServiceFactory::IsHotwordHardwareAvailable()) {
web_ui()->CallJavascriptFunction(
"BrowserOptions.showHotwordAlwaysOnSection");
function_name = "BrowserOptions.showHotwordAlwaysOnSection";
} else {
web_ui()->CallJavascriptFunction(
"BrowserOptions.showHotwordNoDSPSection");
function_name = "BrowserOptions.showHotwordNoDspSection";
}
} else if (!error) {
web_ui()->CallJavascriptFunction("BrowserOptions.showHotwordSection",
enabled);
} else {
function_name = "BrowserOptions.showHotwordSection";
}
if (!error) {
web_ui()->CallJavascriptFunction(function_name);
} else {
base::string16 hotword_help_url =
base::ASCIIToUTF16(chrome::kHotwordLearnMoreURL);
......@@ -1648,8 +1649,7 @@ void BrowserOptionsHandler::HandleRequestHotwordAvailable(
error_message = base::StringValue(
l10n_util::GetStringFUTF16(error, hotword_help_url));
}
web_ui()->CallJavascriptFunction("BrowserOptions.showHotwordSection",
enabled, error_message);
web_ui()->CallJavascriptFunction(function_name, error_message);
}
}
}
......
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