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

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

Issue 319523005: Omnibox: Combine Two Input Type Enums into One (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase again 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/history_url_provider.h" 5 #include "chrome/browser/autocomplete/history_url_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 16 matching lines...) Expand all
27 #include "chrome/browser/history/scored_history_match.h" 27 #include "chrome/browser/history/scored_history_match.h"
28 #include "chrome/browser/omnibox/omnibox_field_trial.h" 28 #include "chrome/browser/omnibox/omnibox_field_trial.h"
29 #include "chrome/browser/profiles/profile.h" 29 #include "chrome/browser/profiles/profile.h"
30 #include "chrome/browser/search_engines/template_url_service.h" 30 #include "chrome/browser/search_engines/template_url_service.h"
31 #include "chrome/browser/search_engines/template_url_service_factory.h" 31 #include "chrome/browser/search_engines/template_url_service_factory.h"
32 #include "chrome/common/chrome_switches.h" 32 #include "chrome/common/chrome_switches.h"
33 #include "chrome/common/net/url_fixer_upper.h" 33 #include "chrome/common/net/url_fixer_upper.h"
34 #include "chrome/common/pref_names.h" 34 #include "chrome/common/pref_names.h"
35 #include "chrome/common/url_constants.h" 35 #include "chrome/common/url_constants.h"
36 #include "components/bookmarks/browser/bookmark_utils.h" 36 #include "components/bookmarks/browser/bookmark_utils.h"
37 #include "components/metrics/proto/omnibox_input_type.pb.h"
37 #include "net/base/net_util.h" 38 #include "net/base/net_util.h"
38 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" 39 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
39 #include "url/gurl.h" 40 #include "url/gurl.h"
40 #include "url/url_parse.h" 41 #include "url/url_parse.h"
41 #include "url/url_util.h" 42 #include "url/url_util.h"
42 43
43 namespace { 44 namespace {
44 45
45 // If |create_if_necessary| is true, ensures that |matches| contains an 46 // If |create_if_necessary| is true, ensures that |matches| contains an
46 // entry for |info|, creating a new such entry if necessary (using 47 // entry for |info|, creating a new such entry if necessary (using
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 const AutocompleteInput& input, 330 const AutocompleteInput& input,
330 history::URLDatabase* db) 331 history::URLDatabase* db)
331 : provider_(provider), 332 : provider_(provider),
332 db_(db), 333 db_(db),
333 type_(INVALID) { 334 type_(INVALID) {
334 const GURL& url = input.canonicalized_url(); 335 const GURL& url = input.canonicalized_url();
335 // Detect email addresses. These cases will look like "http://user@site/", 336 // Detect email addresses. These cases will look like "http://user@site/",
336 // and because the history backend strips auth creds, we'll get a bogus exact 337 // and because the history backend strips auth creds, we'll get a bogus exact
337 // match below if the user has visited "site". 338 // match below if the user has visited "site".
338 if (!url.is_valid() || 339 if (!url.is_valid() ||
339 ((input.type() == AutocompleteInput::UNKNOWN) && 340 ((input.type() == metrics::OmniboxInputType::UNKNOWN) &&
340 input.parts().username.is_nonempty() && 341 input.parts().username.is_nonempty() &&
341 !input.parts().password.is_nonempty() && 342 !input.parts().password.is_nonempty() &&
342 !input.parts().path.is_nonempty())) 343 !input.parts().path.is_nonempty()))
343 return; 344 return;
344 345
345 if (db_->GetRowForURL(url, &url_row_)) { 346 if (db_->GetRowForURL(url, &url_row_)) {
346 type_ = VISITED; 347 type_ = VISITED;
347 return; 348 return;
348 } 349 }
349 350
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 // running, we'd need to wait for it to return to the main thread before 404 // running, we'd need to wait for it to return to the main thread before
404 // doing this (we can't just write new data for it to read due to thread 405 // doing this (we can't just write new data for it to read due to thread
405 // safety issues). At that point it's just as fast, and easier, to simply 406 // safety issues). At that point it's just as fast, and easier, to simply
406 // re-run the query from scratch and ignore |minimal_changes|. 407 // re-run the query from scratch and ignore |minimal_changes|.
407 408
408 // Cancel any in-progress query. 409 // Cancel any in-progress query.
409 Stop(false); 410 Stop(false);
410 411
411 matches_.clear(); 412 matches_.clear();
412 413
413 if ((input.type() == AutocompleteInput::INVALID) || 414 if ((input.type() == metrics::OmniboxInputType::INVALID) ||
414 (input.type() == AutocompleteInput::FORCED_QUERY)) 415 (input.type() == metrics::OmniboxInputType::FORCED_QUERY))
415 return; 416 return;
416 417
417 // Create a match for exactly what the user typed. This will only be used as 418 // Create a match for exactly what the user typed. This will only be used as
418 // a fallback in case we can't get the history service or URL DB; otherwise, 419 // a fallback in case we can't get the history service or URL DB; otherwise,
419 // we'll run this again in DoAutocomplete() and use that result instead. 420 // we'll run this again in DoAutocomplete() and use that result instead.
420 const bool trim_http = !AutocompleteInput::HasHTTPScheme(input.text()); 421 const bool trim_http = !AutocompleteInput::HasHTTPScheme(input.text());
421 // Don't do this for queries -- while we can sometimes mark up a match for 422 // Don't do this for queries -- while we can sometimes mark up a match for
422 // this, it's not what the user wants, and just adds noise. 423 // this, it's not what the user wants, and just adds noise.
423 if (input.type() != AutocompleteInput::QUERY) { 424 if (input.type() != metrics::OmniboxInputType::QUERY) {
424 AutocompleteMatch what_you_typed(SuggestExactInput( 425 AutocompleteMatch what_you_typed(SuggestExactInput(
425 input.text(), input.canonicalized_url(), trim_http)); 426 input.text(), input.canonicalized_url(), trim_http));
426 what_you_typed.relevance = CalculateRelevance(WHAT_YOU_TYPED, 0); 427 what_you_typed.relevance = CalculateRelevance(WHAT_YOU_TYPED, 0);
427 matches_.push_back(what_you_typed); 428 matches_.push_back(what_you_typed);
428 } 429 }
429 430
430 // We'll need the history service to run both passes, so try to obtain it. 431 // We'll need the history service to run both passes, so try to obtain it.
431 if (!profile_) 432 if (!profile_)
432 return; 433 return;
433 HistoryService* const history_service = 434 HistoryService* const history_service =
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 // 590 //
590 // We display this to the user when there's a reasonable chance they actually 591 // We display this to the user when there's a reasonable chance they actually
591 // care: 592 // care:
592 // * Their input can be opened as a URL, and 593 // * Their input can be opened as a URL, and
593 // * We parsed the input as a URL, or it starts with an explicit "http:" or 594 // * We parsed the input as a URL, or it starts with an explicit "http:" or
594 // "https:". 595 // "https:".
595 // that is when their input can be opened as a URL. 596 // that is when their input can be opened as a URL.
596 // Otherwise, this is just low-quality noise. In the cases where we've parsed 597 // Otherwise, this is just low-quality noise. In the cases where we've parsed
597 // as UNKNOWN, we'll still show an accidental search infobar if need be. 598 // as UNKNOWN, we'll still show an accidental search infobar if need be.
598 bool have_what_you_typed_match = 599 bool have_what_you_typed_match =
599 (params->input.type() != AutocompleteInput::QUERY) && 600 (params->input.type() != metrics::OmniboxInputType::QUERY) &&
600 ((params->input.type() != AutocompleteInput::UNKNOWN) || 601 ((params->input.type() != metrics::OmniboxInputType::UNKNOWN) ||
601 (classifier.type() == VisitClassifier::UNVISITED_INTRANET) || 602 (classifier.type() == VisitClassifier::UNVISITED_INTRANET) ||
602 !params->trim_http || 603 !params->trim_http ||
603 (AutocompleteInput::NumNonHostComponents(params->input.parts()) > 0)); 604 (AutocompleteInput::NumNonHostComponents(params->input.parts()) > 0));
604 AutocompleteMatch what_you_typed_match(SuggestExactInput( 605 AutocompleteMatch what_you_typed_match(SuggestExactInput(
605 params->input.text(), params->input.canonicalized_url(), 606 params->input.text(), params->input.canonicalized_url(),
606 params->trim_http)); 607 params->trim_http));
607 what_you_typed_match.relevance = CalculateRelevance(WHAT_YOU_TYPED, 0); 608 what_you_typed_match.relevance = CalculateRelevance(WHAT_YOU_TYPED, 0);
608 609
609 // Get the matching URLs from the DB 610 // Get the matching URLs from the DB
610 history::URLRows url_matches; 611 history::URLRows url_matches;
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
820 // make sure that this code does not trigger if the user did anything to 821 // make sure that this code does not trigger if the user did anything to
821 // indicate the desired match is a URL. For instance, "c/# foo" will not 822 // indicate the desired match is a URL. For instance, "c/# foo" will not
822 // pass the test because that will be classified as input type URL. The 823 // pass the test because that will be classified as input type URL. The
823 // parsed.CountCharactersBefore() in the test looks for the presence of a 824 // parsed.CountCharactersBefore() in the test looks for the presence of a
824 // reference fragment in the URL by checking whether the position differs 825 // reference fragment in the URL by checking whether the position differs
825 // included the delimiter (pound sign) versus not including the delimiter. 826 // included the delimiter (pound sign) versus not including the delimiter.
826 // (One cannot simply check url.ref() because it will not distinguish 827 // (One cannot simply check url.ref() because it will not distinguish
827 // between the input "c" and the input "c#", both of which will have empty 828 // between the input "c" and the input "c#", both of which will have empty
828 // reference fragments.) 829 // reference fragments.)
829 if ((type == UNVISITED_INTRANET) && 830 if ((type == UNVISITED_INTRANET) &&
830 (input.type() != AutocompleteInput::URL) && url.username().empty() && 831 (input.type() != metrics::OmniboxInputType::URL) &&
831 url.password().empty() && url.port().empty() && (url.path() == "/") && 832 url.username().empty() && url.password().empty() && url.port().empty() &&
832 url.query().empty() && 833 (url.path() == "/") && url.query().empty() &&
833 (parsed.CountCharactersBefore(url::Parsed::REF, true) != 834 (parsed.CountCharactersBefore(url::Parsed::REF, true) !=
834 parsed.CountCharactersBefore(url::Parsed::REF, false))) { 835 parsed.CountCharactersBefore(url::Parsed::REF, false))) {
835 return false; 836 return false;
836 } 837 }
837 838
838 match->relevance = CalculateRelevance(type, 0); 839 match->relevance = CalculateRelevance(type, 0);
839 840
840 // If there are any other matches, then don't promote this match here, in 841 // If there are any other matches, then don't promote this match here, in
841 // hopes the caller will be able to inline autocomplete a better suggestion. 842 // hopes the caller will be able to inline autocomplete a better suggestion.
842 // DoAutocomplete() will fall back on this match if inline autocompletion 843 // DoAutocomplete() will fall back on this match if inline autocompletion
843 // fails. This matches how we react to never-visited URL inputs in the non- 844 // fails. This matches how we react to never-visited URL inputs in the non-
844 // intranet case. 845 // intranet case.
845 if (type == UNVISITED_INTRANET && !matches->empty()) 846 if (type == UNVISITED_INTRANET && !matches->empty())
846 return false; 847 return false;
847 848
848 // Put it on the front of the HistoryMatches for redirect culling. 849 // Put it on the front of the HistoryMatches for redirect culling.
849 CreateOrPromoteMatch(classifier.url_row(), base::string16::npos, false, 850 CreateOrPromoteMatch(classifier.url_row(), base::string16::npos, false,
850 matches, true, true); 851 matches, true, true);
851 return true; 852 return true;
852 } 853 }
853 854
854 bool HistoryURLProvider::CanFindIntranetURL( 855 bool HistoryURLProvider::CanFindIntranetURL(
855 history::URLDatabase* db, 856 history::URLDatabase* db,
856 const AutocompleteInput& input) const { 857 const AutocompleteInput& input) const {
857 // Normally passing the first two conditions below ought to guarantee the 858 // Normally passing the first two conditions below ought to guarantee the
858 // third condition, but because FixupUserInput() can run and modify the 859 // third condition, but because FixupUserInput() can run and modify the
859 // input's text and parts between Parse() and here, it seems better to be 860 // input's text and parts between Parse() and here, it seems better to be
860 // paranoid and check. 861 // paranoid and check.
861 if ((input.type() != AutocompleteInput::UNKNOWN) || 862 if ((input.type() != metrics::OmniboxInputType::UNKNOWN) ||
862 !LowerCaseEqualsASCII(input.scheme(), url::kHttpScheme) || 863 !LowerCaseEqualsASCII(input.scheme(), url::kHttpScheme) ||
863 !input.parts().host.is_nonempty()) 864 !input.parts().host.is_nonempty())
864 return false; 865 return false;
865 const std::string host(base::UTF16ToUTF8( 866 const std::string host(base::UTF16ToUTF8(
866 input.text().substr(input.parts().host.begin, input.parts().host.len))); 867 input.text().substr(input.parts().host.begin, input.parts().host.len)));
867 const size_t registry_length = 868 const size_t registry_length =
868 net::registry_controlled_domains::GetRegistryLength( 869 net::registry_controlled_domains::GetRegistryLength(
869 host, 870 host,
870 net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES, 871 net::registry_controlled_domains::EXCLUDE_UNKNOWN_REGISTRIES,
871 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES); 872 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES);
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
1155 // If HistoryURL retrieves any matches (and hence we reach this code), we 1156 // If HistoryURL retrieves any matches (and hence we reach this code), we
1156 // are guaranteed that the beginning of input_text must be a word break. 1157 // are guaranteed that the beginning of input_text must be a word break.
1157 history::WordStarts offsets(1, 0u); 1158 history::WordStarts offsets(1, 0u);
1158 description_matches = 1159 description_matches =
1159 history::ScoredHistoryMatch::FilterTermMatchesByWordStarts( 1160 history::ScoredHistoryMatch::FilterTermMatchesByWordStarts(
1160 description_matches, offsets, description_word_starts, 0, 1161 description_matches, offsets, description_word_starts, 0,
1161 std::string::npos); 1162 std::string::npos);
1162 return SpansFromTermMatch( 1163 return SpansFromTermMatch(
1163 description_matches, clean_description.length(), false); 1164 description_matches, clean_description.length(), false);
1164 } 1165 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/history_quick_provider.cc ('k') | chrome/browser/autocomplete/history_url_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698