Commit 7b4f8bba authored by rlp's avatar rlp Committed by Commit bot

[Hotword] Don't show hotword options if search provider is not Google.

This CL moves the search provider check into the function which
determines how to display hotwording. Prior to this, it was only being
updated when the search provider was changed and other javascript could
come along and re-show the hotword section (even though it was now
supposed to be hidden). Now every time the hotwording should be
displayed, the search provider is checked beforehand. This is the
logically correct way to do it.

BUG=442938

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

Cr-Commit-Position: refs/heads/master@{#309522}
parent 7f84b4cf
......@@ -1190,24 +1190,9 @@ 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.setAllHotwordSectionsVisible",
base::FundamentalValue(false));
HotwordService* hotword_service =
HotwordServiceFactory::GetForProfile(Profile::FromWebUI(web_ui()));
if (hotword_service)
hotword_service->DisableHotwordPreferences();
}
SetupExtensionControlledIndicators();
HandleRequestHotwordAvailable(nullptr);
}
void BrowserOptionsHandler::SetDefaultSearchEngine(
......@@ -1681,6 +1666,30 @@ void BrowserOptionsHandler::SetHotwordAudioHistorySectionVisible(
void BrowserOptionsHandler::HandleRequestHotwordAvailable(
const base::ListValue* args) {
Profile* profile = Profile::FromWebUI(web_ui());
bool is_search_provider_google = false;
if (template_url_service_) {
const TemplateURL* default_url =
template_url_service_->GetDefaultSearchProvider();
if (default_url && default_url->HasGoogleBaseURLs(
template_url_service_->search_terms_data())) {
is_search_provider_google = true;
}
}
if (!is_search_provider_google) {
// 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.setAllHotwordSectionsVisible",
base::FundamentalValue(false));
HotwordService* hotword_service =
HotwordServiceFactory::GetForProfile(profile);
if (hotword_service)
hotword_service->DisableHotwordPreferences();
return;
}
std::string group = base::FieldTrialList::FindFullName("VoiceTrigger");
if (group != "" && group != "Disabled" &&
HotwordServiceFactory::IsHotwordAllowed(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