Home | History | Annotate | Download | only in autocomplete
      1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef CHROME_BROWSER_AUTOCOMPLETE_HISTORY_PROVIDER_UTIL_H_
      6 #define CHROME_BROWSER_AUTOCOMPLETE_HISTORY_PROVIDER_UTIL_H_
      7 #pragma once
      8 
      9 #include <deque>
     10 #include <vector>
     11 
     12 #include "chrome/browser/history/history_types.h"
     13 
     14 namespace history {
     15 
     16 // Used for intermediate history result operations.
     17 struct HistoryMatch {
     18   // Required for STL, we don't use this directly.
     19   HistoryMatch();
     20 
     21   HistoryMatch(const URLRow& url_info,
     22                size_t input_location,
     23                bool match_in_scheme,
     24                bool innermost_match);
     25 
     26   bool operator==(const GURL& url) const;
     27 
     28   URLRow url_info;
     29 
     30   // The offset of the user's input within the URL.
     31   size_t input_location;
     32 
     33   // Whether this is a match in the scheme.  This determines whether we'll go
     34   // ahead and show a scheme on the URL even if the user didn't type one.
     35   // If our best match was in the scheme, not showing the scheme is both
     36   // confusing and, for inline autocomplete of the fill_into_edit, dangerous.
     37   // (If the user types "h" and we match "http://foo/", we need to inline
     38   // autocomplete that, not "foo/", which won't show anything at all, and
     39   // will mislead the user into thinking the What You Typed match is what's
     40   // selected.)
     41   bool match_in_scheme;
     42 
     43   // A match after any scheme/"www.", if the user input could match at both
     44   // locations.  If the user types "w", an innermost match ("website.com") is
     45   // better than a non-innermost match ("www.google.com").  If the user types
     46   // "x", no scheme in our prefix list (or "www.") begins with x, so all
     47   // matches are, vacuously, "innermost matches".
     48   bool innermost_match;
     49 };
     50 typedef std::deque<HistoryMatch> HistoryMatches;
     51 
     52 struct Prefix {
     53   Prefix(const string16& prefix, int num_components)
     54       : prefix(prefix),
     55         num_components(num_components) {}
     56 
     57   string16 prefix;
     58 
     59   // The number of "components" in the prefix.  The scheme is a component,
     60   // and the initial "www." or "ftp." is a component.  So "http://foo.com"
     61   // and "www.bar.com" each have one component, "ftp://ftp.ftp.com" has two,
     62   // and "mysite.com" has none.  This is used to tell whether the user's
     63   // input is an innermost match or not.  See comments in HistoryMatch.
     64   int num_components;
     65 };
     66 typedef std::vector<Prefix> Prefixes;
     67 }
     68 
     69 #endif  // CHROME_BROWSER_AUTOCOMPLETE_HISTORY_PROVIDER_UTIL_H_
     70