OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/omnibox/search_suggestion_parser.h" | 5 #include "components/omnibox/search_suggestion_parser.h" |
6 | 6 |
7 #include "base/i18n/icu_string_conversions.h" | 7 #include "base/i18n/icu_string_conversions.h" |
8 #include "base/json/json_string_value_serializer.h" | 8 #include "base/json/json_string_value_serializer.h" |
9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 // static | 344 // static |
345 scoped_ptr<base::Value> SearchSuggestionParser::DeserializeJsonData( | 345 scoped_ptr<base::Value> SearchSuggestionParser::DeserializeJsonData( |
346 base::StringPiece json_data) { | 346 base::StringPiece json_data) { |
347 // The JSON response should be an array. | 347 // The JSON response should be an array. |
348 for (size_t response_start_index = json_data.find("["), i = 0; | 348 for (size_t response_start_index = json_data.find("["), i = 0; |
349 response_start_index != base::StringPiece::npos && i < 5; | 349 response_start_index != base::StringPiece::npos && i < 5; |
350 response_start_index = json_data.find("[", 1), i++) { | 350 response_start_index = json_data.find("[", 1), i++) { |
351 // Remove any XSSI guards to allow for JSON parsing. | 351 // Remove any XSSI guards to allow for JSON parsing. |
352 json_data.remove_prefix(response_start_index); | 352 json_data.remove_prefix(response_start_index); |
353 | 353 |
354 JSONStringValueSerializer deserializer(json_data); | 354 JSONStringValueDeserializer deserializer(json_data); |
355 deserializer.set_allow_trailing_comma(true); | 355 deserializer.set_allow_trailing_comma(true); |
356 int error_code = 0; | 356 int error_code = 0; |
357 scoped_ptr<base::Value> data(deserializer.Deserialize(&error_code, NULL)); | 357 scoped_ptr<base::Value> data(deserializer.Deserialize(&error_code, NULL)); |
358 if (error_code == 0) | 358 if (error_code == 0) |
359 return data.Pass(); | 359 return data.Pass(); |
360 } | 360 } |
361 return scoped_ptr<base::Value>(); | 361 return scoped_ptr<base::Value>(); |
362 } | 362 } |
363 | 363 |
364 // static | 364 // static |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
521 base::CollapseWhitespace(suggestion, false), match_type, | 521 base::CollapseWhitespace(suggestion, false), match_type, |
522 base::CollapseWhitespace(match_contents, false), | 522 base::CollapseWhitespace(match_contents, false), |
523 match_contents_prefix, annotation, answer_contents, answer_type_str, | 523 match_contents_prefix, annotation, answer_contents, answer_type_str, |
524 answer.Pass(), suggest_query_params, deletion_url, is_keyword_result, | 524 answer.Pass(), suggest_query_params, deletion_url, is_keyword_result, |
525 relevance, relevances != NULL, should_prefetch, trimmed_input)); | 525 relevance, relevances != NULL, should_prefetch, trimmed_input)); |
526 } | 526 } |
527 } | 527 } |
528 results->relevances_from_server = relevances != NULL; | 528 results->relevances_from_server = relevances != NULL; |
529 return true; | 529 return true; |
530 } | 530 } |
OLD | NEW |