OLD | NEW |
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/history_quick_provider.h" | 5 #include "components/omnibox/browser/history_quick_provider.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/debug/crash_logging.h" | 10 #include "base/debug/crash_logging.h" |
11 #include "base/i18n/break_iterator.h" | 11 #include "base/i18n/break_iterator.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/metrics/field_trial.h" | 13 #include "base/metrics/field_trial.h" |
14 #include "base/prefs/pref_service.h" | 14 #include "base/prefs/pref_service.h" |
15 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
16 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
18 #include "components/bookmarks/browser/bookmark_model.h" | 18 #include "components/bookmarks/browser/bookmark_model.h" |
| 19 #include "components/crash_keys/crash_keys.h" |
19 #include "components/history/core/browser/history_database.h" | 20 #include "components/history/core/browser/history_database.h" |
20 #include "components/history/core/browser/history_service.h" | 21 #include "components/history/core/browser/history_service.h" |
21 #include "components/metrics/proto/omnibox_input_type.pb.h" | 22 #include "components/metrics/proto/omnibox_input_type.pb.h" |
22 #include "components/omnibox/browser/autocomplete_match_type.h" | 23 #include "components/omnibox/browser/autocomplete_match_type.h" |
23 #include "components/omnibox/browser/autocomplete_provider_client.h" | 24 #include "components/omnibox/browser/autocomplete_provider_client.h" |
24 #include "components/omnibox/browser/autocomplete_result.h" | 25 #include "components/omnibox/browser/autocomplete_result.h" |
25 #include "components/omnibox/browser/history_url_provider.h" | 26 #include "components/omnibox/browser/history_url_provider.h" |
26 #include "components/omnibox/browser/in_memory_url_index.h" | 27 #include "components/omnibox/browser/in_memory_url_index.h" |
27 #include "components/omnibox/browser/in_memory_url_index_types.h" | 28 #include "components/omnibox/browser/in_memory_url_index_types.h" |
28 #include "components/omnibox/browser/omnibox_field_trial.h" | 29 #include "components/omnibox/browser/omnibox_field_trial.h" |
29 #include "components/search_engines/template_url.h" | 30 #include "components/search_engines/template_url.h" |
30 #include "components/search_engines/template_url_service.h" | 31 #include "components/search_engines/template_url_service.h" |
31 #include "components/url_formatter/url_formatter.h" | 32 #include "components/url_formatter/url_formatter.h" |
32 #include "net/base/escape.h" | 33 #include "net/base/escape.h" |
33 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 34 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
34 #include "url/third_party/mozilla/url_parse.h" | 35 #include "url/third_party/mozilla/url_parse.h" |
35 #include "url/url_util.h" | 36 #include "url/url_util.h" |
36 | 37 |
37 namespace { | |
38 | |
39 // Used to help investigate bug 464926. NOTE: This value is defined multiple | |
40 // places in the codebase due to layering issues. DO NOT change the value here | |
41 // without changing it in all other places that it is defined in the codebase | |
42 // (search for |kBug464926CrashKey|). | |
43 const char kBug464926CrashKey[] = "bug-464926-info"; | |
44 | |
45 } // namespace | |
46 | |
47 bool HistoryQuickProvider::disabled_ = false; | 38 bool HistoryQuickProvider::disabled_ = false; |
48 | 39 |
49 HistoryQuickProvider::HistoryQuickProvider(AutocompleteProviderClient* client) | 40 HistoryQuickProvider::HistoryQuickProvider(AutocompleteProviderClient* client) |
50 : HistoryProvider(AutocompleteProvider::TYPE_HISTORY_QUICK, client), | 41 : HistoryProvider(AutocompleteProvider::TYPE_HISTORY_QUICK, client), |
51 languages_(client->GetAcceptLanguages()), | 42 languages_(client->GetAcceptLanguages()), |
52 in_memory_url_index_(client->GetInMemoryURLIndex()) { | 43 in_memory_url_index_(client->GetInMemoryURLIndex()) { |
53 } | 44 } |
54 | 45 |
55 void HistoryQuickProvider::Start(const AutocompleteInput& input, | 46 void HistoryQuickProvider::Start(const AutocompleteInput& input, |
56 bool minimal_changes) { | 47 bool minimal_changes) { |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 info.url(), languages_, format_types, net::UnescapeRule::SPACES, nullptr, | 228 info.url(), languages_, format_types, net::UnescapeRule::SPACES, nullptr, |
238 nullptr, &adjustments); | 229 nullptr, &adjustments); |
239 base::OffsetAdjuster::AdjustOffsets(adjustments, &offsets); | 230 base::OffsetAdjuster::AdjustOffsets(adjustments, &offsets); |
240 TermMatches new_matches = | 231 TermMatches new_matches = |
241 ReplaceOffsetsInTermMatches(history_match.url_matches, offsets); | 232 ReplaceOffsetsInTermMatches(history_match.url_matches, offsets); |
242 match.contents_class = | 233 match.contents_class = |
243 SpansFromTermMatch(new_matches, match.contents.length(), true); | 234 SpansFromTermMatch(new_matches, match.contents.length(), true); |
244 | 235 |
245 // Set |inline_autocompletion| and |allowed_to_be_default_match| if possible. | 236 // Set |inline_autocompletion| and |allowed_to_be_default_match| if possible. |
246 if (history_match.can_inline) { | 237 if (history_match.can_inline) { |
| 238 // TODO(mpearson): remove this and all dependency of //components/omnibox |
| 239 // on //components/crash_keys once http://crbug.com/464926 is fixed (i.e. |
| 240 // remove #include, exception in components/omnibox/DEPS, and dependency |
| 241 // in components/omnibox.gypi and components/omnibox/browser/BUILD.gn). |
247 base::debug::ScopedCrashKey crash_info( | 242 base::debug::ScopedCrashKey crash_info( |
248 kBug464926CrashKey, | 243 crash_keys::kBug464926CrashKey, |
249 info.url().spec().substr(0, 30) + " " + | 244 info.url().spec().substr(0, 30) + " " + |
250 base::UTF16ToUTF8(autocomplete_input_.text()).substr(0, 20) + " " + | 245 base::UTF16ToUTF8(autocomplete_input_.text()).substr(0, 20) + " " + |
251 base::SizeTToString(history_match.url_matches.size()) + " " + | 246 base::SizeTToString(history_match.url_matches.size()) + " " + |
252 base::SizeTToString(offsets.size())); | 247 base::SizeTToString(offsets.size())); |
253 CHECK(!new_matches.empty()); | 248 CHECK(!new_matches.empty()); |
254 size_t inline_autocomplete_offset = new_matches[0].offset + | 249 size_t inline_autocomplete_offset = new_matches[0].offset + |
255 new_matches[0].length; | 250 new_matches[0].length; |
256 // |inline_autocomplete_offset| may be beyond the end of the | 251 // |inline_autocomplete_offset| may be beyond the end of the |
257 // |fill_into_edit| if the user has typed an URL with a scheme and the | 252 // |fill_into_edit| if the user has typed an URL with a scheme and the |
258 // last character typed is a slash. That slash is removed by the | 253 // last character typed is a slash. That slash is removed by the |
(...skipping 14 matching lines...) Expand all Loading... |
273 match.description = info.title(); | 268 match.description = info.title(); |
274 match.description_class = SpansFromTermMatch( | 269 match.description_class = SpansFromTermMatch( |
275 history_match.title_matches, match.description.length(), false); | 270 history_match.title_matches, match.description.length(), false); |
276 | 271 |
277 match.RecordAdditionalInfo("typed count", info.typed_count()); | 272 match.RecordAdditionalInfo("typed count", info.typed_count()); |
278 match.RecordAdditionalInfo("visit count", info.visit_count()); | 273 match.RecordAdditionalInfo("visit count", info.visit_count()); |
279 match.RecordAdditionalInfo("last visit", info.last_visit()); | 274 match.RecordAdditionalInfo("last visit", info.last_visit()); |
280 | 275 |
281 return match; | 276 return match; |
282 } | 277 } |
OLD | NEW |