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

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

Issue 11416310: Revert 170668 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years 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) 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
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 SpeechRecognitionResults results; 265 SpeechRecognitionResult result;
266 results.push_back(SpeechRecognitionResult());
267 SpeechRecognitionResult& result = results.back();
268 SpeechRecognitionError error(SPEECH_RECOGNITION_ERROR_NETWORK); 266 SpeechRecognitionError error(SPEECH_RECOGNITION_ERROR_NETWORK);
269 std::string data; 267 std::string data;
270 268
271 // The default error code in case of parse errors is NETWORK_FAILURE, however 269 // The default error code in case of parse errors is NETWORK_FAILURE, however
272 // ParseServerResponse can change the error to a more appropriate one. 270 // ParseServerResponse can change the error to a more appropriate one.
273 bool error_occurred = (!source->GetStatus().is_success() || 271 bool error_occurred = (!source->GetStatus().is_success() ||
274 source->GetResponseCode() != 200 || 272 source->GetResponseCode() != 200 ||
275 !source->GetResponseAsString(&data) || 273 !source->GetResponseAsString(&data) ||
276 !ParseServerResponse(data, &result, &error)); 274 !ParseServerResponse(data, &result, &error));
277 url_fetcher_.reset(); 275 url_fetcher_.reset();
278 if (error_occurred) { 276 if (error_occurred) {
279 DVLOG(1) << "GoogleOneShotRemoteEngine: Network Error " << error.code; 277 DVLOG(1) << "GoogleOneShotRemoteEngine: Network Error " << error.code;
280 delegate()->OnSpeechRecognitionEngineError(error); 278 delegate()->OnSpeechRecognitionEngineError(error);
281 } else { 279 } else {
282 DVLOG(1) << "GoogleOneShotRemoteEngine: Invoking delegate with result."; 280 DVLOG(1) << "GoogleOneShotRemoteEngine: Invoking delegate with result.";
283 delegate()->OnSpeechRecognitionEngineResults(results); 281 delegate()->OnSpeechRecognitionEngineResult(result);
284 } 282 }
285 } 283 }
286 284
287 bool GoogleOneShotRemoteEngine::IsRecognitionPending() const { 285 bool GoogleOneShotRemoteEngine::IsRecognitionPending() const {
288 return url_fetcher_ != NULL; 286 return url_fetcher_ != NULL;
289 } 287 }
290 288
291 int GoogleOneShotRemoteEngine::GetDesiredAudioChunkDurationMs() const { 289 int GoogleOneShotRemoteEngine::GetDesiredAudioChunkDurationMs() const {
292 return kAudioPacketIntervalMs; 290 return kAudioPacketIntervalMs;
293 } 291 }
294 292
295 } // namespace content 293 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698