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

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

Issue 242693003: Introduce BookmarkClient interface to abstract embedder (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing reviewer 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
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 BookmarkClient;
15 class BookmarkNode; 16 class BookmarkNode;
16 struct BookmarkTitleMatch; 17 struct BookmarkTitleMatch;
17 18
18 namespace content {
19 class BrowserContext;
20 }
21
22 namespace history {
23 class URLDatabase;
24 }
25
26 namespace query_parser { 19 namespace query_parser {
27 class QueryNode; 20 class QueryNode;
28 class QueryParser; 21 class QueryParser;
29 } 22 }
30 23
31 // BookmarkIndex maintains an index of the titles of bookmarks for quick 24 // BookmarkIndex maintains an index of the titles of bookmarks for quick
32 // look up. BookmarkIndex is owned and maintained by BookmarkModel, you 25 // look up. BookmarkIndex is owned and maintained by BookmarkModel, you
33 // shouldn't need to interact directly with BookmarkIndex. 26 // shouldn't need to interact directly with BookmarkIndex.
34 // 27 //
35 // BookmarkIndex maintains the index (index_) as a map of sets. The map (type 28 // 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 29 // Index) maps from a lower case string to the set (type NodeSet) of
37 // BookmarkNodes that contain that string in their title. 30 // BookmarkNodes that contain that string in their title.
38 class BookmarkIndex { 31 class BookmarkIndex {
39 public: 32 public:
40 explicit BookmarkIndex(content::BrowserContext* browser_context); 33 explicit BookmarkIndex();
41 ~BookmarkIndex(); 34 ~BookmarkIndex();
42 35
43 // Invoked when a bookmark has been added to the model. 36 // Invoked when a bookmark has been added to the model.
44 void Add(const BookmarkNode* node); 37 void Add(const BookmarkNode* node);
45 38
46 // Invoked when a bookmark has been removed from the model. 39 // Invoked when a bookmark has been removed from the model.
47 void Remove(const BookmarkNode* node); 40 void Remove(const BookmarkNode* node);
48 41
49 // Returns up to |max_count| of bookmarks containing the text |query|. 42 // Returns up to |max_count| of bookmarks containing the text |query|.
50 void GetBookmarksWithTitlesMatching( 43 void GetBookmarksWithTitlesMatching(BookmarkClient* client,
51 const base::string16& query, 44 const base::string16& query,
52 size_t max_count, 45 size_t max_count,
53 std::vector<BookmarkTitleMatch>* results); 46 std::vector<BookmarkTitleMatch>* results);
54 47
55 private: 48 private:
56 typedef std::set<const BookmarkNode*> NodeSet; 49 typedef std::set<const BookmarkNode*> NodeSet;
57 typedef std::map<base::string16, NodeSet> Index; 50 typedef std::map<base::string16, NodeSet> Index;
58 51
59 struct Match; 52 struct Match;
60 typedef std::vector<Match> Matches; 53 typedef std::vector<Match> Matches;
61 54
62 // Pairs BookmarkNodes and the number of times the nodes' URLs were typed. 55 // Pairs BookmarkNodes and the number of times the nodes' URLs were typed.
63 // Used to sort Matches in decreasing order of typed count. 56 // Used to sort Matches in decreasing order of typed count.
64 typedef std::pair<const BookmarkNode*, int> NodeTypedCountPair; 57 typedef std::pair<const BookmarkNode*, int> NodeTypedCountPair;
65 typedef std::vector<NodeTypedCountPair> NodeTypedCountPairs; 58 typedef std::vector<NodeTypedCountPair> NodeTypedCountPairs;
66 59
67 // Extracts |matches.nodes| into NodeTypedCountPairs, sorts the pairs in 60 // Extracts |matches.nodes| into NodeTypedCountPairs, sorts the pairs in
68 // decreasing order of typed count, and then de-dupes the matches. 61 // decreasing order of typed count, and then de-dupes the matches.
69 void SortMatches(const Matches& matches, 62 void SortMatches(BookmarkClient* client,
63 const Matches& matches,
70 NodeTypedCountPairs* node_typed_counts) const; 64 NodeTypedCountPairs* node_typed_counts) const;
71 65
72 // Extracts BookmarkNodes from |match| and retrieves typed counts for each
73 // node from the in-memory database. Inserts pairs containing the node and
74 // typed count into the vector |node_typed_counts|. |node_typed_counts| is
75 // sorted in decreasing order of typed count.
76 void ExtractBookmarkNodePairs(history::URLDatabase* url_db,
77 const Match& match,
78 NodeTypedCountPairs* node_typed_counts) const;
79
80 // Sort function for NodeTypedCountPairs. We sort in decreasing order of typed 66 // Sort function for NodeTypedCountPairs. We sort in decreasing order of typed
81 // count so that the best matches will always be added to the results. 67 // count so that the best matches will always be added to the results.
82 static bool NodeTypedCountPairSortFunc(const NodeTypedCountPair& a, 68 static bool NodeTypedCountPairSortFunc(const NodeTypedCountPair& a,
83 const NodeTypedCountPair& b) { 69 const NodeTypedCountPair& b) {
84 return a.second > b.second; 70 return a.second > b.second;
85 } 71 }
86 72
87 // Add |node| to |results| if the node matches the query. 73 // Add |node| to |results| if the node matches the query.
88 void AddMatchToResults( 74 void AddMatchToResults(
89 const BookmarkNode* node, 75 const BookmarkNode* node,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 std::vector<base::string16> ExtractQueryWords(const base::string16& query); 109 std::vector<base::string16> ExtractQueryWords(const base::string16& query);
124 110
125 // Adds |node| to |index_|. 111 // Adds |node| to |index_|.
126 void RegisterNode(const base::string16& term, const BookmarkNode* node); 112 void RegisterNode(const base::string16& term, const BookmarkNode* node);
127 113
128 // Removes |node| from |index_|. 114 // Removes |node| from |index_|.
129 void UnregisterNode(const base::string16& term, const BookmarkNode* node); 115 void UnregisterNode(const base::string16& term, const BookmarkNode* node);
130 116
131 Index index_; 117 Index index_;
132 118
133 content::BrowserContext* browser_context_;
134
135 DISALLOW_COPY_AND_ASSIGN(BookmarkIndex); 119 DISALLOW_COPY_AND_ASSIGN(BookmarkIndex);
136 }; 120 };
137 121
138 #endif // CHROME_BROWSER_BOOKMARKS_BOOKMARK_INDEX_H_ 122 #endif // CHROME_BROWSER_BOOKMARKS_BOOKMARK_INDEX_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/bookmarks/bookmark_index.cc » ('j') | chrome/browser/bookmarks/bookmark_index.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698