Content settings: remove some plugin-related code/resources when... there are no...
[chromium-blink-merge.git] / components / omnibox / browser / bookmark_provider.h
blob2b429f39825779f36916f2d7e9437f2eeff1cdad
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 COMPONENTS_OMNIBOX_BROWSER_BOOKMARK_PROVIDER_H_
6 #define COMPONENTS_OMNIBOX_BROWSER_BOOKMARK_PROVIDER_H_
8 #include <string>
10 #include "components/omnibox/browser/autocomplete_input.h"
11 #include "components/omnibox/browser/autocomplete_match.h"
12 #include "components/omnibox/browser/autocomplete_provider.h"
13 #include "components/query_parser/snippet.h"
15 class AutocompleteProviderClient;
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(AutocompleteProviderClient* client);
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(
41 bookmarks::BookmarkModel* bookmark_model) {
42 bookmark_model_ = bookmark_model;
45 private:
46 FRIEND_TEST_ALL_PREFIXES(BookmarkProviderTest, InlineAutocompletion);
48 ~BookmarkProvider() override;
50 // Performs the actual matching of |input| over the bookmarks and fills in
51 // |matches_|.
52 void DoAutocomplete(const AutocompleteInput& input);
54 // Compose an AutocompleteMatch based on |match| that has 1) the URL of
55 // |match|'s bookmark, and 2) the bookmark's title, not the URL's page
56 // title, as the description. |input| is used to compute the match's
57 // inline_autocompletion. |fixed_up_input_text| is used in that way as well;
58 // it's passed separately so this function doesn't have to compute it.
59 AutocompleteMatch BookmarkMatchToACMatch(
60 const AutocompleteInput& input,
61 const base::string16& fixed_up_input_text,
62 const bookmarks::BookmarkMatch& match);
64 // Converts |positions| into ACMatchClassifications and returns the
65 // classifications. |text_length| is used to determine the need to add an
66 // 'unhighlighted' classification span so the tail of the source string
67 // properly highlighted.
68 static ACMatchClassifications ClassificationsFromMatch(
69 const query_parser::Snippet::MatchPositions& positions,
70 size_t text_length,
71 bool is_url);
73 AutocompleteProviderClient* client_;
74 bookmarks::BookmarkModel* bookmark_model_;
76 // Languages used during the URL formatting.
77 std::string languages_;
79 DISALLOW_COPY_AND_ASSIGN(BookmarkProvider);
82 #endif // COMPONENTS_OMNIBOX_BROWSER_BOOKMARK_PROVIDER_H_