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_
10 #include "components/omnibox/autocomplete_input.h"
11 #include "components/omnibox/autocomplete_match.h"
12 #include "components/omnibox/autocomplete_provider.h"
13 #include "components/query_parser/snippet.h"
22 // This class is an autocomplete provider which quickly (and synchronously)
23 // provides autocomplete suggestions based on the titles of bookmarks. Page
24 // titles, URLs, and typed and visit counts of the bookmarks are not currently
25 // taken into consideration as those factors will have been used by the
26 // HistoryQuickProvider (HQP) while identifying suggestions.
28 // TODO(mrossetti): Propose a way to coordinate with the HQP the taking of typed
29 // and visit counts and last visit dates, etc. into consideration while scoring.
30 class BookmarkProvider
: public AutocompleteProvider
{
32 explicit BookmarkProvider(Profile
* profile
);
34 // When |minimal_changes| is true short circuit any additional searching and
35 // leave the previous matches for this provider unchanged, otherwise perform
36 // a complete search for |input| across all bookmark titles.
37 void Start(const AutocompleteInput
& input
, bool minimal_changes
) override
;
39 // Sets the BookmarkModel for unit tests.
40 void set_bookmark_model_for_testing(BookmarkModel
* bookmark_model
) {
41 bookmark_model_
= bookmark_model
;
45 FRIEND_TEST_ALL_PREFIXES(BookmarkProviderTest
, InlineAutocompletion
);
47 ~BookmarkProvider() override
;
49 // Performs the actual matching of |input| over the bookmarks and fills in
51 void DoAutocomplete(const AutocompleteInput
& input
);
53 // Compose an AutocompleteMatch based on |match| that has 1) the URL of
54 // |match|'s bookmark, and 2) the bookmark's title, not the URL's page
55 // title, as the description. |input| is used to compute the match's
56 // inline_autocompletion. |fixed_up_input_text| is used in that way as well;
57 // it's passed separately so this function doesn't have to compute it.
58 AutocompleteMatch
BookmarkMatchToACMatch(
59 const AutocompleteInput
& input
,
60 const base::string16
& fixed_up_input_text
,
61 const bookmarks::BookmarkMatch
& match
);
63 // Converts |positions| into ACMatchClassifications and returns the
64 // classifications. |text_length| is used to determine the need to add an
65 // 'unhighlighted' classification span so the tail of the source string
66 // properly highlighted.
67 static ACMatchClassifications
ClassificationsFromMatch(
68 const query_parser::Snippet::MatchPositions
& positions
,
73 BookmarkModel
* bookmark_model_
;
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_