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

Side by Side Diff: components/omnibox/browser/bookmark_provider.cc

Issue 2537223008: Add TitledUrlIndex for indexing arbitrary title/URL pairs (Closed)
Patch Set: const Created 4 years 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
« no previous file with comments | « components/bookmarks/browser/titled_url_node.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "components/omnibox/browser/bookmark_provider.h" 5 #include "components/omnibox/browser/bookmark_provider.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <functional> 8 #include <functional>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "base/trace_event/trace_event.h" 14 #include "base/trace_event/trace_event.h"
15 #include "components/bookmarks/browser/bookmark_match.h" 15 #include "components/bookmarks/browser/bookmark_match.h"
16 #include "components/bookmarks/browser/bookmark_model.h" 16 #include "components/bookmarks/browser/bookmark_model.h"
17 #include "components/metrics/proto/omnibox_input_type.pb.h" 17 #include "components/metrics/proto/omnibox_input_type.pb.h"
18 #include "components/omnibox/browser/autocomplete_provider_client.h" 18 #include "components/omnibox/browser/autocomplete_provider_client.h"
19 #include "components/omnibox/browser/autocomplete_result.h" 19 #include "components/omnibox/browser/autocomplete_result.h"
20 #include "components/omnibox/browser/history_provider.h" 20 #include "components/omnibox/browser/history_provider.h"
21 #include "components/omnibox/browser/url_prefix.h" 21 #include "components/omnibox/browser/url_prefix.h"
22 #include "components/prefs/pref_service.h" 22 #include "components/prefs/pref_service.h"
23 #include "components/url_formatter/url_formatter.h" 23 #include "components/url_formatter/url_formatter.h"
24 #include "url/url_constants.h" 24 #include "url/url_constants.h"
25 25
26 using bookmarks::BookmarkMatch; 26 using bookmarks::BookmarkMatch;
27 using BookmarkMatches = std::vector<BookmarkMatch>;
27 using bookmarks::BookmarkNode; 28 using bookmarks::BookmarkNode;
28 29
29 typedef std::vector<BookmarkMatch> BookmarkMatches;
30
31 namespace { 30 namespace {
32 31
33 // Removes leading spaces from |title| before displaying, otherwise it looks 32 // Removes leading spaces from |title| before displaying, otherwise it looks
34 // funny. In the process, corrects |title_match_positions| so the correct 33 // funny. In the process, corrects |title_match_positions| so the correct
35 // characters are highlighted. 34 // characters are highlighted.
36 void CorrectTitleAndMatchPositions( 35 void CorrectTitleAndMatchPositions(
37 base::string16* title, 36 base::string16* title,
38 BookmarkMatch::MatchPositions* title_match_positions) { 37 BookmarkMatch::MatchPositions* title_match_positions) {
39 size_t leading_whitespace_chars = title->length(); 38 size_t leading_whitespace_chars = title->length();
40 base::TrimWhitespace(*title, base::TRIM_LEADING, title); 39 base::TrimWhitespace(*title, base::TRIM_LEADING, title);
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 157
159 AutocompleteMatch BookmarkProvider::BookmarkMatchToACMatch( 158 AutocompleteMatch BookmarkProvider::BookmarkMatchToACMatch(
160 const AutocompleteInput& input, 159 const AutocompleteInput& input,
161 const base::string16& fixed_up_input_text, 160 const base::string16& fixed_up_input_text,
162 const BookmarkMatch& bookmark_match) { 161 const BookmarkMatch& bookmark_match) {
163 // The AutocompleteMatch we construct is non-deletable because the only 162 // The AutocompleteMatch we construct is non-deletable because the only
164 // way to support this would be to delete the underlying bookmark, which is 163 // way to support this would be to delete the underlying bookmark, which is
165 // unlikely to be what the user intends. 164 // unlikely to be what the user intends.
166 AutocompleteMatch match(this, 0, false, 165 AutocompleteMatch match(this, 0, false,
167 AutocompleteMatchType::BOOKMARK_TITLE); 166 AutocompleteMatchType::BOOKMARK_TITLE);
168 base::string16 title(bookmark_match.node->GetTitle()); 167 base::string16 title(bookmark_match.node->GetTitledUrlNodeTitle());
169 BookmarkMatch::MatchPositions new_title_match_positions = 168 BookmarkMatch::MatchPositions new_title_match_positions =
170 bookmark_match.title_match_positions; 169 bookmark_match.title_match_positions;
171 CorrectTitleAndMatchPositions(&title, &new_title_match_positions); 170 CorrectTitleAndMatchPositions(&title, &new_title_match_positions);
172 const GURL& url(bookmark_match.node->url()); 171 const GURL& url(bookmark_match.node->GetTitledUrlNodeUrl());
173 const base::string16& url_utf16 = base::UTF8ToUTF16(url.spec()); 172 const base::string16& url_utf16 = base::UTF8ToUTF16(url.spec());
174 size_t inline_autocomplete_offset = URLPrefix::GetInlineAutocompleteOffset( 173 size_t inline_autocomplete_offset = URLPrefix::GetInlineAutocompleteOffset(
175 input.text(), fixed_up_input_text, false, url_utf16); 174 input.text(), fixed_up_input_text, false, url_utf16);
176 match.destination_url = url; 175 match.destination_url = url;
177 const size_t match_start = bookmark_match.url_match_positions.empty() ? 176 const size_t match_start = bookmark_match.url_match_positions.empty() ?
178 0 : bookmark_match.url_match_positions[0].first; 177 0 : bookmark_match.url_match_positions[0].first;
179 const bool trim_http = !AutocompleteInput::HasHTTPScheme(input.text()) && 178 const bool trim_http = !AutocompleteInput::HasHTTPScheme(input.text()) &&
180 ((match_start == base::string16::npos) || (match_start != 0)); 179 ((match_start == base::string16::npos) || (match_start != 0));
181 std::vector<size_t> offsets = BookmarkMatch::OffsetsFromMatchPositions( 180 std::vector<size_t> offsets = BookmarkMatch::OffsetsFromMatchPositions(
182 bookmark_match.url_match_positions); 181 bookmark_match.url_match_positions);
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 // Pretend empty titles are identical to the URL. 273 // Pretend empty titles are identical to the URL.
275 if (title.empty()) 274 if (title.empty())
276 title = base::ASCIIToUTF16(url.spec()); 275 title = base::ASCIIToUTF16(url.spec());
277 ScoringFunctor title_position_functor = 276 ScoringFunctor title_position_functor =
278 for_each(bookmark_match.title_match_positions.begin(), 277 for_each(bookmark_match.title_match_positions.begin(),
279 bookmark_match.title_match_positions.end(), 278 bookmark_match.title_match_positions.end(),
280 ScoringFunctor(title.size())); 279 ScoringFunctor(title.size()));
281 ScoringFunctor url_position_functor = 280 ScoringFunctor url_position_functor =
282 for_each(bookmark_match.url_match_positions.begin(), 281 for_each(bookmark_match.url_match_positions.begin(),
283 bookmark_match.url_match_positions.end(), 282 bookmark_match.url_match_positions.end(),
284 ScoringFunctor(bookmark_match.node->url().spec().length())); 283 ScoringFunctor(
284 bookmark_match.node->GetTitledUrlNodeUrl().spec().length()));
285 const double title_match_strength = title_position_functor.ScoringFactor(); 285 const double title_match_strength = title_position_functor.ScoringFactor();
286 const double summed_factors = title_match_strength + 286 const double summed_factors = title_match_strength +
287 url_position_functor.ScoringFactor(); 287 url_position_functor.ScoringFactor();
288 const double normalized_sum = 288 const double normalized_sum =
289 std::min(summed_factors / (title.size() + 10), 1.0); 289 std::min(summed_factors / (title.size() + 10), 1.0);
290 // Bookmarks with javascript scheme ("bookmarklets") that do not have title 290 // Bookmarks with javascript scheme ("bookmarklets") that do not have title
291 // matches get a lower base and lower maximum score because returning them 291 // matches get a lower base and lower maximum score because returning them
292 // for matches in their (often very long) URL looks stupid and is often not 292 // for matches in their (often very long) URL looks stupid and is often not
293 // intended by the user. 293 // intended by the user.
294 const bool bookmarklet_without_title_match = 294 const bool bookmarklet_without_title_match =
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 i != positions.end(); 333 i != positions.end();
334 ++i) { 334 ++i) {
335 AutocompleteMatch::ACMatchClassifications new_class; 335 AutocompleteMatch::ACMatchClassifications new_class;
336 AutocompleteMatch::ClassifyLocationInString(i->first, i->second - i->first, 336 AutocompleteMatch::ClassifyLocationInString(i->first, i->second - i->first,
337 text_length, url_style, &new_class); 337 text_length, url_style, &new_class);
338 classifications = AutocompleteMatch::MergeClassifications( 338 classifications = AutocompleteMatch::MergeClassifications(
339 classifications, new_class); 339 classifications, new_class);
340 } 340 }
341 return classifications; 341 return classifications;
342 } 342 }
OLDNEW
« no previous file with comments | « components/bookmarks/browser/titled_url_node.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698