OLD | NEW |
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" |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 parts.push_back("xhw=" + net::EscapeQueryParamValue(hardware_info, true)); | 179 parts.push_back("xhw=" + net::EscapeQueryParamValue(hardware_info, true)); |
180 parts.push_back("maxresults=" + base::IntToString(kMaxResults)); | 180 parts.push_back("maxresults=" + base::IntToString(kMaxResults)); |
181 parts.push_back(filter_profanities ? "pfilter=2" : "pfilter=0"); | 181 parts.push_back(filter_profanities ? "pfilter=2" : "pfilter=0"); |
182 | 182 |
183 GURL url(std::string(kDefaultSpeechRecognitionUrl) + JoinString(parts, '&')); | 183 GURL url(std::string(kDefaultSpeechRecognitionUrl) + JoinString(parts, '&')); |
184 | 184 |
185 url_fetcher_.reset(URLFetcher::Create(url_fetcher_id_for_tests, | 185 url_fetcher_.reset(URLFetcher::Create(url_fetcher_id_for_tests, |
186 url, | 186 url, |
187 URLFetcher::POST, | 187 URLFetcher::POST, |
188 this)); | 188 this)); |
189 url_fetcher_->set_chunked_upload(content_type); | 189 url_fetcher_->SetChunkedUpload(content_type); |
190 url_fetcher_->set_request_context(url_context_); | 190 url_fetcher_->SetRequestContext(url_context_); |
191 url_fetcher_->set_referrer(origin_url); | 191 url_fetcher_->SetReferrer(origin_url); |
192 | 192 |
193 // The speech recognition API does not require user identification as part | 193 // The speech recognition API does not require user identification as part |
194 // of requests, so we don't send cookies or auth data for these requests to | 194 // of requests, so we don't send cookies or auth data for these requests to |
195 // prevent any accidental connection between users who are logged into the | 195 // prevent any accidental connection between users who are logged into the |
196 // domain for other services (e.g. bookmark sync) with the speech requests. | 196 // domain for other services (e.g. bookmark sync) with the speech requests. |
197 url_fetcher_->set_load_flags( | 197 url_fetcher_->SetLoadFlags( |
198 net::LOAD_DO_NOT_SAVE_COOKIES | net::LOAD_DO_NOT_SEND_COOKIES | | 198 net::LOAD_DO_NOT_SAVE_COOKIES | net::LOAD_DO_NOT_SEND_COOKIES | |
199 net::LOAD_DO_NOT_SEND_AUTH_DATA); | 199 net::LOAD_DO_NOT_SEND_AUTH_DATA); |
200 url_fetcher_->Start(); | 200 url_fetcher_->Start(); |
201 } | 201 } |
202 | 202 |
203 void SpeechRecognitionRequest::UploadAudioChunk(const std::string& audio_data, | 203 void SpeechRecognitionRequest::UploadAudioChunk(const std::string& audio_data, |
204 bool is_last_chunk) { | 204 bool is_last_chunk) { |
205 DCHECK(url_fetcher_.get()); | 205 DCHECK(url_fetcher_.get()); |
206 url_fetcher_->AppendChunkToUpload(audio_data, is_last_chunk); | 206 url_fetcher_->AppendChunkToUpload(audio_data, is_last_chunk); |
207 } | 207 } |
208 | 208 |
209 void SpeechRecognitionRequest::OnURLFetchComplete(const URLFetcher* source) { | 209 void SpeechRecognitionRequest::OnURLFetchComplete( |
| 210 const content::URLFetcher* source) { |
210 DCHECK_EQ(url_fetcher_.get(), source); | 211 DCHECK_EQ(url_fetcher_.get(), source); |
211 | 212 |
212 SpeechInputResult result; | 213 SpeechInputResult result; |
213 std::string data; | 214 std::string data; |
214 if (!source->status().is_success() || source->response_code() != 200 || | 215 if (!source->GetStatus().is_success() || source->GetResponseCode() != 200 || |
215 !source->GetResponseAsString(&data) || | 216 !source->GetResponseAsString(&data) || |
216 !ParseServerResponse(data, &result)) { | 217 !ParseServerResponse(data, &result)) { |
217 result.error = kErrorNetwork; | 218 result.error = kErrorNetwork; |
218 } | 219 } |
219 | 220 |
220 DVLOG(1) << "SpeechRecognitionRequest: Invoking delegate with result."; | 221 DVLOG(1) << "SpeechRecognitionRequest: Invoking delegate with result."; |
221 url_fetcher_.reset(); | 222 url_fetcher_.reset(); |
222 delegate_->SetRecognitionResult(result); | 223 delegate_->SetRecognitionResult(result); |
223 } | 224 } |
224 | 225 |
225 } // namespace speech_input | 226 } // namespace speech_input |
OLD | NEW |