Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / autocomplete / bookmark_provider.h
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 "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"
14
15 class BookmarkModel;
16 class Profile;
17
18 namespace bookmarks {
19 struct BookmarkMatch;
20 }
21
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.
27 //
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);
33
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;
38
39   // Sets the BookmarkModel for unit tests.
40   void set_bookmark_model_for_testing(BookmarkModel* bookmark_model) {
41     bookmark_model_ = bookmark_model;
42   }
43
44  private:
45   FRIEND_TEST_ALL_PREFIXES(BookmarkProviderTest, InlineAutocompletion);
46
47   ~BookmarkProvider() override;
48
49   // Performs the actual matching of |input| over the bookmarks and fills in
50   // |matches_|.
51   void DoAutocomplete(const AutocompleteInput& input);
52
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);
62
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,
69       size_t text_length,
70       bool is_url);
71
72   Profile* profile_;
73   BookmarkModel* bookmark_model_;
74
75   // Languages used during the URL formatting.
76   std::string languages_;
77
78   DISALLOW_COPY_AND_ASSIGN(BookmarkProvider);
79 };
80
81 #endif  // CHROME_BROWSER_AUTOCOMPLETE_BOOKMARK_PROVIDER_H_