diff options
author | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-30 15:39:57 +0000 |
---|---|---|
committer | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-30 15:39:57 +0000 |
commit | dcf5fbb73e68623808da498e44c14224050a88c4 (patch) | |
tree | 4a5c9ee2de6f364d11533dfdd01e33d60d227060 /chrome/browser/bookmarks | |
parent | 9c50d97c9729f3376e352f2b539dccb66c1e66e1 (diff) | |
download | chromium_src-dcf5fbb73e68623808da498e44c14224050a88c4.zip chromium_src-dcf5fbb73e68623808da498e44c14224050a88c4.tar.gz chromium_src-dcf5fbb73e68623808da498e44c14224050a88c4.tar.bz2 |
bookmarks: Get rid of the dependency on c/b/history/snippet.h
In order to do this we move Snippet Match definitions into BookmarkTitleMatch.
BUG=144783
R=sky@chromium.org
Review URL: https://codereview.chromium.org/15963014
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@203150 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/bookmarks')
-rw-r--r-- | chrome/browser/bookmarks/DEPS | 1 | ||||
-rw-r--r-- | chrome/browser/bookmarks/bookmark_codec_unittest.cc | 1 | ||||
-rw-r--r-- | chrome/browser/bookmarks/bookmark_index.cc | 8 | ||||
-rw-r--r-- | chrome/browser/bookmarks/bookmark_index.h | 9 | ||||
-rw-r--r-- | chrome/browser/bookmarks/bookmark_index_unittest.cc | 25 | ||||
-rw-r--r-- | chrome/browser/bookmarks/bookmark_model.cc | 3 | ||||
-rw-r--r-- | chrome/browser/bookmarks/bookmark_model.h | 7 | ||||
-rw-r--r-- | chrome/browser/bookmarks/bookmark_title_match.cc | 9 | ||||
-rw-r--r-- | chrome/browser/bookmarks/bookmark_title_match.h | 31 | ||||
-rw-r--r-- | chrome/browser/bookmarks/bookmark_utils.cc | 6 | ||||
-rw-r--r-- | chrome/browser/bookmarks/bookmark_utils.h | 13 |
11 files changed, 64 insertions, 49 deletions
diff --git a/chrome/browser/bookmarks/DEPS b/chrome/browser/bookmarks/DEPS index 9993cad..0086137 100644 --- a/chrome/browser/bookmarks/DEPS +++ b/chrome/browser/bookmarks/DEPS @@ -13,7 +13,6 @@ include_rules = [ "!chrome/browser/history/history_service.h", "!chrome/browser/history/history_service_factory.h", "!chrome/browser/history/query_parser.h", - "!chrome/browser/history/snippet.h", "!chrome/browser/history/url_database.h", "!chrome/browser/profiles/incognito_helpers.h", "!chrome/browser/profiles/profile.h", diff --git a/chrome/browser/bookmarks/bookmark_codec_unittest.cc b/chrome/browser/bookmarks/bookmark_codec_unittest.cc index c3fded1..0ed88b0 100644 --- a/chrome/browser/bookmarks/bookmark_codec_unittest.cc +++ b/chrome/browser/bookmarks/bookmark_codec_unittest.cc @@ -13,7 +13,6 @@ #include "chrome/browser/bookmarks/bookmark_codec.h" #include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/bookmarks/bookmark_model_test_utils.h" -#include "chrome/browser/bookmarks/bookmark_utils.h" #include "chrome/common/chrome_paths.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/chrome/browser/bookmarks/bookmark_index.cc b/chrome/browser/bookmarks/bookmark_index.cc index 9086858..3977589 100644 --- a/chrome/browser/bookmarks/bookmark_index.cc +++ b/chrome/browser/bookmarks/bookmark_index.cc @@ -11,7 +11,7 @@ #include "base/i18n/case_conversion.h" #include "base/string16.h" #include "chrome/browser/bookmarks/bookmark_model.h" -#include "chrome/browser/bookmarks/bookmark_utils.h" +#include "chrome/browser/bookmarks/bookmark_title_match.h" #include "chrome/browser/history/history_service.h" #include "chrome/browser/history/history_service_factory.h" #include "chrome/browser/history/query_parser.h" @@ -78,7 +78,7 @@ void BookmarkIndex::Remove(const BookmarkNode* node) { void BookmarkIndex::GetBookmarksWithTitlesMatching( const string16& query, size_t max_count, - std::vector<bookmark_utils::TitleMatch>* results) { + std::vector<BookmarkTitleMatch>* results) { std::vector<string16> terms = ExtractQueryWords(query); if (terms.empty()) return; @@ -149,8 +149,8 @@ void BookmarkIndex::AddMatchToResults( const BookmarkNode* node, QueryParser* parser, const std::vector<QueryNode*>& query_nodes, - std::vector<bookmark_utils::TitleMatch>* results) { - bookmark_utils::TitleMatch title_match; + std::vector<BookmarkTitleMatch>* results) { + BookmarkTitleMatch title_match; // Check that the result matches the query. The previous search // was a simple per-word search, while the more complex matching // of QueryParser may filter it out. For example, the query diff --git a/chrome/browser/bookmarks/bookmark_index.h b/chrome/browser/bookmarks/bookmark_index.h index 942a376..beac384 100644 --- a/chrome/browser/bookmarks/bookmark_index.h +++ b/chrome/browser/bookmarks/bookmark_index.h @@ -13,13 +13,10 @@ #include "base/string16.h" class BookmarkNode; +struct BookmarkTitleMatch; class QueryNode; class QueryParser; -namespace bookmark_utils { -struct TitleMatch; -} - namespace content { class BrowserContext; } @@ -50,7 +47,7 @@ class BookmarkIndex { void GetBookmarksWithTitlesMatching( const string16& query, size_t max_count, - std::vector<bookmark_utils::TitleMatch>* results); + std::vector<BookmarkTitleMatch>* results); private: typedef std::set<const BookmarkNode*> NodeSet; @@ -88,7 +85,7 @@ class BookmarkIndex { void AddMatchToResults(const BookmarkNode* node, QueryParser* parser, const std::vector<QueryNode*>& query_nodes, - std::vector<bookmark_utils::TitleMatch>* results); + std::vector<BookmarkTitleMatch>* results); // Populates |matches| for the specified term. If |first_term| is true, this // is the first term in the query. Returns true if there is at least one node diff --git a/chrome/browser/bookmarks/bookmark_index_unittest.cc b/chrome/browser/bookmarks/bookmark_index_unittest.cc index d6eb132..af6062d 100644 --- a/chrome/browser/bookmarks/bookmark_index_unittest.cc +++ b/chrome/browser/bookmarks/bookmark_index_unittest.cc @@ -14,7 +14,7 @@ #include "base/utf_string_conversions.h" #include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/bookmarks/bookmark_model_factory.h" -#include "chrome/browser/bookmarks/bookmark_utils.h" +#include "chrome/browser/bookmarks/bookmark_title_match.h" #include "chrome/browser/history/history_service.h" #include "chrome/browser/history/history_service_factory.h" #include "chrome/browser/history/url_database.h" @@ -54,7 +54,7 @@ class BookmarkIndexTest : public testing::Test { void ExpectMatches(const std::string& query, const std::vector<std::string>& expected_titles) { - std::vector<bookmark_utils::TitleMatch> matches; + std::vector<BookmarkTitleMatch> matches; model_->GetBookmarksWithTitlesMatching(ASCIIToUTF16(query), 1000, &matches); ASSERT_EQ(expected_titles.size(), matches.size()); for (size_t i = 0; i < expected_titles.size(); ++i) { @@ -71,14 +71,14 @@ class BookmarkIndexTest : public testing::Test { } void ExtractMatchPositions(const std::string& string, - Snippet::MatchPositions* matches) { + BookmarkTitleMatch::MatchPositions* matches) { std::vector<std::string> match_strings; base::SplitString(string, ':', &match_strings); for (size_t i = 0; i < match_strings.size(); ++i) { std::vector<std::string> chunks; base::SplitString(match_strings[i], ',', &chunks); ASSERT_EQ(2U, chunks.size()); - matches->push_back(Snippet::MatchPosition()); + matches->push_back(BookmarkTitleMatch::MatchPosition()); int chunks0, chunks1; base::StringToInt(chunks[0], &chunks0); base::StringToInt(chunks[1], &chunks1); @@ -87,12 +87,13 @@ class BookmarkIndexTest : public testing::Test { } } - void ExpectMatchPositions(const std::string& query, - const Snippet::MatchPositions& expected_positions) { - std::vector<bookmark_utils::TitleMatch> matches; + void ExpectMatchPositions( + const std::string& query, + const BookmarkTitleMatch::MatchPositions& expected_positions) { + std::vector<BookmarkTitleMatch> matches; model_->GetBookmarksWithTitlesMatching(ASCIIToUTF16(query), 1000, &matches); ASSERT_EQ(1U, matches.size()); - const bookmark_utils::TitleMatch& match = matches[0]; + const BookmarkTitleMatch& match = matches[0]; ASSERT_EQ(expected_positions.size(), match.match_positions.size()); for (size_t i = 0; i < expected_positions.size(); ++i) { EXPECT_EQ(expected_positions[i].first, match.match_positions[i].first); @@ -178,7 +179,7 @@ TEST_F(BookmarkIndexTest, MatchPositions) { titles.push_back(data[i].title); AddBookmarksWithTitles(titles); - Snippet::MatchPositions expected_matches; + BookmarkTitleMatch::MatchPositions expected_matches; ExtractMatchPositions(data[i].expected, &expected_matches); ExpectMatchPositions(data[i].query, expected_matches); @@ -212,7 +213,7 @@ TEST_F(BookmarkIndexTest, HonorMax) { const char* input[] = { "abcd", "abcde" }; AddBookmarksWithTitles(input, ARRAYSIZE_UNSAFE(input)); - std::vector<bookmark_utils::TitleMatch> matches; + std::vector<BookmarkTitleMatch> matches; model_->GetBookmarksWithTitlesMatching(ASCIIToUTF16("ABc"), 1, &matches); EXPECT_EQ(1U, matches.size()); } @@ -224,7 +225,7 @@ TEST_F(BookmarkIndexTest, EmptyMatchOnMultiwideLowercaseString) { WideToUTF16(L"\u0130 i"), GURL("http://www.google.com")); - std::vector<bookmark_utils::TitleMatch> matches; + std::vector<BookmarkTitleMatch> matches; model_->GetBookmarksWithTitlesMatching(ASCIIToUTF16("i"), 100, &matches); ASSERT_EQ(1U, matches.size()); EXPECT_TRUE(matches[0].node == n1); @@ -291,7 +292,7 @@ TEST_F(BookmarkIndexTest, GetResultsSortedByTypedCount) { EXPECT_EQ(data[3].title, UTF16ToUTF8(result4.title())); // Populate match nodes. - std::vector<bookmark_utils::TitleMatch> matches; + std::vector<BookmarkTitleMatch> matches; model->GetBookmarksWithTitlesMatching(ASCIIToUTF16("google"), 4, &matches); // The resulting order should be: diff --git a/chrome/browser/bookmarks/bookmark_model.cc b/chrome/browser/bookmarks/bookmark_model.cc index bfa9ab2..bdef521 100644 --- a/chrome/browser/bookmarks/bookmark_model.cc +++ b/chrome/browser/bookmarks/bookmark_model.cc @@ -20,6 +20,7 @@ #include "chrome/browser/bookmarks/bookmark_index.h" #include "chrome/browser/bookmarks/bookmark_model_observer.h" #include "chrome/browser/bookmarks/bookmark_storage.h" +#include "chrome/browser/bookmarks/bookmark_title_match.h" #include "chrome/browser/bookmarks/bookmark_utils.h" #include "chrome/browser/favicon/favicon_changed_details.h" #include "chrome/browser/favicon/favicon_service.h" @@ -658,7 +659,7 @@ void BookmarkModel::ResetDateFolderModified(const BookmarkNode* node) { void BookmarkModel::GetBookmarksWithTitlesMatching( const string16& text, size_t max_count, - std::vector<bookmark_utils::TitleMatch>* matches) { + std::vector<BookmarkTitleMatch>* matches) { if (!loaded_) return; diff --git a/chrome/browser/bookmarks/bookmark_model.h b/chrome/browser/bookmarks/bookmark_model.h index 7205561..f55b8be 100644 --- a/chrome/browser/bookmarks/bookmark_model.h +++ b/chrome/browser/bookmarks/bookmark_model.h @@ -31,16 +31,13 @@ class BookmarkLoadDetails; class BookmarkModel; class BookmarkModelObserver; class BookmarkStorage; +struct BookmarkTitleMatch; class Profile; namespace base { class SequencedTaskRunner; } -namespace bookmark_utils { -struct TitleMatch; -} - namespace chrome { struct FaviconImageResult; } @@ -383,7 +380,7 @@ class BookmarkModel : public content::NotificationObserver, void GetBookmarksWithTitlesMatching( const string16& text, size_t max_count, - std::vector<bookmark_utils::TitleMatch>* matches); + std::vector<BookmarkTitleMatch>* matches); // Sets the store to NULL, making it so the BookmarkModel does not persist // any changes to disk. This is only useful during testing to speed up diff --git a/chrome/browser/bookmarks/bookmark_title_match.cc b/chrome/browser/bookmarks/bookmark_title_match.cc new file mode 100644 index 0000000..92cd790 --- /dev/null +++ b/chrome/browser/bookmarks/bookmark_title_match.cc @@ -0,0 +1,9 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/bookmarks/bookmark_title_match.h" + +BookmarkTitleMatch::BookmarkTitleMatch() : node(NULL) {} + +BookmarkTitleMatch::~BookmarkTitleMatch() {} diff --git a/chrome/browser/bookmarks/bookmark_title_match.h b/chrome/browser/bookmarks/bookmark_title_match.h new file mode 100644 index 0000000..334c66e --- /dev/null +++ b/chrome/browser/bookmarks/bookmark_title_match.h @@ -0,0 +1,31 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_BOOKMARKS_BOOKMARK_TITLE_MATCH_H_ +#define CHROME_BROWSER_BOOKMARKS_BOOKMARK_TITLE_MATCH_H_ + +#include <stddef.h> + +#include <utility> +#include <vector> + +class BookmarkNode; + +struct BookmarkTitleMatch { + // Each MatchPosition is the [begin, end) positions of a match within a + // string. + typedef std::pair<size_t, size_t> MatchPosition; + typedef std::vector<MatchPosition> MatchPositions; + + BookmarkTitleMatch(); + ~BookmarkTitleMatch(); + + // The matching node of a query. + const BookmarkNode* node; + + // Location of the matching words in the title of the node. + MatchPositions match_positions; +}; + +#endif // CHROME_BROWSER_BOOKMARKS_BOOKMARK_TITLE_MATCH_H_ diff --git a/chrome/browser/bookmarks/bookmark_utils.cc b/chrome/browser/bookmarks/bookmark_utils.cc index e3624e7..9c92535 100644 --- a/chrome/browser/bookmarks/bookmark_utils.cc +++ b/chrome/browser/bookmarks/bookmark_utils.cc @@ -232,12 +232,6 @@ void GetMostRecentlyAddedEntries(BookmarkModel* model, } } -TitleMatch::TitleMatch() - : node(NULL) { -} - -TitleMatch::~TitleMatch() {} - bool MoreRecentlyAdded(const BookmarkNode* n1, const BookmarkNode* n2) { return n1->date_added() > n2->date_added(); } diff --git a/chrome/browser/bookmarks/bookmark_utils.h b/chrome/browser/bookmarks/bookmark_utils.h index 3bb4ab5..8d53450 100644 --- a/chrome/browser/bookmarks/bookmark_utils.h +++ b/chrome/browser/bookmarks/bookmark_utils.h @@ -11,7 +11,6 @@ #include "base/string16.h" #include "chrome/browser/bookmarks/bookmark_editor.h" #include "chrome/browser/bookmarks/bookmark_node_data.h" -#include "chrome/browser/history/snippet.h" class BookmarkModel; class BookmarkNode; @@ -59,18 +58,6 @@ void GetMostRecentlyAddedEntries(BookmarkModel* model, size_t count, std::vector<const BookmarkNode*>* nodes); -// Used by GetBookmarksMatchingText to return a matching node and the location -// of the match in the title. -struct TitleMatch { - TitleMatch(); - ~TitleMatch(); - - const BookmarkNode* node; - - // Location of the matching words in the title of the node. - Snippet::MatchPositions match_positions; -}; - // Returns true if |n1| was added more recently than |n2|. bool MoreRecentlyAdded(const BookmarkNode* n1, const BookmarkNode* n2); |