| 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 27 matching lines...) Expand all Loading... |
| 38 | 38 |
| 39 // Parse the response, ignoring comments. | 39 // Parse the response, ignoring comments. |
| 40 std::string error_msg; | 40 std::string error_msg; |
| 41 scoped_ptr<Value> response_value(base::JSONReader::ReadAndReturnError( | 41 scoped_ptr<Value> response_value(base::JSONReader::ReadAndReturnError( |
| 42 response_body, false, NULL, &error_msg)); | 42 response_body, false, NULL, &error_msg)); |
| 43 if (response_value == NULL) { | 43 if (response_value == NULL) { |
| 44 LOG(WARNING) << "ParseServerResponse: JSONReader failed : " << error_msg; | 44 LOG(WARNING) << "ParseServerResponse: JSONReader failed : " << error_msg; |
| 45 return false; | 45 return false; |
| 46 } | 46 } |
| 47 | 47 |
| 48 if (!response_value->IsType(Value::TYPE_DICTIONARY)) { | 48 if (!response_value->IsDictionary()) { |
| 49 VLOG(1) << "ParseServerResponse: Unexpected response type " | 49 VLOG(1) << "ParseServerResponse: Unexpected response type " |
| 50 << response_value->GetType(); | 50 << response_value->GetType(); |
| 51 return false; | 51 return false; |
| 52 } | 52 } |
| 53 const DictionaryValue* response_object = | 53 const DictionaryValue* response_object = |
| 54 static_cast<DictionaryValue*>(response_value.get()); | 54 static_cast<DictionaryValue*>(response_value.get()); |
| 55 | 55 |
| 56 // Get the hypotheses | 56 // Get the hypotheses |
| 57 Value* hypotheses_value = NULL; | 57 Value* hypotheses_value = NULL; |
| 58 if (!response_object->Get(kHypothesesString, &hypotheses_value)) { | 58 if (!response_object->Get(kHypothesesString, &hypotheses_value)) { |
| 59 VLOG(1) << "ParseServerResponse: Missing hypotheses attribute."; | 59 VLOG(1) << "ParseServerResponse: Missing hypotheses attribute."; |
| 60 return false; | 60 return false; |
| 61 } | 61 } |
| 62 DCHECK(hypotheses_value); | 62 DCHECK(hypotheses_value); |
| 63 if (!hypotheses_value->IsType(Value::TYPE_LIST)) { | 63 if (!hypotheses_value->IsList()) { |
| 64 VLOG(1) << "ParseServerResponse: Unexpected hypotheses type " | 64 VLOG(1) << "ParseServerResponse: Unexpected hypotheses type " |
| 65 << hypotheses_value->GetType(); | 65 << hypotheses_value->GetType(); |
| 66 return false; | 66 return false; |
| 67 } | 67 } |
| 68 const ListValue* hypotheses_list = static_cast<ListValue*>(hypotheses_value); | 68 const ListValue* hypotheses_list = static_cast<ListValue*>(hypotheses_value); |
| 69 | 69 |
| 70 size_t index = 0; | 70 size_t index = 0; |
| 71 for (; index < hypotheses_list->GetSize(); ++index) { | 71 for (; index < hypotheses_list->GetSize(); ++index) { |
| 72 Value* hypothesis = NULL; | 72 Value* hypothesis = NULL; |
| 73 if (!hypotheses_list->Get(index, &hypothesis)) { | 73 if (!hypotheses_list->Get(index, &hypothesis)) { |
| 74 LOG(WARNING) << "ParseServerResponse: Unable to read hypothesis value."; | 74 LOG(WARNING) << "ParseServerResponse: Unable to read hypothesis value."; |
| 75 break; | 75 break; |
| 76 } | 76 } |
| 77 DCHECK(hypothesis); | 77 DCHECK(hypothesis); |
| 78 if (!hypothesis->IsType(Value::TYPE_DICTIONARY)) { | 78 if (!hypothesis->IsDictionary()) { |
| 79 LOG(WARNING) << "ParseServerResponse: Unexpected value type " | 79 LOG(WARNING) << "ParseServerResponse: Unexpected value type " |
| 80 << hypothesis->GetType(); | 80 << hypothesis->GetType(); |
| 81 break; | 81 break; |
| 82 } | 82 } |
| 83 | 83 |
| 84 const DictionaryValue* hypothesis_value = | 84 const DictionaryValue* hypothesis_value = |
| 85 static_cast<DictionaryValue*>(hypothesis); | 85 static_cast<DictionaryValue*>(hypothesis); |
| 86 string16 utterance; | 86 string16 utterance; |
| 87 if (!hypothesis_value->GetString(kUtteranceString, &utterance)) { | 87 if (!hypothesis_value->GetString(kUtteranceString, &utterance)) { |
| 88 LOG(WARNING) << "ParseServerResponse: Missing utterance value."; | 88 LOG(WARNING) << "ParseServerResponse: Missing utterance value."; |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 SpeechInputResultArray result; | 192 SpeechInputResultArray result; |
| 193 if (!error) | 193 if (!error) |
| 194 error = !ParseServerResponse(data, &result); | 194 error = !ParseServerResponse(data, &result); |
| 195 url_fetcher_.reset(); | 195 url_fetcher_.reset(); |
| 196 | 196 |
| 197 DVLOG(1) << "SpeechRecognitionRequest: Invoking delegate with result."; | 197 DVLOG(1) << "SpeechRecognitionRequest: Invoking delegate with result."; |
| 198 delegate_->SetRecognitionResult(error, result); | 198 delegate_->SetRecognitionResult(error, result); |
| 199 } | 199 } |
| 200 | 200 |
| 201 } // namespace speech_input | 201 } // namespace speech_input |
| OLD | NEW |