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

Side by Side Diff: chrome/browser/autocomplete/search_provider.cc

Issue 3117017: Remove deprecated wstring Get(As)String() methods from Value, etc. (Closed)
Patch Set: fix win Created 10 years, 4 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
« no previous file with comments | « base/values_unittest.cc ('k') | chrome/browser/command_line_pref_store_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "chrome/browser/autocomplete/search_provider.h" 5 #include "chrome/browser/autocomplete/search_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "app/l10n_util.h" 9 #include "app/l10n_util.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/i18n/icu_string_conversions.h" 11 #include "base/i18n/icu_string_conversions.h"
12 #include "base/message_loop.h" 12 #include "base/message_loop.h"
13 #include "base/string16.h"
13 #include "base/utf_string_conversions.h" 14 #include "base/utf_string_conversions.h"
14 #include "chrome/browser/autocomplete/keyword_provider.h" 15 #include "chrome/browser/autocomplete/keyword_provider.h"
15 #include "chrome/browser/browser_process.h" 16 #include "chrome/browser/browser_process.h"
16 #include "chrome/browser/google_util.h" 17 #include "chrome/browser/google_util.h"
17 #include "chrome/browser/history/history.h" 18 #include "chrome/browser/history/history.h"
18 #include "chrome/browser/net/url_fixer_upper.h" 19 #include "chrome/browser/net/url_fixer_upper.h"
19 #include "chrome/browser/pref_service.h" 20 #include "chrome/browser/pref_service.h"
20 #include "chrome/browser/profile.h" 21 #include "chrome/browser/profile.h"
21 #include "chrome/browser/search_engines/template_url_model.h" 22 #include "chrome/browser/search_engines/template_url_model.h"
22 #include "chrome/common/json_value_serializer.h" 23 #include "chrome/common/json_value_serializer.h"
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 390
390 bool SearchProvider::ParseSuggestResults(Value* root_val, 391 bool SearchProvider::ParseSuggestResults(Value* root_val,
391 bool is_keyword, 392 bool is_keyword,
392 const std::wstring& input_text, 393 const std::wstring& input_text,
393 SuggestResults* suggest_results) { 394 SuggestResults* suggest_results) {
394 if (!root_val->IsType(Value::TYPE_LIST)) 395 if (!root_val->IsType(Value::TYPE_LIST))
395 return false; 396 return false;
396 ListValue* root_list = static_cast<ListValue*>(root_val); 397 ListValue* root_list = static_cast<ListValue*>(root_val);
397 398
398 Value* query_val; 399 Value* query_val;
399 std::wstring query_str; 400 string16 query_str;
400 Value* result_val; 401 Value* result_val;
401 if ((root_list->GetSize() < 2) || !root_list->Get(0, &query_val) || 402 if ((root_list->GetSize() < 2) || !root_list->Get(0, &query_val) ||
402 !query_val->GetAsString(&query_str) || (query_str != input_text) || 403 !query_val->GetAsString(&query_str) ||
404 (query_str != WideToUTF16Hack(input_text)) ||
403 !root_list->Get(1, &result_val) || !result_val->IsType(Value::TYPE_LIST)) 405 !root_list->Get(1, &result_val) || !result_val->IsType(Value::TYPE_LIST))
404 return false; 406 return false;
405 407
406 ListValue* description_list = NULL; 408 ListValue* description_list = NULL;
407 if (root_list->GetSize() > 2) { 409 if (root_list->GetSize() > 2) {
408 // 3rd element: Description list. 410 // 3rd element: Description list.
409 Value* description_val; 411 Value* description_val;
410 if (root_list->Get(2, &description_val) && 412 if (root_list->Get(2, &description_val) &&
411 description_val->IsType(Value::TYPE_LIST)) 413 description_val->IsType(Value::TYPE_LIST))
412 description_list = static_cast<ListValue*>(description_val); 414 description_list = static_cast<ListValue*>(description_val);
(...skipping 16 matching lines...) Expand all
429 // Parse Google Suggest specific type extension. 431 // Parse Google Suggest specific type extension.
430 static const std::wstring kGoogleSuggestType(L"google:suggesttype"); 432 static const std::wstring kGoogleSuggestType(L"google:suggesttype");
431 if (dict_val->HasKey(kGoogleSuggestType)) 433 if (dict_val->HasKey(kGoogleSuggestType))
432 dict_val->GetList(kGoogleSuggestType, &type_list); 434 dict_val->GetList(kGoogleSuggestType, &type_list);
433 } 435 }
434 } 436 }
435 437
436 ListValue* result_list = static_cast<ListValue*>(result_val); 438 ListValue* result_list = static_cast<ListValue*>(result_val);
437 for (size_t i = 0; i < result_list->GetSize(); ++i) { 439 for (size_t i = 0; i < result_list->GetSize(); ++i) {
438 Value* suggestion_val; 440 Value* suggestion_val;
439 std::wstring suggestion_str; 441 string16 suggestion_str;
440 if (!result_list->Get(i, &suggestion_val) || 442 if (!result_list->Get(i, &suggestion_val) ||
441 !suggestion_val->GetAsString(&suggestion_str)) 443 !suggestion_val->GetAsString(&suggestion_str))
442 return false; 444 return false;
443 445
444 Value* type_val; 446 Value* type_val;
445 std::wstring type_str; 447 std::string type_str;
446 if (type_list && type_list->Get(i, &type_val) && 448 if (type_list && type_list->Get(i, &type_val) &&
447 type_val->GetAsString(&type_str) && (type_str == L"NAVIGATION")) { 449 type_val->GetAsString(&type_str) && (type_str == "NAVIGATION")) {
448 Value* site_val; 450 Value* site_val;
449 std::wstring site_name; 451 string16 site_name;
450 NavigationResults& navigation_results = 452 NavigationResults& navigation_results =
451 is_keyword ? keyword_navigation_results_ : 453 is_keyword ? keyword_navigation_results_ :
452 default_navigation_results_; 454 default_navigation_results_;
453 if ((navigation_results.size() < kMaxMatches) && 455 if ((navigation_results.size() < kMaxMatches) &&
454 description_list && description_list->Get(i, &site_val) && 456 description_list && description_list->Get(i, &site_val) &&
455 site_val->IsType(Value::TYPE_STRING) && 457 site_val->IsType(Value::TYPE_STRING) &&
456 site_val->GetAsString(&site_name)) { 458 site_val->GetAsString(&site_name)) {
457 // We can't blindly trust the URL coming from the server to be valid. 459 // We can't blindly trust the URL coming from the server to be valid.
458 GURL result_url(URLFixerUpper::FixupURL(WideToUTF8(suggestion_str), 460 GURL result_url(URLFixerUpper::FixupURL(UTF16ToUTF8(suggestion_str),
459 std::string())); 461 std::string()));
460 if (result_url.is_valid()) 462 if (result_url.is_valid()) {
461 navigation_results.push_back(NavigationResult(result_url, site_name)); 463 navigation_results.push_back(NavigationResult(result_url,
464 UTF16ToWideHack(site_name)));
465 }
462 } 466 }
463 } else { 467 } else {
464 // TODO(kochi): Currently we treat a calculator result as a query, but it 468 // TODO(kochi): Currently we treat a calculator result as a query, but it
465 // is better to have better presentation for caluculator results. 469 // is better to have better presentation for caluculator results.
466 if (suggest_results->size() < kMaxMatches) 470 if (suggest_results->size() < kMaxMatches)
467 suggest_results->push_back(suggestion_str); 471 suggest_results->push_back(UTF16ToWideHack(suggestion_str));
468 } 472 }
469 } 473 }
470 474
471 return true; 475 return true;
472 } 476 }
473 477
474 void SearchProvider::ConvertResultsToAutocompleteMatches() { 478 void SearchProvider::ConvertResultsToAutocompleteMatches() {
475 // Convert all the results to matches and add them to a map, so we can keep 479 // Convert all the results to matches and add them to a map, so we can keep
476 // the most relevant match for each result. 480 // the most relevant match for each result.
477 MatchMap map; 481 MatchMap map;
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
765 if (input_.type() == AutocompleteInput::FORCED_QUERY) 769 if (input_.type() == AutocompleteInput::FORCED_QUERY)
766 match.fill_into_edit.assign(L"?"); 770 match.fill_into_edit.assign(L"?");
767 match.fill_into_edit.append( 771 match.fill_into_edit.append(
768 AutocompleteInput::FormattedStringWithEquivalentMeaning(navigation.url, 772 AutocompleteInput::FormattedStringWithEquivalentMeaning(navigation.url,
769 match.contents)); 773 match.contents));
770 // TODO(pkasting): http://b/1112879 These should perhaps be 774 // TODO(pkasting): http://b/1112879 These should perhaps be
771 // inline-autocompletable? 775 // inline-autocompletable?
772 776
773 return match; 777 return match;
774 } 778 }
OLDNEW
« no previous file with comments | « base/values_unittest.cc ('k') | chrome/browser/command_line_pref_store_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698