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

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

Issue 903493002: Componentize ScoredHistoryMatch (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 10 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/command_line.h" 10 #include "base/command_line.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/metrics/histogram.h" 14 #include "base/metrics/histogram.h"
15 #include "base/prefs/pref_service.h" 15 #include "base/prefs/pref_service.h"
16 #include "base/strings/string_number_conversions.h" 16 #include "base/strings/string_number_conversions.h"
17 #include "base/strings/string_util.h" 17 #include "base/strings/string_util.h"
18 #include "base/strings/utf_string_conversions.h" 18 #include "base/strings/utf_string_conversions.h"
19 #include "base/time/time.h" 19 #include "base/time/time.h"
20 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h" 20 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h"
21 #include "chrome/browser/autocomplete/history_url_provider.h" 21 #include "chrome/browser/autocomplete/history_url_provider.h"
22 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
23 #include "chrome/browser/history/chrome_scored_history_match_client.h"
22 #include "chrome/browser/history/history_service.h" 24 #include "chrome/browser/history/history_service.h"
23 #include "chrome/browser/history/history_service_factory.h" 25 #include "chrome/browser/history/history_service_factory.h"
24 #include "chrome/browser/history/in_memory_url_index.h" 26 #include "chrome/browser/history/in_memory_url_index.h"
25 #include "chrome/browser/history/scored_history_match.h"
26 #include "chrome/browser/profiles/profile.h" 27 #include "chrome/browser/profiles/profile.h"
27 #include "chrome/browser/search_engines/template_url_service_factory.h" 28 #include "chrome/browser/search_engines/template_url_service_factory.h"
28 #include "chrome/common/chrome_switches.h" 29 #include "chrome/common/chrome_switches.h"
29 #include "chrome/common/pref_names.h" 30 #include "chrome/common/pref_names.h"
30 #include "chrome/common/url_constants.h" 31 #include "chrome/common/url_constants.h"
32 #include "components/bookmarks/browser/bookmark_model.h"
31 #include "components/history/core/browser/history_database.h" 33 #include "components/history/core/browser/history_database.h"
32 #include "components/history/core/browser/in_memory_url_index_types.h" 34 #include "components/history/core/browser/in_memory_url_index_types.h"
35 #include "components/history/core/browser/scored_history_match.h"
33 #include "components/metrics/proto/omnibox_input_type.pb.h" 36 #include "components/metrics/proto/omnibox_input_type.pb.h"
34 #include "components/omnibox/autocomplete_match_type.h" 37 #include "components/omnibox/autocomplete_match_type.h"
35 #include "components/omnibox/autocomplete_result.h" 38 #include "components/omnibox/autocomplete_result.h"
36 #include "components/omnibox/omnibox_field_trial.h" 39 #include "components/omnibox/omnibox_field_trial.h"
37 #include "components/search_engines/template_url.h" 40 #include "components/search_engines/template_url.h"
38 #include "components/search_engines/template_url_service.h" 41 #include "components/search_engines/template_url_service.h"
39 #include "content/public/browser/notification_source.h" 42 #include "content/public/browser/notification_source.h"
40 #include "content/public/browser/notification_types.h" 43 #include "content/public/browser/notification_types.h"
41 #include "net/base/escape.h" 44 #include "net/base/escape.h"
42 #include "net/base/net_util.h" 45 #include "net/base/net_util.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 } 89 }
87 } 90 }
88 91
89 HistoryQuickProvider::~HistoryQuickProvider() {} 92 HistoryQuickProvider::~HistoryQuickProvider() {}
90 93
91 void HistoryQuickProvider::DoAutocomplete() { 94 void HistoryQuickProvider::DoAutocomplete() {
92 // Get the matching URLs from the DB. 95 // Get the matching URLs from the DB.
93 ScoredHistoryMatches matches = GetIndex()->HistoryItemsForTerms( 96 ScoredHistoryMatches matches = GetIndex()->HistoryItemsForTerms(
94 autocomplete_input_.text(), 97 autocomplete_input_.text(),
95 autocomplete_input_.cursor_position(), 98 autocomplete_input_.cursor_position(),
96 AutocompleteProvider::kMaxMatches); 99 AutocompleteProvider::kMaxMatches,
100 GetScoredHistoryMatchClient());
97 if (matches.empty()) 101 if (matches.empty())
98 return; 102 return;
99 103
100 // Figure out if HistoryURL provider has a URL-what-you-typed match 104 // Figure out if HistoryURL provider has a URL-what-you-typed match
101 // that ought to go first and what its score will be. 105 // that ought to go first and what its score will be.
102 bool will_have_url_what_you_typed_match_first = false; 106 bool will_have_url_what_you_typed_match_first = false;
103 int url_what_you_typed_match_score = -1; // undefined 107 int url_what_you_typed_match_score = -1; // undefined
104 // These are necessary (but not sufficient) conditions for the omnibox 108 // These are necessary (but not sufficient) conditions for the omnibox
105 // input to be a URL-what-you-typed match. The username test checks that 109 // input to be a URL-what-you-typed match. The username test checks that
106 // either the username does not exist (a regular URL such as http://site/) 110 // either the username does not exist (a regular URL such as http://site/)
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 if (index_for_testing_.get()) 296 if (index_for_testing_.get())
293 return index_for_testing_.get(); 297 return index_for_testing_.get();
294 298
295 HistoryService* const history_service = HistoryServiceFactory::GetForProfile( 299 HistoryService* const history_service = HistoryServiceFactory::GetForProfile(
296 profile_, ServiceAccessType::EXPLICIT_ACCESS); 300 profile_, ServiceAccessType::EXPLICIT_ACCESS);
297 if (!history_service) 301 if (!history_service)
298 return NULL; 302 return NULL;
299 303
300 return history_service->InMemoryIndex(); 304 return history_service->InMemoryIndex();
301 } 305 }
306
307 const history::ScoredHistoryMatchClient*
308 HistoryQuickProvider::GetScoredHistoryMatchClient() {
309 if (!scored_history_match_client_) {
310 scored_history_match_client_.reset(new ChromeScoredHistoryMatchClient(
311 BookmarkModelFactory::GetForProfile(profile_)));
312 }
313 return scored_history_match_client_.get();
314 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/history_quick_provider.h ('k') | chrome/browser/autocomplete/history_url_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698