| Index: chrome/browser/bookmarks/bookmark_index.h
|
| ===================================================================
|
| --- chrome/browser/bookmarks/bookmark_index.h (revision 24426)
|
| +++ chrome/browser/bookmarks/bookmark_index.h (working copy)
|
| @@ -14,6 +14,7 @@
|
| #include "base/basictypes.h"
|
|
|
| class BookmarkNode;
|
| +class Profile;
|
| class QueryNode;
|
| class QueryParser;
|
|
|
| @@ -21,6 +22,10 @@
|
| struct TitleMatch;
|
| }
|
|
|
| +namespace history {
|
| +class URLDatabase;
|
| +}
|
| +
|
| // BookmarkIndex maintains an index of the titles of bookmarks for quick
|
| // look up. BookmarkIndex is owned and maintained by BookmarkModel, you
|
| // shouldn't need to interact directly with BookmarkIndex.
|
| @@ -31,7 +36,7 @@
|
|
|
| class BookmarkIndex {
|
| public:
|
| - BookmarkIndex() {}
|
| + explicit BookmarkIndex(Profile* profile) : profile_(profile) {}
|
|
|
| // Invoked when a bookmark has been added to the model.
|
| void Add(const BookmarkNode* node);
|
| @@ -70,16 +75,39 @@
|
| NodeSet::const_iterator nodes_begin() const;
|
|
|
| // Returns an iterator to the beginning of the matching nodes. See
|
| - // description of nodes for why this should be used over nodes.begin().
|
| + // description of nodes for why this should be used over nodes.end().
|
| NodeSet::const_iterator nodes_end() const;
|
| };
|
|
|
| typedef std::vector<Match> Matches;
|
|
|
| - // Add all the matching nodes in |match.nodes| to |results| until there are
|
| - // at most |max_count| matches in |results|.
|
| - void AddMatchToResults(const Match& match,
|
| - size_t max_count,
|
| + // Pairs BookmarkNodes and the number of times the nodes' URLs were typed.
|
| + // Used to sort Matches in decreasing order of typed count.
|
| + typedef std::pair<const BookmarkNode*, int> NodeTypedCountPair;
|
| + typedef std::vector<NodeTypedCountPair> NodeTypedCountPairs;
|
| +
|
| + // Extracts |matches.nodes| into NodeTypedCountPairs and sorts the pairs in
|
| + // decreasing order of typed count.
|
| + void SortMatches(const Matches& matches,
|
| + NodeTypedCountPairs* node_typed_counts) const;
|
| +
|
| + // Extracts BookmarkNodes from |match| and retrieves typed counts for each
|
| + // node from the in-memory database. Inserts pairs containing the node and
|
| + // typed count into the vector |node_typed_counts|. |node_typed_counts| is
|
| + // sorted in decreasing order of typed count.
|
| + void ExtractBookmarkNodePairs(history::URLDatabase* url_db,
|
| + const Match& match,
|
| + NodeTypedCountPairs* node_typed_counts) const;
|
| +
|
| + // Sort function for NodeTypedCountPairs. We sort in decreasing order of typed
|
| + // count so that the best matches will always be added to the results.
|
| + static bool NodeTypedCountPairSortFunc(const NodeTypedCountPair& a,
|
| + const NodeTypedCountPair& b) {
|
| + return a.second > b.second;
|
| + }
|
| +
|
| + // Add |node| to |results| if the node matches the query.
|
| + void AddMatchToResults(const BookmarkNode* node,
|
| QueryParser* parser,
|
| const std::vector<QueryNode*>& query_nodes,
|
| std::vector<bookmark_utils::TitleMatch>* results);
|
| @@ -123,6 +151,8 @@
|
|
|
| Index index_;
|
|
|
| + Profile* profile_;
|
| +
|
| DISALLOW_COPY_AND_ASSIGN(BookmarkIndex);
|
| };
|
|
|
|
|