| 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" |
| 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/common/net/url_fetcher.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 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 void SpeechRecognitionRequest::UploadAudioChunk(const std::string& audio_data, | 203 void SpeechRecognitionRequest::UploadAudioChunk(const std::string& audio_data, |
| 203 bool is_last_chunk) { | 204 bool is_last_chunk) { |
| 204 DCHECK(url_fetcher_.get()); | 205 DCHECK(url_fetcher_.get()); |
| 205 url_fetcher_->AppendChunkToUpload(audio_data, is_last_chunk); | 206 url_fetcher_->AppendChunkToUpload(audio_data, is_last_chunk); |
| 206 } | 207 } |
| 207 | 208 |
| 208 void SpeechRecognitionRequest::OnURLFetchComplete(const URLFetcher* source) { | 209 void SpeechRecognitionRequest::OnURLFetchComplete(const URLFetcher* source) { |
| 209 DCHECK_EQ(url_fetcher_.get(), source); | 210 DCHECK_EQ(url_fetcher_.get(), source); |
| 210 | 211 |
| 211 SpeechInputResult result; | 212 SpeechInputResult result; |
| 213 std::string data; |
| 212 if (!source->status().is_success() || source->response_code() != 200 || | 214 if (!source->status().is_success() || source->response_code() != 200 || |
| 213 !ParseServerResponse(source->GetResponseStringRef(), &result)) { | 215 !source->GetResponseAsString(&data) || |
| 216 !ParseServerResponse(data, &result)) { |
| 214 result.error = kErrorNetwork; | 217 result.error = kErrorNetwork; |
| 215 } | 218 } |
| 216 | 219 |
| 217 DVLOG(1) << "SpeechRecognitionRequest: Invoking delegate with result."; | 220 DVLOG(1) << "SpeechRecognitionRequest: Invoking delegate with result."; |
| 218 url_fetcher_.reset(); | 221 url_fetcher_.reset(); |
| 219 delegate_->SetRecognitionResult(result); | 222 delegate_->SetRecognitionResult(result); |
| 220 } | 223 } |
| 221 | 224 |
| 222 } // namespace speech_input | 225 } // namespace speech_input |
| OLD | NEW |