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

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

Issue 800523002: [Hotword] Sync Audio History pref every 24 hours, when opening chrome://settings and . . . (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase 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/ui/webui/options/browser_options_handler.h ('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 26 matching lines...) Expand all
37 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h" 37 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h"
38 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory. h" 38 #include "chrome/browser/printing/cloud_print/cloud_print_proxy_service_factory. h"
39 #include "chrome/browser/profiles/profile.h" 39 #include "chrome/browser/profiles/profile.h"
40 #include "chrome/browser/profiles/profile_avatar_icon_util.h" 40 #include "chrome/browser/profiles/profile_avatar_icon_util.h"
41 #include "chrome/browser/profiles/profile_info_cache.h" 41 #include "chrome/browser/profiles/profile_info_cache.h"
42 #include "chrome/browser/profiles/profile_manager.h" 42 #include "chrome/browser/profiles/profile_manager.h"
43 #include "chrome/browser/profiles/profile_metrics.h" 43 #include "chrome/browser/profiles/profile_metrics.h"
44 #include "chrome/browser/profiles/profile_shortcut_manager.h" 44 #include "chrome/browser/profiles/profile_shortcut_manager.h"
45 #include "chrome/browser/profiles/profile_window.h" 45 #include "chrome/browser/profiles/profile_window.h"
46 #include "chrome/browser/profiles/profiles_state.h" 46 #include "chrome/browser/profiles/profiles_state.h"
47 #include "chrome/browser/search/hotword_audio_history_handler.h"
47 #include "chrome/browser/search/hotword_service.h" 48 #include "chrome/browser/search/hotword_service.h"
48 #include "chrome/browser/search/hotword_service_factory.h" 49 #include "chrome/browser/search/hotword_service_factory.h"
49 #include "chrome/browser/search/search.h" 50 #include "chrome/browser/search/search.h"
50 #include "chrome/browser/search_engines/template_url_service_factory.h" 51 #include "chrome/browser/search_engines/template_url_service_factory.h"
51 #include "chrome/browser/signin/easy_unlock_service.h" 52 #include "chrome/browser/signin/easy_unlock_service.h"
52 #include "chrome/browser/signin/signin_manager_factory.h" 53 #include "chrome/browser/signin/signin_manager_factory.h"
53 #include "chrome/browser/sync/profile_sync_service.h" 54 #include "chrome/browser/sync/profile_sync_service.h"
54 #include "chrome/browser/sync/profile_sync_service_factory.h" 55 #include "chrome/browser/sync/profile_sync_service_factory.h"
55 #include "chrome/browser/sync/sync_ui_util.h" 56 #include "chrome/browser/sync/sync_ui_util.h"
56 #include "chrome/browser/themes/theme_service.h" 57 #include "chrome/browser/themes/theme_service.h"
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 user_manager::User* user = 547 user_manager::User* user =
547 chromeos::ProfileHelper::Get()->GetUserByProfile(profile); 548 chromeos::ProfileHelper::Get()->GetUserByProfile(profile);
548 if (user && (user->GetType() != user_manager::USER_TYPE_GUEST)) 549 if (user && (user->GetType() != user_manager::USER_TYPE_GUEST))
549 username = user->email(); 550 username = user->email();
550 } 551 }
551 if (!username.empty()) 552 if (!username.empty())
552 username = gaia::SanitizeEmail(gaia::CanonicalizeEmail(username)); 553 username = gaia::SanitizeEmail(gaia::CanonicalizeEmail(username));
553 554
554 values->SetString("username", username); 555 values->SetString("username", username);
555 #endif 556 #endif
556
557 // 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.
558 values->Set("syncData", GetSyncStateDictionary().release()); 558 values->Set("syncData", GetSyncStateDictionary().release());
559 559
560 values->SetString("privacyLearnMoreURL", chrome::kPrivacyLearnMoreURL); 560 values->SetString("privacyLearnMoreURL", chrome::kPrivacyLearnMoreURL);
561 values->SetString("doNotTrackLearnMoreURL", chrome::kDoNotTrackLearnMoreURL); 561 values->SetString("doNotTrackLearnMoreURL", chrome::kDoNotTrackLearnMoreURL);
562 562
563 #if !defined(OS_CHROMEOS) 563 #if !defined(OS_CHROMEOS)
564 values->SetBoolean("metricsReportingEnabledAtStart", 564 values->SetBoolean("metricsReportingEnabledAtStart",
565 ChromeMetricsServiceAccessor::IsMetricsReportingEnabled()); 565 ChromeMetricsServiceAccessor::IsMetricsReportingEnabled());
566 #endif 566 #endif
(...skipping 1093 matching lines...) Expand 10 before | Expand all | Expand 10 after
1660 content::RecordAction(UserMetricsAction("Options_CloudPrintDevicesPage")); 1660 content::RecordAction(UserMetricsAction("Options_CloudPrintDevicesPage"));
1661 // Navigate in current tab to devices page. 1661 // Navigate in current tab to devices page.
1662 OpenURLParams params( 1662 OpenURLParams params(
1663 GURL(chrome::kChromeUIDevicesURL), Referrer(), 1663 GURL(chrome::kChromeUIDevicesURL), Referrer(),
1664 CURRENT_TAB, ui::PAGE_TRANSITION_LINK, false); 1664 CURRENT_TAB, ui::PAGE_TRANSITION_LINK, false);
1665 web_ui()->GetWebContents()->OpenURL(params); 1665 web_ui()->GetWebContents()->OpenURL(params);
1666 } 1666 }
1667 1667
1668 #endif 1668 #endif
1669 1669
1670 void BrowserOptionsHandler::SetHotwordAudioHistorySectionVisible(
1671 bool always_on, const base::string16& audio_history_state,
1672 bool success, bool logging_enabled) {
1673 web_ui()->CallJavascriptFunction(
1674 "BrowserOptions.setAudioHistorySectionVisible",
1675 base::FundamentalValue(logging_enabled),
1676 base::FundamentalValue(always_on),
1677 base::StringValue(audio_history_state));
1678
1679 // TODO(rlp): Add version with error display if !success.
1680 }
1681
1670 void BrowserOptionsHandler::HandleRequestHotwordAvailable( 1682 void BrowserOptionsHandler::HandleRequestHotwordAvailable(
1671 const base::ListValue* args) { 1683 const base::ListValue* args) {
1672 Profile* profile = Profile::FromWebUI(web_ui()); 1684 Profile* profile = Profile::FromWebUI(web_ui());
1673 std::string group = base::FieldTrialList::FindFullName("VoiceTrigger"); 1685 std::string group = base::FieldTrialList::FindFullName("VoiceTrigger");
1674 if (group != "" && group != "Disabled" && 1686 if (group != "" && group != "Disabled" &&
1675 HotwordServiceFactory::IsHotwordAllowed(profile)) { 1687 HotwordServiceFactory::IsHotwordAllowed(profile)) {
1676 // Update the current error value. 1688 // Update the current error value.
1677 HotwordServiceFactory::IsServiceAvailable(profile); 1689 HotwordServiceFactory::IsServiceAvailable(profile);
1678 int error = HotwordServiceFactory::GetCurrentError(profile); 1690 int error = HotwordServiceFactory::GetCurrentError(profile);
1679 1691
(...skipping 17 matching lines...) Expand all
1697 function_name = "BrowserOptions.showHotwordNoDspSection"; 1709 function_name = "BrowserOptions.showHotwordNoDspSection";
1698 } 1710 }
1699 } else { 1711 } else {
1700 function_name = "BrowserOptions.showHotwordSection"; 1712 function_name = "BrowserOptions.showHotwordSection";
1701 } 1713 }
1702 1714
1703 // Audio history should be displayed if it's enabled regardless of the 1715 // Audio history should be displayed if it's enabled regardless of the
1704 // hotword error state if the user is signed in. If the user is not signed 1716 // hotword error state if the user is signed in. If the user is not signed
1705 // in, audio history is meaningless. An additional message is displayed if 1717 // in, audio history is meaningless. An additional message is displayed if
1706 // always-on hotwording is enabled. 1718 // always-on hotwording is enabled.
1707 if (profile->GetPrefs()->GetBoolean(prefs::kHotwordAudioLoggingEnabled) && 1719 if (HotwordService::IsExperimentalHotwordingEnabled() &&
1708 HotwordService::IsExperimentalHotwordingEnabled() &&
1709 authenticated) { 1720 authenticated) {
1710 std::string user_display_name = signin->GetAuthenticatedUsername(); 1721 std::string user_display_name = signin->GetAuthenticatedUsername();
1711 DCHECK(!user_display_name.empty()); 1722 DCHECK(!user_display_name.empty());
1712
1713 base::string16 audio_history_state = 1723 base::string16 audio_history_state =
1714 l10n_util::GetStringFUTF16(IDS_HOTWORD_AUDIO_HISTORY_ENABLED, 1724 l10n_util::GetStringFUTF16(IDS_HOTWORD_AUDIO_HISTORY_ENABLED,
1715 base::ASCIIToUTF16(user_display_name)); 1725 base::ASCIIToUTF16(user_display_name));
1716 web_ui()->CallJavascriptFunction("BrowserOptions.showAudioHistorySection", 1726 HotwordService* hotword_service =
1717 base::FundamentalValue(always_on), 1727 HotwordServiceFactory::GetForProfile(profile);
1718 base::StringValue(audio_history_state)); 1728 if (hotword_service) {
1729 hotword_service->GetAudioHistoryHandler()->GetAudioHistoryEnabled(
1730 base::Bind(
1731 &BrowserOptionsHandler::SetHotwordAudioHistorySectionVisible,
1732 weak_ptr_factory_.GetWeakPtr(),
1733 always_on, audio_history_state));
1734 }
1719 } 1735 }
1720 1736
1721 if (!error) { 1737 if (!error) {
1722 web_ui()->CallJavascriptFunction(function_name); 1738 web_ui()->CallJavascriptFunction(function_name);
1723 } else { 1739 } else {
1724 base::string16 hotword_help_url = 1740 base::string16 hotword_help_url =
1725 base::ASCIIToUTF16(chrome::kHotwordLearnMoreURL); 1741 base::ASCIIToUTF16(chrome::kHotwordLearnMoreURL);
1726 base::StringValue error_message(l10n_util::GetStringUTF16(error)); 1742 base::StringValue error_message(l10n_util::GetStringUTF16(error));
1727 if (error == IDS_HOTWORD_GENERIC_ERROR_MESSAGE) { 1743 if (error == IDS_HOTWORD_GENERIC_ERROR_MESSAGE) {
1728 error_message = base::StringValue( 1744 error_message = base::StringValue(
(...skipping 14 matching lines...) Expand all
1743 HotwordService::LaunchMode launch_mode = 1759 HotwordService::LaunchMode launch_mode =
1744 HotwordService::HOTWORD_AND_AUDIO_HISTORY; 1760 HotwordService::HOTWORD_AND_AUDIO_HISTORY;
1745 1761
1746 if (retrain) { 1762 if (retrain) {
1747 DCHECK(profile->GetPrefs()->GetBoolean( 1763 DCHECK(profile->GetPrefs()->GetBoolean(
1748 prefs::kHotwordAlwaysOnSearchEnabled)); 1764 prefs::kHotwordAlwaysOnSearchEnabled));
1749 DCHECK(profile->GetPrefs()->GetBoolean( 1765 DCHECK(profile->GetPrefs()->GetBoolean(
1750 prefs::kHotwordAudioLoggingEnabled)); 1766 prefs::kHotwordAudioLoggingEnabled));
1751 1767
1752 launch_mode = HotwordService::RETRAIN; 1768 launch_mode = HotwordService::RETRAIN;
1753 // TODO(rlp): Make sure the Chrome Audio History pref is synced
1754 // to the account-level Audio History setting from footprints.
1755 } else if (profile->GetPrefs()->GetBoolean( 1769 } else if (profile->GetPrefs()->GetBoolean(
1756 prefs::kHotwordAudioLoggingEnabled)) { 1770 prefs::kHotwordAudioLoggingEnabled)) {
1757 DCHECK(!profile->GetPrefs()->GetBoolean( 1771 DCHECK(!profile->GetPrefs()->GetBoolean(
1758 prefs::kHotwordAlwaysOnSearchEnabled)); 1772 prefs::kHotwordAlwaysOnSearchEnabled));
1759 launch_mode = HotwordService::HOTWORD_ONLY; 1773 launch_mode = HotwordService::HOTWORD_ONLY;
1760 } else { 1774 } else {
1761 DCHECK(!profile->GetPrefs()->GetBoolean( 1775 DCHECK(!profile->GetPrefs()->GetBoolean(
1762 prefs::kHotwordAlwaysOnSearchEnabled)); 1776 prefs::kHotwordAlwaysOnSearchEnabled));
1763 } 1777 }
1764 1778
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
2076 void BrowserOptionsHandler::OnPolicyUpdated(const policy::PolicyNamespace& ns, 2090 void BrowserOptionsHandler::OnPolicyUpdated(const policy::PolicyNamespace& ns,
2077 const policy::PolicyMap& previous, 2091 const policy::PolicyMap& previous,
2078 const policy::PolicyMap& current) { 2092 const policy::PolicyMap& current) {
2079 std::set<std::string> different_keys; 2093 std::set<std::string> different_keys;
2080 current.GetDifferingKeys(previous, &different_keys); 2094 current.GetDifferingKeys(previous, &different_keys);
2081 if (ContainsKey(different_keys, policy::key::kMetricsReportingEnabled)) 2095 if (ContainsKey(different_keys, policy::key::kMetricsReportingEnabled))
2082 SetupMetricsReportingCheckbox(); 2096 SetupMetricsReportingCheckbox();
2083 } 2097 }
2084 2098
2085 } // namespace options 2099 } // namespace options
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/options/browser_options_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698