summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/BUILD.gn2
-rw-r--r--chrome/browser/autocomplete/BUILD.gn12
-rw-r--r--chrome/browser/autocomplete/history_provider.cc2
-rw-r--r--chrome/browser/autocomplete/history_provider.h2
-rw-r--r--chrome/browser/autocomplete/history_quick_provider.cc4
-rw-r--r--chrome/browser/autocomplete/history_quick_provider.h2
-rw-r--r--chrome/browser/autocomplete/history_quick_provider_unittest.cc4
-rw-r--r--chrome/browser/autocomplete/history_url_provider.cc2
-rw-r--r--chrome/browser/autocomplete/in_memory_url_index.cc (renamed from chrome/browser/history/in_memory_url_index.cc)4
-rw-r--r--chrome/browser/autocomplete/in_memory_url_index.h (renamed from chrome/browser/history/in_memory_url_index.h)10
-rw-r--r--chrome/browser/autocomplete/in_memory_url_index_cache.proto103
-rw-r--r--chrome/browser/autocomplete/in_memory_url_index_types.cc163
-rw-r--r--chrome/browser/autocomplete/in_memory_url_index_types.h179
-rw-r--r--chrome/browser/autocomplete/in_memory_url_index_types_unittest.cc150
-rw-r--r--chrome/browser/autocomplete/in_memory_url_index_unittest.cc (renamed from chrome/browser/history/in_memory_url_index_unittest.cc)6
-rw-r--r--chrome/browser/autocomplete/scored_history_match.cc72
-rw-r--r--chrome/browser/autocomplete/scored_history_match.h111
-rw-r--r--chrome/browser/autocomplete/scored_history_match_builder_impl.h4
-rw-r--r--chrome/browser/autocomplete/shortcuts_provider_unittest.cc2
-rw-r--r--chrome/browser/autocomplete/url_index_private_data.cc (renamed from chrome/browser/history/url_index_private_data.cc)4
-rw-r--r--chrome/browser/autocomplete/url_index_private_data.h (renamed from chrome/browser/history/url_index_private_data.h)12
-rw-r--r--chrome/browser/chromeos/BUILD.gn1
-rw-r--r--chrome/browser/extensions/BUILD.gn1
-rw-r--r--chrome/browser/history/DEPS2
-rw-r--r--chrome/browser/history/history_service.cc2
-rw-r--r--chrome/browser/ui/BUILD.gn1
-rw-r--r--chrome/chrome_browser.gypi26
-rw-r--r--chrome/chrome_browser_chromeos.gypi1
-rw-r--r--chrome/chrome_browser_extensions.gypi1
-rw-r--r--chrome/chrome_browser_ui.gypi1
-rw-r--r--chrome/chrome_tests.gypi1
-rw-r--r--chrome/chrome_tests_unit.gypi2
-rw-r--r--chrome/test/base/history_index_restore_observer.h2
33 files changed, 847 insertions, 44 deletions
diff --git a/chrome/browser/BUILD.gn b/chrome/browser/BUILD.gn
index 9905279..9799cc1 100644
--- a/chrome/browser/BUILD.gn
+++ b/chrome/browser/BUILD.gn
@@ -74,6 +74,7 @@ static_library("browser") {
"//chrome/app:generated_resources_map",
"//chrome/app/resources:platform_locale_settings",
"//chrome/app/theme:theme_resources",
+ "//chrome/browser/autocomplete:in_memory_url_index_cache_proto",
"//chrome/browser/net:cert_logger_proto",
"//chrome/browser/net:probe_message_proto",
"//chrome/browser/ui",
@@ -98,7 +99,6 @@ static_library("browser") {
"//components/google/core/browser",
"//components/handoff",
"//components/history/core/browser",
- "//components/history/core/browser:proto",
"//components/history/core/common",
"//components/infobars/core",
"//components/invalidation",
diff --git a/chrome/browser/autocomplete/BUILD.gn b/chrome/browser/autocomplete/BUILD.gn
new file mode 100644
index 0000000..3f09281
--- /dev/null
+++ b/chrome/browser/autocomplete/BUILD.gn
@@ -0,0 +1,12 @@
+# Copyright 2015 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.
+
+import("//third_party/protobuf/proto_library.gni")
+
+# GYP version: chrome/chrome_browser.gypi:in_memory_url_index_cache_proto
+proto_library("in_memory_url_index_cache_proto") {
+ sources = [
+ "in_memory_url_index_cache.proto",
+ ]
+}
diff --git a/chrome/browser/autocomplete/history_provider.cc b/chrome/browser/autocomplete/history_provider.cc
index 7f4d314..6d940bc 100644
--- a/chrome/browser/autocomplete/history_provider.cc
+++ b/chrome/browser/autocomplete/history_provider.cc
@@ -8,13 +8,13 @@
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
+#include "chrome/browser/autocomplete/in_memory_url_index_types.h"
#include "chrome/browser/bookmarks/bookmark_model_factory.h"
#include "chrome/browser/history/history_service.h"
#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/url_constants.h"
#include "components/bookmarks/browser/bookmark_model.h"
-#include "components/history/core/browser/in_memory_url_index_types.h"
#include "components/omnibox/autocomplete_input.h"
#include "components/omnibox/autocomplete_match.h"
#include "url/url_util.h"
diff --git a/chrome/browser/autocomplete/history_provider.h b/chrome/browser/autocomplete/history_provider.h
index ed957ad..53e6dcc 100644
--- a/chrome/browser/autocomplete/history_provider.h
+++ b/chrome/browser/autocomplete/history_provider.h
@@ -6,7 +6,7 @@
#define CHROME_BROWSER_AUTOCOMPLETE_HISTORY_PROVIDER_H_
#include "base/compiler_specific.h"
-#include "components/history/core/browser/in_memory_url_index_types.h"
+#include "chrome/browser/autocomplete/in_memory_url_index_types.h"
#include "components/omnibox/autocomplete_provider.h"
class AutocompleteInput;
diff --git a/chrome/browser/autocomplete/history_quick_provider.cc b/chrome/browser/autocomplete/history_quick_provider.cc
index f961e35..e977ab1 100644
--- a/chrome/browser/autocomplete/history_quick_provider.cc
+++ b/chrome/browser/autocomplete/history_quick_provider.cc
@@ -19,11 +19,12 @@
#include "base/time/time.h"
#include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h"
#include "chrome/browser/autocomplete/history_url_provider.h"
+#include "chrome/browser/autocomplete/in_memory_url_index.h"
+#include "chrome/browser/autocomplete/in_memory_url_index_types.h"
#include "chrome/browser/autocomplete/scored_history_match_builder_impl.h"
#include "chrome/browser/bookmarks/bookmark_model_factory.h"
#include "chrome/browser/history/history_service.h"
#include "chrome/browser/history/history_service_factory.h"
-#include "chrome/browser/history/in_memory_url_index.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/common/chrome_switches.h"
@@ -31,7 +32,6 @@
#include "chrome/common/url_constants.h"
#include "components/bookmarks/browser/bookmark_model.h"
#include "components/history/core/browser/history_database.h"
-#include "components/history/core/browser/in_memory_url_index_types.h"
#include "components/metrics/proto/omnibox_input_type.pb.h"
#include "components/omnibox/autocomplete_match_type.h"
#include "components/omnibox/autocomplete_result.h"
diff --git a/chrome/browser/autocomplete/history_quick_provider.h b/chrome/browser/autocomplete/history_quick_provider.h
index 57db8c8..aadbd60 100644
--- a/chrome/browser/autocomplete/history_quick_provider.h
+++ b/chrome/browser/autocomplete/history_quick_provider.h
@@ -10,7 +10,7 @@
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "chrome/browser/autocomplete/history_provider.h"
-#include "chrome/browser/history/in_memory_url_index.h"
+#include "chrome/browser/autocomplete/in_memory_url_index.h"
#include "components/history/core/browser/history_types.h"
#include "components/omnibox/autocomplete_input.h"
#include "components/omnibox/autocomplete_match.h"
diff --git a/chrome/browser/autocomplete/history_quick_provider_unittest.cc b/chrome/browser/autocomplete/history_quick_provider_unittest.cc
index 2345278..44c2bb1 100644
--- a/chrome/browser/autocomplete/history_quick_provider_unittest.cc
+++ b/chrome/browser/autocomplete/history_quick_provider_unittest.cc
@@ -18,12 +18,12 @@
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h"
#include "chrome/browser/autocomplete/history_url_provider.h"
+#include "chrome/browser/autocomplete/in_memory_url_index.h"
+#include "chrome/browser/autocomplete/url_index_private_data.h"
#include "chrome/browser/bookmarks/bookmark_model_factory.h"
#include "chrome/browser/history/history_backend.h"
#include "chrome/browser/history/history_service.h"
#include "chrome/browser/history/history_service_factory.h"
-#include "chrome/browser/history/in_memory_url_index.h"
-#include "chrome/browser/history/url_index_private_data.h"
#include "chrome/browser/search_engines/chrome_template_url_service_client.h"
#include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/test/base/testing_browser_process.h"
diff --git a/chrome/browser/autocomplete/history_url_provider.cc b/chrome/browser/autocomplete/history_url_provider.cc
index ccfce94..4b865e7 100644
--- a/chrome/browser/autocomplete/history_url_provider.cc
+++ b/chrome/browser/autocomplete/history_url_provider.cc
@@ -16,6 +16,7 @@
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h"
+#include "chrome/browser/autocomplete/in_memory_url_index_types.h"
#include "chrome/browser/autocomplete/scored_history_match_builder_impl.h"
#include "chrome/browser/history/history_backend.h"
#include "chrome/browser/history/history_service.h"
@@ -29,7 +30,6 @@
#include "components/bookmarks/browser/bookmark_utils.h"
#include "components/history/core/browser/history_database.h"
#include "components/history/core/browser/history_types.h"
-#include "components/history/core/browser/in_memory_url_index_types.h"
#include "components/metrics/proto/omnibox_input_type.pb.h"
#include "components/omnibox/autocomplete_match.h"
#include "components/omnibox/autocomplete_provider_listener.h"
diff --git a/chrome/browser/history/in_memory_url_index.cc b/chrome/browser/autocomplete/in_memory_url_index.cc
index e3c2a91..8c84c1a 100644
--- a/chrome/browser/history/in_memory_url_index.cc
+++ b/chrome/browser/autocomplete/in_memory_url_index.cc
@@ -2,13 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/history/in_memory_url_index.h"
+#include "chrome/browser/autocomplete/in_memory_url_index.h"
#include "base/files/file_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/trace_event/trace_event.h"
+#include "chrome/browser/autocomplete/url_index_private_data.h"
#include "chrome/browser/history/history_service.h"
-#include "chrome/browser/history/url_index_private_data.h"
#include "chrome/common/url_constants.h"
#include "components/history/core/browser/url_database.h"
#include "content/public/browser/browser_thread.h"
diff --git a/chrome/browser/history/in_memory_url_index.h b/chrome/browser/autocomplete/in_memory_url_index.h
index fa1647f..ec5d588 100644
--- a/chrome/browser/history/in_memory_url_index.h
+++ b/chrome/browser/autocomplete/in_memory_url_index.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef CHROME_BROWSER_HISTORY_IN_MEMORY_URL_INDEX_H_
-#define CHROME_BROWSER_HISTORY_IN_MEMORY_URL_INDEX_H_
+#ifndef CHROME_BROWSER_AUTOCOMPLETE_IN_MEMORY_URL_INDEX_H_
+#define CHROME_BROWSER_AUTOCOMPLETE_IN_MEMORY_URL_INDEX_H_
#include <functional>
#include <map>
@@ -18,10 +18,10 @@
#include "base/memory/weak_ptr.h"
#include "base/strings/string16.h"
#include "base/task/cancelable_task_tracker.h"
+#include "chrome/browser/autocomplete/scored_history_match.h"
#include "components/history/core/browser/history_db_task.h"
#include "components/history/core/browser/history_service_observer.h"
#include "components/history/core/browser/history_types.h"
-#include "components/history/core/browser/scored_history_match.h"
#include "sql/connection.h"
class HistoryService;
@@ -294,7 +294,7 @@ class InMemoryURLIndex : public HistoryServiceObserver,
// index has been destructed.
bool needs_to_be_cached_;
- // This flag is set to true,if we want to listen to the
+ // This flag is set to true if we want to listen to the
// HistoryServiceLoaded Notification.
bool listen_to_history_service_loaded_;
@@ -303,4 +303,4 @@ class InMemoryURLIndex : public HistoryServiceObserver,
} // namespace history
-#endif // CHROME_BROWSER_HISTORY_IN_MEMORY_URL_INDEX_H_
+#endif // CHROME_BROWSER_AUTOCOMPLETE_IN_MEMORY_URL_INDEX_H_
diff --git a/chrome/browser/autocomplete/in_memory_url_index_cache.proto b/chrome/browser/autocomplete/in_memory_url_index_cache.proto
new file mode 100644
index 0000000..df2de1b
--- /dev/null
+++ b/chrome/browser/autocomplete/in_memory_url_index_cache.proto
@@ -0,0 +1,103 @@
+// Copyright (c) 2011 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.
+//
+// InMemoryURLIndex caching protocol buffers.
+//
+// At certain times during browser operation, the indexes from the
+// InMemoryURLIndex are written to a disk-based cache using the
+// following protobuf description.
+
+syntax = "proto2";
+
+option optimize_for = LITE_RUNTIME;
+
+package in_memory_url_index;
+
+message InMemoryURLIndexCacheItem {
+
+ message WordListItem {
+ required uint32 word_count = 1;
+ repeated string word = 2;
+ }
+
+ message WordMapItem {
+ message WordMapEntry {
+ required string word = 1;
+ required int32 word_id = 2;
+ }
+
+ required uint32 item_count = 1;
+ repeated WordMapEntry word_map_entry = 2;
+ }
+
+ message CharWordMapItem {
+ message CharWordMapEntry {
+ required uint32 item_count = 1;
+ required int32 char_16 = 2;
+ repeated int32 word_id = 3 [packed=true];
+ }
+
+ required uint32 item_count = 1;
+ repeated CharWordMapEntry char_word_map_entry = 2;
+ }
+
+ message WordIDHistoryMapItem {
+ message WordIDHistoryMapEntry {
+ required uint32 item_count = 1;
+ required int32 word_id = 2;
+ repeated int64 history_id = 3 [packed=true];
+ }
+
+ required uint32 item_count = 1;
+ repeated WordIDHistoryMapEntry word_id_history_map_entry = 2;
+ }
+
+ message HistoryInfoMapItem {
+ message HistoryInfoMapEntry {
+ message VisitInfo {
+ required int64 visit_time = 1;
+ // Corresponds to ui::PageTransition.
+ required uint64 transition_type = 2;
+ }
+ required int64 history_id = 1;
+ required int32 visit_count = 2;
+ required int32 typed_count = 3;
+ required int64 last_visit = 4;
+ required string url = 5;
+ optional string title = 6;
+ repeated VisitInfo visits = 7;
+ }
+
+ required uint32 item_count = 1;
+ repeated HistoryInfoMapEntry history_info_map_entry = 2;
+ }
+
+ message WordStartsMapItem {
+ message WordStartsMapEntry {
+ required int64 history_id = 1;
+ repeated int32 url_word_starts = 2 [packed=true];
+ repeated int32 title_word_starts = 3 [packed=true];
+ }
+
+ required uint32 item_count = 1;
+ repeated WordStartsMapEntry word_starts_map_entry = 2;
+ }
+
+ // The date that the cache was last rebuilt from history. Note that
+ // this cache may include items that were visited after this date if
+ // the InMemoryURLIndex was updated on the fly. This timestamp is meant
+ // to indicate the last date the index was rebuilt from the ground truth:
+ // the history database on disk.
+ required int64 last_rebuild_timestamp = 1;
+ // If there is no version we'll assume version 0.
+ optional int32 version = 2;
+ required int32 history_item_count = 3;
+
+ optional WordListItem word_list = 4;
+ optional WordMapItem word_map = 5;
+ optional CharWordMapItem char_word_map = 6;
+ optional WordIDHistoryMapItem word_id_history_map = 7;
+ optional HistoryInfoMapItem history_info_map = 8;
+ optional WordStartsMapItem word_starts_map = 9;
+}
diff --git a/chrome/browser/autocomplete/in_memory_url_index_types.cc b/chrome/browser/autocomplete/in_memory_url_index_types.cc
new file mode 100644
index 0000000..bb64822
--- /dev/null
+++ b/chrome/browser/autocomplete/in_memory_url_index_types.cc
@@ -0,0 +1,163 @@
+// Copyright (c) 2012 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/autocomplete/in_memory_url_index_types.h"
+
+#include <algorithm>
+#include <functional>
+#include <iterator>
+#include <numeric>
+#include <set>
+
+#include "base/i18n/break_iterator.h"
+#include "base/i18n/case_conversion.h"
+#include "base/strings/string_util.h"
+#include "net/base/escape.h"
+#include "net/base/net_util.h"
+
+namespace history {
+
+// Matches within URL and Title Strings ----------------------------------------
+
+TermMatches MatchTermInString(const base::string16& term,
+ const base::string16& cleaned_string,
+ int term_num) {
+ const size_t kMaxCompareLength = 2048;
+ const base::string16& short_string =
+ (cleaned_string.length() > kMaxCompareLength) ?
+ cleaned_string.substr(0, kMaxCompareLength) : cleaned_string;
+ TermMatches matches;
+ for (size_t location = short_string.find(term);
+ location != base::string16::npos;
+ location = short_string.find(term, location + 1))
+ matches.push_back(TermMatch(term_num, location, term.length()));
+ return matches;
+}
+
+// Comparison function for sorting TermMatches by their offsets.
+bool MatchOffsetLess(const TermMatch& m1, const TermMatch& m2) {
+ return m1.offset < m2.offset;
+}
+
+TermMatches SortAndDeoverlapMatches(const TermMatches& matches) {
+ if (matches.empty())
+ return matches;
+ TermMatches sorted_matches = matches;
+ std::sort(sorted_matches.begin(), sorted_matches.end(), MatchOffsetLess);
+ TermMatches clean_matches;
+ TermMatch last_match;
+ for (TermMatches::const_iterator iter = sorted_matches.begin();
+ iter != sorted_matches.end(); ++iter) {
+ if (iter->offset >= last_match.offset + last_match.length) {
+ last_match = *iter;
+ clean_matches.push_back(last_match);
+ }
+ }
+ return clean_matches;
+}
+
+std::vector<size_t> OffsetsFromTermMatches(const TermMatches& matches) {
+ std::vector<size_t> offsets;
+ for (TermMatches::const_iterator i = matches.begin(); i != matches.end();
+ ++i) {
+ offsets.push_back(i->offset);
+ offsets.push_back(i->offset + i->length);
+ }
+ return offsets;
+}
+
+TermMatches ReplaceOffsetsInTermMatches(const TermMatches& matches,
+ const std::vector<size_t>& offsets) {
+ DCHECK_EQ(2 * matches.size(), offsets.size());
+ TermMatches new_matches;
+ std::vector<size_t>::const_iterator offset_iter = offsets.begin();
+ for (TermMatches::const_iterator term_iter = matches.begin();
+ term_iter != matches.end(); ++term_iter, ++offset_iter) {
+ const size_t starting_offset = *offset_iter;
+ ++offset_iter;
+ const size_t ending_offset = *offset_iter;
+ if ((starting_offset != base::string16::npos) &&
+ (ending_offset != base::string16::npos) &&
+ (starting_offset != ending_offset)) {
+ TermMatch new_match(*term_iter);
+ new_match.offset = starting_offset;
+ new_match.length = ending_offset - starting_offset;
+ new_matches.push_back(new_match);
+ }
+ }
+ return new_matches;
+}
+
+// Utility Functions -----------------------------------------------------------
+
+String16Set String16SetFromString16(const base::string16& cleaned_uni_string,
+ WordStarts* word_starts) {
+ String16Vector words =
+ String16VectorFromString16(cleaned_uni_string, false, word_starts);
+ String16Set word_set;
+ for (String16Vector::const_iterator iter = words.begin(); iter != words.end();
+ ++iter)
+ word_set.insert(base::i18n::ToLower(*iter).substr(0, kMaxSignificantChars));
+ return word_set;
+}
+
+String16Vector String16VectorFromString16(
+ const base::string16& cleaned_uni_string,
+ bool break_on_space,
+ WordStarts* word_starts) {
+ if (word_starts)
+ word_starts->clear();
+ base::i18n::BreakIterator iter(cleaned_uni_string,
+ break_on_space ? base::i18n::BreakIterator::BREAK_SPACE :
+ base::i18n::BreakIterator::BREAK_WORD);
+ String16Vector words;
+ if (!iter.Init())
+ return words;
+ while (iter.Advance()) {
+ if (break_on_space || iter.IsWord()) {
+ base::string16 word(iter.GetString());
+ size_t initial_whitespace = 0;
+ if (break_on_space) {
+ base::string16 trimmed_word;
+ base::TrimWhitespace(word, base::TRIM_LEADING, &trimmed_word);
+ initial_whitespace = word.length() - trimmed_word.length();
+ base::TrimWhitespace(trimmed_word, base::TRIM_TRAILING, &word);
+ }
+ if (word.empty())
+ continue;
+ words.push_back(word);
+ if (!word_starts)
+ continue;
+ size_t word_start = iter.prev() + initial_whitespace;
+ if (word_start < kMaxSignificantChars)
+ word_starts->push_back(word_start);
+ }
+ }
+ return words;
+}
+
+Char16Set Char16SetFromString16(const base::string16& term) {
+ Char16Set characters;
+ for (base::string16::const_iterator iter = term.begin(); iter != term.end();
+ ++iter)
+ characters.insert(*iter);
+ return characters;
+}
+
+// HistoryInfoMapValue ---------------------------------------------------------
+
+HistoryInfoMapValue::HistoryInfoMapValue() {}
+HistoryInfoMapValue::~HistoryInfoMapValue() {}
+
+// RowWordStarts ---------------------------------------------------------------
+
+RowWordStarts::RowWordStarts() {}
+RowWordStarts::~RowWordStarts() {}
+
+void RowWordStarts::Clear() {
+ url_word_starts_.clear();
+ title_word_starts_.clear();
+}
+
+} // namespace history
diff --git a/chrome/browser/autocomplete/in_memory_url_index_types.h b/chrome/browser/autocomplete/in_memory_url_index_types.h
new file mode 100644
index 0000000..ad2153a
--- /dev/null
+++ b/chrome/browser/autocomplete/in_memory_url_index_types.h
@@ -0,0 +1,179 @@
+// Copyright (c) 2012 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_AUTOCOMPLETE_IN_MEMORY_URL_INDEX_TYPES_H_
+#define CHROME_BROWSER_AUTOCOMPLETE_IN_MEMORY_URL_INDEX_TYPES_H_
+
+#include <map>
+#include <set>
+#include <vector>
+
+#include "base/strings/string16.h"
+#include "components/history/core/browser/history_types.h"
+#include "url/gurl.h"
+
+namespace history {
+
+// The maximum number of characters to consider from an URL and page title
+// while matching user-typed terms.
+const size_t kMaxSignificantChars = 200;
+
+// Matches within URL and Title Strings ----------------------------------------
+
+// Specifies where an omnibox term occurs within a string. Used for specifying
+// highlights in AutocompleteMatches (ACMatchClassifications) and to assist in
+// scoring a result.
+struct TermMatch {
+ TermMatch() : term_num(0), offset(0), length(0) {}
+ TermMatch(int term_num, size_t offset, size_t length)
+ : term_num(term_num),
+ offset(offset),
+ length(length) {}
+
+ int term_num; // The index of the term in the original search string.
+ size_t offset; // The starting offset of the substring match.
+ size_t length; // The length of the substring match.
+};
+typedef std::vector<TermMatch> TermMatches;
+
+// Returns a TermMatches which has an entry for each occurrence of the
+// string |term| found in the string |cleaned_string|. Use
+// CleanUpUrlForMatching() or CleanUpUrlTitleMatching() before passing
+// |cleaned_string| to this function. The function marks each match
+// with |term_num| so that the resulting TermMatches can be merged
+// with other TermMatches for other terms. Note that only the first
+// 2,048 characters of |string| are considered during the match
+// operation.
+TermMatches MatchTermInString(const base::string16& term,
+ const base::string16& cleaned_string,
+ int term_num);
+
+// Sorts and removes overlapping substring matches from |matches| and
+// returns the cleaned up matches.
+TermMatches SortAndDeoverlapMatches(const TermMatches& matches);
+
+// Extracts and returns the offsets from |matches|. This includes both
+// the offsets corresponding to the beginning of a match and the offsets
+// corresponding to the end of a match (i.e., offset+length for that match).
+std::vector<size_t> OffsetsFromTermMatches(const TermMatches& matches);
+
+// Replaces the offsets and lengths in |matches| with those given in |offsets|.
+// |offsets| gives beginning and ending offsets for each match; this function
+// translates (beginning, ending) offset into (beginning offset, length of
+// match). It deletes any matches for which an endpoint is npos and returns
+// the updated list of matches.
+TermMatches ReplaceOffsetsInTermMatches(const TermMatches& matches,
+ const std::vector<size_t>& offsets);
+
+// Convenience Types -----------------------------------------------------------
+
+typedef std::vector<base::string16> String16Vector;
+typedef std::set<base::string16> String16Set;
+typedef std::set<base::char16> Char16Set;
+typedef std::vector<base::char16> Char16Vector;
+
+// A vector that contains the offsets at which each word starts within a string.
+typedef std::vector<size_t> WordStarts;
+
+// Utility Functions -----------------------------------------------------------
+
+// Breaks the string |cleaned_uni_string| down into individual words.
+// Use CleanUpUrlForMatching() or CleanUpUrlTitleMatching() before
+// passing |cleaned_uni_string| to this function. If |word_starts| is
+// not NULL then clears and pushes the offsets within
+// |cleaned_uni_string| at which each word starts onto
+// |word_starts|. These offsets are collected only up to the first
+// kMaxSignificantChars of |cleaned_uni_string|.
+String16Set String16SetFromString16(const base::string16& cleaned_uni_string,
+ WordStarts* word_starts);
+
+// Breaks the |cleaned_uni_string| string down into individual words
+// and return a vector with the individual words in their original
+// order. Use CleanUpUrlForMatching() or CleanUpUrlTitleMatching()
+// before passing |cleaned_uni_string| to this function. If
+// |break_on_space| is false then the resulting list will contain only
+// words containing alpha-numeric characters. If |break_on_space| is
+// true then the resulting list will contain strings broken at
+// whitespace. (|break_on_space| indicates that the
+// BreakIterator::BREAK_SPACE (equivalent to BREAK_LINE) approach is
+// to be used. For a complete description of this algorithm refer to
+// the comments in base/i18n/break_iterator.h.) If |word_starts| is
+// not NULL then clears and pushes the word starts onto |word_starts|.
+//
+// Example:
+// Given: |cleaned_uni_string|: "http://www.google.com/ harry the rabbit."
+// With |break_on_space| false the returned list will contain:
+// "http", "www", "google", "com", "harry", "the", "rabbit"
+// With |break_on_space| true the returned list will contain:
+// "http://", "www.google.com/", "harry", "the", "rabbit."
+String16Vector String16VectorFromString16(
+ const base::string16& cleaned_uni_string,
+ bool break_on_space,
+ WordStarts* word_starts);
+
+// Breaks the |uni_word| string down into its individual characters.
+// Note that this is temporarily intended to work on a single word, but
+// _will_ work on a string of words, perhaps with unexpected results.
+// TODO(mrossetti): Lots of optimizations possible here for not restarting
+// a search if the user is just typing along. Also, change this to uniString
+// and properly handle substring matches, scoring and sorting the results
+// by score. Also, provide the metrics for where the matches occur so that
+// the UI can highlight the matched sections.
+Char16Set Char16SetFromString16(const base::string16& uni_word);
+
+// Support for InMemoryURLIndex Private Data -----------------------------------
+
+// An index into a list of all of the words we have indexed.
+typedef size_t WordID;
+
+// A map allowing a WordID to be determined given a word.
+typedef std::map<base::string16, WordID> WordMap;
+
+// A map from character to the word_ids of words containing that character.
+typedef std::set<WordID> WordIDSet; // An index into the WordList.
+typedef std::map<base::char16, WordIDSet> CharWordIDMap;
+
+// A map from word (by word_id) to history items containing that word.
+typedef URLID HistoryID;
+typedef std::set<HistoryID> HistoryIDSet;
+typedef std::vector<HistoryID> HistoryIDVector;
+typedef std::map<WordID, HistoryIDSet> WordIDHistoryMap;
+typedef std::map<HistoryID, WordIDSet> HistoryIDWordMap;
+
+
+// Information used in scoring a particular URL.
+typedef std::vector<VisitInfo> VisitInfoVector;
+struct HistoryInfoMapValue {
+ HistoryInfoMapValue();
+ ~HistoryInfoMapValue();
+
+ // This field is always populated.
+ URLRow url_row;
+
+ // This field gets filled in asynchronously after a visit. As such,
+ // it's almost always correct. If it's wrong, it's likely to either
+ // be empty (if this URL was recently added to the index) or
+ // slightly out-of-date (one visit behind).
+ VisitInfoVector visits;
+};
+
+// A map from history_id to the history's URL and title.
+typedef std::map<HistoryID, HistoryInfoMapValue> HistoryInfoMap;
+
+// A map from history_id to URL and page title word start metrics.
+struct RowWordStarts {
+ RowWordStarts();
+ ~RowWordStarts();
+
+ // Clears both url_word_starts_ and title_word_starts_.
+ void Clear();
+
+ WordStarts url_word_starts_;
+ WordStarts title_word_starts_;
+};
+typedef std::map<HistoryID, RowWordStarts> WordStartsMap;
+
+} // namespace history
+
+#endif // CHROME_BROWSER_AUTOCOMPLETE_IN_MEMORY_URL_INDEX_TYPES_H_
diff --git a/chrome/browser/autocomplete/in_memory_url_index_types_unittest.cc b/chrome/browser/autocomplete/in_memory_url_index_types_unittest.cc
new file mode 100644
index 0000000..59b05d5
--- /dev/null
+++ b/chrome/browser/autocomplete/in_memory_url_index_types_unittest.cc
@@ -0,0 +1,150 @@
+// Copyright (c) 2012 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/autocomplete/in_memory_url_index_types.h"
+
+#include <algorithm>
+
+#include "base/strings/string16.h"
+#include "base/strings/utf_string_conversions.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using base::UTF8ToUTF16;
+
+namespace history {
+
+// Helper function for verifying that the contents of a C++ iterable container
+// of ints matches a C array ints.
+template <typename T>
+bool IntArraysEqual(const size_t* expected,
+ size_t expected_size,
+ const T& actual) {
+ if (expected_size != actual.size())
+ return false;
+ for (size_t i = 0; i < expected_size; ++i)
+ if (expected[i] != actual[i])
+ return false;
+ return true;
+}
+
+class InMemoryURLIndexTypesTest : public testing::Test {
+};
+
+TEST_F(InMemoryURLIndexTypesTest, StaticFunctions) {
+ // Test String16VectorFromString16
+ base::string16 string_a(
+ base::UTF8ToUTF16("http://www.google.com/ frammy the brammy"));
+ WordStarts actual_starts_a;
+ String16Vector string_vec =
+ String16VectorFromString16(string_a, false, &actual_starts_a);
+ ASSERT_EQ(7U, string_vec.size());
+ // See if we got the words we expected.
+ EXPECT_EQ(UTF8ToUTF16("http"), string_vec[0]);
+ EXPECT_EQ(UTF8ToUTF16("www"), string_vec[1]);
+ EXPECT_EQ(UTF8ToUTF16("google"), string_vec[2]);
+ EXPECT_EQ(UTF8ToUTF16("com"), string_vec[3]);
+ EXPECT_EQ(UTF8ToUTF16("frammy"), string_vec[4]);
+ EXPECT_EQ(UTF8ToUTF16("the"), string_vec[5]);
+ EXPECT_EQ(UTF8ToUTF16("brammy"), string_vec[6]);
+ // Verify the word starts.
+ size_t expected_starts_a[] = {0, 7, 11, 18, 23, 31, 35};
+ EXPECT_TRUE(IntArraysEqual(expected_starts_a, arraysize(expected_starts_a),
+ actual_starts_a));
+
+ WordStarts actual_starts_b;
+ string_vec = String16VectorFromString16(string_a, true, &actual_starts_b);
+ ASSERT_EQ(5U, string_vec.size());
+ EXPECT_EQ(UTF8ToUTF16("http://"), string_vec[0]);
+ EXPECT_EQ(UTF8ToUTF16("www.google.com/"), string_vec[1]);
+ EXPECT_EQ(UTF8ToUTF16("frammy"), string_vec[2]);
+ EXPECT_EQ(UTF8ToUTF16("the"), string_vec[3]);
+ EXPECT_EQ(UTF8ToUTF16("brammy"), string_vec[4]);
+ size_t expected_starts_b[] = {0, 7, 23, 31, 35};
+ EXPECT_TRUE(IntArraysEqual(expected_starts_b, arraysize(expected_starts_b),
+ actual_starts_b));
+
+ base::string16 string_c(base::ASCIIToUTF16(
+ " funky%20string-with=@strange sequences, intended(to exceed)"));
+ WordStarts actual_starts_c;
+ string_vec = String16VectorFromString16(string_c, false, &actual_starts_c);
+ ASSERT_EQ(8U, string_vec.size());
+ // Note that we stop collecting words and word starts at kMaxSignificantChars.
+ size_t expected_starts_c[] = {1, 7, 16, 22, 32, 43, 52, 55};
+ EXPECT_TRUE(IntArraysEqual(expected_starts_c, arraysize(expected_starts_c),
+ actual_starts_c));
+
+ // Test String16SetFromString16
+ base::string16 string_d(base::ASCIIToUTF16(
+ "http://web.google.com/search Google Web Search"));
+ WordStarts actual_starts_d;
+ String16Set string_set = String16SetFromString16(string_d, &actual_starts_d);
+ EXPECT_EQ(5U, string_set.size());
+ // See if we got the words we expected.
+ EXPECT_TRUE(string_set.find(UTF8ToUTF16("com")) != string_set.end());
+ EXPECT_TRUE(string_set.find(UTF8ToUTF16("google")) != string_set.end());
+ EXPECT_TRUE(string_set.find(UTF8ToUTF16("http")) != string_set.end());
+ EXPECT_TRUE(string_set.find(UTF8ToUTF16("search")) != string_set.end());
+ EXPECT_TRUE(string_set.find(UTF8ToUTF16("web")) != string_set.end());
+ size_t expected_starts_d[] = {0, 7, 11, 18, 22, 29, 36, 40};
+ EXPECT_TRUE(IntArraysEqual(expected_starts_d, arraysize(expected_starts_d),
+ actual_starts_d));
+
+ // Test SortAndDeoverlapMatches
+ TermMatches matches_e;
+ matches_e.push_back(TermMatch(1, 13, 10));
+ matches_e.push_back(TermMatch(2, 23, 10));
+ matches_e.push_back(TermMatch(3, 3, 10));
+ matches_e.push_back(TermMatch(4, 40, 5));
+ TermMatches matches_f = SortAndDeoverlapMatches(matches_e);
+ // Nothing should have been eliminated.
+ EXPECT_EQ(matches_e.size(), matches_f.size());
+ // The order should now be 3, 1, 2, 4.
+ EXPECT_EQ(3, matches_f[0].term_num);
+ EXPECT_EQ(1, matches_f[1].term_num);
+ EXPECT_EQ(2, matches_f[2].term_num);
+ EXPECT_EQ(4, matches_f[3].term_num);
+ matches_e.push_back(TermMatch(5, 18, 10));
+ matches_e.push_back(TermMatch(6, 38, 5));
+ matches_f = SortAndDeoverlapMatches(matches_e);
+ // Two matches should have been eliminated.
+ EXPECT_EQ(matches_e.size() - 2, matches_f.size());
+ // The order should now be 3, 1, 2, 6.
+ EXPECT_EQ(3, matches_f[0].term_num);
+ EXPECT_EQ(1, matches_f[1].term_num);
+ EXPECT_EQ(2, matches_f[2].term_num);
+ EXPECT_EQ(6, matches_f[3].term_num);
+
+ // Test MatchTermInString
+ TermMatches matches_g = MatchTermInString(
+ UTF8ToUTF16("x"), UTF8ToUTF16("axbxcxdxex fxgx/hxixjx.kx"), 123);
+ const size_t expected_offsets[] = { 1, 3, 5, 7, 9, 12, 14, 17, 19, 21, 24 };
+ ASSERT_EQ(arraysize(expected_offsets), matches_g.size());
+ for (size_t i = 0; i < arraysize(expected_offsets); ++i)
+ EXPECT_EQ(expected_offsets[i], matches_g[i].offset);
+}
+
+TEST_F(InMemoryURLIndexTypesTest, OffsetsAndTermMatches) {
+ // Test OffsetsFromTermMatches
+ TermMatches matches_a;
+ matches_a.push_back(TermMatch(1, 1, 2));
+ matches_a.push_back(TermMatch(2, 4, 3));
+ matches_a.push_back(TermMatch(3, 9, 1));
+ matches_a.push_back(TermMatch(3, 10, 1));
+ matches_a.push_back(TermMatch(4, 14, 5));
+ std::vector<size_t> offsets = OffsetsFromTermMatches(matches_a);
+ const size_t expected_offsets_a[] = {1, 3, 4, 7, 9, 10, 10, 11, 14, 19};
+ ASSERT_EQ(offsets.size(), arraysize(expected_offsets_a));
+ for (size_t i = 0; i < offsets.size(); ++i)
+ EXPECT_EQ(expected_offsets_a[i], offsets[i]);
+
+ // Test ReplaceOffsetsInTermMatches
+ offsets[4] = base::string16::npos; // offset of third term
+ TermMatches matches_b = ReplaceOffsetsInTermMatches(matches_a, offsets);
+ const size_t expected_offsets_b[] = {1, 4, 10, 14};
+ ASSERT_EQ(arraysize(expected_offsets_b), matches_b.size());
+ for (size_t i = 0; i < matches_b.size(); ++i)
+ EXPECT_EQ(expected_offsets_b[i], matches_b[i].offset);
+}
+
+} // namespace history
diff --git a/chrome/browser/history/in_memory_url_index_unittest.cc b/chrome/browser/autocomplete/in_memory_url_index_unittest.cc
index 345382d..adb068d 100644
--- a/chrome/browser/history/in_memory_url_index_unittest.cc
+++ b/chrome/browser/autocomplete/in_memory_url_index_unittest.cc
@@ -14,19 +14,19 @@
#include "base/strings/string16.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
+#include "chrome/browser/autocomplete/in_memory_url_index.h"
+#include "chrome/browser/autocomplete/in_memory_url_index_types.h"
#include "chrome/browser/autocomplete/scored_history_match_builder_impl.h"
+#include "chrome/browser/autocomplete/url_index_private_data.h"
#include "chrome/browser/bookmarks/bookmark_model_factory.h"
#include "chrome/browser/history/history_backend.h"
#include "chrome/browser/history/history_service.h"
#include "chrome/browser/history/history_service_factory.h"
-#include "chrome/browser/history/in_memory_url_index.h"
-#include "chrome/browser/history/url_index_private_data.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/test/base/history_index_restore_observer.h"
#include "chrome/test/base/testing_profile.h"
#include "components/bookmarks/test/bookmark_test_helpers.h"
#include "components/history/core/browser/history_database.h"
-#include "components/history/core/browser/in_memory_url_index_types.h"
#include "content/public/test/test_browser_thread_bundle.h"
#include "sql/transaction.h"
#include "testing/gtest/include/gtest/gtest.h"
diff --git a/chrome/browser/autocomplete/scored_history_match.cc b/chrome/browser/autocomplete/scored_history_match.cc
new file mode 100644
index 0000000..93c1503
--- /dev/null
+++ b/chrome/browser/autocomplete/scored_history_match.cc
@@ -0,0 +1,72 @@
+// Copyright (c) 2012 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/autocomplete/scored_history_match.h"
+
+namespace history {
+
+// static
+const size_t ScoredHistoryMatch::kMaxVisitsToScore = 10;
+
+ScoredHistoryMatch::ScoredHistoryMatch() : raw_score(0), can_inline(false) {
+}
+
+ScoredHistoryMatch::ScoredHistoryMatch(const URLRow& url_info,
+ size_t input_location,
+ bool match_in_scheme,
+ bool innermost_match,
+ int raw_score,
+ const TermMatches& url_matches,
+ const TermMatches& title_matches,
+ bool can_inline)
+ : HistoryMatch(url_info, input_location, match_in_scheme, innermost_match),
+ raw_score(raw_score),
+ url_matches(url_matches),
+ title_matches(title_matches),
+ can_inline(can_inline) {
+}
+
+ScoredHistoryMatch::~ScoredHistoryMatch() {
+}
+
+// Comparison function for sorting ScoredMatches by their scores with
+// intelligent tie-breaking.
+bool ScoredHistoryMatch::MatchScoreGreater(const ScoredHistoryMatch& m1,
+ const ScoredHistoryMatch& m2) {
+ if (m1.raw_score != m2.raw_score)
+ return m1.raw_score > m2.raw_score;
+
+ // This tie-breaking logic is inspired by / largely copied from the
+ // ordering logic in history_url_provider.cc CompareHistoryMatch().
+
+ // A URL that has been typed at all is better than one that has never been
+ // typed. (Note "!"s on each side.)
+ if (!m1.url_info.typed_count() != !m2.url_info.typed_count())
+ return m1.url_info.typed_count() > m2.url_info.typed_count();
+
+ // Innermost matches (matches after any scheme or "www.") are better than
+ // non-innermost matches.
+ if (m1.innermost_match != m2.innermost_match)
+ return m1.innermost_match;
+
+ // URLs that have been typed more often are better.
+ if (m1.url_info.typed_count() != m2.url_info.typed_count())
+ return m1.url_info.typed_count() > m2.url_info.typed_count();
+
+ // For URLs that have each been typed once, a host (alone) is better
+ // than a page inside.
+ if (m1.url_info.typed_count() == 1) {
+ if (m1.IsHostOnly() != m2.IsHostOnly())
+ return m1.IsHostOnly();
+ }
+
+ // URLs that have been visited more often are better.
+ if (m1.url_info.visit_count() != m2.url_info.visit_count())
+ return m1.url_info.visit_count() > m2.url_info.visit_count();
+
+ // URLs that have been visited more recently are better.
+ return m1.url_info.last_visit() > m2.url_info.last_visit();
+}
+
+} // namespace history
diff --git a/chrome/browser/autocomplete/scored_history_match.h b/chrome/browser/autocomplete/scored_history_match.h
new file mode 100644
index 0000000..82e078f
--- /dev/null
+++ b/chrome/browser/autocomplete/scored_history_match.h
@@ -0,0 +1,111 @@
+// Copyright (c) 2012 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_AUTOCOMPLETE_SCORED_HISTORY_MATCH_H_
+#define CHROME_BROWSER_AUTOCOMPLETE_SCORED_HISTORY_MATCH_H_
+
+#include <string>
+#include <vector>
+
+#include "base/strings/string16.h"
+#include "base/time/time.h"
+#include "chrome/browser/autocomplete/in_memory_url_index_types.h"
+#include "components/history/core/browser/history_match.h"
+#include "components/history/core/browser/history_types.h"
+
+namespace history {
+
+// An HistoryMatch that has a score as well as metrics defining where in the
+// history item's URL and/or page title matches have occurred.
+struct ScoredHistoryMatch : public HistoryMatch {
+ // The Builder inner class allows the embedder to control how matches are
+ // scored (we cannot use a base::Callback<> as base::Bind() is limited to 6
+ // parameters).
+ // TODO(sdefresne): remove this since ScoredHistoryMatch can now depends on
+ // chrome/browser/autocomplete and components/bookmarks
+ // http://crbug.com/462645
+ class Builder {
+ public:
+ Builder() {}
+ virtual ~Builder() {}
+
+ // Creates a new match with a raw score calculated for the history item
+ // given in |row| with recent visits as indicated in |visits|. First
+ // determines if the row qualifies by seeing if all of the terms in
+ // |terms_vector| occur in |row|. If so, calculates a raw score. This raw
+ // score is in part determined by whether the matches occur at word
+ // boundaries, the locations of which are stored in |word_starts|. For some
+ // terms, it's appropriate to look for the word boundary within the term.
+ // For instance, the term ".net" should look for a word boundary at the "n".
+ // These offsets (".net" should have an offset of 1) come from
+ // |terms_to_word_starts_offsets|. |history_client| is used to determine
+ // if the match's URL is referenced by any bookmarks, which can also affect
+ // the raw score. The raw score allows the matches to be ordered and can be
+ // used to influence the final score calculated by the client of this index.
+ // If the row does not qualify the raw score will be 0. |languages| is used
+ // to help parse/format the URL before looking for the terms.
+ virtual ScoredHistoryMatch Build(
+ const URLRow& row,
+ const VisitInfoVector& visits,
+ const std::string& languages,
+ const base::string16& lower_string,
+ const String16Vector& terms_vector,
+ const WordStarts& terms_to_word_starts_offsets,
+ const RowWordStarts& word_starts,
+ const base::Time now) const = 0;
+ };
+
+ // Required for STL, we don't use this directly.
+ ScoredHistoryMatch();
+
+ // Initialize the ScoredHistoryMatch, passing |url_info|, |input_location|,
+ // |match_in_scheme| and |innermost_match| to HistoryMatch constructor, and
+ // using |raw_score|, |url_matches|, |title_matches| and |can_inline| to
+ // initialize the corresponding properties of this class.
+ ScoredHistoryMatch(const URLRow& url_info,
+ size_t input_location,
+ bool match_in_scheme,
+ bool innermost_match,
+ int raw_score,
+ const TermMatches& url_matches,
+ const TermMatches& title_matches,
+ bool can_inline);
+
+ ~ScoredHistoryMatch();
+
+ // Compares two matches by score. Functor supporting URLIndexPrivateData's
+ // HistoryItemsForTerms function. Looks at particular fields within
+ // with url_info to make tie-breaking a bit smarter.
+ static bool MatchScoreGreater(const ScoredHistoryMatch& m1,
+ const ScoredHistoryMatch& m2);
+
+ // The maximum number of recent visits to examine in GetFrequency().
+ // Public so url_index_private_data.cc knows how many visits it is
+ // expected to deliver (at minimum) to this class.
+ static const size_t kMaxVisitsToScore;
+
+ // An interim score taking into consideration location and completeness
+ // of the match.
+ int raw_score;
+
+ // Both these TermMatches contain the set of matches that are considered
+ // important. At this time, that means they exclude mid-word matches
+ // except in the hostname of the URL. (Technically, during early
+ // construction of ScoredHistoryMatch, they may contain all matches, but
+ // unimportant matches are eliminated by GetTopicalityScore(), called
+ // during construction.)
+
+ // Term matches within the URL.
+ TermMatches url_matches;
+ // Term matches within the page title.
+ TermMatches title_matches;
+
+ // True if this is a candidate for in-line autocompletion.
+ bool can_inline;
+};
+typedef std::vector<ScoredHistoryMatch> ScoredHistoryMatches;
+
+} // namespace history
+
+#endif // CHROME_BROWSER_AUTOCOMPLETE_SCORED_HISTORY_MATCH_H_
diff --git a/chrome/browser/autocomplete/scored_history_match_builder_impl.h b/chrome/browser/autocomplete/scored_history_match_builder_impl.h
index 578d243..83cf269 100644
--- a/chrome/browser/autocomplete/scored_history_match_builder_impl.h
+++ b/chrome/browser/autocomplete/scored_history_match_builder_impl.h
@@ -7,9 +7,9 @@
#include "base/callback.h"
#include "base/strings/string16.h"
+#include "chrome/browser/autocomplete/in_memory_url_index_types.h"
+#include "chrome/browser/autocomplete/scored_history_match.h"
#include "components/history/core/browser/history_types.h"
-#include "components/history/core/browser/in_memory_url_index_types.h"
-#include "components/history/core/browser/scored_history_match.h"
#include "testing/gtest/include/gtest/gtest_prod.h"
class ScoredHistoryMatchBuilderImplTest;
diff --git a/chrome/browser/autocomplete/shortcuts_provider_unittest.cc b/chrome/browser/autocomplete/shortcuts_provider_unittest.cc
index e503dd1..8acb8b4 100644
--- a/chrome/browser/autocomplete/shortcuts_provider_unittest.cc
+++ b/chrome/browser/autocomplete/shortcuts_provider_unittest.cc
@@ -18,10 +18,10 @@
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h"
+#include "chrome/browser/autocomplete/in_memory_url_index.h"
#include "chrome/browser/autocomplete/shortcuts_backend.h"
#include "chrome/browser/autocomplete/shortcuts_backend_factory.h"
#include "chrome/browser/history/history_service.h"
-#include "chrome/browser/history/in_memory_url_index.h"
#include "chrome/test/base/testing_profile.h"
#include "components/history/core/browser/url_database.h"
#include "components/metrics/proto/omnibox_event.pb.h"
diff --git a/chrome/browser/history/url_index_private_data.cc b/chrome/browser/autocomplete/url_index_private_data.cc
index 88ef8e5..1652830 100644
--- a/chrome/browser/history/url_index_private_data.cc
+++ b/chrome/browser/autocomplete/url_index_private_data.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/history/url_index_private_data.h"
+#include "chrome/browser/autocomplete/url_index_private_data.h"
#include <functional>
#include <iterator>
@@ -19,8 +19,8 @@
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
+#include "chrome/browser/autocomplete/in_memory_url_index.h"
#include "chrome/browser/history/history_service.h"
-#include "chrome/browser/history/in_memory_url_index.h"
#include "components/bookmarks/browser/bookmark_utils.h"
#include "components/history/core/browser/history_database.h"
#include "components/history/core/browser/history_db_task.h"
diff --git a/chrome/browser/history/url_index_private_data.h b/chrome/browser/autocomplete/url_index_private_data.h
index bb9d675..acaea05 100644
--- a/chrome/browser/history/url_index_private_data.h
+++ b/chrome/browser/autocomplete/url_index_private_data.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef CHROME_BROWSER_HISTORY_URL_INDEX_PRIVATE_DATA_H_
-#define CHROME_BROWSER_HISTORY_URL_INDEX_PRIVATE_DATA_H_
+#ifndef CHROME_BROWSER_AUTOCOMPLETE_URL_INDEX_PRIVATE_DATA_H_
+#define CHROME_BROWSER_AUTOCOMPLETE_URL_INDEX_PRIVATE_DATA_H_
#include <set>
#include <string>
@@ -11,10 +11,10 @@
#include "base/files/file_path.h"
#include "base/gtest_prod_util.h"
#include "base/memory/ref_counted.h"
+#include "chrome/browser/autocomplete/in_memory_url_index_cache.pb.h"
+#include "chrome/browser/autocomplete/in_memory_url_index_types.h"
+#include "chrome/browser/autocomplete/scored_history_match.h"
#include "chrome/browser/history/history_service.h"
-#include "components/history/core/browser/in_memory_url_index_cache.pb.h"
-#include "components/history/core/browser/in_memory_url_index_types.h"
-#include "components/history/core/browser/scored_history_match.h"
class HistoryQuickProviderTest;
@@ -391,4 +391,4 @@ class URLIndexPrivateData
} // namespace history
-#endif // CHROME_BROWSER_HISTORY_URL_INDEX_PRIVATE_DATA_H_
+#endif // CHROME_BROWSER_AUTOCOMPLETE_URL_INDEX_PRIVATE_DATA_H_
diff --git a/chrome/browser/chromeos/BUILD.gn b/chrome/browser/chromeos/BUILD.gn
index 0436a7b..1448c08 100644
--- a/chrome/browser/chromeos/BUILD.gn
+++ b/chrome/browser/chromeos/BUILD.gn
@@ -61,7 +61,6 @@ source_set("chromeos") {
"//chromeos:cryptohome_proto",
"//chromeos:cryptohome_signkey_proto",
"//chromeos:power_manager_proto",
- "//components/history/core/browser:proto",
"//components/onc",
"//components/ownership",
"//components/pairing",
diff --git a/chrome/browser/extensions/BUILD.gn b/chrome/browser/extensions/BUILD.gn
index 061b8c1..3e1bc66 100644
--- a/chrome/browser/extensions/BUILD.gn
+++ b/chrome/browser/extensions/BUILD.gn
@@ -45,7 +45,6 @@ static_library("extensions") {
"//chrome/common/safe_browsing:proto",
"//chrome/installer/util",
"//components/copresence",
- "//components/history/core/browser:proto",
"//components/onc",
"//components/proximity_auth",
"//components/strings",
diff --git a/chrome/browser/history/DEPS b/chrome/browser/history/DEPS
index 41d25c1..26d717d 100644
--- a/chrome/browser/history/DEPS
+++ b/chrome/browser/history/DEPS
@@ -20,6 +20,7 @@ include_rules = [
#
# Do not add to the list of temporarily-allowed dependencies below,
# and please do not introduce more #includes of these files.
+ "!chrome/browser/autocomplete/in_memory_url_index.h",
"!chrome/browser/chrome_notification_types.h",
"!chrome/browser/prerender/prerender_contents.h",
"!chrome/browser/prerender/prerender_manager.h",
@@ -29,7 +30,6 @@ include_rules = [
"!chrome/browser/profiles/profile_manager.h",
"!chrome/browser/ui/browser.h",
"!chrome/browser/ui/browser_finder.h",
- "!components/bookmarks/browser/bookmark_utils.h",
"!components/dom_distiller/core/url_constants.h",
]
diff --git a/chrome/browser/history/history_service.cc b/chrome/browser/history/history_service.cc
index d57d8af..8708738 100644
--- a/chrome/browser/history/history_service.cc
+++ b/chrome/browser/history/history_service.cc
@@ -28,9 +28,9 @@
#include "base/thread_task_runner_handle.h"
#include "base/threading/thread.h"
#include "base/time/time.h"
+#include "chrome/browser/autocomplete/in_memory_url_index.h"
#include "chrome/browser/history/history_backend.h"
#include "chrome/browser/history/in_memory_history_backend.h"
-#include "chrome/browser/history/in_memory_url_index.h"
#include "components/history/core/browser/download_row.h"
#include "components/history/core/browser/history_client.h"
#include "components/history/core/browser/history_database_params.h"
diff --git a/chrome/browser/ui/BUILD.gn b/chrome/browser/ui/BUILD.gn
index 3e39d0d..ca6c6f7 100644
--- a/chrome/browser/ui/BUILD.gn
+++ b/chrome/browser/ui/BUILD.gn
@@ -49,7 +49,6 @@ static_library("ui") {
"//components/auto_login_parser",
"//components/dom_distiller/webui",
"//components/feedback/proto",
- "//components/history/core/browser:proto",
"//components/invalidation",
"//components/onc",
"//components/password_manager/core/browser",
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index be4f0d3..2e130f3 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -1193,6 +1193,12 @@
'browser/autocomplete/history_quick_provider.h',
'browser/autocomplete/history_url_provider.cc',
'browser/autocomplete/history_url_provider.h',
+ 'browser/autocomplete/in_memory_url_index.cc',
+ 'browser/autocomplete/in_memory_url_index.h',
+ 'browser/autocomplete/in_memory_url_index_types.cc',
+ 'browser/autocomplete/in_memory_url_index_types.h',
+ 'browser/autocomplete/scored_history_match.cc',
+ 'browser/autocomplete/scored_history_match.h',
'browser/autocomplete/scored_history_match_builder_impl.cc',
'browser/autocomplete/scored_history_match_builder_impl.h',
'browser/autocomplete/shortcuts_backend.cc',
@@ -1203,6 +1209,8 @@
'browser/autocomplete/shortcuts_database.h',
'browser/autocomplete/shortcuts_provider.cc',
'browser/autocomplete/shortcuts_provider.h',
+ 'browser/autocomplete/url_index_private_data.cc',
+ 'browser/autocomplete/url_index_private_data.h',
'browser/autocomplete/zero_suggest_provider.cc',
'browser/autocomplete/zero_suggest_provider.h',
],
@@ -1569,16 +1577,12 @@
'browser/history/history_utils.h',
'browser/history/in_memory_history_backend.cc',
'browser/history/in_memory_history_backend.h',
- 'browser/history/in_memory_url_index.cc',
- 'browser/history/in_memory_url_index.h',
'browser/history/top_sites_factory.cc',
'browser/history/top_sites_factory.h',
'browser/history/top_sites_impl.cc',
'browser/history/top_sites_impl.h',
'browser/history/typed_url_syncable_service.cc',
'browser/history/typed_url_syncable_service.h',
- 'browser/history/url_index_private_data.cc',
- 'browser/history/url_index_private_data.h',
'browser/history/web_history_service_factory.cc',
'browser/history/web_history_service_factory.h',
],
@@ -2900,6 +2904,7 @@
'chrome_resources.gyp:theme_resources',
'common',
'common_net',
+ 'in_memory_url_index_cache_proto',
'probe_message_proto',
'../components/components.gyp:autofill_core_browser',
'../components/components.gyp:bookmarks_browser',
@@ -3561,6 +3566,19 @@
],
},
{
+ # Protobuf compiler / generator for the InMemoryURLIndex caching
+ # protocol buffer.
+ # GN version: //chrome/browser/autocomplete:in_memory_url_index_cache_proto
+ 'target_name': 'in_memory_url_index_cache_proto',
+ 'type': 'static_library',
+ 'sources': [ 'browser/autocomplete/in_memory_url_index_cache.proto', ],
+ 'variables': {
+ 'proto_in_dir': 'browser/autocomplete',
+ 'proto_out_dir': 'chrome/browser/autocomplete',
+ },
+ 'includes': [ '../build/protoc.gypi', ],
+ },
+ {
# Protobuf compiler / generator for the fraudulent certificate reporting
# protocol buffer.
# GN version: //chrome/browser/net:cert_logger_proto
diff --git a/chrome/chrome_browser_chromeos.gypi b/chrome/chrome_browser_chromeos.gypi
index 4b5c2ad..7bdaeff 100644
--- a/chrome/chrome_browser_chromeos.gypi
+++ b/chrome/chrome_browser_chromeos.gypi
@@ -1112,7 +1112,6 @@
'../chromeos/chromeos.gyp:power_manager_proto',
'../chromeos/ime/input_method.gyp:gencode',
'../components/components.gyp:cloud_policy_proto',
- '../components/components.gyp:history_core_browser_proto',
'../components/components.gyp:login',
'../components/components.gyp:onc_component',
'../components/components.gyp:ownership',
diff --git a/chrome/chrome_browser_extensions.gypi b/chrome/chrome_browser_extensions.gypi
index e8b7998..a100bd3 100644
--- a/chrome/chrome_browser_extensions.gypi
+++ b/chrome/chrome_browser_extensions.gypi
@@ -861,7 +861,6 @@
'installer_util',
'safe_browsing_proto',
'../components/components.gyp:copresence',
- '../components/components.gyp:history_core_browser_proto',
'../components/components.gyp:onc_component',
'../components/components.gyp:proximity_auth',
'../components/components.gyp:update_client',
diff --git a/chrome/chrome_browser_ui.gypi b/chrome/chrome_browser_ui.gypi
index 2adceb4..c3c5689 100644
--- a/chrome/chrome_browser_ui.gypi
+++ b/chrome/chrome_browser_ui.gypi
@@ -2689,7 +2689,6 @@
'../components/components.gyp:dom_distiller_core',
'../components/components.gyp:dom_distiller_webui',
'../components/components.gyp:feedback_proto',
- '../components/components.gyp:history_core_browser_proto',
'../components/components.gyp:invalidation',
'../components/components.gyp:onc_component',
'../components/components.gyp:password_manager_core_browser',
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index 0f7d859..4960e11 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -69,6 +69,7 @@
'browser/apps/speech_recognition_browsertest.cc',
'browser/apps/window_controls_browsertest.cc',
'browser/autocomplete/autocomplete_browsertest.cc',
+ 'browser/autocomplete/in_memory_url_index_types_unittest.cc',
'browser/autofill/autofill_browsertest.cc',
'browser/autofill/autofill_server_browsertest.cc',
'browser/autofill/content_autofill_driver_browsertest.cc',
diff --git a/chrome/chrome_tests_unit.gypi b/chrome/chrome_tests_unit.gypi
index e30e8ef..2e2ae40 100644
--- a/chrome/chrome_tests_unit.gypi
+++ b/chrome/chrome_tests_unit.gypi
@@ -28,6 +28,7 @@
'browser/autocomplete/builtin_provider_unittest.cc',
'browser/autocomplete/history_quick_provider_unittest.cc',
'browser/autocomplete/history_url_provider_unittest.cc',
+ 'browser/autocomplete/in_memory_url_index_unittest.cc',
'browser/autocomplete/scored_history_match_builder_impl_unittest.cc',
'browser/autocomplete/search_provider_unittest.cc',
'browser/autocomplete/shortcuts_backend_unittest.cc',
@@ -113,7 +114,6 @@
'browser/history/history_database_unittest.cc',
'browser/history/history_querying_unittest.cc',
'browser/history/history_unittest.cc',
- 'browser/history/in_memory_url_index_unittest.cc',
'browser/history/thumbnail_database_unittest.cc',
'browser/history/top_sites_impl_unittest.cc',
'browser/history/typed_url_syncable_service_unittest.cc',
diff --git a/chrome/test/base/history_index_restore_observer.h b/chrome/test/base/history_index_restore_observer.h
index 4d76aee..6990b21 100644
--- a/chrome/test/base/history_index_restore_observer.h
+++ b/chrome/test/base/history_index_restore_observer.h
@@ -8,7 +8,7 @@
#include "base/basictypes.h"
#include "base/callback.h"
#include "base/compiler_specific.h"
-#include "chrome/browser/history/in_memory_url_index.h"
+#include "chrome/browser/autocomplete/in_memory_url_index.h"
// HistoryIndexRestoreObserver is used when blocking until the InMemoryURLIndex
// finishes restoring. As soon as the InMemoryURLIndex finishes restoring the