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

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: fixed problem that caused the unit test to crash. 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 unified diff | Download patch | 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 <vector>
8
7 #include "app/l10n_util.h" 9 #include "app/l10n_util.h"
8 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
9 #include "base/string_util.h" 11 #include "base/string_util.h"
10 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
11 #include "base/values.h" 13 #include "base/values.h"
12 #include "chrome/common/net/url_request_context_getter.h" 14 #include "chrome/common/net/url_request_context_getter.h"
13 #include "net/base/escape.h" 15 #include "net/base/escape.h"
14 #include "net/base/load_flags.h" 16 #include "net/base/load_flags.h"
17 #include "net/url_request/url_request_context.h"
15 #include "net/url_request/url_request_status.h" 18 #include "net/url_request/url_request_status.h"
16 19
17 namespace { 20 namespace {
18 21
19 const char* const kDefaultSpeechRecognitionUrl = 22 const char* const kDefaultSpeechRecognitionUrl =
20 "http://www.google.com/speech-api/v1/recognize?client=chromium&"; 23 "http://www.google.com/speech-api/v1/recognize?client=chromium&";
21 const char* const kHypothesesString = "hypotheses"; 24 const char* const kHypothesesString = "hypotheses";
22 const char* const kUtteranceString = "utterance"; 25 const char* const kUtteranceString = "utterance";
23 const char* const kConfidenceString = "confidence"; 26 const char* const kConfidenceString = "confidence";
24 27
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 bool SpeechRecognitionRequest::Send(const std::string& language, 124 bool SpeechRecognitionRequest::Send(const std::string& language,
122 const std::string& grammar, 125 const std::string& grammar,
123 const std::string& content_type, 126 const std::string& content_type,
124 const std::string& audio_data) { 127 const std::string& audio_data) {
125 DCHECK(!url_fetcher_.get()); 128 DCHECK(!url_fetcher_.get());
126 129
127 std::vector<std::string> parts; 130 std::vector<std::string> parts;
128 if (!language.empty()) { 131 if (!language.empty()) {
129 parts.push_back("lang=" + EscapeQueryParamValue(language, true)); 132 parts.push_back("lang=" + EscapeQueryParamValue(language, true));
130 } else { 133 } else {
131 std::string app_locale = l10n_util::GetApplicationLocale(""); 134 // If no language is provided then we use the first from the accepted
132 parts.push_back("lang=" + EscapeQueryParamValue(app_locale, true)); 135 // language list. If this list is empty then it defaults to "en-US".
136 // Example of the contents of this list: "es,en-GB;q=0.8", ""
137 std::string language;
138 if (url_context_) {
139 URLRequestContext* request_context = url_context_->GetURLRequestContext();
140 DCHECK(request_context);
141 std::string accepted_language_list = request_context->accept_language();
142 size_t separator = accepted_language_list.find_first_of(",;");
143 language = accepted_language_list.substr(0, separator);
144 }
145 if (language.empty()) language = "en-US";
Satish 2010/11/16 14:23:42 Having a local var with the same name 'language' m
Leandro GraciĆ” Gil 2010/11/16 17:03:00 Done.
146 parts.push_back("lang=" + EscapeQueryParamValue(language, true));
133 } 147 }
134 148
135 if (!grammar.empty()) 149 if (!grammar.empty())
136 parts.push_back("grammar=" + EscapeQueryParamValue(grammar, true)); 150 parts.push_back("grammar=" + EscapeQueryParamValue(grammar, true));
137 GURL url(std::string(kDefaultSpeechRecognitionUrl) + JoinString(parts, '&')); 151 GURL url(std::string(kDefaultSpeechRecognitionUrl) + JoinString(parts, '&'));
138 152
139 url_fetcher_.reset(URLFetcher::Create(url_fetcher_id_for_tests, 153 url_fetcher_.reset(URLFetcher::Create(url_fetcher_id_for_tests,
140 url, 154 url,
141 URLFetcher::POST, 155 URLFetcher::POST,
142 this)); 156 this));
(...skipping 24 matching lines...) Expand all
167 SpeechInputResultArray result; 181 SpeechInputResultArray result;
168 if (!error) 182 if (!error)
169 error = !ParseServerResponse(data, &result); 183 error = !ParseServerResponse(data, &result);
170 url_fetcher_.reset(); 184 url_fetcher_.reset();
171 185
172 DVLOG(1) << "SpeechRecognitionRequest: Invoking delegate with result."; 186 DVLOG(1) << "SpeechRecognitionRequest: Invoking delegate with result.";
173 delegate_->SetRecognitionResult(error, result); 187 delegate_->SetRecognitionResult(error, result);
174 } 188 }
175 189
176 } // namespace speech_input 190 } // 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
This is Rietveld 408576698