| Index: chrome/browser/bookmarks/bookmark_index.cc
|
| diff --git a/chrome/browser/bookmarks/bookmark_index.cc b/chrome/browser/bookmarks/bookmark_index.cc
|
| index feb2384f9d82ef473a929867b52a089a87118a47..579aa3cfcd467868ef1a14716fc5514e54998426 100644
|
| --- a/chrome/browser/bookmarks/bookmark_index.cc
|
| +++ b/chrome/browser/bookmarks/bookmark_index.cc
|
| @@ -10,10 +10,8 @@
|
|
|
| #include "base/i18n/case_conversion.h"
|
| #include "base/strings/string16.h"
|
| -#include "chrome/browser/bookmarks/bookmark_model.h"
|
| -#include "chrome/browser/history/history_service.h"
|
| -#include "chrome/browser/history/history_service_factory.h"
|
| -#include "chrome/browser/history/url_database.h"
|
| +#include "components/bookmarks/core/browser/bookmark_client.h"
|
| +#include "components/bookmarks/core/browser/bookmark_node.h"
|
| #include "components/bookmarks/core/browser/bookmark_title_match.h"
|
| #include "components/query_parser/query_parser.h"
|
| #include "third_party/icu/source/common/unicode/normalizer2.h"
|
| @@ -71,8 +69,7 @@ BookmarkIndex::NodeSet::const_iterator BookmarkIndex::Match::nodes_end() const {
|
| return nodes.empty() ? terms.front()->second.end() : nodes.end();
|
| }
|
|
|
| -BookmarkIndex::BookmarkIndex(content::BrowserContext* browser_context)
|
| - : browser_context_(browser_context) {
|
| +BookmarkIndex::BookmarkIndex() {
|
| }
|
|
|
| BookmarkIndex::~BookmarkIndex() {
|
| @@ -98,6 +95,7 @@ void BookmarkIndex::Remove(const BookmarkNode* node) {
|
| }
|
|
|
| void BookmarkIndex::GetBookmarksWithTitlesMatching(
|
| + BookmarkClient* client,
|
| const base::string16& input_query,
|
| size_t max_count,
|
| std::vector<BookmarkTitleMatch>* results) {
|
| @@ -113,7 +111,7 @@ void BookmarkIndex::GetBookmarksWithTitlesMatching(
|
| }
|
|
|
| NodeTypedCountPairs node_typed_counts;
|
| - SortMatches(matches, &node_typed_counts);
|
| + SortMatches(client, matches, &node_typed_counts);
|
|
|
| // We use a QueryParser to fill in match positions for us. It's not the most
|
| // efficient way to go about this, but by the time we get here we know what
|
| @@ -132,18 +130,14 @@ void BookmarkIndex::GetBookmarksWithTitlesMatching(
|
| AddMatchToResults(i->first, &parser, query_nodes.get(), results);
|
| }
|
|
|
| -void BookmarkIndex::SortMatches(const Matches& matches,
|
| +void BookmarkIndex::SortMatches(BookmarkClient* client,
|
| + const Matches& matches,
|
| NodeTypedCountPairs* node_typed_counts) const {
|
| - HistoryService* const history_service = browser_context_ ?
|
| - HistoryServiceFactory::GetForProfile(
|
| - Profile::FromBrowserContext(browser_context_),
|
| - Profile::EXPLICIT_ACCESS) : NULL;
|
| -
|
| - history::URLDatabase* url_db = history_service ?
|
| - history_service->InMemoryDatabase() : NULL;
|
| -
|
| - for (Matches::const_iterator i = matches.begin(); i != matches.end(); ++i)
|
| - ExtractBookmarkNodePairs(url_db, *i, node_typed_counts);
|
| + for (Matches::const_iterator i = matches.begin(); i != matches.end(); ++i) {
|
| + const NodeSet& nodes =
|
| + i->nodes.empty() ? i->terms.front()->second : i->nodes;
|
| + client->ExtractBookmarkNodePairs(nodes, node_typed_counts);
|
| + }
|
|
|
| std::sort(node_typed_counts->begin(), node_typed_counts->end(),
|
| &NodeTypedCountPairSortFunc);
|
| @@ -153,27 +147,6 @@ void BookmarkIndex::SortMatches(const Matches& matches,
|
| node_typed_counts->end());
|
| }
|
|
|
| -void BookmarkIndex::ExtractBookmarkNodePairs(
|
| - history::URLDatabase* url_db,
|
| - const Match& match,
|
| - NodeTypedCountPairs* node_typed_counts) const {
|
| -
|
| - for (NodeSet::const_iterator i = match.nodes_begin();
|
| - i != match.nodes_end(); ++i) {
|
| - int typed_count = 0;
|
| -
|
| - // If |url_db| is the InMemoryDatabase, it might not cache all URLRows, but
|
| - // it guarantees to contain those with |typed_count| > 0. Thus, if we cannot
|
| - // fetch the URLRow, it is safe to assume that its |typed_count| is 0.
|
| - history::URLRow url;
|
| - if (url_db && url_db->GetRowForURL((*i)->url(), &url))
|
| - typed_count = url.typed_count();
|
| -
|
| - NodeTypedCountPair pair(*i, typed_count);
|
| - node_typed_counts->push_back(pair);
|
| - }
|
| -}
|
| -
|
| void BookmarkIndex::AddMatchToResults(
|
| const BookmarkNode* node,
|
| query_parser::QueryParser* parser,
|
|
|