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

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: Peter's comments 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 14
15 class BookmarkNode; 15 class BookmarkNode;
16 struct BookmarkTitleMatch; 16 struct BookmarkMatch;
17 class QueryNode;
18 class QueryParser;
17 19
18 namespace content { 20 namespace content {
19 class BrowserContext; 21 class BrowserContext;
20 } 22 }
21 23
22 namespace history { 24 namespace history {
23 class URLDatabase; 25 class URLDatabase;
24 } 26 }
25 27
26 namespace query_parser { 28 namespace query_parser {
27 class QueryNode; 29 class QueryNode;
28 class QueryParser; 30 class QueryParser;
29 } 31 }
30 32
31 // BookmarkIndex maintains an index of the titles of bookmarks for quick 33 // BookmarkIndex maintains an index of the titles and URLs of bookmarks for
32 // look up. BookmarkIndex is owned and maintained by BookmarkModel, you 34 // quick look up. BookmarkIndex is owned and maintained by BookmarkModel, you
33 // shouldn't need to interact directly with BookmarkIndex. 35 // shouldn't need to interact directly with BookmarkIndex.
34 // 36 //
35 // BookmarkIndex maintains the index (index_) as a map of sets. The map (type 37 // 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 38 // Index) maps from a lower case string to the set (type NodeSet) of
37 // BookmarkNodes that contain that string in their title. 39 // BookmarkNodes that contain that string in their title or URL.
38 class BookmarkIndex { 40 class BookmarkIndex {
39 public: 41 public:
40 explicit BookmarkIndex(content::BrowserContext* browser_context); 42 BookmarkIndex(content::BrowserContext* browser_context,
43 const std::string& languages);
41 ~BookmarkIndex(); 44 ~BookmarkIndex();
42 45
43 // Invoked when a bookmark has been added to the model. 46 // Invoked when a bookmark has been added to the model.
44 void Add(const BookmarkNode* node); 47 void Add(const BookmarkNode* node);
45 48
46 // Invoked when a bookmark has been removed from the model. 49 // Invoked when a bookmark has been removed from the model.
47 void Remove(const BookmarkNode* node); 50 void Remove(const BookmarkNode* node);
48 51
49 // Returns up to |max_count| of bookmarks containing the text |query|. 52 // Returns up to |max_count| of bookmarks containing each term from
50 void GetBookmarksWithTitlesMatching( 53 // the text |query| in either the title or the URL.
54 void GetBookmarksMatching(
51 const base::string16& query, 55 const base::string16& query,
52 size_t max_count, 56 size_t max_count,
53 std::vector<BookmarkTitleMatch>* results); 57 std::vector<BookmarkMatch>* results);
54 58
55 private: 59 private:
56 typedef std::set<const BookmarkNode*> NodeSet; 60 typedef std::set<const BookmarkNode*> NodeSet;
57 typedef std::map<base::string16, NodeSet> Index; 61 typedef std::map<base::string16, NodeSet> Index;
58 62
59 struct Match; 63 struct Match;
60 typedef std::vector<Match> Matches; 64 typedef std::vector<Match> Matches;
61 65
62 // Pairs BookmarkNodes and the number of times the nodes' URLs were typed. 66 // Pairs BookmarkNodes and the number of times the nodes' URLs were typed.
63 // Used to sort Matches in decreasing order of typed count. 67 // Used to sort Matches in decreasing order of typed count.
(...skipping 18 matching lines...) Expand all
82 static bool NodeTypedCountPairSortFunc(const NodeTypedCountPair& a, 86 static bool NodeTypedCountPairSortFunc(const NodeTypedCountPair& a,
83 const NodeTypedCountPair& b) { 87 const NodeTypedCountPair& b) {
84 return a.second > b.second; 88 return a.second > b.second;
85 } 89 }
86 90
87 // Add |node| to |results| if the node matches the query. 91 // Add |node| to |results| if the node matches the query.
88 void AddMatchToResults( 92 void AddMatchToResults(
89 const BookmarkNode* node, 93 const BookmarkNode* node,
90 query_parser::QueryParser* parser, 94 query_parser::QueryParser* parser,
91 const std::vector<query_parser::QueryNode*>& query_nodes, 95 const std::vector<query_parser::QueryNode*>& query_nodes,
92 std::vector<BookmarkTitleMatch>* results); 96 std::vector<BookmarkMatch>* results);
93 97
94 // Populates |matches| for the specified term. If |first_term| is true, this 98 // 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 99 // is the first term in the query. Returns true if there is at least one node
96 // matching the term. 100 // matching the term.
97 bool GetBookmarksWithTitleMatchingTerm(const base::string16& term, 101 bool GetBookmarksMatchingTerm(const base::string16& term,
98 bool first_term, 102 bool first_term,
99 Matches* matches); 103 Matches* matches);
100 104
101 // Iterates over |matches| updating each Match's nodes to contain the 105 // 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|. 106 // intersection of the Match's current nodes and the nodes at |index_i|.
103 // If the intersection is empty, the Match is removed. 107 // If the intersection is empty, the Match is removed.
104 // 108 //
105 // This is invoked from GetBookmarksWithTitleMatchingTerm. 109 // This is invoked from GetBookmarksMatchingTerm.
106 void CombineMatchesInPlace(const Index::const_iterator& index_i, 110 void CombineMatchesInPlace(const Index::const_iterator& index_i,
107 Matches* matches); 111 Matches* matches);
108 112
109 // Iterates over |current_matches| calculating the intersection between the 113 // Iterates over |current_matches| calculating the intersection between the
110 // Match's nodes and the nodes at |index_i|. If the intersection between the 114 // 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|. 115 // two is non-empty, a new match is added to |result|.
112 // 116 //
113 // This differs from CombineMatchesInPlace in that if the intersection is 117 // This differs from CombineMatchesInPlace in that if the intersection is
114 // non-empty the result is added to result, not combined in place. This 118 // non-empty the result is added to result, not combined in place. This
115 // variant is used for prefix matching. 119 // variant is used for prefix matching.
116 // 120 //
117 // This is invoked from GetBookmarksWithTitleMatchingTerm. 121 // This is invoked from GetBookmarksMatchingTerm.
118 void CombineMatches(const Index::const_iterator& index_i, 122 void CombineMatches(const Index::const_iterator& index_i,
119 const Matches& current_matches, 123 const Matches& current_matches,
120 Matches* result); 124 Matches* result);
121 125
122 // Returns the set of query words from |query|. 126 // Returns the set of query words from |query|.
123 std::vector<base::string16> ExtractQueryWords(const base::string16& query); 127 std::vector<base::string16> ExtractQueryWords(const base::string16& query);
124 128
125 // Adds |node| to |index_|. 129 // Adds |node| to |index_|.
126 void RegisterNode(const base::string16& term, const BookmarkNode* node); 130 void RegisterNode(const base::string16& term, const BookmarkNode* node);
127 131
128 // Removes |node| from |index_|. 132 // Removes |node| from |index_|.
129 void UnregisterNode(const base::string16& term, const BookmarkNode* node); 133 void UnregisterNode(const base::string16& term, const BookmarkNode* node);
130 134
131 Index index_; 135 Index index_;
132 136
137 // True if URLs are stored in the index as well as bookmark titles.
138 const bool index_urls_;
139
133 content::BrowserContext* browser_context_; 140 content::BrowserContext* browser_context_;
134 141
142 // Languages used to help parse IDNs in URLs for the bookmark index.
143 std::string languages_;
144
135 DISALLOW_COPY_AND_ASSIGN(BookmarkIndex); 145 DISALLOW_COPY_AND_ASSIGN(BookmarkIndex);
136 }; 146 };
137 147
138 #endif // CHROME_BROWSER_BOOKMARKS_BOOKMARK_INDEX_H_ 148 #endif // CHROME_BROWSER_BOOKMARKS_BOOKMARK_INDEX_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698