|
OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 #ifndef CHROME_BROWSER_AUTOCOMPLETE_BOOKMARK_PROVIDER_H_ | |
6 #define CHROME_BROWSER_AUTOCOMPLETE_BOOKMARK_PROVIDER_H_ | |
7 | |
8 #include <string> | |
9 | |
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 "chrome/browser/bookmarks/bookmark_utils.h" | |
14 #include "chrome/browser/history/snippet.h" | |
15 | |
16 class BookmarkModel; | |
17 class Profile; | |
18 | |
19 // This class is an autocomplete provider which quickly (and synchronously) | |
20 // provides autocomplete suggestions based on matches between the search terms | |
Peter Kasting
2012/10/04 20:40:31
Nit: "matches between the search terms entered by
mrossetti
2012/10/05 22:10:04
Done.
| |
21 // entered by the user into the omnibox and the titles of bookmarks. Page | |
22 // titles and URLs of the bookmarks are not matched. | |
Peter Kasting
2012/10/04 20:40:31
Nit: Mention why.
mrossetti
2012/10/05 22:10:04
Done, hopefully it's clear enough of an explanatio
| |
23 class BookmarkProvider : public AutocompleteProvider { | |
24 public: | |
25 BookmarkProvider(AutocompleteProviderListener* listener, Profile* profile); | |
26 | |
27 // AutocompleteProvider. |minimal_changes| is ignored since there is no | |
28 // asynch completion performed. | |
29 virtual void Start(const AutocompleteInput& input, | |
30 bool minimal_changes) OVERRIDE; | |
31 | |
32 // Sets the BookmarkModel for unit tests. | |
33 void set_bookmark_model_for_testing(BookmarkModel* bookmark_model) { | |
34 bookmark_model_ = bookmark_model; | |
35 } | |
36 | |
37 private: | |
38 virtual ~BookmarkProvider(); | |
39 | |
40 // Performs the actual matching of |input| over the bookmarks and fills in | |
41 // |matches_|. If |best_match| then only suggest the single best match, | |
42 // otherwise suggest the top |kMaxMatches| matches. | |
43 void DoAutocomplete(const AutocompleteInput& input, bool best_match); | |
44 | |
45 // Converts |title_match| to an AutocompleteMatch and returns the converted | |
46 // match. | |
47 AutocompleteMatch TitleMatchToACMatch( | |
48 const bookmark_utils::TitleMatch& title_match); | |
49 | |
50 // Converts |positions| into ACMatchClassifications and returns the | |
51 // classifications. |text_length| is used to determine the need to add an | |
52 // 'unhighlighted' classification span so the tail of the source string | |
53 // properly highlighted. | |
54 static ACMatchClassifications SpansFromMatch( | |
55 const Snippet::MatchPositions& positions, | |
56 size_t text_length); | |
57 | |
58 BookmarkModel* bookmark_model_; | |
59 | |
60 // Languages used during the URL formatting. | |
61 std::string languages_; | |
62 | |
63 DISALLOW_COPY_AND_ASSIGN(BookmarkProvider); | |
64 }; | |
65 | |
66 #endif // CHROME_BROWSER_AUTOCOMPLETE_BOOKMARK_PROVIDER_H_ | |
OLD | NEW |