Chromium Code Reviews| Index: chrome/browser/ui/webui/options/browser_options_handler.cc |
| diff --git a/chrome/browser/ui/webui/options/browser_options_handler.cc b/chrome/browser/ui/webui/options/browser_options_handler.cc |
| index 6cd7245380864daf316a1121434b3a04fa3fa538..d470d94d4e96b6267c37d13323b066e5a30652ba 100644 |
| --- a/chrome/browser/ui/webui/options/browser_options_handler.cc |
| +++ b/chrome/browser/ui/webui/options/browser_options_handler.cc |
| @@ -539,8 +539,8 @@ void BrowserOptionsHandler::GetLocalizedValues(base::DictionaryValue* values) { |
| values->SetString("hotwordManageAudioHistoryURL", |
| chrome::kManageAudioHistoryURL); |
| - Profile* profile = Profile::FromWebUI(web_ui()); |
| #if defined(OS_CHROMEOS) |
| + Profile* profile = Profile::FromWebUI(web_ui()); |
| std::string username = profile->GetProfileName(); |
| if (username.empty()) { |
| user_manager::User* user = |
| @@ -554,21 +554,6 @@ void BrowserOptionsHandler::GetLocalizedValues(base::DictionaryValue* values) { |
| values->SetString("username", username); |
| #endif |
| - base::string16 user_email; |
| - // If the profile is a guest session, it will not be found in the cache. |
| - // In that case, just set the value with an empty string for the email since |
| - // it won't be displayed anyways for a guest profile. |
| - if (!profile->IsGuestSession()) { |
| - ProfileInfoCache& cache = |
| - g_browser_process->profile_manager()->GetProfileInfoCache(); |
| - user_email = cache.GetUserNameOfProfileAtIndex( |
| - cache.GetIndexOfProfileWithPath(profile->GetPath())); |
| - } |
| - values->SetString( |
| - "hotwordAudioHistoryEnabled", |
| - l10n_util::GetStringFUTF16(IDS_HOTWORD_AUDIO_HISTORY_ENABLED, |
| - user_email)); |
| - |
| // Pass along sync status early so it will be available during page init. |
| values->Set("syncData", GetSyncStateDictionary().release()); |
| @@ -1214,8 +1199,9 @@ void BrowserOptionsHandler::OnTemplateURLServiceChanged() { |
| } 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)); |
| + web_ui()->CallJavascriptFunction( |
| + "BrowserOptions.setAllHotwordSectionsVisible", |
| + base::FundamentalValue(false)); |
| HotwordService* hotword_service = |
| HotwordServiceFactory::GetForProfile(Profile::FromWebUI(web_ui())); |
| if (hotword_service) |
| @@ -1566,6 +1552,13 @@ void BrowserOptionsHandler::OnConsumerManagementStatusChanged() { |
| void BrowserOptionsHandler::UpdateSyncState() { |
| web_ui()->CallJavascriptFunction("BrowserOptions.updateSyncState", |
| *GetSyncStateDictionary()); |
| + |
| + // A change in sign-in state also affects how hotwording and audio history are |
| + // displayed. Hide all hotwording and re-display properly. |
| + web_ui()->CallJavascriptFunction( |
| + "BrowserOptions.setAllHotwordSectionsVisible", |
| + base::FundamentalValue(false)); |
| + HandleRequestHotwordAvailable(nullptr); |
| } |
| void BrowserOptionsHandler::OnSigninAllowedPrefChange() { |
| @@ -1686,8 +1679,11 @@ void BrowserOptionsHandler::HandleRequestHotwordAvailable( |
| std::string function_name; |
| bool always_on = false; |
| + SigninManagerBase* signin = SigninManagerFactory::GetForProfile(profile); |
| + bool authenticated = signin && signin->IsAuthenticated(); |
| if (HotwordService::IsExperimentalHotwordingEnabled()) { |
| - if (HotwordServiceFactory::IsHotwordHardwareAvailable()) { |
| + if (HotwordServiceFactory::IsHotwordHardwareAvailable() && |
| + authenticated) { |
| function_name = "BrowserOptions.showHotwordAlwaysOnSection"; |
| always_on = true; |
| // Show the retrain link if always-on is enabled. |
| @@ -1705,12 +1701,20 @@ void BrowserOptionsHandler::HandleRequestHotwordAvailable( |
| } |
| // Audio history should be displayed if it's enabled regardless of the |
| - // hotword error state. An additional message is displayed if always-on |
| - // hotwording is enabled. |
| + // hotword error state if the user is signed in. If the user is not signed |
| + // in, audio history is meaningless. An additional message is displayed if |
| + // always-on hotwording is enabled. |
| if (profile->GetPrefs()->GetBoolean(prefs::kHotwordAudioLoggingEnabled) && |
| - HotwordService::IsExperimentalHotwordingEnabled()) { |
| + HotwordService::IsExperimentalHotwordingEnabled() && |
| + authenticated) { |
| + std::string user_display_name = signin->GetAuthenticatedUsername(); |
|
Dan Beam
2014/12/12 20:06:32
DCHECK(!user_display_name.empty());
rpetterson
2014/12/12 20:10:38
Done.
|
| + |
| + base::string16 audio_history_state = |
| + l10n_util::GetStringFUTF16(IDS_HOTWORD_AUDIO_HISTORY_ENABLED, |
| + base::ASCIIToUTF16(user_display_name)); |
| web_ui()->CallJavascriptFunction("BrowserOptions.showAudioHistorySection", |
| - base::FundamentalValue(always_on)); |
| + base::FundamentalValue(always_on), |
| + base::StringValue(audio_history_state)); |
| } |
| if (!error) { |