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/browser/search_suggestion_parser.h" | 5 #include "components/omnibox/browser/search_suggestion_parser.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/i18n/icu_string_conversions.h" | 11 #include "base/i18n/icu_string_conversions.h" |
| 12 #include "base/json/json_reader.h" |
12 #include "base/json/json_string_value_serializer.h" | 13 #include "base/json/json_string_value_serializer.h" |
13 #include "base/json/json_writer.h" | 14 #include "base/json/json_writer.h" |
14 #include "base/logging.h" | 15 #include "base/logging.h" |
15 #include "base/metrics/histogram_macros.h" | 16 #include "base/metrics/histogram_macros.h" |
16 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
17 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
18 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
19 #include "base/values.h" | 20 #include "base/values.h" |
20 #include "components/omnibox/browser/autocomplete_i18n.h" | 21 #include "components/omnibox/browser/autocomplete_i18n.h" |
21 #include "components/omnibox/browser/autocomplete_input.h" | 22 #include "components/omnibox/browser/autocomplete_input.h" |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 // static | 368 // static |
368 std::unique_ptr<base::Value> SearchSuggestionParser::DeserializeJsonData( | 369 std::unique_ptr<base::Value> SearchSuggestionParser::DeserializeJsonData( |
369 base::StringPiece json_data) { | 370 base::StringPiece json_data) { |
370 // The JSON response should be an array. | 371 // The JSON response should be an array. |
371 for (size_t response_start_index = json_data.find("["), i = 0; | 372 for (size_t response_start_index = json_data.find("["), i = 0; |
372 response_start_index != base::StringPiece::npos && i < 5; | 373 response_start_index != base::StringPiece::npos && i < 5; |
373 response_start_index = json_data.find("[", 1), i++) { | 374 response_start_index = json_data.find("[", 1), i++) { |
374 // Remove any XSSI guards to allow for JSON parsing. | 375 // Remove any XSSI guards to allow for JSON parsing. |
375 json_data.remove_prefix(response_start_index); | 376 json_data.remove_prefix(response_start_index); |
376 | 377 |
377 JSONStringValueDeserializer deserializer(json_data); | 378 JSONStringValueDeserializer deserializer(json_data, |
378 deserializer.set_allow_trailing_comma(true); | 379 base::JSON_ALLOW_TRAILING_COMMAS); |
379 int error_code = 0; | 380 int error_code = 0; |
380 std::unique_ptr<base::Value> data = | 381 std::unique_ptr<base::Value> data = |
381 deserializer.Deserialize(&error_code, NULL); | 382 deserializer.Deserialize(&error_code, NULL); |
382 if (error_code == 0) | 383 if (error_code == 0) |
383 return data; | 384 return data; |
384 } | 385 } |
385 return std::unique_ptr<base::Value>(); | 386 return std::unique_ptr<base::Value>(); |
386 } | 387 } |
387 | 388 |
388 // static | 389 // static |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 base::CollapseWhitespace(match_contents, false), | 547 base::CollapseWhitespace(match_contents, false), |
547 match_contents_prefix, annotation, answer_contents, answer_type_str, | 548 match_contents_prefix, annotation, answer_contents, answer_type_str, |
548 std::move(answer), suggest_query_params, deletion_url, | 549 std::move(answer), suggest_query_params, deletion_url, |
549 is_keyword_result, relevance, relevances != NULL, should_prefetch, | 550 is_keyword_result, relevance, relevances != NULL, should_prefetch, |
550 trimmed_input)); | 551 trimmed_input)); |
551 } | 552 } |
552 } | 553 } |
553 results->relevances_from_server = relevances != NULL; | 554 results->relevances_from_server = relevances != NULL; |
554 return true; | 555 return true; |
555 } | 556 } |
OLD | NEW |