15f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#ifndef COMPONENTS_OMNIBOX_AUTOCOMPLETE_PROVIDER_H_
65f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#define COMPONENTS_OMNIBOX_AUTOCOMPLETE_PROVIDER_H_
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/basictypes.h"
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/ref_counted.h"
10868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/string16.h"
11010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "components/metrics/proto/omnibox_event.pb.h"
125f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "components/omnibox/autocomplete_match.h"
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class AutocompleteInput;
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef std::vector<metrics::OmniboxEventProto_ProviderInfo> ProvidersInfo;
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The AutocompleteProviders each return different kinds of matches,
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// such as history or search matches.  These matches are given
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// "relevance" scores.  Higher scores are better matches than lower
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// scores.  The relevance scores and classes providing the respective
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// matches are as listed below.
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// IMPORTANT CAVEAT: The tables below are NOT COMPLETE.  Developers
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// often forget to keep these tables in sync with the code when they
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// change scoring algorithms or add new providers.  For example,
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// neither the HistoryQuickProvider (which is a provider that appears
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// often) nor the ShortcutsProvider are listed here.  For the best
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// idea of how scoring works and what providers are affecting which
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// queries, play with chrome://omnibox/ for a while.  While the tables
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// below may have some utility, nothing compares with first-hand
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// investigation and experience.
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// UNKNOWN input type:
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// --------------------------------------------------------------------|-----
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Keyword (non-substituting or in keyword UI mode, exact match)       | 1500
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// HistoryURL (good exact or inline autocomplete matches, some inexact)| 1410++
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// HistoryURL (intranet url never visited match, some inexact matches) | 1400++
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Search Primary Provider (past query in history within 2 days)       | 1399**
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Search Primary Provider (what you typed)                            | 1300
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// HistoryURL (what you typed, some inexact matches)                   | 1200++
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Keyword (substituting, exact match)                                 | 1100
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Search Primary Provider (past query in history older than 2 days)   | 1050--
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// HistoryURL (some inexact matches)                                   |  900++
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// BookmarkProvider (prefix match in bookmark title)                   |  900+-
467dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// Built-in                                                            |  860++
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Search Primary Provider (navigational suggestion)                   |  800++
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Search Primary Provider (suggestion)                                |  600++
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Keyword (inexact match)                                             |  450
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Search Secondary Provider (what you typed)                          |  250
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Search Secondary Provider (past query in history)                   |  200--
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Search Secondary Provider (navigational suggestion)                 |  150++
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Search Secondary Provider (suggestion)                              |  100++
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// URL input type:
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// --------------------------------------------------------------------|-----
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Keyword (non-substituting or in keyword UI mode, exact match)       | 1500
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// HistoryURL (good exact or inline autocomplete matches, some inexact)| 1410++
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// HistoryURL (intranet url never visited match, some inexact matches) | 1400++
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// HistoryURL (what you typed, some inexact matches)                   | 1200++
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Keyword (substituting, exact match)                                 | 1100
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// HistoryURL (some inexact matches)                                   |  900++
637dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch// Built-in                                                            |  860++
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Search Primary Provider (what you typed)                            |  850
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Search Primary Provider (navigational suggestion)                   |  800++
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Search Primary Provider (past query in history)                     |  750--
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Keyword (inexact match)                                             |  700
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Search Primary Provider (suggestion)                                |  300++
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Search Secondary Provider (what you typed)                          |  250
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Search Secondary Provider (past query in history)                   |  200--
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Search Secondary Provider (navigational suggestion)                 |  150++
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Search Secondary Provider (suggestion)                              |  100++
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// QUERY input type:
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// --------------------------------------------------------------------|-----
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Search Primary or Secondary (past query in history within 2 days)   | 1599**
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Keyword (non-substituting or in keyword UI mode, exact match)       | 1500
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Keyword (substituting, exact match)                                 | 1450
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Search Primary Provider (past query in history within 2 days)       | 1399**
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Search Primary Provider (what you typed)                            | 1300
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Search Primary Provider (past query in history older than 2 days)   | 1050--
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// HistoryURL (inexact match)                                          |  900++
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// BookmarkProvider (prefix match in bookmark title)                   |  900+-
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Search Primary Provider (navigational suggestion)                   |  800++
855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Search Primary Provider (suggestion)                                |  600++
865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Keyword (inexact match)                                             |  450
875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Search Secondary Provider (what you typed)                          |  250
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Search Secondary Provider (past query in history)                   |  200--
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Search Secondary Provider (navigational suggestion)                 |  150++
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Search Secondary Provider (suggestion)                              |  100++
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// FORCED_QUERY input type:
935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// --------------------------------------------------------------------|-----
945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Search Primary Provider (past query in history within 2 days)       | 1399**
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Search Primary Provider (what you typed)                            | 1300
965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Search Primary Provider (past query in history older than 2 days)   | 1050--
975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Search Primary Provider (navigational suggestion)                   |  800++
985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Search Primary Provider (suggestion)                                |  600++
995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// (A search keyword is a keyword with a replacement string; a bookmark keyword
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// is a keyword with no replacement string, that is, a shortcut for a URL.)
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// There are two possible providers for search suggestions. If the user has
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// typed a keyword, then the primary provider is the keyword provider and the
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// secondary provider is the default provider. If the user has not typed a
1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// keyword, then the primary provider corresponds to the default provider.
1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Search providers may supply relevance values along with their results to be
1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// used in place of client-side calculated values.
1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The value column gives the ranking returned from the various providers.
1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// ++: a series of matches with relevance from n up to (n + max_matches).
1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// --: relevance score falls off over time (discounted 50 points @ 15 minutes,
1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//     450 points @ two weeks)
1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// **: relevance score falls off over two days (discounted 99 points after two
1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//     days).
1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// +-: A base score that the provider will adjust upward or downward based on
1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//     provider-specific metrics.
1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// A single result provider for the autocomplete system.  Given user input, the
1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// provider decides what (if any) matches to return, their relevance, and their
1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// classifications.
1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class AutocompleteProvider
1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    : public base::RefCountedThreadSafe<AutocompleteProvider> {
1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Different AutocompleteProvider implementations.
1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  enum Type {
1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    TYPE_BOOKMARK         = 1 << 0,
1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    TYPE_BUILTIN          = 1 << 1,
130116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    TYPE_HISTORY_QUICK    = 1 << 2,
131116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    TYPE_HISTORY_URL      = 1 << 3,
132116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    TYPE_KEYWORD          = 1 << 4,
133116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    TYPE_SEARCH           = 1 << 5,
134116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    TYPE_SHORTCUTS        = 1 << 6,
135116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    TYPE_ZERO_SUGGEST     = 1 << 7,
1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
138116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  explicit AutocompleteProvider(Type type);
1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns a string describing a particular AutocompleteProvider type.
1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static const char* TypeToString(Type type);
1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called to start an autocomplete query.  The provider is responsible for
1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // tracking its matches for this query and whether it is done processing the
1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // query.  When new matches are available or the provider finishes, it
1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // calls the controller's OnProviderUpdate() method.  The controller can then
1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // get the new matches using the provider's accessors.
1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Exception: Matches available immediately after starting the query (that
1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // is, synchronously) do not cause any notifications to be sent.  The
1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // controller is expected to check for these without prompting (since
1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // otherwise, starting each provider running would result in a flurry of
1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // notifications).
1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Once Stop() has been called, no more notifications should be sent.
1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |minimal_changes| is an optimization that lets the provider do less work
1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // when the |input|'s text hasn't changed.  See the body of
1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // OmniboxPopupModel::StartAutocomplete().
1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void Start(const AutocompleteInput& input, bool minimal_changes) = 0;
1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called when a provider must not make any more callbacks for the current
1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // query. This will be called regardless of whether the provider is already
1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // done.  If the provider caches any results, it should clear the cache based
1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // on the value of |clear_cached_results|.
1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void Stop(bool clear_cached_results);
1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns the enum equivalent to the name of this provider.
1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // TODO(derat): Make metrics use AutocompleteProvider::Type directly, or at
1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // least move this method to the metrics directory.
1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  metrics::OmniboxEventProto_ProviderType AsOmniboxEventProviderType() const;
1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called to delete a match and the backing data that produced it.  This
1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // match should not appear again in this or future queries.  This can only be
1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // called for matches the provider marks as deletable.  This should only be
1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // called when no query is running.
176a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // NOTE: Do NOT call OnProviderUpdate() in this method, it is the
177a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // responsibility of the caller to do so after calling us.
1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void DeleteMatch(const AutocompleteMatch& match);
1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called when an omnibox event log entry is generated.  This gives
1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // a provider the opportunity to add diagnostic information to the
1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // logs.  A provider is expected to append a single entry of whatever
1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // information it wants to |provider_info|.
1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void AddProviderInfo(ProvidersInfo* provider_info) const;
1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Called when a new omnibox session starts or the current session ends.
1872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // This gives the opportunity to reset the internal state, if any, associated
1882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // with the previous session.
1892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void ResetSession();
1902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Returns the set of matches for the current query.
1922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  const ACMatches& matches() const { return matches_; }
1932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Returns whether the provider is done processing the query.
1952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  bool done() const { return done_; }
1962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Returns this provider's type.
1982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  Type type() const { return type_; }
1992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Returns a string describing this provider's type.
2012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  const char* GetName() const;
2022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // A suggested upper bound for how many matches a provider should return.
2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // TODO(pkasting): http://b/1111299 , http://b/933133 This should go away once
2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // we have good relevance heuristics; the controller should handle all
2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // culling.
2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static const size_t kMaxMatches;
2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected:
2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  friend class base::RefCountedThreadSafe<AutocompleteProvider>;
211a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  FRIEND_TEST_ALL_PREFIXES(BookmarkProviderTest, InlineAutocompletion);
2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
21346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  typedef std::pair<bool, base::string16> FixupReturn;
21446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)
2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~AutocompleteProvider();
2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Fixes up user URL input to make it more possible to match against.  Among
2185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // many other things, this takes care of the following:
2195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // * Prepending file:// to file URLs
2205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // * Converting drive letters in file URLs to uppercase
2215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // * Converting case-insensitive parts of URLs (like the scheme and domain)
2225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  //   to lowercase
2235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // * Convert spaces to %20s
2245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Note that we don't do this in AutocompleteInput's constructor, because if
2255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // e.g. we convert a Unicode hostname to punycode, other providers will show
2265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // output that surprises the user ("Search Google for xn--6ca.com").
22746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  // Returns a bool indicating whether fixup succeeded, as well as the fixed-up
22846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  // input text.  The returned string will be the same as the input string if
22946d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  // fixup failed; this lets callers who don't care about failure simply use the
23046d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  // string unconditionally.
23146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  static FixupReturn FixupUserInput(const AutocompleteInput& input);
2325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // Trims "http:" and up to two subsequent slashes from |url|.  Returns the
2345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // number of characters that were trimmed.
2355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // NOTE: For a view-source: URL, this will trim from after "view-source:" and
2365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  // return 0.
2375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  static size_t TrimHttpPrefix(base::string16* url);
2385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ACMatches matches_;
2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool done_;
2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Type type_;
2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(AutocompleteProvider);
2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2485f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#endif  // COMPONENTS_OMNIBOX_AUTOCOMPLETE_PROVIDER_H_
249