Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(165)

Side by Side Diff: chrome/browser/ui/webui/options/browser_options_handler.cc

Issue 797763002: [Hotword] Hotword and Audio History settings should reflect sync sign in (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nit and DCHECK Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/resources/options/browser_options.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/webui/options/browser_options_handler.h" 5 #include "chrome/browser/ui/webui/options/browser_options_handler.h"
6 6
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 base::string16 omnibox_url = base::ASCIIToUTF16(chrome::kOmniboxLearnMoreURL); 532 base::string16 omnibox_url = base::ASCIIToUTF16(chrome::kOmniboxLearnMoreURL);
533 values->SetString( 533 values->SetString(
534 "defaultSearchGroupLabel", 534 "defaultSearchGroupLabel",
535 l10n_util::GetStringFUTF16(IDS_SEARCH_PREF_EXPLANATION, omnibox_url)); 535 l10n_util::GetStringFUTF16(IDS_SEARCH_PREF_EXPLANATION, omnibox_url));
536 values->SetString("hotwordLearnMoreURL", chrome::kHotwordLearnMoreURL); 536 values->SetString("hotwordLearnMoreURL", chrome::kHotwordLearnMoreURL);
537 RegisterTitle(values, "hotwordConfirmOverlay", 537 RegisterTitle(values, "hotwordConfirmOverlay",
538 IDS_HOTWORD_CONFIRM_BUBBLE_TITLE); 538 IDS_HOTWORD_CONFIRM_BUBBLE_TITLE);
539 values->SetString("hotwordManageAudioHistoryURL", 539 values->SetString("hotwordManageAudioHistoryURL",
540 chrome::kManageAudioHistoryURL); 540 chrome::kManageAudioHistoryURL);
541 541
542 #if defined(OS_CHROMEOS)
542 Profile* profile = Profile::FromWebUI(web_ui()); 543 Profile* profile = Profile::FromWebUI(web_ui());
543 #if defined(OS_CHROMEOS)
544 std::string username = profile->GetProfileName(); 544 std::string username = profile->GetProfileName();
545 if (username.empty()) { 545 if (username.empty()) {
546 user_manager::User* user = 546 user_manager::User* user =
547 chromeos::ProfileHelper::Get()->GetUserByProfile(profile); 547 chromeos::ProfileHelper::Get()->GetUserByProfile(profile);
548 if (user && (user->GetType() != user_manager::USER_TYPE_GUEST)) 548 if (user && (user->GetType() != user_manager::USER_TYPE_GUEST))
549 username = user->email(); 549 username = user->email();
550 } 550 }
551 if (!username.empty()) 551 if (!username.empty())
552 username = gaia::SanitizeEmail(gaia::CanonicalizeEmail(username)); 552 username = gaia::SanitizeEmail(gaia::CanonicalizeEmail(username));
553 553
554 values->SetString("username", username); 554 values->SetString("username", username);
555 #endif 555 #endif
556 556
557 base::string16 user_email;
558 // If the profile is a guest session, it will not be found in the cache.
559 // In that case, just set the value with an empty string for the email since
560 // it won't be displayed anyways for a guest profile.
561 if (!profile->IsGuestSession()) {
562 ProfileInfoCache& cache =
563 g_browser_process->profile_manager()->GetProfileInfoCache();
564 user_email = cache.GetUserNameOfProfileAtIndex(
565 cache.GetIndexOfProfileWithPath(profile->GetPath()));
566 }
567 values->SetString(
568 "hotwordAudioHistoryEnabled",
569 l10n_util::GetStringFUTF16(IDS_HOTWORD_AUDIO_HISTORY_ENABLED,
570 user_email));
571
572 // Pass along sync status early so it will be available during page init. 557 // Pass along sync status early so it will be available during page init.
573 values->Set("syncData", GetSyncStateDictionary().release()); 558 values->Set("syncData", GetSyncStateDictionary().release());
574 559
575 values->SetString("privacyLearnMoreURL", chrome::kPrivacyLearnMoreURL); 560 values->SetString("privacyLearnMoreURL", chrome::kPrivacyLearnMoreURL);
576 values->SetString("doNotTrackLearnMoreURL", chrome::kDoNotTrackLearnMoreURL); 561 values->SetString("doNotTrackLearnMoreURL", chrome::kDoNotTrackLearnMoreURL);
577 562
578 #if !defined(OS_CHROMEOS) 563 #if !defined(OS_CHROMEOS)
579 values->SetBoolean("metricsReportingEnabledAtStart", 564 values->SetBoolean("metricsReportingEnabledAtStart",
580 ChromeMetricsServiceAccessor::IsMetricsReportingEnabled()); 565 ChromeMetricsServiceAccessor::IsMetricsReportingEnabled());
581 #endif 566 #endif
(...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after
1207 template_url_service_->IsExtensionControlledDefaultSearch())); 1192 template_url_service_->IsExtensionControlledDefaultSearch()));
1208 1193
1209 if (default_index != -1 && model_urls[default_index]->HasGoogleBaseURLs( 1194 if (default_index != -1 && model_urls[default_index]->HasGoogleBaseURLs(
1210 template_url_service_->search_terms_data())) { 1195 template_url_service_->search_terms_data())) {
1211 // If the user has chosen Google as the default search provider, make 1196 // If the user has chosen Google as the default search provider, make
1212 // hotwording as an option available again. 1197 // hotwording as an option available again.
1213 HandleRequestHotwordAvailable(nullptr); 1198 HandleRequestHotwordAvailable(nullptr);
1214 } else { 1199 } else {
1215 // If the user has chosen a default search provide other than Google, turn 1200 // If the user has chosen a default search provide other than Google, turn
1216 // off hotwording since other providers don't provide that functionality. 1201 // off hotwording since other providers don't provide that functionality.
1217 web_ui()->CallJavascriptFunction("BrowserOptions.setHotwordSectionVisible", 1202 web_ui()->CallJavascriptFunction(
1218 base::FundamentalValue(false)); 1203 "BrowserOptions.setAllHotwordSectionsVisible",
1204 base::FundamentalValue(false));
1219 HotwordService* hotword_service = 1205 HotwordService* hotword_service =
1220 HotwordServiceFactory::GetForProfile(Profile::FromWebUI(web_ui())); 1206 HotwordServiceFactory::GetForProfile(Profile::FromWebUI(web_ui()));
1221 if (hotword_service) 1207 if (hotword_service)
1222 hotword_service->DisableHotwordPreferences(); 1208 hotword_service->DisableHotwordPreferences();
1223 } 1209 }
1224 1210
1225 SetupExtensionControlledIndicators(); 1211 SetupExtensionControlledIndicators();
1226 } 1212 }
1227 1213
1228 void BrowserOptionsHandler::SetDefaultSearchEngine( 1214 void BrowserOptionsHandler::SetDefaultSearchEngine(
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
1559 GetStatusString(); 1545 GetStatusString();
1560 web_ui()->CallJavascriptFunction( 1546 web_ui()->CallJavascriptFunction(
1561 "BrowserOptions.setConsumerManagementStatus", base::StringValue(status)); 1547 "BrowserOptions.setConsumerManagementStatus", base::StringValue(status));
1562 } 1548 }
1563 1549
1564 #endif // defined(OS_CHROMEOS) 1550 #endif // defined(OS_CHROMEOS)
1565 1551
1566 void BrowserOptionsHandler::UpdateSyncState() { 1552 void BrowserOptionsHandler::UpdateSyncState() {
1567 web_ui()->CallJavascriptFunction("BrowserOptions.updateSyncState", 1553 web_ui()->CallJavascriptFunction("BrowserOptions.updateSyncState",
1568 *GetSyncStateDictionary()); 1554 *GetSyncStateDictionary());
1555
1556 // A change in sign-in state also affects how hotwording and audio history are
1557 // displayed. Hide all hotwording and re-display properly.
1558 web_ui()->CallJavascriptFunction(
1559 "BrowserOptions.setAllHotwordSectionsVisible",
1560 base::FundamentalValue(false));
1561 HandleRequestHotwordAvailable(nullptr);
1569 } 1562 }
1570 1563
1571 void BrowserOptionsHandler::OnSigninAllowedPrefChange() { 1564 void BrowserOptionsHandler::OnSigninAllowedPrefChange() {
1572 UpdateSyncState(); 1565 UpdateSyncState();
1573 } 1566 }
1574 1567
1575 void BrowserOptionsHandler::HandleAutoOpenButton(const base::ListValue* args) { 1568 void BrowserOptionsHandler::HandleAutoOpenButton(const base::ListValue* args) {
1576 content::RecordAction(UserMetricsAction("Options_ResetAutoOpenFiles")); 1569 content::RecordAction(UserMetricsAction("Options_ResetAutoOpenFiles"));
1577 DownloadManager* manager = BrowserContext::GetDownloadManager( 1570 DownloadManager* manager = BrowserContext::GetDownloadManager(
1578 web_ui()->GetWebContents()->GetBrowserContext()); 1571 web_ui()->GetWebContents()->GetBrowserContext());
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1679 Profile* profile = Profile::FromWebUI(web_ui()); 1672 Profile* profile = Profile::FromWebUI(web_ui());
1680 std::string group = base::FieldTrialList::FindFullName("VoiceTrigger"); 1673 std::string group = base::FieldTrialList::FindFullName("VoiceTrigger");
1681 if (group != "" && group != "Disabled" && 1674 if (group != "" && group != "Disabled" &&
1682 HotwordServiceFactory::IsHotwordAllowed(profile)) { 1675 HotwordServiceFactory::IsHotwordAllowed(profile)) {
1683 // Update the current error value. 1676 // Update the current error value.
1684 HotwordServiceFactory::IsServiceAvailable(profile); 1677 HotwordServiceFactory::IsServiceAvailable(profile);
1685 int error = HotwordServiceFactory::GetCurrentError(profile); 1678 int error = HotwordServiceFactory::GetCurrentError(profile);
1686 1679
1687 std::string function_name; 1680 std::string function_name;
1688 bool always_on = false; 1681 bool always_on = false;
1682 SigninManagerBase* signin = SigninManagerFactory::GetForProfile(profile);
1683 bool authenticated = signin && signin->IsAuthenticated();
1689 if (HotwordService::IsExperimentalHotwordingEnabled()) { 1684 if (HotwordService::IsExperimentalHotwordingEnabled()) {
1690 if (HotwordServiceFactory::IsHotwordHardwareAvailable()) { 1685 if (HotwordServiceFactory::IsHotwordHardwareAvailable() &&
1686 authenticated) {
1691 function_name = "BrowserOptions.showHotwordAlwaysOnSection"; 1687 function_name = "BrowserOptions.showHotwordAlwaysOnSection";
1692 always_on = true; 1688 always_on = true;
1693 // Show the retrain link if always-on is enabled. 1689 // Show the retrain link if always-on is enabled.
1694 if (profile->GetPrefs()->GetBoolean( 1690 if (profile->GetPrefs()->GetBoolean(
1695 prefs::kHotwordAlwaysOnSearchEnabled)) { 1691 prefs::kHotwordAlwaysOnSearchEnabled)) {
1696 web_ui()->CallJavascriptFunction( 1692 web_ui()->CallJavascriptFunction(
1697 "BrowserOptions.setHotwordRetrainLinkVisible", 1693 "BrowserOptions.setHotwordRetrainLinkVisible",
1698 base::FundamentalValue(true)); 1694 base::FundamentalValue(true));
1699 } 1695 }
1700 } else { 1696 } else {
1701 function_name = "BrowserOptions.showHotwordNoDspSection"; 1697 function_name = "BrowserOptions.showHotwordNoDspSection";
1702 } 1698 }
1703 } else { 1699 } else {
1704 function_name = "BrowserOptions.showHotwordSection"; 1700 function_name = "BrowserOptions.showHotwordSection";
1705 } 1701 }
1706 1702
1707 // Audio history should be displayed if it's enabled regardless of the 1703 // Audio history should be displayed if it's enabled regardless of the
1708 // hotword error state. An additional message is displayed if always-on 1704 // hotword error state if the user is signed in. If the user is not signed
1709 // hotwording is enabled. 1705 // in, audio history is meaningless. An additional message is displayed if
1706 // always-on hotwording is enabled.
1710 if (profile->GetPrefs()->GetBoolean(prefs::kHotwordAudioLoggingEnabled) && 1707 if (profile->GetPrefs()->GetBoolean(prefs::kHotwordAudioLoggingEnabled) &&
1711 HotwordService::IsExperimentalHotwordingEnabled()) { 1708 HotwordService::IsExperimentalHotwordingEnabled() &&
1709 authenticated) {
1710 std::string user_display_name = signin->GetAuthenticatedUsername();
1711 DCHECK(!user_display_name.empty());
1712
1713 base::string16 audio_history_state =
1714 l10n_util::GetStringFUTF16(IDS_HOTWORD_AUDIO_HISTORY_ENABLED,
1715 base::ASCIIToUTF16(user_display_name));
1712 web_ui()->CallJavascriptFunction("BrowserOptions.showAudioHistorySection", 1716 web_ui()->CallJavascriptFunction("BrowserOptions.showAudioHistorySection",
1713 base::FundamentalValue(always_on)); 1717 base::FundamentalValue(always_on),
1718 base::StringValue(audio_history_state));
1714 } 1719 }
1715 1720
1716 if (!error) { 1721 if (!error) {
1717 web_ui()->CallJavascriptFunction(function_name); 1722 web_ui()->CallJavascriptFunction(function_name);
1718 } else { 1723 } else {
1719 base::string16 hotword_help_url = 1724 base::string16 hotword_help_url =
1720 base::ASCIIToUTF16(chrome::kHotwordLearnMoreURL); 1725 base::ASCIIToUTF16(chrome::kHotwordLearnMoreURL);
1721 base::StringValue error_message(l10n_util::GetStringUTF16(error)); 1726 base::StringValue error_message(l10n_util::GetStringUTF16(error));
1722 if (error == IDS_HOTWORD_GENERIC_ERROR_MESSAGE) { 1727 if (error == IDS_HOTWORD_GENERIC_ERROR_MESSAGE) {
1723 error_message = base::StringValue( 1728 error_message = base::StringValue(
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
2071 void BrowserOptionsHandler::OnPolicyUpdated(const policy::PolicyNamespace& ns, 2076 void BrowserOptionsHandler::OnPolicyUpdated(const policy::PolicyNamespace& ns,
2072 const policy::PolicyMap& previous, 2077 const policy::PolicyMap& previous,
2073 const policy::PolicyMap& current) { 2078 const policy::PolicyMap& current) {
2074 std::set<std::string> different_keys; 2079 std::set<std::string> different_keys;
2075 current.GetDifferingKeys(previous, &different_keys); 2080 current.GetDifferingKeys(previous, &different_keys);
2076 if (ContainsKey(different_keys, policy::key::kMetricsReportingEnabled)) 2081 if (ContainsKey(different_keys, policy::key::kMetricsReportingEnabled))
2077 SetupMetricsReportingCheckbox(); 2082 SetupMetricsReportingCheckbox();
2078 } 2083 }
2079 2084
2080 } // namespace options 2085 } // namespace options
OLDNEW
« no previous file with comments | « chrome/browser/resources/options/browser_options.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698