OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/google_one_shot_remote_engine.h" | 5 #include "content/browser/speech/google_one_shot_remote_engine.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 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 encoder_->GetEncodedDataAndClear()); | 255 encoder_->GetEncodedDataAndClear()); |
256 DCHECK(!encoded_dummy_data->IsEmpty()); | 256 DCHECK(!encoded_dummy_data->IsEmpty()); |
257 encoder_.reset(); | 257 encoder_.reset(); |
258 | 258 |
259 url_fetcher_->AppendChunkToUpload(encoded_dummy_data->AsString(), true); | 259 url_fetcher_->AppendChunkToUpload(encoded_dummy_data->AsString(), true); |
260 } | 260 } |
261 | 261 |
262 void GoogleOneShotRemoteEngine::OnURLFetchComplete( | 262 void GoogleOneShotRemoteEngine::OnURLFetchComplete( |
263 const net::URLFetcher* source) { | 263 const net::URLFetcher* source) { |
264 DCHECK_EQ(url_fetcher_.get(), source); | 264 DCHECK_EQ(url_fetcher_.get(), source); |
265 SpeechRecognitionResult result; | 265 SpeechRecognitionResults results; |
| 266 results.push_back(SpeechRecognitionResult()); |
| 267 SpeechRecognitionResult& result = results.back(); |
266 SpeechRecognitionError error(SPEECH_RECOGNITION_ERROR_NETWORK); | 268 SpeechRecognitionError error(SPEECH_RECOGNITION_ERROR_NETWORK); |
267 std::string data; | 269 std::string data; |
268 | 270 |
269 // The default error code in case of parse errors is NETWORK_FAILURE, however | 271 // The default error code in case of parse errors is NETWORK_FAILURE, however |
270 // ParseServerResponse can change the error to a more appropriate one. | 272 // ParseServerResponse can change the error to a more appropriate one. |
271 bool error_occurred = (!source->GetStatus().is_success() || | 273 bool error_occurred = (!source->GetStatus().is_success() || |
272 source->GetResponseCode() != 200 || | 274 source->GetResponseCode() != 200 || |
273 !source->GetResponseAsString(&data) || | 275 !source->GetResponseAsString(&data) || |
274 !ParseServerResponse(data, &result, &error)); | 276 !ParseServerResponse(data, &result, &error)); |
275 url_fetcher_.reset(); | 277 url_fetcher_.reset(); |
276 if (error_occurred) { | 278 if (error_occurred) { |
277 DVLOG(1) << "GoogleOneShotRemoteEngine: Network Error " << error.code; | 279 DVLOG(1) << "GoogleOneShotRemoteEngine: Network Error " << error.code; |
278 delegate()->OnSpeechRecognitionEngineError(error); | 280 delegate()->OnSpeechRecognitionEngineError(error); |
279 } else { | 281 } else { |
280 DVLOG(1) << "GoogleOneShotRemoteEngine: Invoking delegate with result."; | 282 DVLOG(1) << "GoogleOneShotRemoteEngine: Invoking delegate with result."; |
281 delegate()->OnSpeechRecognitionEngineResult(result); | 283 delegate()->OnSpeechRecognitionEngineResults(results); |
282 } | 284 } |
283 } | 285 } |
284 | 286 |
285 bool GoogleOneShotRemoteEngine::IsRecognitionPending() const { | 287 bool GoogleOneShotRemoteEngine::IsRecognitionPending() const { |
286 return url_fetcher_ != NULL; | 288 return url_fetcher_ != NULL; |
287 } | 289 } |
288 | 290 |
289 int GoogleOneShotRemoteEngine::GetDesiredAudioChunkDurationMs() const { | 291 int GoogleOneShotRemoteEngine::GetDesiredAudioChunkDurationMs() const { |
290 return kAudioPacketIntervalMs; | 292 return kAudioPacketIntervalMs; |
291 } | 293 } |
292 | 294 |
293 } // namespace content | 295 } // namespace content |
OLD | NEW |