Commit ebcd19b1 authored by Matt Menke's avatar Matt Menke Committed by Commit Bot

Implement CastContentBrowserClient::GetAcceptLangs();

This method was previously unused, but with the network service moving
out of process, the speech recognition code will now need to use it.

Bug: 841445
Change-Id: I886b10dbe6a4687ddb6e72e5296398f01534f221
Reviewed-on: https://chromium-review.googlesource.com/1145709
Commit-Queue: Matt Menke <mmenke@chromium.org>
Reviewed-by: default avatarLuke Halliwell <halliwell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#580391}
parent 0dad9bc7
......@@ -29,6 +29,7 @@
#include "chromecast/browser/cast_browser_context.h"
#include "chromecast/browser/cast_browser_main_parts.h"
#include "chromecast/browser/cast_browser_process.h"
#include "chromecast/browser/cast_http_user_agent_settings.h"
#include "chromecast/browser/cast_navigation_ui_data.h"
#include "chromecast/browser/cast_network_delegate.h"
#include "chromecast/browser/cast_quota_permission_context.h"
......@@ -474,6 +475,11 @@ void CastContentBrowserClient::AppendExtraCommandLineSwitches(
}
}
std::string CastContentBrowserClient::GetAcceptLangs(
content::BrowserContext* context) {
return CastHttpUserAgentSettings::AcceptLanguage();
}
void CastContentBrowserClient::OverrideWebkitPrefs(
content::RenderViewHost* render_view_host,
content::WebPreferences* prefs) {
......
......@@ -133,6 +133,7 @@ class CastContentBrowserClient : public content::ContentBrowserClient {
void SiteInstanceGotProcess(content::SiteInstance* site_instance) override;
void AppendExtraCommandLineSwitches(base::CommandLine* command_line,
int child_process_id) override;
std::string GetAcceptLangs(content::BrowserContext* context) override;
void OverrideWebkitPrefs(content::RenderViewHost* render_view_host,
content::WebPreferences* prefs) override;
void ResourceDispatcherHostCreated() override;
......
......@@ -17,6 +17,32 @@
#include "base/android/locale_utils.h"
#endif // defined(OS_ANDROID)
namespace {
std::string GetLocale() {
#if defined(OS_ANDROID)
// TODO(byungchul): Use transient locale set when new app starts.
return base::android::GetDefaultLocaleString();
#else
return base::i18n::GetConfiguredLocale();
#endif
}
std::string LocaleToAcceptLanguage(const std::string locale) {
return net::HttpUtil::GenerateAcceptLanguageHeader(
#if defined(OS_ANDROID)
locale
#else
// Ignoring |locale| here is a bit weird, but locale is still used to
// avoid a l10n_util::GetStringUTF8() call when GetAcceptLanguage() is
// called.
l10n_util::GetStringUTF8(IDS_CHROMECAST_SETTINGS_ACCEPT_LANGUAGES)
#endif
);
}
} // namespace
namespace chromecast {
namespace shell {
......@@ -30,23 +56,10 @@ CastHttpUserAgentSettings::~CastHttpUserAgentSettings() {
std::string CastHttpUserAgentSettings::GetAcceptLanguage() const {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
std::string new_locale(
#if defined(OS_ANDROID)
// TODO(byungchul): Use transient locale set when new app starts.
base::android::GetDefaultLocaleString()
#else
base::i18n::GetConfiguredLocale()
#endif
);
std::string new_locale(GetLocale());
if (new_locale != last_locale_ || accept_language_.empty()) {
last_locale_ = new_locale;
accept_language_ = net::HttpUtil::GenerateAcceptLanguageHeader(
#if defined(OS_ANDROID)
last_locale_
#else
l10n_util::GetStringUTF8(IDS_CHROMECAST_SETTINGS_ACCEPT_LANGUAGES)
#endif
);
accept_language_ = LocaleToAcceptLanguage(new_locale);
LOG(INFO) << "Locale changed: accept_language=" << accept_language_;
}
return accept_language_;
......@@ -56,5 +69,9 @@ std::string CastHttpUserAgentSettings::GetUserAgent() const {
return chromecast::shell::GetUserAgent();
}
std::string CastHttpUserAgentSettings::AcceptLanguage() {
return LocaleToAcceptLanguage(GetLocale());
}
} // namespace shell
} // namespace chromecast
......@@ -5,6 +5,8 @@
#ifndef CHROMECAST_BROWSER_CAST_HTTP_USER_AGENT_SETTINGS_H_
#define CHROMECAST_BROWSER_CAST_HTTP_USER_AGENT_SETTINGS_H_
#include <string>
#include "base/compiler_specific.h"
#include "base/macros.h"
#include "net/url_request/http_user_agent_settings.h"
......@@ -21,6 +23,10 @@ class CastHttpUserAgentSettings : public net::HttpUserAgentSettings {
std::string GetAcceptLanguage() const override;
std::string GetUserAgent() const override;
// Returns the same value as GetAcceptLanguage(), but is static and can be
// called on any thread.
static std::string AcceptLanguage();
private:
mutable std::string last_locale_;
mutable std::string accept_language_;
......
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