Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / autocomplete / bookmark_provider.h
blob54ccc975e09b3429e7d86e346eca4d90a3915e22
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 "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"
15 class Profile;
17 namespace bookmarks {
18 class BookmarkModel;
19 struct BookmarkMatch;
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 {
31 public:
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,
38 bool minimal_changes,
39 bool called_due_to_focus) override;
41 // Sets the BookmarkModel for unit tests.
42 void set_bookmark_model_for_testing(
43 bookmarks::BookmarkModel* bookmark_model) {
44 bookmark_model_ = bookmark_model;
47 private:
48 FRIEND_TEST_ALL_PREFIXES(BookmarkProviderTest, InlineAutocompletion);
50 ~BookmarkProvider() override;
52 // Performs the actual matching of |input| over the bookmarks and fills in
53 // |matches_|.
54 void DoAutocomplete(const AutocompleteInput& input);
56 // Compose an AutocompleteMatch based on |match| that has 1) the URL of
57 // |match|'s bookmark, and 2) the bookmark's title, not the URL's page
58 // title, as the description. |input| is used to compute the match's
59 // inline_autocompletion. |fixed_up_input_text| is used in that way as well;
60 // it's passed separately so this function doesn't have to compute it.
61 AutocompleteMatch BookmarkMatchToACMatch(
62 const AutocompleteInput& input,
63 const base::string16& fixed_up_input_text,
64 const bookmarks::BookmarkMatch& match);
66 // Converts |positions| into ACMatchClassifications and returns the
67 // classifications. |text_length| is used to determine the need to add an
68 // 'unhighlighted' classification span so the tail of the source string
69 // properly highlighted.
70 static ACMatchClassifications ClassificationsFromMatch(
71 const query_parser::Snippet::MatchPositions& positions,
72 size_t text_length,
73 bool is_url);
75 Profile* profile_;
76 bookmarks::BookmarkModel* bookmark_model_;
78 // Languages used during the URL formatting.
79 std::string languages_;
81 DISALLOW_COPY_AND_ASSIGN(BookmarkProvider);
84 #endif // CHROME_BROWSER_AUTOCOMPLETE_BOOKMARK_PROVIDER_H_