diff options
author | leandrogracia@chromium.org <leandrogracia@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-18 10:47:35 +0000 |
---|---|---|
committer | leandrogracia@chromium.org <leandrogracia@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-18 10:47:35 +0000 |
commit | 57cc331accd443243e9223356e42bfeaeb912d6c (patch) | |
tree | 1350aac3419cc3ed20d68b22d1522ccc3238a149 /chrome/browser/speech | |
parent | d6f45d89b6dc089bb2eb9e0be58c8f8e2aae132f (diff) | |
download | chromium_src-57cc331accd443243e9223356e42bfeaeb912d6c.zip chromium_src-57cc331accd443243e9223356e42bfeaeb912d6c.tar.gz chromium_src-57cc331accd443243e9223356e42bfeaeb912d6c.tar.bz2 |
In the current speech input implementation, the application locale is used as
language in case that no language attribute is provided. For this, the
l10n_util::GetApplicationLocale was used from the IO thread. However this is
not valid since that function requires file access.
After considering different options this patch now uses the first of the accepted languages, defaulting to "en-US" in case that this list is empty.
BUG=53598
TEST=SpeechRecognitionRequestTest
Review URL: http://codereview.chromium.org/4896001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@66605 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/speech')
-rw-r--r-- | chrome/browser/speech/speech_recognition_request.cc | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/chrome/browser/speech/speech_recognition_request.cc b/chrome/browser/speech/speech_recognition_request.cc index e17f69b1..b9ee40b 100644 --- a/chrome/browser/speech/speech_recognition_request.cc +++ b/chrome/browser/speech/speech_recognition_request.cc @@ -4,6 +4,8 @@ #include "chrome/browser/speech/speech_recognition_request.h" +#include <vector> + #include "app/l10n_util.h" #include "base/json/json_reader.h" #include "base/string_util.h" @@ -12,6 +14,7 @@ #include "chrome/common/net/url_request_context_getter.h" #include "net/base/escape.h" #include "net/base/load_flags.h" +#include "net/url_request/url_request_context.h" #include "net/url_request/url_request_status.h" namespace { @@ -125,12 +128,21 @@ bool SpeechRecognitionRequest::Send(const std::string& language, DCHECK(!url_fetcher_.get()); std::vector<std::string> parts; - if (!language.empty()) { - parts.push_back("lang=" + EscapeQueryParamValue(language, true)); - } else { - std::string app_locale = l10n_util::GetApplicationLocale(""); - parts.push_back("lang=" + EscapeQueryParamValue(app_locale, true)); + + std::string lang_param = language; + if (lang_param.empty() && url_context_) { + // If no language is provided then we use the first from the accepted + // language list. If this list is empty then it defaults to "en-US". + // Example of the contents of this list: "es,en-GB;q=0.8", "" + URLRequestContext* request_context = url_context_->GetURLRequestContext(); + DCHECK(request_context); + std::string accepted_language_list = request_context->accept_language(); + size_t separator = accepted_language_list.find_first_of(",;"); + lang_param = accepted_language_list.substr(0, separator); } + if (lang_param.empty()) + lang_param = "en-US"; + parts.push_back("lang=" + EscapeQueryParamValue(lang_param, true)); if (!grammar.empty()) parts.push_back("grammar=" + EscapeQueryParamValue(grammar, true)); |