[safe-browsing] Database full hash matches like prefix match.
[chromium-blink-merge.git] / chrome / browser / autocomplete / bookmark_provider.h
blobbe256e90dd9b63d74980fb9724dec4614d22dccd
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_AUTOCOMPLETE_BOOKMARK_PROVIDER_H_
6 #define CHROME_BROWSER_AUTOCOMPLETE_BOOKMARK_PROVIDER_H_
8 #include <string>
10 #include "chrome/browser/autocomplete/autocomplete_input.h"
11 #include "chrome/browser/autocomplete/autocomplete_match.h"
12 #include "chrome/browser/autocomplete/autocomplete_provider.h"
13 #include "components/query_parser/snippet.h"
15 class BookmarkModel;
16 struct BookmarkMatch;
17 class Profile;
19 // This class is an autocomplete provider which quickly (and synchronously)
20 // provides autocomplete suggestions based on the titles of bookmarks. Page
21 // titles, URLs, and typed and visit counts of the bookmarks are not currently
22 // taken into consideration as those factors will have been used by the
23 // HistoryQuickProvider (HQP) while identifying suggestions.
25 // TODO(mrossetti): Propose a way to coordinate with the HQP the taking of typed
26 // and visit counts and last visit dates, etc. into consideration while scoring.
27 class BookmarkProvider : public AutocompleteProvider {
28 public:
29 BookmarkProvider(AutocompleteProviderListener* listener, Profile* profile);
31 // When |minimal_changes| is true short circuit any additional searching and
32 // leave the previous matches for this provider unchanged, otherwise perform
33 // a complete search for |input| across all bookmark titles.
34 virtual void Start(const AutocompleteInput& input,
35 bool minimal_changes) OVERRIDE;
37 // Sets the BookmarkModel for unit tests.
38 void set_bookmark_model_for_testing(BookmarkModel* bookmark_model) {
39 bookmark_model_ = bookmark_model;
42 private:
43 FRIEND_TEST_ALL_PREFIXES(BookmarkProviderTest, InlineAutocompletion);
45 virtual ~BookmarkProvider();
47 // Performs the actual matching of |input| over the bookmarks and fills in
48 // |matches_|.
49 void DoAutocomplete(const AutocompleteInput& input);
51 // Compose an AutocompleteMatch based on |match| that has 1) the URL of
52 // |match|'s bookmark, and 2) the bookmark's title, not the URL's page
53 // title, as the description. |input| is used to compute the match's
54 // inline_autocompletion. |fixed_up_input| is used in that way as well;
55 // it's passed separately so this function doesn't have to compute it.
56 AutocompleteMatch BookmarkMatchToACMatch(
57 const AutocompleteInput& input,
58 const AutocompleteInput& fixed_up_input,
59 const BookmarkMatch& match);
61 // Converts |positions| into ACMatchClassifications and returns the
62 // classifications. |text_length| is used to determine the need to add an
63 // 'unhighlighted' classification span so the tail of the source string
64 // properly highlighted.
65 static ACMatchClassifications ClassificationsFromMatch(
66 const query_parser::Snippet::MatchPositions& positions,
67 size_t text_length,
68 bool is_url);
70 BookmarkModel* bookmark_model_;
72 // True if we should use matches in the URL for scoring.
73 const bool score_using_url_matches_;
75 // Languages used during the URL formatting.
76 std::string languages_;
78 DISALLOW_COPY_AND_ASSIGN(BookmarkProvider);
81 #endif // CHROME_BROWSER_AUTOCOMPLETE_BOOKMARK_PROVIDER_H_