Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(308)

Side by Side Diff: chrome/browser/bookmarks/bookmark_index.h

Issue 184663002: Omnibox: Make URLs of Bookmarks Searchable (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_BOOKMARKS_BOOKMARK_INDEX_H_ 5 #ifndef CHROME_BROWSER_BOOKMARKS_BOOKMARK_INDEX_H_
6 #define CHROME_BROWSER_BOOKMARKS_BOOKMARK_INDEX_H_ 6 #define CHROME_BROWSER_BOOKMARKS_BOOKMARK_INDEX_H_
7 7
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/strings/string16.h" 13 #include "base/strings/string16.h"
14 #include "components/query_parser/query_parser.h"
14 15
15 class BookmarkNode; 16 class BookmarkNode;
16 struct BookmarkTitleMatch; 17 struct BookmarkMatch;
17 18
18 namespace content { 19 namespace content {
19 class BrowserContext; 20 class BrowserContext;
20 } 21 }
21 22
22 namespace history { 23 namespace history {
23 class URLDatabase; 24 class URLDatabase;
24 } 25 }
25 26
26 namespace query_parser { 27 // BookmarkIndex maintains an index of the titles and URLs of bookmarks for
27 class QueryNode; 28 // quick look up. BookmarkIndex is owned and maintained by BookmarkModel, you
28 class QueryParser;
29 }
30
31 // BookmarkIndex maintains an index of the titles of bookmarks for quick
32 // look up. BookmarkIndex is owned and maintained by BookmarkModel, you
33 // shouldn't need to interact directly with BookmarkIndex. 29 // shouldn't need to interact directly with BookmarkIndex.
34 // 30 //
35 // BookmarkIndex maintains the index (index_) as a map of sets. The map (type 31 // BookmarkIndex maintains the index (index_) as a map of sets. The map (type
36 // Index) maps from a lower case string to the set (type NodeSet) of 32 // Index) maps from a lower case string to the set (type NodeSet) of
37 // BookmarkNodes that contain that string in their title. 33 // BookmarkNodes that contain that string in their title or URL.
38 class BookmarkIndex { 34 class BookmarkIndex {
39 public: 35 public:
40 explicit BookmarkIndex(content::BrowserContext* browser_context); 36 // |index_urls| says whether URLs should be stored in the index in addition
37 // to bookmark titles. |languages| used to help parse IDNs in URLs for the
38 // bookmark index.
39 BookmarkIndex(content::BrowserContext* browser_context,
40 bool index_urls,
41 const std::string& languages);
41 ~BookmarkIndex(); 42 ~BookmarkIndex();
42 43
43 // Invoked when a bookmark has been added to the model. 44 // Invoked when a bookmark has been added to the model.
44 void Add(const BookmarkNode* node); 45 void Add(const BookmarkNode* node);
45 46
46 // Invoked when a bookmark has been removed from the model. 47 // Invoked when a bookmark has been removed from the model.
47 void Remove(const BookmarkNode* node); 48 void Remove(const BookmarkNode* node);
48 49
49 // Returns up to |max_count| of bookmarks containing the text |query|. 50 // Returns up to |max_count| of bookmarks containing each term from
50 void GetBookmarksWithTitlesMatching( 51 // the text |query| in either the title or the URL.
52 void GetBookmarksMatching(
51 const base::string16& query, 53 const base::string16& query,
52 size_t max_count, 54 size_t max_count,
53 std::vector<BookmarkTitleMatch>* results); 55 std::vector<BookmarkMatch>* results);
54 56
55 private: 57 private:
56 typedef std::set<const BookmarkNode*> NodeSet; 58 typedef std::set<const BookmarkNode*> NodeSet;
57 typedef std::map<base::string16, NodeSet> Index; 59 typedef std::map<base::string16, NodeSet> Index;
58 60
59 struct Match; 61 struct Match;
60 typedef std::vector<Match> Matches; 62 typedef std::vector<Match> Matches;
61 63
62 // Pairs BookmarkNodes and the number of times the nodes' URLs were typed. 64 // Pairs BookmarkNodes and the number of times the nodes' URLs were typed.
63 // Used to sort Matches in decreasing order of typed count. 65 // Used to sort Matches in decreasing order of typed count.
(...skipping 17 matching lines...) Expand all
81 // count so that the best matches will always be added to the results. 83 // count so that the best matches will always be added to the results.
82 static bool NodeTypedCountPairSortFunc(const NodeTypedCountPair& a, 84 static bool NodeTypedCountPairSortFunc(const NodeTypedCountPair& a,
83 const NodeTypedCountPair& b) { 85 const NodeTypedCountPair& b) {
84 return a.second > b.second; 86 return a.second > b.second;
85 } 87 }
86 88
87 // Add |node| to |results| if the node matches the query. 89 // Add |node| to |results| if the node matches the query.
88 void AddMatchToResults( 90 void AddMatchToResults(
89 const BookmarkNode* node, 91 const BookmarkNode* node,
90 query_parser::QueryParser* parser, 92 query_parser::QueryParser* parser,
91 const std::vector<query_parser::QueryNode*>& query_nodes, 93 const query_parser::QueryNodeStarVector& query_nodes,
92 std::vector<BookmarkTitleMatch>* results); 94 std::vector<BookmarkMatch>* results);
93 95
94 // Populates |matches| for the specified term. If |first_term| is true, this 96 // Populates |matches| for the specified term. If |first_term| is true, this
95 // is the first term in the query. Returns true if there is at least one node 97 // is the first term in the query. Returns true if there is at least one node
96 // matching the term. 98 // matching the term.
97 bool GetBookmarksWithTitleMatchingTerm(const base::string16& term, 99 bool GetBookmarksMatchingTerm(const base::string16& term,
98 bool first_term, 100 bool first_term,
99 Matches* matches); 101 Matches* matches);
100 102
101 // Iterates over |matches| updating each Match's nodes to contain the 103 // Iterates over |matches| updating each Match's nodes to contain the
102 // intersection of the Match's current nodes and the nodes at |index_i|. 104 // intersection of the Match's current nodes and the nodes at |index_i|.
103 // If the intersection is empty, the Match is removed. 105 // If the intersection is empty, the Match is removed.
104 // 106 //
105 // This is invoked from GetBookmarksWithTitleMatchingTerm. 107 // This is invoked from GetBookmarksMatchingTerm.
106 void CombineMatchesInPlace(const Index::const_iterator& index_i, 108 void CombineMatchesInPlace(const Index::const_iterator& index_i,
107 Matches* matches); 109 Matches* matches);
108 110
109 // Iterates over |current_matches| calculating the intersection between the 111 // Iterates over |current_matches| calculating the intersection between the
110 // Match's nodes and the nodes at |index_i|. If the intersection between the 112 // Match's nodes and the nodes at |index_i|. If the intersection between the
111 // two is non-empty, a new match is added to |result|. 113 // two is non-empty, a new match is added to |result|.
112 // 114 //
113 // This differs from CombineMatchesInPlace in that if the intersection is 115 // This differs from CombineMatchesInPlace in that if the intersection is
114 // non-empty the result is added to result, not combined in place. This 116 // non-empty the result is added to result, not combined in place. This
115 // variant is used for prefix matching. 117 // variant is used for prefix matching.
116 // 118 //
117 // This is invoked from GetBookmarksWithTitleMatchingTerm. 119 // This is invoked from GetBookmarksMatchingTerm.
118 void CombineMatches(const Index::const_iterator& index_i, 120 void CombineMatches(const Index::const_iterator& index_i,
119 const Matches& current_matches, 121 const Matches& current_matches,
120 Matches* result); 122 Matches* result);
121 123
122 // Returns the set of query words from |query|. 124 // Returns the set of query words from |query|.
123 std::vector<base::string16> ExtractQueryWords(const base::string16& query); 125 std::vector<base::string16> ExtractQueryWords(const base::string16& query);
124 126
125 // Adds |node| to |index_|. 127 // Adds |node| to |index_|.
126 void RegisterNode(const base::string16& term, const BookmarkNode* node); 128 void RegisterNode(const base::string16& term, const BookmarkNode* node);
127 129
128 // Removes |node| from |index_|. 130 // Removes |node| from |index_|.
129 void UnregisterNode(const base::string16& term, const BookmarkNode* node); 131 void UnregisterNode(const base::string16& term, const BookmarkNode* node);
130 132
131 Index index_; 133 Index index_;
132 134
135 // True if URLs are stored in the index as well as bookmark titles.
136 const bool index_urls_;
137
133 content::BrowserContext* browser_context_; 138 content::BrowserContext* browser_context_;
134 139
140 // Languages used to help parse IDNs in URLs for the bookmark index.
141 std::string languages_;
sky 2014/04/21 23:09:01 nit: const.
Mark P 2014/04/21 23:41:36 Done.
142
135 DISALLOW_COPY_AND_ASSIGN(BookmarkIndex); 143 DISALLOW_COPY_AND_ASSIGN(BookmarkIndex);
136 }; 144 };
137 145
138 #endif // CHROME_BROWSER_BOOKMARKS_BOOKMARK_INDEX_H_ 146 #endif // CHROME_BROWSER_BOOKMARKS_BOOKMARK_INDEX_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698