Chromium Code Reviews

Side by Side 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: now using the first of the accepted languages. Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | | Annotate | Revision Log
« no previous file with comments | « no previous file | 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/speech/speech_recognition_request.h" 5 #include "chrome/browser/speech/speech_recognition_request.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "base/json/json_reader.h" 8 #include "base/json/json_reader.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "chrome/common/net/url_request_context_getter.h" 12 #include "chrome/common/net/url_request_context_getter.h"
13 #include "net/base/escape.h" 13 #include "net/base/escape.h"
14 #include "net/base/load_flags.h" 14 #include "net/base/load_flags.h"
15 #include "net/url_request/url_request_context.h"
15 #include "net/url_request/url_request_status.h" 16 #include "net/url_request/url_request_status.h"
16 17
17 namespace { 18 namespace {
18 19
19 const char* const kDefaultSpeechRecognitionUrl = 20 const char* const kDefaultSpeechRecognitionUrl =
20 "http://www.google.com/speech-api/v1/recognize?client=chromium&"; 21 "http://www.google.com/speech-api/v1/recognize?client=chromium&";
21 const char* const kHypothesesString = "hypotheses"; 22 const char* const kHypothesesString = "hypotheses";
22 const char* const kUtteranceString = "utterance"; 23 const char* const kUtteranceString = "utterance";
23 const char* const kConfidenceString = "confidence"; 24 const char* const kConfidenceString = "confidence";
24 25
(...skipping 96 matching lines...)
121 bool SpeechRecognitionRequest::Send(const std::string& language, 122 bool SpeechRecognitionRequest::Send(const std::string& language,
122 const std::string& grammar, 123 const std::string& grammar,
123 const std::string& content_type, 124 const std::string& content_type,
124 const std::string& audio_data) { 125 const std::string& audio_data) {
125 DCHECK(!url_fetcher_.get()); 126 DCHECK(!url_fetcher_.get());
126 127
127 std::vector<std::string> parts; 128 std::vector<std::string> parts;
128 if (!language.empty()) { 129 if (!language.empty()) {
129 parts.push_back("lang=" + EscapeQueryParamValue(language, true)); 130 parts.push_back("lang=" + EscapeQueryParamValue(language, true));
130 } else { 131 } else {
131 std::string app_locale = l10n_util::GetApplicationLocale(""); 132 // If no language is provided then we use the 1st from the accepted language list.
Leandro Graciá Gil 2010/11/15 16:57:07 Just noticed the line length. I'll fix this.
132 parts.push_back("lang=" + EscapeQueryParamValue(app_locale, true)); 133 // If this list is empty then we default to "en-US".
134 // Example of the contents of this list: "es,en-GB;q=0.8" , ""
135 std::string list = url_context_->GetURLRequestContext()->accept_language();
136 size_t separator = list.find_first_of(",;");
137 std::string lang = list.substr(0, separator);
138 if (lang.empty()) lang = "en-US";
139 parts.push_back("lang=" + EscapeQueryParamValue(lang, true));
133 } 140 }
134 141
135 if (!grammar.empty()) 142 if (!grammar.empty())
136 parts.push_back("grammar=" + EscapeQueryParamValue(grammar, true)); 143 parts.push_back("grammar=" + EscapeQueryParamValue(grammar, true));
137 GURL url(std::string(kDefaultSpeechRecognitionUrl) + JoinString(parts, '&')); 144 GURL url(std::string(kDefaultSpeechRecognitionUrl) + JoinString(parts, '&'));
138 145
139 url_fetcher_.reset(URLFetcher::Create(url_fetcher_id_for_tests, 146 url_fetcher_.reset(URLFetcher::Create(url_fetcher_id_for_tests,
140 url, 147 url,
141 URLFetcher::POST, 148 URLFetcher::POST,
142 this)); 149 this));
(...skipping 24 matching lines...)
167 SpeechInputResultArray result; 174 SpeechInputResultArray result;
168 if (!error) 175 if (!error)
169 error = !ParseServerResponse(data, &result); 176 error = !ParseServerResponse(data, &result);
170 url_fetcher_.reset(); 177 url_fetcher_.reset();
171 178
172 DVLOG(1) << "SpeechRecognitionRequest: Invoking delegate with result."; 179 DVLOG(1) << "SpeechRecognitionRequest: Invoking delegate with result.";
173 delegate_->SetRecognitionResult(error, result); 180 delegate_->SetRecognitionResult(error, result);
174 } 181 }
175 182
176 } // namespace speech_input 183 } // namespace speech_input
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine