| 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 | |
| 9 #include <algorithm> | 8 #include <algorithm> |
| 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_string_value_serializer.h" | 12 #include "base/json/json_string_value_serializer.h" |
| 13 #include "base/json/json_writer.h" | 13 #include "base/json/json_writer.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/metrics/histogram_macros.h" | 15 #include "base/metrics/histogram_macros.h" |
| 16 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
| 17 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
| 18 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
| 19 #include "base/values.h" | 19 #include "base/values.h" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 relevance, | 86 relevance, |
| 87 relevance_from_server, | 87 relevance_from_server, |
| 88 type, | 88 type, |
| 89 deletion_url), | 89 deletion_url), |
| 90 suggestion_(suggestion), | 90 suggestion_(suggestion), |
| 91 match_contents_prefix_(match_contents_prefix), | 91 match_contents_prefix_(match_contents_prefix), |
| 92 annotation_(annotation), | 92 annotation_(annotation), |
| 93 suggest_query_params_(suggest_query_params), | 93 suggest_query_params_(suggest_query_params), |
| 94 answer_contents_(answer_contents), | 94 answer_contents_(answer_contents), |
| 95 answer_type_(answer_type), | 95 answer_type_(answer_type), |
| 96 answer_(answer.Pass()), | 96 answer_(std::move(answer)), |
| 97 should_prefetch_(should_prefetch) { | 97 should_prefetch_(should_prefetch) { |
| 98 match_contents_ = match_contents; | 98 match_contents_ = match_contents; |
| 99 DCHECK(!match_contents_.empty()); | 99 DCHECK(!match_contents_.empty()); |
| 100 ClassifyMatchContents(true, input_text); | 100 ClassifyMatchContents(true, input_text); |
| 101 } | 101 } |
| 102 | 102 |
| 103 SearchSuggestionParser::SuggestResult::SuggestResult( | 103 SearchSuggestionParser::SuggestResult::SuggestResult( |
| 104 const SuggestResult& result) | 104 const SuggestResult& result) |
| 105 : Result(result), | 105 : Result(result), |
| 106 suggestion_(result.suggestion_), | 106 suggestion_(result.suggestion_), |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 response_start_index != base::StringPiece::npos && i < 5; | 373 response_start_index != base::StringPiece::npos && i < 5; |
| 374 response_start_index = json_data.find("[", 1), i++) { | 374 response_start_index = json_data.find("[", 1), i++) { |
| 375 // Remove any XSSI guards to allow for JSON parsing. | 375 // Remove any XSSI guards to allow for JSON parsing. |
| 376 json_data.remove_prefix(response_start_index); | 376 json_data.remove_prefix(response_start_index); |
| 377 | 377 |
| 378 JSONStringValueDeserializer deserializer(json_data); | 378 JSONStringValueDeserializer deserializer(json_data); |
| 379 deserializer.set_allow_trailing_comma(true); | 379 deserializer.set_allow_trailing_comma(true); |
| 380 int error_code = 0; | 380 int error_code = 0; |
| 381 scoped_ptr<base::Value> data = deserializer.Deserialize(&error_code, NULL); | 381 scoped_ptr<base::Value> data = deserializer.Deserialize(&error_code, NULL); |
| 382 if (error_code == 0) | 382 if (error_code == 0) |
| 383 return data.Pass(); | 383 return data; |
| 384 } | 384 } |
| 385 return scoped_ptr<base::Value>(); | 385 return scoped_ptr<base::Value>(); |
| 386 } | 386 } |
| 387 | 387 |
| 388 // static | 388 // static |
| 389 bool SearchSuggestionParser::ParseSuggestResults( | 389 bool SearchSuggestionParser::ParseSuggestResults( |
| 390 const base::Value& root_val, | 390 const base::Value& root_val, |
| 391 const AutocompleteInput& input, | 391 const AutocompleteInput& input, |
| 392 const AutocompleteSchemeClassifier& scheme_classifier, | 392 const AutocompleteSchemeClassifier& scheme_classifier, |
| 393 int default_result_relevance, | 393 int default_result_relevance, |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 543 answer_parsed_successfully); | 543 answer_parsed_successfully); |
| 544 } | 544 } |
| 545 } | 545 } |
| 546 } | 546 } |
| 547 | 547 |
| 548 bool should_prefetch = static_cast<int>(index) == prefetch_index; | 548 bool should_prefetch = static_cast<int>(index) == prefetch_index; |
| 549 results->suggest_results.push_back(SuggestResult( | 549 results->suggest_results.push_back(SuggestResult( |
| 550 base::CollapseWhitespace(suggestion, false), match_type, | 550 base::CollapseWhitespace(suggestion, false), match_type, |
| 551 base::CollapseWhitespace(match_contents, false), | 551 base::CollapseWhitespace(match_contents, false), |
| 552 match_contents_prefix, annotation, answer_contents, answer_type_str, | 552 match_contents_prefix, annotation, answer_contents, answer_type_str, |
| 553 answer.Pass(), suggest_query_params, deletion_url, is_keyword_result, | 553 std::move(answer), suggest_query_params, deletion_url, |
| 554 relevance, relevances != NULL, should_prefetch, trimmed_input)); | 554 is_keyword_result, relevance, relevances != NULL, should_prefetch, |
| 555 trimmed_input)); |
| 555 } | 556 } |
| 556 } | 557 } |
| 557 results->relevances_from_server = relevances != NULL; | 558 results->relevances_from_server = relevances != NULL; |
| 558 return true; | 559 return true; |
| 559 } | 560 } |
| OLD | NEW |