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

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

Issue 7989001: Remove use of default request context and fix use of speech censor flag (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update SpeechInputPreferences when preference changes Created 9 years, 2 months 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "content/browser/speech/speech_recognition_request.h" 5 #include "content/browser/speech/speech_recognition_request.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/json/json_reader.h" 9 #include "base/json/json_reader.h"
10 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
11 #include "base/string_util.h" 11 #include "base/string_util.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 #include "content/browser/speech/speech_input_preferences.h"
13 #include "net/base/escape.h" 14 #include "net/base/escape.h"
14 #include "net/base/load_flags.h" 15 #include "net/base/load_flags.h"
15 #include "net/url_request/url_request_context.h" 16 #include "net/url_request/url_request_context.h"
16 #include "net/url_request/url_request_context_getter.h" 17 #include "net/url_request/url_request_context_getter.h"
17 #include "net/url_request/url_request_status.h" 18 #include "net/url_request/url_request_status.h"
18 19
19 namespace { 20 namespace {
20 21
21 const char* const kDefaultSpeechRecognitionUrl = 22 const char* const kDefaultSpeechRecognitionUrl =
22 "https://www.google.com/speech-api/v1/recognize?xjerr=1&client=chromium&"; 23 "https://www.google.com/speech-api/v1/recognize?xjerr=1&client=chromium&";
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 net::URLRequestContextGetter* context, Delegate* delegate) 116 net::URLRequestContextGetter* context, Delegate* delegate)
116 : url_context_(context), 117 : url_context_(context),
117 delegate_(delegate) { 118 delegate_(delegate) {
118 DCHECK(delegate); 119 DCHECK(delegate);
119 } 120 }
120 121
121 SpeechRecognitionRequest::~SpeechRecognitionRequest() {} 122 SpeechRecognitionRequest::~SpeechRecognitionRequest() {}
122 123
123 void SpeechRecognitionRequest::Start(const std::string& language, 124 void SpeechRecognitionRequest::Start(const std::string& language,
124 const std::string& grammar, 125 const std::string& grammar,
125 bool censor_results, 126 SpeechInputPreferences* speech_input_prefs,
126 const std::string& hardware_info, 127 const std::string& hardware_info,
127 const std::string& origin_url, 128 const std::string& origin_url,
128 const std::string& content_type) { 129 const std::string& content_type) {
129 DCHECK(!url_fetcher_.get()); 130 DCHECK(!url_fetcher_.get());
130 131
131 std::vector<std::string> parts; 132 std::vector<std::string> parts;
132 133
133 std::string lang_param = language; 134 std::string lang_param = language;
134 if (lang_param.empty() && url_context_) { 135 if (lang_param.empty() && url_context_) {
135 // If no language is provided then we use the first from the accepted 136 // If no language is provided then we use the first from the accepted
136 // language list. If this list is empty then it defaults to "en-US". 137 // language list. If this list is empty then it defaults to "en-US".
137 // Example of the contents of this list: "es,en-GB;q=0.8", "" 138 // Example of the contents of this list: "es,en-GB;q=0.8", ""
138 net::URLRequestContext* request_context = 139 net::URLRequestContext* request_context =
139 url_context_->GetURLRequestContext(); 140 url_context_->GetURLRequestContext();
140 DCHECK(request_context); 141 DCHECK(request_context);
141 std::string accepted_language_list = request_context->accept_language(); 142 std::string accepted_language_list = request_context->accept_language();
142 size_t separator = accepted_language_list.find_first_of(",;"); 143 size_t separator = accepted_language_list.find_first_of(",;");
143 lang_param = accepted_language_list.substr(0, separator); 144 lang_param = accepted_language_list.substr(0, separator);
144 } 145 }
145 if (lang_param.empty()) 146 if (lang_param.empty())
146 lang_param = "en-US"; 147 lang_param = "en-US";
147 parts.push_back("lang=" + net::EscapeQueryParamValue(lang_param, true)); 148 parts.push_back("lang=" + net::EscapeQueryParamValue(lang_param, true));
148 149
149 if (!grammar.empty()) 150 if (!grammar.empty())
150 parts.push_back("lm=" + net::EscapeQueryParamValue(grammar, true)); 151 parts.push_back("lm=" + net::EscapeQueryParamValue(grammar, true));
151 if (!hardware_info.empty()) 152 if (!hardware_info.empty())
152 parts.push_back("xhw=" + net::EscapeQueryParamValue(hardware_info, true)); 153 parts.push_back("xhw=" + net::EscapeQueryParamValue(hardware_info, true));
153 parts.push_back("maxresults=" + base::IntToString(kMaxResults)); 154 parts.push_back("maxresults=" + base::IntToString(kMaxResults));
154 parts.push_back(censor_results ? "pfilter=2" : "pfilter=0"); 155 parts.push_back(speech_input_prefs->censor_results()
156 ? "pfilter=2" : "pfilter=0");
155 157
156 GURL url(std::string(kDefaultSpeechRecognitionUrl) + JoinString(parts, '&')); 158 GURL url(std::string(kDefaultSpeechRecognitionUrl) + JoinString(parts, '&'));
157 159
158 url_fetcher_.reset(URLFetcher::Create(url_fetcher_id_for_tests, 160 url_fetcher_.reset(URLFetcher::Create(url_fetcher_id_for_tests,
159 url, 161 url,
160 URLFetcher::POST, 162 URLFetcher::POST,
161 this)); 163 this));
162 url_fetcher_->set_chunked_upload(content_type); 164 url_fetcher_->set_chunked_upload(content_type);
163 url_fetcher_->set_request_context(url_context_); 165 url_fetcher_->set_request_context(url_context_);
164 url_fetcher_->set_referrer(origin_url); 166 url_fetcher_->set_referrer(origin_url);
(...skipping 27 matching lines...) Expand all
192 SpeechInputResultArray result; 194 SpeechInputResultArray result;
193 if (!error) 195 if (!error)
194 error = !ParseServerResponse(data, &result); 196 error = !ParseServerResponse(data, &result);
195 url_fetcher_.reset(); 197 url_fetcher_.reset();
196 198
197 DVLOG(1) << "SpeechRecognitionRequest: Invoking delegate with result."; 199 DVLOG(1) << "SpeechRecognitionRequest: Invoking delegate with result.";
198 delegate_->SetRecognitionResult(error, result); 200 delegate_->SetRecognitionResult(error, result);
199 } 201 }
200 202
201 } // namespace speech_input 203 } // namespace speech_input
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698