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

Unified 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: Rebase 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/bookmarks/bookmark_index.h
diff --git a/chrome/browser/bookmarks/bookmark_index.h b/chrome/browser/bookmarks/bookmark_index.h
index 4027e14def711b865eb2c144c15a9d573043d61f..7a4a06bc40306350d9a1870738925a91ed4d5985 100644
--- a/chrome/browser/bookmarks/bookmark_index.h
+++ b/chrome/browser/bookmarks/bookmark_index.h
@@ -12,17 +12,10 @@
#include "base/basictypes.h"
#include "base/strings/string16.h"
+class BookmarkClient;
class BookmarkNode;
struct BookmarkTitleMatch;
-namespace content {
-class BrowserContext;
-}
-
-namespace history {
-class URLDatabase;
-}
-
namespace query_parser {
class QueryNode;
class QueryParser;
@@ -37,7 +30,7 @@ class QueryParser;
// BookmarkNodes that contain that string in their title.
class BookmarkIndex {
public:
- explicit BookmarkIndex(content::BrowserContext* browser_context);
+ explicit BookmarkIndex(BookmarkClient* client);
~BookmarkIndex();
// Invoked when a bookmark has been added to the model.
@@ -47,42 +40,21 @@ class BookmarkIndex {
void Remove(const BookmarkNode* node);
// Returns up to |max_count| of bookmarks containing the text |query|.
- void GetBookmarksWithTitlesMatching(
- const base::string16& query,
- size_t max_count,
- std::vector<BookmarkTitleMatch>* results);
+ void GetBookmarksWithTitlesMatching(const base::string16& query,
+ size_t max_count,
+ std::vector<BookmarkTitleMatch>* results);
private:
+ typedef std::vector<const BookmarkNode*> Nodes;
typedef std::set<const BookmarkNode*> NodeSet;
typedef std::map<base::string16, NodeSet> Index;
struct Match;
typedef std::vector<Match> Matches;
- // 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, sorts the pairs in
- // decreasing order of typed count, and then de-dupes the matches.
- 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;
- }
+ // Extracts |matches.nodes| into Nodes, sorts the pairs in decreasing order of
+ // typed count (if supported by the client), and then de-dupes the matches.
+ void SortMatches(const Matches& matches, Nodes* sorted_nodes) const;
// Add |node| to |results| if the node matches the query.
void AddMatchToResults(
@@ -128,9 +100,9 @@ class BookmarkIndex {
// Removes |node| from |index_|.
void UnregisterNode(const base::string16& term, const BookmarkNode* node);
- Index index_;
+ BookmarkClient* client_;
- content::BrowserContext* browser_context_;
+ Index index_;
DISALLOW_COPY_AND_ASSIGN(BookmarkIndex);
};

Powered by Google App Engine
This is Rietveld 408576698