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 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
336 base::OnStringConversionError::FAIL, | 336 base::OnStringConversionError::FAIL, |
337 &data_16)) | 337 &data_16)) |
338 json_data = base::UTF16ToUTF8(data_16); | 338 json_data = base::UTF16ToUTF8(data_16); |
339 } | 339 } |
340 } | 340 } |
341 return json_data; | 341 return json_data; |
342 } | 342 } |
343 | 343 |
344 // static | 344 // static |
345 scoped_ptr<base::Value> SearchSuggestionParser::DeserializeJsonData( | 345 scoped_ptr<base::Value> SearchSuggestionParser::DeserializeJsonData( |
346 std::string 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 != std::string::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 if (response_start_index > 0) | 352 if (response_start_index > 0) |
Peter Kasting
2015/02/05 09:20:36
Nit: This conditional could just be removed and th
Matt Giuca
2015/02/06 00:30:02
Done.
| |
353 json_data.erase(0, response_start_index); | 353 json_data.remove_prefix(response_start_index); |
354 | 354 |
355 JSONStringValueSerializer deserializer(json_data); | 355 JSONStringValueSerializer deserializer(json_data); |
356 deserializer.set_allow_trailing_comma(true); | 356 deserializer.set_allow_trailing_comma(true); |
357 int error_code = 0; | 357 int error_code = 0; |
358 scoped_ptr<base::Value> data(deserializer.Deserialize(&error_code, NULL)); | 358 scoped_ptr<base::Value> data(deserializer.Deserialize(&error_code, NULL)); |
359 if (error_code == 0) | 359 if (error_code == 0) |
360 return data.Pass(); | 360 return data.Pass(); |
361 } | 361 } |
362 return scoped_ptr<base::Value>(); | 362 return scoped_ptr<base::Value>(); |
363 } | 363 } |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
523 base::CollapseWhitespace(suggestion, false), match_type, | 523 base::CollapseWhitespace(suggestion, false), match_type, |
524 base::CollapseWhitespace(match_contents, false), | 524 base::CollapseWhitespace(match_contents, false), |
525 match_contents_prefix, annotation, answer_contents, answer_type_str, | 525 match_contents_prefix, annotation, answer_contents, answer_type_str, |
526 answer.Pass(), suggest_query_params, deletion_url, is_keyword_result, | 526 answer.Pass(), suggest_query_params, deletion_url, is_keyword_result, |
527 relevance, relevances != NULL, should_prefetch, trimmed_input)); | 527 relevance, relevances != NULL, should_prefetch, trimmed_input)); |
528 } | 528 } |
529 } | 529 } |
530 results->relevances_from_server = relevances != NULL; | 530 results->relevances_from_server = relevances != NULL; |
531 return true; | 531 return true; |
532 } | 532 } |
OLD | NEW |