Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(363)

Side by Side Diff: components/omnibox/browser/search_suggestion_parser.cc

Issue 1394993004: Make ValueDeserializer::Deserialize return scoped_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix and add todo about not failed trybot Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <algorithm> 7 #include <algorithm>
8 8
9 #include "base/i18n/icu_string_conversions.h" 9 #include "base/i18n/icu_string_conversions.h"
10 #include "base/json/json_string_value_serializer.h" 10 #include "base/json/json_string_value_serializer.h"
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 // The JSON response should be an array. 369 // The JSON response should be an array.
370 for (size_t response_start_index = json_data.find("["), i = 0; 370 for (size_t response_start_index = json_data.find("["), i = 0;
371 response_start_index != base::StringPiece::npos && i < 5; 371 response_start_index != base::StringPiece::npos && i < 5;
372 response_start_index = json_data.find("[", 1), i++) { 372 response_start_index = json_data.find("[", 1), i++) {
373 // Remove any XSSI guards to allow for JSON parsing. 373 // Remove any XSSI guards to allow for JSON parsing.
374 json_data.remove_prefix(response_start_index); 374 json_data.remove_prefix(response_start_index);
375 375
376 JSONStringValueDeserializer deserializer(json_data); 376 JSONStringValueDeserializer deserializer(json_data);
377 deserializer.set_allow_trailing_comma(true); 377 deserializer.set_allow_trailing_comma(true);
378 int error_code = 0; 378 int error_code = 0;
379 scoped_ptr<base::Value> data(deserializer.Deserialize(&error_code, NULL)); 379 scoped_ptr<base::Value> data = deserializer.Deserialize(&error_code, NULL);
380 if (error_code == 0) 380 if (error_code == 0)
381 return data.Pass(); 381 return data.Pass();
382 } 382 }
383 return scoped_ptr<base::Value>(); 383 return scoped_ptr<base::Value>();
384 } 384 }
385 385
386 // static 386 // static
387 bool SearchSuggestionParser::ParseSuggestResults( 387 bool SearchSuggestionParser::ParseSuggestResults(
388 const base::Value& root_val, 388 const base::Value& root_val,
389 const AutocompleteInput& input, 389 const AutocompleteInput& input,
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 base::CollapseWhitespace(suggestion, false), match_type, 548 base::CollapseWhitespace(suggestion, false), match_type,
549 base::CollapseWhitespace(match_contents, false), 549 base::CollapseWhitespace(match_contents, false),
550 match_contents_prefix, annotation, answer_contents, answer_type_str, 550 match_contents_prefix, annotation, answer_contents, answer_type_str,
551 answer.Pass(), suggest_query_params, deletion_url, is_keyword_result, 551 answer.Pass(), suggest_query_params, deletion_url, is_keyword_result,
552 relevance, relevances != NULL, should_prefetch, trimmed_input)); 552 relevance, relevances != NULL, should_prefetch, trimmed_input));
553 } 553 }
554 } 554 }
555 results->relevances_from_server = relevances != NULL; 555 results->relevances_from_server = relevances != NULL;
556 return true; 556 return true;
557 } 557 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698