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