Commit a8649e00 authored by rlp's avatar rlp Committed by Commit bot

[Hotword] Ok Google options disappear if search provider is changed from

Google to other.

This also resets the pref to off if they go away from Google.

BUG=437889

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

Cr-Commit-Position: refs/heads/master@{#307041}
parent 521a0ab3
......@@ -1197,6 +1197,18 @@ cr.define('options', function() {
opt_error);
},
/**
* Controls the visibility of all the hotword sections.
* @param {boolean} visible Whether to show hotword sections.
* @private
*/
setHotwordSectionVisible_: function(visible) {
$('hotword-search').hidden = !visible;
$('hotword-always-on-search').hidden = !visible;
$('hotword-no-dsp-search').hidden = !visible;
$('audio-history').hidden = !visible;
},
/**
* Shows or hides the hotword retrain link
* @param {boolean} visible Whether to show the link.
......@@ -2115,6 +2127,7 @@ cr.define('options', function() {
'setNativeThemeButtonEnabled',
'setNetworkPredictionValue',
'setHighContrastCheckboxState',
'setHotwordSectionVisible',
'setMetricsReportingCheckboxState',
'setMetricsReportingSettingVisibility',
'setProfilesInfo',
......
......@@ -743,6 +743,19 @@ void HotwordService::SetAudioHistoryHandler(
audio_history_handler_.reset(handler);
}
void HotwordService::DisableHotwordPreferences() {
if (IsSometimesOnEnabled()) {
if (profile_->GetPrefs()->HasPrefPath(prefs::kHotwordSearchEnabled))
profile_->GetPrefs()->SetBoolean(prefs::kHotwordSearchEnabled, false);
} else if (IsAlwaysOnEnabled()) {
if (profile_->GetPrefs()->HasPrefPath(
prefs::kHotwordAlwaysOnSearchEnabled)) {
profile_->GetPrefs()->SetBoolean(prefs::kHotwordAlwaysOnSearchEnabled,
false);
}
}
}
void HotwordService::OnHotwordSearchEnabledChanged(
const std::string& pref_name) {
DCHECK_EQ(pref_name, std::string(prefs::kHotwordSearchEnabled));
......
......@@ -148,6 +148,9 @@ class HotwordService : public extensions::ExtensionRegistryObserver,
// Sets the audio history handler. Used for tests.
void SetAudioHistoryHandler(HotwordAudioHistoryHandler* handler);
// Turn off the currently enabled version of hotwording if one exists.
void DisableHotwordPreferences();
private:
class HotwordUserSessionStateObserver;
......
......@@ -1208,6 +1208,22 @@ void BrowserOptionsHandler::OnTemplateURLServiceChanged() {
template_url_service_->is_default_search_managed() ||
template_url_service_->IsExtensionControlledDefaultSearch()));
if (default_index != -1 && model_urls[default_index]->HasGoogleBaseURLs(
template_url_service_->search_terms_data())) {
// If the user has chosen Google as the default search provider, make
// hotwording as an option available again.
HandleRequestHotwordAvailable(nullptr);
} else {
// If the user has chosen a default search provide other than Google, turn
// off hotwording since other providers don't provide that functionality.
web_ui()->CallJavascriptFunction("BrowserOptions.setHotwordSectionVisible",
base::FundamentalValue(false));
HotwordService* hotword_service =
HotwordServiceFactory::GetForProfile(Profile::FromWebUI(web_ui()));
if (hotword_service)
hotword_service->DisableHotwordPreferences();
}
SetupExtensionControlledIndicators();
}
......
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