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

Side by Side Diff: chrome/browser/speech/speech_recognition_request.cc

Issue 3595018: Language tag for speech. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: rebase. 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
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 "base/json/json_reader.h" 8 #include "base/json/json_reader.h"
8 #include "base/string_util.h" 9 #include "base/string_util.h"
9 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
10 #include "base/values.h" 11 #include "base/values.h"
11 #include "chrome/common/net/url_request_context_getter.h" 12 #include "chrome/common/net/url_request_context_getter.h"
12 #include "net/base/escape.h" 13 #include "net/base/escape.h"
13 #include "net/base/load_flags.h" 14 #include "net/base/load_flags.h"
14 #include "net/url_request/url_request_status.h" 15 #include "net/url_request/url_request_status.h"
15 16
16 namespace { 17 namespace {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 111
111 SpeechRecognitionRequest::SpeechRecognitionRequest( 112 SpeechRecognitionRequest::SpeechRecognitionRequest(
112 URLRequestContextGetter* context, Delegate* delegate) 113 URLRequestContextGetter* context, Delegate* delegate)
113 : url_context_(context), 114 : url_context_(context),
114 delegate_(delegate) { 115 delegate_(delegate) {
115 DCHECK(delegate); 116 DCHECK(delegate);
116 } 117 }
117 118
118 SpeechRecognitionRequest::~SpeechRecognitionRequest() {} 119 SpeechRecognitionRequest::~SpeechRecognitionRequest() {}
119 120
120 bool SpeechRecognitionRequest::Send(const std::string& grammar, 121 bool SpeechRecognitionRequest::Send(const std::string& language,
122 const std::string& grammar,
121 const std::string& content_type, 123 const std::string& content_type,
122 const std::string& audio_data) { 124 const std::string& audio_data) {
123 DCHECK(!url_fetcher_.get()); 125 DCHECK(!url_fetcher_.get());
124 126
125 std::vector<std::string> parts; 127 std::vector<std::string> parts;
126 // TODO(leandro): Replace with the language tag given by WebKit. 128 if (!language.empty()) {
127 parts.push_back("lang=en-us"); 129 parts.push_back("lang=" + EscapeQueryParamValue(language, true));
130 } else {
131 std::string app_locale = l10n_util::GetApplicationLocale("");
132 parts.push_back("lang=" + EscapeQueryParamValue(app_locale, true));
133 }
134
128 if (!grammar.empty()) 135 if (!grammar.empty())
129 parts.push_back("grammar=" + EscapeQueryParamValue(grammar, true)); 136 parts.push_back("grammar=" + EscapeQueryParamValue(grammar, true));
130 GURL url(std::string(kDefaultSpeechRecognitionUrl) + JoinString(parts, '&')); 137 GURL url(std::string(kDefaultSpeechRecognitionUrl) + JoinString(parts, '&'));
131 138
132 url_fetcher_.reset(URLFetcher::Create(url_fetcher_id_for_tests, 139 url_fetcher_.reset(URLFetcher::Create(url_fetcher_id_for_tests,
133 url, 140 url,
134 URLFetcher::POST, 141 URLFetcher::POST,
135 this)); 142 this));
136 url_fetcher_->set_upload_data(content_type, audio_data); 143 url_fetcher_->set_upload_data(content_type, audio_data);
137 url_fetcher_->set_request_context(url_context_); 144 url_fetcher_->set_request_context(url_context_);
(...skipping 22 matching lines...) Expand all
160 SpeechInputResultArray result; 167 SpeechInputResultArray result;
161 if (!error) 168 if (!error)
162 error = !ParseServerResponse(data, &result); 169 error = !ParseServerResponse(data, &result);
163 url_fetcher_.reset(); 170 url_fetcher_.reset();
164 171
165 DVLOG(1) << "SpeechRecognitionRequest: Invoking delegate with result."; 172 DVLOG(1) << "SpeechRecognitionRequest: Invoking delegate with result.";
166 delegate_->SetRecognitionResult(error, result); 173 delegate_->SetRecognitionResult(error, result);
167 } 174 }
168 175
169 } // namespace speech_input 176 } // namespace speech_input
OLDNEW
« no previous file with comments | « chrome/browser/speech/speech_recognition_request.h ('k') | chrome/browser/speech/speech_recognition_request_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698