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

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

Issue 372843005: Remove Profile from BaseSearchProvider::NavigationResult (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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 | Annotate | Revision Log
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 "chrome/browser/autocomplete/base_search_provider.h" 5 #include "chrome/browser/autocomplete/base_search_provider.h"
6 6
7 #include "base/i18n/case_conversion.h" 7 #include "base/i18n/case_conversion.h"
8 #include "base/i18n/icu_string_conversions.h" 8 #include "base/i18n/icu_string_conversions.h"
9 #include "base/json/json_string_value_serializer.h" 9 #include "base/json/json_string_value_serializer.h"
10 #include "base/json/json_writer.h" 10 #include "base/json/json_writer.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 return AutocompleteMatchType::SEARCH_SUGGEST_PERSONALIZED; 58 return AutocompleteMatchType::SEARCH_SUGGEST_PERSONALIZED;
59 if (type == "PROFILE") 59 if (type == "PROFILE")
60 return AutocompleteMatchType::SEARCH_SUGGEST_PROFILE; 60 return AutocompleteMatchType::SEARCH_SUGGEST_PROFILE;
61 if (type == "NAVIGATION") 61 if (type == "NAVIGATION")
62 return AutocompleteMatchType::NAVSUGGEST; 62 return AutocompleteMatchType::NAVSUGGEST;
63 if (type == "PERSONALIZED_NAVIGATION") 63 if (type == "PERSONALIZED_NAVIGATION")
64 return AutocompleteMatchType::NAVSUGGEST_PERSONALIZED; 64 return AutocompleteMatchType::NAVSUGGEST_PERSONALIZED;
65 return AutocompleteMatchType::SEARCH_SUGGEST; 65 return AutocompleteMatchType::SEARCH_SUGGEST;
66 } 66 }
67 67
68 base::string16 StringForURLDisplayWithAcceptLanguages(Profile* profile,
69 const GURL& url) {
70 std::string languages = profile ?
71 profile->GetPrefs()->GetString(prefs::kAcceptLanguages) : std::string();
72 return net::FormatUrl(url, languages,
73 net::kFormatUrlOmitAll & ~net::kFormatUrlOmitHTTP,
74 net::UnescapeRule::SPACES, NULL, NULL, NULL);
75 }
76
77 } // namespace 68 } // namespace
78 69
79 // SuggestionDeletionHandler ------------------------------------------------- 70 // SuggestionDeletionHandler -------------------------------------------------
80 71
81 // This class handles making requests to the server in order to delete 72 // This class handles making requests to the server in order to delete
82 // personalized suggestions. 73 // personalized suggestions.
83 class SuggestionDeletionHandler : public net::URLFetcherDelegate { 74 class SuggestionDeletionHandler : public net::URLFetcherDelegate {
84 public: 75 public:
85 typedef base::Callback<void(bool, SuggestionDeletionHandler*)> 76 typedef base::Callback<void(bool, SuggestionDeletionHandler*)>
86 DeletionCompletedCallback; 77 DeletionCompletedCallback;
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 const AutocompleteInput& input, 348 const AutocompleteInput& input,
358 bool keyword_provider_requested) const { 349 bool keyword_provider_requested) const {
359 if (!from_keyword_provider_ && keyword_provider_requested) 350 if (!from_keyword_provider_ && keyword_provider_requested)
360 return 100; 351 return 100;
361 return ((input.type() == metrics::OmniboxInputType::URL) ? 300 : 600); 352 return ((input.type() == metrics::OmniboxInputType::URL) ? 300 : 600);
362 } 353 }
363 354
364 // BaseSearchProvider::NavigationResult ---------------------------------------- 355 // BaseSearchProvider::NavigationResult ----------------------------------------
365 356
366 BaseSearchProvider::NavigationResult::NavigationResult( 357 BaseSearchProvider::NavigationResult::NavigationResult(
367 const AutocompleteProvider& provider, 358 const AutocompleteSchemeClassifier& scheme_classifier,
368 Profile* profile,
369 const GURL& url, 359 const GURL& url,
370 AutocompleteMatchType::Type type, 360 AutocompleteMatchType::Type type,
371 const base::string16& description, 361 const base::string16& description,
372 const std::string& deletion_url, 362 const std::string& deletion_url,
373 bool from_keyword_provider, 363 bool from_keyword_provider,
374 int relevance, 364 int relevance,
375 bool relevance_from_server, 365 bool relevance_from_server,
376 const base::string16& input_text, 366 const base::string16& input_text,
377 const std::string& languages) 367 const std::string& languages)
378 : Result(from_keyword_provider, relevance, relevance_from_server, type, 368 : Result(from_keyword_provider, relevance, relevance_from_server, type,
379 deletion_url), 369 deletion_url),
380 url_(url), 370 url_(url),
381 formatted_url_(AutocompleteInput::FormattedStringWithEquivalentMeaning( 371 formatted_url_(AutocompleteInput::FormattedStringWithEquivalentMeaning(
382 url, StringForURLDisplayWithAcceptLanguages(profile, url), 372 url, net::FormatUrl(url, languages,
383 ChromeAutocompleteSchemeClassifier(profile))), 373 net::kFormatUrlOmitAll & ~net::kFormatUrlOmitHTTP,
374 net::UnescapeRule::SPACES, NULL, NULL, NULL),
375 scheme_classifier)),
384 description_(description) { 376 description_(description) {
385 DCHECK(url_.is_valid()); 377 DCHECK(url_.is_valid());
386 CalculateAndClassifyMatchContents(true, input_text, languages); 378 CalculateAndClassifyMatchContents(true, input_text, languages);
387 } 379 }
388 380
389 BaseSearchProvider::NavigationResult::~NavigationResult() {} 381 BaseSearchProvider::NavigationResult::~NavigationResult() {}
390 382
391 void BaseSearchProvider::NavigationResult::CalculateAndClassifyMatchContents( 383 void BaseSearchProvider::NavigationResult::CalculateAndClassifyMatchContents(
392 const bool allow_bolding_nothing, 384 const bool allow_bolding_nothing,
393 const base::string16& input_text, 385 const base::string16& input_text,
(...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after
906 if ((match_type == AutocompleteMatchType::NAVSUGGEST) || 898 if ((match_type == AutocompleteMatchType::NAVSUGGEST) ||
907 (match_type == AutocompleteMatchType::NAVSUGGEST_PERSONALIZED)) { 899 (match_type == AutocompleteMatchType::NAVSUGGEST_PERSONALIZED)) {
908 // Do not blindly trust the URL coming from the server to be valid. 900 // Do not blindly trust the URL coming from the server to be valid.
909 GURL url( 901 GURL url(
910 url_fixer::FixupURL(base::UTF16ToUTF8(suggestion), std::string())); 902 url_fixer::FixupURL(base::UTF16ToUTF8(suggestion), std::string()));
911 if (url.is_valid() && allow_navsuggest) { 903 if (url.is_valid() && allow_navsuggest) {
912 base::string16 title; 904 base::string16 title;
913 if (descriptions != NULL) 905 if (descriptions != NULL)
914 descriptions->GetString(index, &title); 906 descriptions->GetString(index, &title);
915 results->navigation_results.push_back(NavigationResult( 907 results->navigation_results.push_back(NavigationResult(
916 *this, profile_, url, match_type, title, deletion_url, 908 ChromeAutocompleteSchemeClassifier(profile_), url, match_type,
917 is_keyword_result, relevance, relevances != NULL, input.text(), 909 title, deletion_url, is_keyword_result, relevance,
918 languages)); 910 relevances != NULL, input.text(), languages));
919 } 911 }
920 } else { 912 } else {
921 base::string16 match_contents = suggestion; 913 base::string16 match_contents = suggestion;
922 base::string16 match_contents_prefix; 914 base::string16 match_contents_prefix;
923 base::string16 annotation; 915 base::string16 annotation;
924 base::string16 answer_contents; 916 base::string16 answer_contents;
925 base::string16 answer_type; 917 base::string16 answer_type;
926 std::string suggest_query_params; 918 std::string suggest_query_params;
927 919
928 if (suggestion_details) { 920 if (suggestion_details) {
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
1021 } 1013 }
1022 1014
1023 void BaseSearchProvider::OnDeletionComplete( 1015 void BaseSearchProvider::OnDeletionComplete(
1024 bool success, SuggestionDeletionHandler* handler) { 1016 bool success, SuggestionDeletionHandler* handler) {
1025 RecordDeletionResult(success); 1017 RecordDeletionResult(success);
1026 SuggestionDeletionHandlers::iterator it = std::find( 1018 SuggestionDeletionHandlers::iterator it = std::find(
1027 deletion_handlers_.begin(), deletion_handlers_.end(), handler); 1019 deletion_handlers_.begin(), deletion_handlers_.end(), handler);
1028 DCHECK(it != deletion_handlers_.end()); 1020 DCHECK(it != deletion_handlers_.end());
1029 deletion_handlers_.erase(it); 1021 deletion_handlers_.erase(it);
1030 } 1022 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/base_search_provider.h ('k') | chrome/browser/autocomplete/search_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698