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

Side by Side Diff: chrome/browser/history/url_index_private_data.cc

Issue 11757004: Omnibox: Add Mid-Input Matching to HistoryQuick Provider (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Actual code + Peter's comments. Created 7 years, 11 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/history/url_index_private_data.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 "chrome/browser/history/url_index_private_data.h" 5 #include "chrome/browser/history/url_index_private_data.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <functional> 8 #include <functional>
9 #include <iterator> 9 #include <iterator>
10 #include <limits> 10 #include <limits>
11 #include <numeric> 11 #include <numeric>
12 #include <string>
12 #include <vector> 13 #include <vector>
13 14
14 #include "base/basictypes.h" 15 #include "base/basictypes.h"
15 #include "base/file_util.h" 16 #include "base/file_util.h"
16 #include "base/i18n/case_conversion.h" 17 #include "base/i18n/case_conversion.h"
17 #include "base/metrics/histogram.h" 18 #include "base/metrics/histogram.h"
18 #include "base/string_util.h" 19 #include "base/string_util.h"
19 #include "base/time.h" 20 #include "base/time.h"
20 #include "base/utf_string_conversions.h" 21 #include "base/utf_string_conversions.h"
21 #include "chrome/browser/api/bookmarks/bookmark_service.h" 22 #include "chrome/browser/api/bookmarks/bookmark_service.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 URLIndexPrivateData::URLIndexPrivateData() 72 URLIndexPrivateData::URLIndexPrivateData()
72 : restored_cache_version_(0), 73 : restored_cache_version_(0),
73 saved_cache_version_(kCurrentCacheFileVersion), 74 saved_cache_version_(kCurrentCacheFileVersion),
74 pre_filter_item_count_(0), 75 pre_filter_item_count_(0),
75 post_filter_item_count_(0), 76 post_filter_item_count_(0),
76 post_scoring_item_count_(0) { 77 post_scoring_item_count_(0) {
77 } 78 }
78 79
79 ScoredHistoryMatches URLIndexPrivateData::HistoryItemsForTerms( 80 ScoredHistoryMatches URLIndexPrivateData::HistoryItemsForTerms(
80 const string16& search_string, 81 const string16& search_string,
82 size_t cursor_position,
81 BookmarkService* bookmark_service) { 83 BookmarkService* bookmark_service) {
84 // If cursor position is set and useful (not at either end of the string),
85 // allow the search string to be broken at cursor position. We do this
86 // by pretending there's a space where the cursor is.
87 // TODO(figure out highlighting).
88 const string16& search_string_with_cursor =
89 ((cursor_position != string16::npos) &&
90 (cursor_position < search_string.length()) &&
91 (cursor_position > 0)) ?
92 search_string.substr(0, cursor_position) + kWhitespaceUTF16 +
Peter Kasting 2013/01/04 23:47:39 This doesn't insert a space, it inserts a whole st
Mark P 2013/01/09 19:51:53 Done.
93 search_string.substr(cursor_position) : search_string;
82 pre_filter_item_count_ = 0; 94 pre_filter_item_count_ = 0;
83 post_filter_item_count_ = 0; 95 post_filter_item_count_ = 0;
84 post_scoring_item_count_ = 0; 96 post_scoring_item_count_ = 0;
85 // The search string we receive may contain escaped characters. For reducing 97 // The search string we receive may contain escaped characters. For reducing
86 // the index we need individual, lower-cased words, ignoring escapings. For 98 // the index we need individual, lower-cased words, ignoring escapings. For
87 // the final filtering we need whitespace separated substrings possibly 99 // the final filtering we need whitespace separated substrings possibly
88 // containing escaped characters. 100 // containing escaped characters.
89 string16 lower_raw_string(base::i18n::ToLower(search_string)); 101 string16 lower_raw_string(base::i18n::ToLower(search_string_with_cursor));
90 string16 lower_unescaped_string = 102 string16 lower_unescaped_string =
91 net::UnescapeURLComponent(lower_raw_string, 103 net::UnescapeURLComponent(lower_raw_string,
92 net::UnescapeRule::SPACES | net::UnescapeRule::URL_SPECIAL_CHARS); 104 net::UnescapeRule::SPACES | net::UnescapeRule::URL_SPECIAL_CHARS);
93 // Extract individual 'words' (as opposed to 'terms'; see below) from the 105 // Extract individual 'words' (as opposed to 'terms'; see below) from the
94 // search string. When the user types "colspec=ID%20Mstone Release" we get 106 // search string. When the user types "colspec=ID%20Mstone Release" we get
95 // four 'words': "colspec", "id", "mstone" and "release". 107 // four 'words': "colspec", "id", "mstone" and "release".
96 String16Vector lower_words( 108 String16Vector lower_words(
97 history::String16VectorFromString16(lower_unescaped_string, false, NULL)); 109 history::String16VectorFromString16(lower_unescaped_string, false, NULL));
98 ScoredHistoryMatches scored_items; 110 ScoredHistoryMatches scored_items;
99 111
(...skipping 1053 matching lines...) Expand 10 before | Expand all | Expand 10 after
1153 } 1165 }
1154 1166
1155 // static 1167 // static
1156 bool URLIndexPrivateData::URLSchemeIsWhitelisted( 1168 bool URLIndexPrivateData::URLSchemeIsWhitelisted(
1157 const GURL& gurl, 1169 const GURL& gurl,
1158 const std::set<std::string>& whitelist) { 1170 const std::set<std::string>& whitelist) {
1159 return whitelist.find(gurl.scheme()) != whitelist.end(); 1171 return whitelist.find(gurl.scheme()) != whitelist.end();
1160 } 1172 }
1161 1173
1162 } // namespace history 1174 } // namespace history
OLDNEW
« no previous file with comments | « chrome/browser/history/url_index_private_data.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698