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

Side by Side Diff: chrome/browser/autocomplete/history_quick_provider.cc

Issue 1185723002: Prepare HistoryProvider for componentization (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Response to review Created 5 years, 6 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
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/autocomplete/history_quick_provider.h" 5 #include "chrome/browser/autocomplete/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 "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" 18 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h"
19 #include "chrome/browser/autocomplete/history_url_provider.h" 19 #include "chrome/browser/autocomplete/history_url_provider.h"
20 #include "chrome/browser/autocomplete/in_memory_url_index.h" 20 #include "chrome/browser/autocomplete/in_memory_url_index.h"
21 #include "chrome/browser/bookmarks/bookmark_model_factory.h" 21 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
22 #include "chrome/browser/history/history_service_factory.h"
23 #include "chrome/browser/profiles/profile.h" 22 #include "chrome/browser/profiles/profile.h"
24 #include "chrome/browser/search_engines/template_url_service_factory.h" 23 #include "chrome/browser/search_engines/template_url_service_factory.h"
25 #include "chrome/common/chrome_switches.h" 24 #include "chrome/common/chrome_switches.h"
26 #include "chrome/common/crash_keys.h" 25 #include "chrome/common/crash_keys.h"
27 #include "chrome/common/pref_names.h" 26 #include "chrome/common/pref_names.h"
28 #include "chrome/common/url_constants.h" 27 #include "chrome/common/url_constants.h"
29 #include "components/bookmarks/browser/bookmark_model.h" 28 #include "components/bookmarks/browser/bookmark_model.h"
30 #include "components/history/core/browser/history_database.h" 29 #include "components/history/core/browser/history_database.h"
31 #include "components/history/core/browser/history_service.h" 30 #include "components/history/core/browser/history_service.h"
32 #include "components/metrics/proto/omnibox_input_type.pb.h" 31 #include "components/metrics/proto/omnibox_input_type.pb.h"
33 #include "components/omnibox/autocomplete_match_type.h" 32 #include "components/omnibox/autocomplete_match_type.h"
34 #include "components/omnibox/autocomplete_result.h" 33 #include "components/omnibox/autocomplete_result.h"
35 #include "components/omnibox/in_memory_url_index_types.h" 34 #include "components/omnibox/in_memory_url_index_types.h"
36 #include "components/omnibox/omnibox_field_trial.h" 35 #include "components/omnibox/omnibox_field_trial.h"
37 #include "components/search_engines/template_url.h" 36 #include "components/search_engines/template_url.h"
38 #include "components/search_engines/template_url_service.h" 37 #include "components/search_engines/template_url_service.h"
39 #include "content/public/browser/notification_source.h" 38 #include "content/public/browser/notification_source.h"
40 #include "content/public/browser/notification_types.h" 39 #include "content/public/browser/notification_types.h"
41 #include "net/base/escape.h" 40 #include "net/base/escape.h"
42 #include "net/base/net_util.h" 41 #include "net/base/net_util.h"
43 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" 42 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
44 #include "url/third_party/mozilla/url_parse.h" 43 #include "url/third_party/mozilla/url_parse.h"
45 #include "url/url_util.h" 44 #include "url/url_util.h"
46 45
47 bool HistoryQuickProvider::disabled_ = false; 46 bool HistoryQuickProvider::disabled_ = false;
48 47
49 HistoryQuickProvider::HistoryQuickProvider( 48 HistoryQuickProvider::HistoryQuickProvider(
49 AutocompleteProviderClient* client,
50 Profile* profile, 50 Profile* profile,
51 InMemoryURLIndex* in_memory_url_index) 51 InMemoryURLIndex* in_memory_url_index)
52 : HistoryProvider(profile, AutocompleteProvider::TYPE_HISTORY_QUICK), 52 : HistoryProvider(AutocompleteProvider::TYPE_HISTORY_QUICK, client),
53 profile_(profile),
53 languages_(profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)), 54 languages_(profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)),
54 in_memory_url_index_(in_memory_url_index) { 55 in_memory_url_index_(in_memory_url_index) {
55 } 56 }
56 57
57 void HistoryQuickProvider::Start(const AutocompleteInput& input, 58 void HistoryQuickProvider::Start(const AutocompleteInput& input,
58 bool minimal_changes, 59 bool minimal_changes,
59 bool called_due_to_focus) { 60 bool called_due_to_focus) {
60 matches_.clear(); 61 matches_.clear();
61 if (disabled_ || called_due_to_focus) 62 if (disabled_ || called_due_to_focus)
62 return; 63 return;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 // a password or a port. Together these exclude pure username@site 99 // a password or a port. Together these exclude pure username@site
99 // inputs because these are likely to be an e-mail address. HistoryURL 100 // inputs because these are likely to be an e-mail address. HistoryURL
100 // provider won't promote the URL-what-you-typed match to first 101 // provider won't promote the URL-what-you-typed match to first
101 // for these inputs. 102 // for these inputs.
102 const bool can_have_url_what_you_typed_match_first = 103 const bool can_have_url_what_you_typed_match_first =
103 (autocomplete_input_.type() != metrics::OmniboxInputType::QUERY) && 104 (autocomplete_input_.type() != metrics::OmniboxInputType::QUERY) &&
104 (!autocomplete_input_.parts().username.is_nonempty() || 105 (!autocomplete_input_.parts().username.is_nonempty() ||
105 autocomplete_input_.parts().password.is_nonempty() || 106 autocomplete_input_.parts().password.is_nonempty() ||
106 autocomplete_input_.parts().path.is_nonempty()); 107 autocomplete_input_.parts().path.is_nonempty());
107 if (can_have_url_what_you_typed_match_first) { 108 if (can_have_url_what_you_typed_match_first) {
108 history::HistoryService* const history_service = 109 history::HistoryService* const history_service = client()->HistoryService();
109 HistoryServiceFactory::GetForProfile(
110 profile_, ServiceAccessType::EXPLICIT_ACCESS);
111 // We expect HistoryService to be available. In case it's not, 110 // We expect HistoryService to be available. In case it's not,
112 // (e.g., due to Profile corruption) we let HistoryQuick provider 111 // (e.g., due to Profile corruption) we let HistoryQuick provider
113 // completions (which may be available because it's a different 112 // completions (which may be available because it's a different
114 // data structure) compete with the URL-what-you-typed match as 113 // data structure) compete with the URL-what-you-typed match as
115 // normal. 114 // normal.
116 if (history_service) { 115 if (history_service) {
117 history::URLDatabase* url_db = history_service->InMemoryDatabase(); 116 history::URLDatabase* url_db = history_service->InMemoryDatabase();
118 // url_db can be NULL if it hasn't finished initializing (or 117 // url_db can be NULL if it hasn't finished initializing (or
119 // failed to to initialize). In this case, we let HistoryQuick 118 // failed to to initialize). In this case, we let HistoryQuick
120 // provider completions compete with the URL-what-you-typed 119 // provider completions compete with the URL-what-you-typed
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 match.description = info.title(); 275 match.description = info.title();
277 match.description_class = SpansFromTermMatch( 276 match.description_class = SpansFromTermMatch(
278 history_match.title_matches, match.description.length(), false); 277 history_match.title_matches, match.description.length(), false);
279 278
280 match.RecordAdditionalInfo("typed count", info.typed_count()); 279 match.RecordAdditionalInfo("typed count", info.typed_count());
281 match.RecordAdditionalInfo("visit count", info.visit_count()); 280 match.RecordAdditionalInfo("visit count", info.visit_count());
282 match.RecordAdditionalInfo("last visit", info.last_visit()); 281 match.RecordAdditionalInfo("last visit", info.last_visit());
283 282
284 return match; 283 return match;
285 } 284 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/history_quick_provider.h ('k') | chrome/browser/autocomplete/history_quick_provider_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698