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

Unified Diff: chrome/browser/speech/speech_recognition_request.cc

Issue 4896001: Locale access from the IO thread for null language tags in speech. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: code review fixes. Created 10 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/speech/speech_recognition_request.cc
diff --git a/chrome/browser/speech/speech_recognition_request.cc b/chrome/browser/speech/speech_recognition_request.cc
index e17f69b1f09c2275cb31f54d1e97647c00602773..b2befa1531ad2108e2e071897ccef399b3a4b3c3 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,20 @@ 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";
jam 2010/11/17 17:58:59 nit: while this isn't against the style guide, it
+ parts.push_back("lang=" + EscapeQueryParamValue(lang_param, true));
if (!grammar.empty())
parts.push_back("grammar=" + EscapeQueryParamValue(grammar, true));
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698