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

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: clarify comments 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
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 977 matching lines...) Expand 10 before | Expand all | Expand 10 after
1559 GetStatusString(); 1544 GetStatusString();
1560 web_ui()->CallJavascriptFunction( 1545 web_ui()->CallJavascriptFunction(
1561 "BrowserOptions.setConsumerManagementStatus", base::StringValue(status)); 1546 "BrowserOptions.setConsumerManagementStatus", base::StringValue(status));
1562 } 1547 }
1563 1548
1564 #endif // defined(OS_CHROMEOS) 1549 #endif // defined(OS_CHROMEOS)
1565 1550
1566 void BrowserOptionsHandler::UpdateSyncState() { 1551 void BrowserOptionsHandler::UpdateSyncState() {
1567 web_ui()->CallJavascriptFunction("BrowserOptions.updateSyncState", 1552 web_ui()->CallJavascriptFunction("BrowserOptions.updateSyncState",
1568 *GetSyncStateDictionary()); 1553 *GetSyncStateDictionary());
1554
1555 // A change in sign-in state also affects how hotwording and audio history are
1556 // displayed. Hide all hotwording and re-display properly.
Dan Beam 2014/12/11 22:16:53 indent off
rpetterson 2014/12/12 19:52:47 Done.
1557 web_ui()->CallJavascriptFunction("BrowserOptions.setHotwordSectionVisible",
1558 base::FundamentalValue(false));
1559 HandleRequestHotwordAvailable(nullptr);
1569 } 1560 }
1570 1561
1571 void BrowserOptionsHandler::OnSigninAllowedPrefChange() { 1562 void BrowserOptionsHandler::OnSigninAllowedPrefChange() {
1572 UpdateSyncState(); 1563 UpdateSyncState();
1573 } 1564 }
1574 1565
1575 void BrowserOptionsHandler::HandleAutoOpenButton(const base::ListValue* args) { 1566 void BrowserOptionsHandler::HandleAutoOpenButton(const base::ListValue* args) {
1576 content::RecordAction(UserMetricsAction("Options_ResetAutoOpenFiles")); 1567 content::RecordAction(UserMetricsAction("Options_ResetAutoOpenFiles"));
1577 DownloadManager* manager = BrowserContext::GetDownloadManager( 1568 DownloadManager* manager = BrowserContext::GetDownloadManager(
1578 web_ui()->GetWebContents()->GetBrowserContext()); 1569 web_ui()->GetWebContents()->GetBrowserContext());
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1679 Profile* profile = Profile::FromWebUI(web_ui()); 1670 Profile* profile = Profile::FromWebUI(web_ui());
1680 std::string group = base::FieldTrialList::FindFullName("VoiceTrigger"); 1671 std::string group = base::FieldTrialList::FindFullName("VoiceTrigger");
1681 if (group != "" && group != "Disabled" && 1672 if (group != "" && group != "Disabled" &&
1682 HotwordServiceFactory::IsHotwordAllowed(profile)) { 1673 HotwordServiceFactory::IsHotwordAllowed(profile)) {
1683 // Update the current error value. 1674 // Update the current error value.
1684 HotwordServiceFactory::IsServiceAvailable(profile); 1675 HotwordServiceFactory::IsServiceAvailable(profile);
1685 int error = HotwordServiceFactory::GetCurrentError(profile); 1676 int error = HotwordServiceFactory::GetCurrentError(profile);
1686 1677
1687 std::string function_name; 1678 std::string function_name;
1688 bool always_on = false; 1679 bool always_on = false;
1680 SigninManagerBase* signin = SigninManagerFactory::GetForProfile(profile);
1681 bool authenticated = signin && signin->IsAuthenticated();
1689 if (HotwordService::IsExperimentalHotwordingEnabled()) { 1682 if (HotwordService::IsExperimentalHotwordingEnabled()) {
1690 if (HotwordServiceFactory::IsHotwordHardwareAvailable()) { 1683 if (HotwordServiceFactory::IsHotwordHardwareAvailable() &&
1684 authenticated) {
1691 function_name = "BrowserOptions.showHotwordAlwaysOnSection"; 1685 function_name = "BrowserOptions.showHotwordAlwaysOnSection";
1692 always_on = true; 1686 always_on = true;
1693 // Show the retrain link if always-on is enabled. 1687 // Show the retrain link if always-on is enabled.
1694 if (profile->GetPrefs()->GetBoolean( 1688 if (profile->GetPrefs()->GetBoolean(
1695 prefs::kHotwordAlwaysOnSearchEnabled)) { 1689 prefs::kHotwordAlwaysOnSearchEnabled)) {
1696 web_ui()->CallJavascriptFunction( 1690 web_ui()->CallJavascriptFunction(
1697 "BrowserOptions.setHotwordRetrainLinkVisible", 1691 "BrowserOptions.setHotwordRetrainLinkVisible",
1698 base::FundamentalValue(true)); 1692 base::FundamentalValue(true));
1699 } 1693 }
1700 } else { 1694 } else {
1701 function_name = "BrowserOptions.showHotwordNoDspSection"; 1695 function_name = "BrowserOptions.showHotwordNoDspSection";
1702 } 1696 }
1703 } else { 1697 } else {
1704 function_name = "BrowserOptions.showHotwordSection"; 1698 function_name = "BrowserOptions.showHotwordSection";
Dan Beam 2014/12/11 22:16:53 why isn't this using setHotwordSectionVisible?
rpetterson 2014/12/12 19:52:47 setHotwordSectionVisible is a catch all for all th
1705 } 1699 }
1706 1700
1707 // Audio history should be displayed if it's enabled regardless of the 1701 // Audio history should be displayed if it's enabled regardless of the
1708 // hotword error state. An additional message is displayed if always-on 1702 // hotword error state if the user is signed in. If the user is not signed
1709 // hotwording is enabled. 1703 // in, audio history is meaningless. An additional message is displayed if
1704 // always-on hotwording is enabled.
1710 if (profile->GetPrefs()->GetBoolean(prefs::kHotwordAudioLoggingEnabled) && 1705 if (profile->GetPrefs()->GetBoolean(prefs::kHotwordAudioLoggingEnabled) &&
1711 HotwordService::IsExperimentalHotwordingEnabled()) { 1706 HotwordService::IsExperimentalHotwordingEnabled() &&
1707 authenticated) {
1708 std::string user_display_name = signin->GetAuthenticatedUsername();
1709
1710 base::string16 audio_history_state =
1711 l10n_util::GetStringFUTF16(IDS_HOTWORD_AUDIO_HISTORY_ENABLED,
1712 base::ASCIIToUTF16(user_display_name));
Dan Beam 2014/12/11 22:16:53 indent off
rpetterson 2014/12/12 19:52:47 Done.
1712 web_ui()->CallJavascriptFunction("BrowserOptions.showAudioHistorySection", 1713 web_ui()->CallJavascriptFunction("BrowserOptions.showAudioHistorySection",
1713 base::FundamentalValue(always_on)); 1714 base::FundamentalValue(always_on),
1715 base::StringValue(audio_history_state));
1714 } 1716 }
1715 1717
1716 if (!error) { 1718 if (!error) {
1717 web_ui()->CallJavascriptFunction(function_name); 1719 web_ui()->CallJavascriptFunction(function_name);
1718 } else { 1720 } else {
1719 base::string16 hotword_help_url = 1721 base::string16 hotword_help_url =
1720 base::ASCIIToUTF16(chrome::kHotwordLearnMoreURL); 1722 base::ASCIIToUTF16(chrome::kHotwordLearnMoreURL);
1721 base::StringValue error_message(l10n_util::GetStringUTF16(error)); 1723 base::StringValue error_message(l10n_util::GetStringUTF16(error));
1722 if (error == IDS_HOTWORD_GENERIC_ERROR_MESSAGE) { 1724 if (error == IDS_HOTWORD_GENERIC_ERROR_MESSAGE) {
1723 error_message = base::StringValue( 1725 error_message = base::StringValue(
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
2071 void BrowserOptionsHandler::OnPolicyUpdated(const policy::PolicyNamespace& ns, 2073 void BrowserOptionsHandler::OnPolicyUpdated(const policy::PolicyNamespace& ns,
2072 const policy::PolicyMap& previous, 2074 const policy::PolicyMap& previous,
2073 const policy::PolicyMap& current) { 2075 const policy::PolicyMap& current) {
2074 std::set<std::string> different_keys; 2076 std::set<std::string> different_keys;
2075 current.GetDifferingKeys(previous, &different_keys); 2077 current.GetDifferingKeys(previous, &different_keys);
2076 if (ContainsKey(different_keys, policy::key::kMetricsReportingEnabled)) 2078 if (ContainsKey(different_keys, policy::key::kMetricsReportingEnabled))
2077 SetupMetricsReportingCheckbox(); 2079 SetupMetricsReportingCheckbox();
2078 } 2080 }
2079 2081
2080 } // namespace options 2082 } // namespace options
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698