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

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

Issue 319523005: Omnibox: Combine Two Input Type Enums into One (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove blank line Created 6 years, 6 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 11 matching lines...) Expand all
22 #include "chrome/browser/search/instant_service_factory.h" 22 #include "chrome/browser/search/instant_service_factory.h"
23 #include "chrome/browser/search/search.h" 23 #include "chrome/browser/search/search.h"
24 #include "chrome/browser/search_engines/template_url.h" 24 #include "chrome/browser/search_engines/template_url.h"
25 #include "chrome/browser/search_engines/template_url_prepopulate_data.h" 25 #include "chrome/browser/search_engines/template_url_prepopulate_data.h"
26 #include "chrome/browser/search_engines/template_url_service.h" 26 #include "chrome/browser/search_engines/template_url_service.h"
27 #include "chrome/browser/search_engines/template_url_service_factory.h" 27 #include "chrome/browser/search_engines/template_url_service_factory.h"
28 #include "chrome/browser/sync/profile_sync_service.h" 28 #include "chrome/browser/sync/profile_sync_service.h"
29 #include "chrome/browser/sync/profile_sync_service_factory.h" 29 #include "chrome/browser/sync/profile_sync_service_factory.h"
30 #include "chrome/common/net/url_fixer_upper.h" 30 #include "chrome/common/net/url_fixer_upper.h"
31 #include "chrome/common/pref_names.h" 31 #include "chrome/common/pref_names.h"
32 #include "components/metrics/proto/omnibox_input_type.pb.h"
32 #include "components/sync_driver/sync_prefs.h" 33 #include "components/sync_driver/sync_prefs.h"
33 #include "content/public/common/url_constants.h" 34 #include "content/public/common/url_constants.h"
34 #include "net/base/escape.h" 35 #include "net/base/escape.h"
35 #include "net/base/net_util.h" 36 #include "net/base/net_util.h"
36 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" 37 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
37 #include "net/http/http_response_headers.h" 38 #include "net/http/http_response_headers.h"
38 #include "net/url_request/url_fetcher.h" 39 #include "net/url_request/url_fetcher.h"
39 #include "net/url_request/url_fetcher_delegate.h" 40 #include "net/url_request/url_fetcher_delegate.h"
40 #include "url/gurl.h" 41 #include "url/gurl.h"
41 42
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 bool BaseSearchProvider::SuggestResult::IsInlineable( 331 bool BaseSearchProvider::SuggestResult::IsInlineable(
331 const base::string16& input) const { 332 const base::string16& input) const {
332 return StartsWith(suggestion_, input, false); 333 return StartsWith(suggestion_, input, false);
333 } 334 }
334 335
335 int BaseSearchProvider::SuggestResult::CalculateRelevance( 336 int BaseSearchProvider::SuggestResult::CalculateRelevance(
336 const AutocompleteInput& input, 337 const AutocompleteInput& input,
337 bool keyword_provider_requested) const { 338 bool keyword_provider_requested) const {
338 if (!from_keyword_provider_ && keyword_provider_requested) 339 if (!from_keyword_provider_ && keyword_provider_requested)
339 return 100; 340 return 100;
340 return ((input.type() == AutocompleteInput::URL) ? 300 : 600); 341 return ((input.type() == metrics::OmniboxInputType::URL) ? 300 : 600);
341 } 342 }
342 343
343 // BaseSearchProvider::NavigationResult ---------------------------------------- 344 // BaseSearchProvider::NavigationResult ----------------------------------------
344 345
345 BaseSearchProvider::NavigationResult::NavigationResult( 346 BaseSearchProvider::NavigationResult::NavigationResult(
346 const AutocompleteProvider& provider, 347 const AutocompleteProvider& provider,
347 const GURL& url, 348 const GURL& url,
348 AutocompleteMatchType::Type type, 349 AutocompleteMatchType::Type type,
349 const base::string16& description, 350 const base::string16& description,
350 const std::string& deletion_url, 351 const std::string& deletion_url,
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 match.description = suggestion.annotation(); 512 match.description = suggestion.annotation();
512 513
513 // suggestion.match_contents() should have already been collapsed. 514 // suggestion.match_contents() should have already been collapsed.
514 match.allowed_to_be_default_match = 515 match.allowed_to_be_default_match =
515 (base::CollapseWhitespace(input.text(), false) == 516 (base::CollapseWhitespace(input.text(), false) ==
516 suggestion.match_contents()); 517 suggestion.match_contents());
517 518
518 // When the user forced a query, we need to make sure all the fill_into_edit 519 // When the user forced a query, we need to make sure all the fill_into_edit
519 // values preserve that property. Otherwise, if the user starts editing a 520 // values preserve that property. Otherwise, if the user starts editing a
520 // suggestion, non-Search results will suddenly appear. 521 // suggestion, non-Search results will suddenly appear.
521 if (input.type() == AutocompleteInput::FORCED_QUERY) 522 if (input.type() == metrics::OmniboxInputType::FORCED_QUERY)
522 match.fill_into_edit.assign(base::ASCIIToUTF16("?")); 523 match.fill_into_edit.assign(base::ASCIIToUTF16("?"));
523 if (suggestion.from_keyword_provider()) 524 if (suggestion.from_keyword_provider())
524 match.fill_into_edit.append(match.keyword + base::char16(' ')); 525 match.fill_into_edit.append(match.keyword + base::char16(' '));
525 if (!input.prevent_inline_autocomplete() && 526 if (!input.prevent_inline_autocomplete() &&
526 StartsWith(suggestion.suggestion(), input.text(), false)) { 527 StartsWith(suggestion.suggestion(), input.text(), false)) {
527 match.inline_autocompletion = 528 match.inline_autocompletion =
528 suggestion.suggestion().substr(input.text().length()); 529 suggestion.suggestion().substr(input.text().length());
529 match.allowed_to_be_default_match = true; 530 match.allowed_to_be_default_match = true;
530 } 531 }
531 match.fill_into_edit.append(suggestion.suggestion()); 532 match.fill_into_edit.append(suggestion.suggestion());
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
846 } 847 }
847 848
848 // Clear the previous results now that new results are available. 849 // Clear the previous results now that new results are available.
849 results->suggest_results.clear(); 850 results->suggest_results.clear();
850 results->navigation_results.clear(); 851 results->navigation_results.clear();
851 852
852 base::string16 suggestion; 853 base::string16 suggestion;
853 std::string type; 854 std::string type;
854 int relevance = GetDefaultResultRelevance(); 855 int relevance = GetDefaultResultRelevance();
855 // Prohibit navsuggest in FORCED_QUERY mode. Users wants queries, not URLs. 856 // Prohibit navsuggest in FORCED_QUERY mode. Users wants queries, not URLs.
856 const bool allow_navsuggest = input.type() != AutocompleteInput::FORCED_QUERY; 857 const bool allow_navsuggest =
858 input.type() != metrics::OmniboxInputType::FORCED_QUERY;
857 const std::string languages( 859 const std::string languages(
858 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)); 860 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages));
859 const base::string16& trimmed_input = 861 const base::string16& trimmed_input =
860 base::CollapseWhitespace(input.text(), false); 862 base::CollapseWhitespace(input.text(), false);
861 for (size_t index = 0; results_list->GetString(index, &suggestion); ++index) { 863 for (size_t index = 0; results_list->GetString(index, &suggestion); ++index) {
862 // Google search may return empty suggestions for weird input characters, 864 // Google search may return empty suggestions for weird input characters,
863 // they make no sense at all and can cause problems in our code. 865 // they make no sense at all and can cause problems in our code.
864 if (suggestion.empty()) 866 if (suggestion.empty())
865 continue; 867 continue;
866 868
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
966 } 968 }
967 969
968 void BaseSearchProvider::OnDeletionComplete( 970 void BaseSearchProvider::OnDeletionComplete(
969 bool success, SuggestionDeletionHandler* handler) { 971 bool success, SuggestionDeletionHandler* handler) {
970 RecordDeletionResult(success); 972 RecordDeletionResult(success);
971 SuggestionDeletionHandlers::iterator it = std::find( 973 SuggestionDeletionHandlers::iterator it = std::find(
972 deletion_handlers_.begin(), deletion_handlers_.end(), handler); 974 deletion_handlers_.begin(), deletion_handlers_.end(), handler);
973 DCHECK(it != deletion_handlers_.end()); 975 DCHECK(it != deletion_handlers_.end());
974 deletion_handlers_.erase(it); 976 deletion_handlers_.erase(it);
975 } 977 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698